In a DVC pipeline, after fixing a bug in `src/textnorm.py`, a helper the featurize script imports, `dvc repro` says featurize didn't change. Why, and what do you fix?
answer
- only declared inputs are hashed
- deps lists the script, not its imports
- run cache keys on declared inputs too
- check frozen and dvc status
- add the dep, then force once
basics
~10 sDVC hashes only the paths listed in a stage's deps and never follows the script's imports, so with textnorm.py undeclared nothing featurize depends on changed. Add it, or the src directory, to deps.
solid answer
~50 s`dvc repro` decides staleness from what `dvc.yaml` declares: the command, the hashes of the listed `deps`, the listed param keys and the outputs. It does not inspect what `src/featurize.py` imports, so editing an undeclared helper leaves every recorded hash unchanged and DVC prints `Stage 'featurize' didn't change, skipping`. The durable fix is to add `src/textnorm.py` to the `deps` of every stage that imports it; on the next `dvc repro` the new dependency has no recorded hash, so the stage counts as changed and the cascade reaches train and evaluate if the features differ. For a one-off, `dvc repro -f -s featurize` forces it. Also check the other quiet causes: a stage marked `frozen`, a param key the code reads but the stage does not list, and the run cache restoring an older result for the same declared inputs.
go deeper
Remember that DVC reruns a stage only when something listed in dvc.yaml for that stage changed, so every file the command reads belongs in deps.
Explain the four checks against dvc.lock and why an imported helper is invisible to them. Know dvc status, --dry and the -f -s pair.
Diagnose a silent stale output: check deps against imports, frozen stages, undeclared param keys and run-cache restores, then fix the declaration rather than forcing runs by habit.
Set the team convention for declaring code and environment dependencies, trading directory-level deps that over-trigger against file-level deps that drift out of date.
## DVC knows only what you declare A DVC **stage** is a shell command with declared inputs and outputs. `dvc repro` decides whether a stage is stale by comparing four things with the stage's entry in **`dvc.lock`**: the `cmd` text, the content hash of every path in `deps`, the value of every key in `params`, and whether the recorded `outs` still exist and are in the cache. For change detection, DVC does not parse Python, follow imports or look at installed library versions. If the featurize command runs `python src/featurize.py`, and that script imports `src/textnorm.py`, DVC has no idea the helper exists unless `deps` lists it. That is why the text-normalization fix produced `Stage 'featurize' didn't change, skipping`. The features, the model and the metrics in the workspace still come from the buggy normalizer, and nothing warns you. Why a cache key must cover every input is a design question for the material on restartable step graphs; this answer is about how DVC does it. ## Usual causes of a skipped stage | Cause | What you see | Fix | |---|---|---| | Imported module not in `deps` | Stage skipped after a code change | Add the file, or the `src/` directory, to the `deps` of each stage that imports it | | Param key read by the code but not listed | Stage skipped after a `params.yaml` change | List the key under `params`, or track the whole file | | Stage marked `frozen: true` (for example by `dvc freeze`) | Stage never executes, even with `-f` | `dvc unfreeze featurize`, or remove the field | | Run cache restored an older run | `Stage 'featurize' is cached - skipping run, checking out outputs` | Expected when declared inputs match a past run; `--no-run-cache` if outputs are not deterministic | | Shared input declared only on the first stage | Later stages skipped though they use it | Declare it where used, or run with `--force-downstream` | The run-cache row deserves care. The run cache keys each past run on the command, the dependency contents and the param values, so it has the same blind spot. While the helper stays undeclared, setting `featurize.ngram_max` back to a value used last week can restore last week's features, computed with the old helper. ## Diagnosing it 1. Run `dvc status`. If featurize is not listed, DVC believes its inputs are unchanged, which points to an undeclared input or a frozen stage. 2. Read the stage in `dvc.yaml`: compare `deps` with what the script actually imports and opens, and look for `frozen`. 3. Run `dvc repro --dry` to see which commands would run without running them. 4. Run `dvc repro -v` to see debug lines such as `Dependency 'data/prepared' of stage: 'featurize' changed because it is 'modified'`, which name the input that triggered a rerun. ## Fixing it durably, then once - **Declare the dependency.** Add `src/textnorm.py` under `deps` for featurize and for any other stage that imports it. On the next `dvc repro`, the new dependency has no recorded hash, so the stage is changed and runs; its new `data/features` then invalidates train, and the new model invalidates evaluate. - **Choose the right granularity.** Listing the whole `src/` directory catches future imports, but then editing `src/evaluate.py` also reruns featurize. Listing individual files is precise but has to be kept in step with the imports. - **Force a single run when you only need one.** `dvc repro -f -s featurize` runs just that stage and skips the run cache; without `-s`, `-f` also forces every upstream stage. - **Declare the environment where it matters.** A pinned requirements file listed as a dependency makes a library upgrade invalidate the stages that use it. ## What interviewers listen for - That DVC's change detection is declarative and hash-based, not import tracing. - That `--no-run-cache` alone does not rerun a stage DVC considers unchanged; it only stops restoring outputs for a stage that is already going to run. - That the fix belongs in `dvc.yaml`, reviewed and committed, not in someone's habit of running `-f` before a demo.
- Would `dvc repro --no-run-cache` have picked up the helper fix?No. `--no-run-cache` makes DVC execute a stage's command instead of restoring outputs from a previous identical run, but only for stages it already considers changed. With the helper undeclared, featurize is unchanged, so it is still skipped. `-f` forces the run; declaring the dependency fixes the cause.
- When is `--force-downstream` the right tool rather than more `deps`?When one input, such as a pinned requirements file, is declared only on the first stage and everything after it depends on it implicitly, or when a stage's outputs are not deterministic, so identical hashes cannot be trusted. It reruns all descendants of a changed stage even if their own dependencies match.
- DVC traces a script's Python imports and reruns when a helper changes
- Any change to a Git-tracked file invalidates every stage
- dvc repro --no-run-cache reruns stages whose inputs did not change
- If dvc status shows nothing, the outputs are guaranteed to match the code
- The run cache keys on the script's full source tree, so it cannot be stale