Skip to content

fix(repro): record dependency hashes before running the stage command (#11058)#11062

Open
ChetanyaRathi wants to merge 2 commits into
treeverse:mainfrom
ChetanyaRathi:fix-repro-dep-hash-11058
Open

fix(repro): record dependency hashes before running the stage command (#11058)#11062
ChetanyaRathi wants to merge 2 commits into
treeverse:mainfrom
ChetanyaRathi:fix-repro-dep-hash-11058

Conversation

@ChetanyaRathi

Copy link
Copy Markdown

Fixes #11058.

Problem

dvc repro computes dependency hashes after the stage command finishes.
If a dependency is modified while the command is running, dvc.lock records
the post-run hash, so the outputs get linked to the wrong version of the
inputs and the stage is incorrectly reported as unchanged (and skipped) on
the next run.

Fix

Snapshot dependency hashes before the command runs (in _run_stage) and
use them when writing dvc.lock. If a dependency changed during execution,
the pre-run hash is kept and a warning is logged; because the recorded hash
then differs from the mutated workspace file, the stage is correctly reported
as changed on the next run and re-executed.

run() and save() are unchanged — the logic lives in _run_stage and
save_deps, keyed by id(dep) so it is robust across regular deps and params.

Note: dependencies are hashed twice per run (once for the snapshot, once in
the post-run save). This is negligible for typical code/config deps and was
kept for a small, obviously-correct diff. Happy to reuse the snapshot in the
post-run save instead if preferred.

Test

Added test_repro_records_pre_run_dep_hash in tests/func/repro/test_repro.py,
which uses a self-mutating command to deterministically simulate a mid-run
dependency change and asserts the stage is reported as changed and re-runs.

  • I have followed the Contributing to DVC checklist.
  • This PR does not require documentation updates.

@github-project-automation github-project-automation Bot moved this to Backlog in DVC Jul 6, 2026
@CLAassistant

CLAassistant commented Jul 6, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.98%. Comparing base (2431ec6) to head (f1cab8d).
⚠️ Report is 210 commits behind head on main.

Files with missing lines Patch % Lines
dvc/stage/__init__.py 94.44% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11062      +/-   ##
==========================================
+ Coverage   90.68%   90.98%   +0.30%     
==========================================
  Files         504      505       +1     
  Lines       39795    41164    +1369     
  Branches     3141     3268     +127     
==========================================
+ Hits        36087    37454    +1367     
- Misses       3042     3071      +29     
+ Partials      666      639      -27     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ChetanyaRathi ChetanyaRathi force-pushed the fix-repro-dep-hash-11058 branch from c777e1d to f162eb3 Compare July 7, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dvc repro: dvc.lock records dependency hashes from after cmd finishes, allowing the recorded code↔output linkage to be falsified

2 participants