Repository navigation
fix(depgraph): normalize workspace-path inputs out of rustc cache key (#139) - #160
Merged
Merged
Conversation
) Adds four failing tests asserting that `RustcCompileContext::context_key` is invariant under workspace-location changes. Demonstrates fix #1 from issue #139 — cache hits at 0.35% because the same crate at two on-disk paths gets two different keys. New tests: - rustc_context_key_ignores_cargo_manifest_dir — vary CARGO_MANIFEST_DIR - rustc_context_key_ignores_cargo_manifest_path — vary CARGO_MANIFEST_PATH - rustc_context_key_sensitive_to_cargo_pkg_version — negative control, PASSES on main (CARGO_PKG_VERSION must still affect the key) - rustc_context_key_ignores_extern_directory_prefix — same-filename rmeta in two different target dirs must hash the same Current failure output (RED state): ---- rustc_context_key_ignores_cargo_manifest_dir ---- assertion `left == right` failed: CARGO_MANIFEST_DIR is volatile ... ---- rustc_context_key_ignores_cargo_manifest_path ---- assertion `left == right` failed: CARGO_MANIFEST_PATH is volatile ... ---- rustc_context_key_ignores_extern_directory_prefix ---- assertion `left == right` failed: extern rmeta paths with the same filename ... must produce equal cache keys ... test result: FAILED. 315 passed; 3 failed. GREEN implementation follows in next commit. Refs #139 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…#139) Cache hits sat at 0.35% (2227 misses / 8 hits / 53 errors in the compile journal) because the rustc cache key embedded inputs that vary per on-disk workspace location. Same project at `...\zccache` vs `...\zccache2` produced two disjoint key spaces, so every dep-crate compile cold-missed. Two changes: 1. Strip volatile CARGO_* env vars before hashing. Introduces `VOLATILE_CARGO_ENV_VARS = ["CARGO_MANIFEST_DIR", "CARGO_MANIFEST_PATH"]`. Both are absolute paths handed in by cargo and neither affects compiled output in a way that other key components do not already cover (the source path is hashed directly, `CARGO_PKG_*` carries the identity of the crate). The filter is applied in `from_parsed_args` AND in `context_key()` itself — defense-in-depth so the public struct cannot be hand-built into a path-sensitive key. Kept (and asserted by negative-control test): `CARGO_PKG_VERSION`, `CARGO_PKG_NAME`, every other `CARGO_PKG_*` — these feed `env!()` macros and are baked into rustc output. Already-excluded for orthogonal reasons (unchanged): `CARGO_MAKEFLAGS` (job-server token), `CARGO_INCREMENTAL` (handled via `-C incremental` stripping). 2. Hash only the file-name component of `--extern name=path` values. Cargo embeds its per-package `metadata=` hash in the file name (`libserde-abc123.rmeta`), which uniquely identifies the extern's identity. The directory prefix is incidental — it changes per workspace location and per target-dir layout, and including it cascaded misses through the entire dep graph after any move. Two extern values with different file names (e.g. `liba_v1.rlib` vs `liba_v2.rlib`) still produce different keys, so the existing `rustc_different_extern_paths_different_key` test continues to pass. Tests added in the preceding RED commit (T1, T2, T4) now pass; T3 (`CARGO_PKG_VERSION` sensitivity) was already passing on main and continues to pass — the filter is intentionally narrow. test result: ok. 318 passed; 0 failed; 0 ignored Refs #139 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
2 tasks
zackees
added a commit
that referenced
this pull request
May 11, 2026
Patch bump covering everything merged since v1.4.0: - fix(daemon,ci): tolerate unknown sessions and stop killing soldr's daemon (#168, closes #166 + #167) - feat(cli): expose session_end_idempotent for all daemon callers (#163) - fix(daemon): deterministic flush primitive for event log (#162) - feat(cli,daemon): relocate daemon exe to global runtime-binaries dir (#158) - fix(depgraph): normalize workspace-path inputs out of rustc cache key (#160) - perf(ci): trim platform Test, drop --all-targets from Check, split Test/Check jobs (#161, #164, #165) - chore(ci): drop invalid target-cache-paths from build-target action (#157) Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes item #1 of #139 — cache hits sat at 0.35% (2227 miss / 8 hit / 53 err in the compile journal) because the rustc cache key embedded inputs that vary per on-disk workspace location. Same project checked out at
...\zccacheand...\zccache2produced disjoint key spaces; every dep crate cold-missed.After this change, key inputs are independent of workspace location while remaining sensitive to everything that actually affects compiled output.
TDD split (two atomic commits on the branch)
Branch keeps RED and GREEN as separate commits for posterity. PR will squash-merge.
RED —
6c0a3bd test(depgraph): RED tests pin path-independence of rustc cache keyFour new tests in
crates/zccache-depgraph/src/context.rs:rustc_context_key_ignores_cargo_manifest_dir— same crate at two paths must hash equal.rustc_context_key_ignores_cargo_manifest_path—Cargo.tomlpath is volatile.rustc_context_key_sensitive_to_cargo_pkg_version— negative control; passes on main and after fix.rustc_context_key_ignores_extern_directory_prefix— same-named rmeta in two target dirs must hash equal.Confirmed RED (3 of 4 failing) before the GREEN commit; failure output is in the RED commit body.
GREEN —
0fb9338 fix(depgraph): normalize path-dependent inputs out of rustc cache keyVOLATILE_CARGO_ENV_VARSconstant incontext.rslistingCARGO_MANIFEST_DIRandCARGO_MANIFEST_PATH. Filtered both infrom_parsed_argsand insidecontext_key()(defense-in-depth — the public struct may be hand-built).Path::file_name()via a newextern_path_keyhelper. Cargo's per-packagemetadata=hash is part of the file name, so identity is preserved; the absolute directory prefix is dropped.What is intentionally kept:
CARGO_PKG_VERSION,CARGO_PKG_NAME,CARGO_PKG_AUTHORS, every otherCARGO_PKG_*— they feedenv!()macros baked into rustc output. The version-sensitivity test asserts this.rustc_different_extern_paths_different_keytest (different file names) still passes, so distinct rlibs still get distinct keys.What was considered and rejected:
metadata=filename already carries the identity bit. Using only the filename is simpler and strictly stronger.CARGO_PKG_*: would silently drop futureCARGO_*env vars cargo introduces. Denylist is conservative.Test plan
soldr cargo test -p zccache-depgraph --lib— 318 passed, 0 failed (315 prior + 3 new RED→GREEN).soldr cargo check --workspace --all-targets— clean.soldr cargo clippy --workspace --all-targets -- -D warnings— clean.soldr cargo fmt --all -- --check— clean../test— all green, no real failures (only a benignsoldr session-enddaemon-not-running message at the very end of the run).windows / Checksoldr-bundled-version block and daemon: event_log::test_rotation_triggers_at_threshold flakes on slow CI runners #146 event-log flake are unrelated to this PR).Hit-rate impact
Not measurable in CI — the journal lives on the developer's machine and the same-workspace path doesn't vary across CI runs. The path-independence unit tests are the proxy: T1/T2/T4 exercise exactly the invalidation vector that produced the 0.35% number. Expected outcome on the developer's machine: turn 0.35% into 80%+ across project clones and
Cargo.tomledits.Closes #139
🤖 Generated with Claude Code