Skip to content

Checksum watched files by repo-relative path - #171

Open
omnibs wants to merge 2 commits into
masterfrom
repo-relative-checksums
Open

Checksum watched files by repo-relative path#171
omnibs wants to merge 2 commits into
masterfrom
repo-relative-checksums

Conversation

@omnibs

@omnibs omnibs commented Jul 28, 2026

Copy link
Copy Markdown
Member

A cache built in one checkout can never be fresh in another: Checksum serializes each watched file's absolute path, so identical trees at different paths (e.g. linked git worktrees warmed by cloning _build/firstaide from the main checkout) get a different cache.<sig> name and fail the sums::equal freshness check. Result: "Nix environment is out of date! … Loading STALE environment" on every single load, even when the cache is byte-for-byte current.

This stores checksum paths relative to the build directory instead. Content hashes are unchanged. The hook absolutizes the paths against the build dir when emitting watch_file lines, so direnv still watches the right files wherever the cache came from. Paths outside the build dir stay absolute.

Old caches degrade gracefully: they still load through the cache symlink fallback, compare stale once, and the next firstaide build writes a portable cache. Bumped the version to 0.1.7 since existing cache signatures all change.

Verified with a synthetic project — cache built in tree-a, tree copied to tree-b at a different path:

--- OLD binary (firstaide 0.1.6) in tree-b:
Environment is STALE!
--- NEW binary (firstaide 0.1.7) in tree-b:
Environment is up to date!

and the upgrade path (new binary on an old-format cache): stale once, up to date after one rebuild.

The cache signature (the hash in the cache.<sig> filename) and the
freshness comparison both serialize each watched file's PathBuf. Since
watch_files() absolutizes against the build directory, a cache built in
one checkout could never be fresh in another: identical trees at
different paths (e.g. linked git worktrees) produced different sums, so
a cloned, byte-for-byte-current cache still reported "Nix environment
is out of date" on every load.

Store paths relative to the build directory instead. Content hashes are
unchanged; the hook absolutizes the (possibly relative) paths against
the build directory when emitting watch_file lines, so direnv still
watches the right files wherever the cache came from. Paths outside the
build directory are kept absolute.

Caches written by older versions keep working through the fallback
symlink: they compare as stale once (their sums carry absolute paths),
and the next `firstaide build` writes a portable cache.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 28, 2026 14:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the checksum (and derived cache signature) portable across different checkouts of the same working tree by storing watched file paths relative to the build directory, eliminating stale-cache behavior when the repo is located at a different absolute path.

Changes:

  • Make Checksums/Checksum serialize watched paths relative to a provided root directory (keeping paths outside the root absolute).
  • Update commands that compute checksums to pass config.build_dir as the root and update the hook to absolutize stored paths when emitting watch_file entries.
  • Bump crate version to 0.1.7 and add unit tests covering root-relative and outside-root path behavior.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/sums.rs Store checksum paths root-relative and add tests ensuring portability across different roots.
src/config.rs Expose abspath so other commands can absolutize stored (now-relative) watch paths.
src/cmds/status.rs Compute checksums using a root (build dir) for consistent signatures.
src/cmds/hook.rs Absolutize cached watch paths when generating direnv watch_file directives.
src/cmds/build.rs Compute checksums using a root (build dir) so cache keys don’t depend on absolute checkout location.
Cargo.toml Bump package version to 0.1.7.
Cargo.lock Update locked package version to 0.1.7.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/config.rs
Comment thread src/sums.rs
macos-11 was retired from GitHub's hosted runner pool, so that leg of
the matrix never got a runner and sat queued until the 24h timeout.
Switch to macos-latest, and bump actions/checkout and
install-nix-action off their Node 20 versions.

Note: macos-latest is arm64, so nix-build now targets aarch64-darwin
for the first time.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

2 participants