Skip to content

Feature request: dvc fsck — verify integrity of cache and remote objects #11115

Open

Description

@braindevices

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 status can say everything is up to date while a file inside a tracked directory is corrupted in the cache.
  • dvc status -c and dvc data status --not-in-remote only check that objects exist on a remote, not that their contents are intact.
  • remote.verify only checks objects at download time, so verifying a remote requires a full dvc fetch into a clean cache.
  • dvc push skips 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 .dir manifests) 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

Prior art

  • git fsck
  • restic 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

  1. akshitkhokhani commented on Oct 26, 2026

    @akshitkhokhani

    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.
    • Bypassing the state cache alone is not sufficient to guarantee independently streaming and hashing the object’s bytes: 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 .dir manifest 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 actual LocalHashFileDB.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 raised ObjectFormatError and 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions