Repository navigation
Description
Feature request: dvc fsck — verify integrity of cache and remote objects
Problem
DVC's cache is content-addressed, but there is no user-facing command to verify that stored objects still match their hashes. In practice:
- DVC trusts its state database (inode/mtime/size) and does not rehash cache objects, so silent corruption (interrupted or partial transfers, bad disks, faulty NFS/shared caches) goes undetected. As reported in dvc status: 'up-to-date' but cache is corrupted #9641,
dvc statuscan say everything is up to date while a file inside a tracked directory is corrupted in the cache. dvc status -canddvc data status --not-in-remoteonly check that objects exist on a remote, not that their contents are intact.remote.verifyonly checks objects at download time, so verifying a remote requires a fulldvc fetchinto a clean cache.dvc pushskips objects that already exist on the remote, so a corrupted remote object can't be fixed by pushing again (Force push option #7268). Users have had to trace hashes back and delete remote objects by hand.
Users currently work around this with scripts that walk .dvc/cache/files/md5/ and compare md5sum output against the object path. This is fragile: it depends on internal layout details that changed between major versions, and it gives false positives on DVC 2.x caches, where files detected as text were hashed after dos2unix normalization, so their DVC hash doesn't match a plain md5sum. Verification really needs to live in DVC, which knows how each object was hashed.
Proposal
Add a dvc fsck command (name open to discussion, e.g. dvc cache verify, or a --verify flag on dvc status as suggested in #9652), similar in spirit to git fsck:
dvc fsck [-r <remote>] [-j <jobs>] [--all-commits | --all-branches | --all-tags] [targets...]
Behaviour:
- Default: rehash every object in the local cache (including
.dirmanifests) using the same hashing rules DVC used to create it, and report any mismatches. -r/--remote: stream objects from the given remote and verify their hashes without writing them into the local cache.- Scope options: same semantics as
dvc fetch/dvc gc, to verify only objects referenced by the workspace or by selected revisions instead of everything. -j/--jobs: parallel hashing, since caches and remotes can be very large.- Exit code: nonzero if any corruption is found, so it can run in CI or on a schedule (cron, etc.).
- Output: list corrupted object hashes and, where possible, the tracked paths that reference them. Optionally
--json.
This command is read-only, which keeps the first version low-risk.
Possible follow-up: repair (separate PR)
A --repair flag could:
- remove corrupted local cache objects and refetch them from a remote (or re-add from the workspace if the workspace copy verifies), and
- remove corrupted remote objects so they can be re-pushed from a verified cache, which addresses the use case in Force push option #7268.
The concerns raised in #7268 apply here: some remote types restrict overwriting, so repair may need delete-then-write semantics, and it should be clear whether the local cache, the local index, or the remote is the source of truth. Detection by dvc fsck would at least make these cases visible and diagnosable, which also helps with understanding why corruption happens (a priority noted in #7268).
Implementation notes
Most of the required logic seems to exist already in dvc-data (hashing, object iteration, and the remote.verify code path). This could be a thin CLI command in dvc on top of a verification API in dvc-data. I'm happy to take guidance on where maintainers would prefer the core logic to live.
Related issues
- dvc status: 'up-to-date' but cache is corrupted #9641 —
dvc statusreports up to date while the cache is corrupted; maintainers noted there's no way to force a local cache check yet - dvc status: --verify #9652 — request for
dvc status --verify - Force push option #7268 — force push option for corrupted remote objects
Prior art
git fsckrestic check/borg check(including optional full-data verification of remote repositories)lode verify, a third-party DVC-compatible tool that rehashes cached objects against their recorded hashes
Environment
DVC version:
I'm willing to work on a PR for this if the approach looks acceptable.
Activity
akshitkhokhani commentedon Oct 26, 2026
I looked at the existing verification paths to check the read-only boundary. Two details matter for reusing them:
HashFileDB.check()can remove an object on a hash mismatch and protect a valid object.LocalHashFileDB.check()can return based on the cache file mode without hashing.hash_file()also reaches a helper that can reuse filesystem metadata or a filesystem-provided hash.A forced, non-mutating byte-verification path therefore seems worth separating from the existing cache-maintenance checks. Regression cases could include protected corrupt objects, a same-size corruption with preserved timestamps, a valid
.dirmanifest with a corrupt child, and a local-directory remote whose verification leaves the cache and object bytes/modes unchanged. Legacy hash rules should remain explicit rather than treating every object as raw MD5. I also checked the three maintenance behaviors with actualLocalHashFileDB.check()calls from dvc-data 3.18.3 / dvc-objects 5.2.0 on separate disposable synthetic objects: protected corrupt bytes were retained without an error, writable corrupt bytes raisedObjectFormatErrorand were removed, and valid writable bytes changed from mode 0644 to 0444. All three matched the source behavior and received independent review. These are backend characterization results, not a new integrity command, a product-bug claim, or validation of remote/legacy/directory coverage.Since you offered to implement this, I can help with isolated regression fixtures or review once the command and hash-version contract are agreed, without duplicating your implementation.