Skip to content

fix(rust): isolate cache inputs across worktrees - #769

Draft
jleni wants to merge 6 commits into
mainfrom
fix/issue-760-proc-macro-file-inputs
Draft

fix(rust): isolate cache inputs across worktrees#769
jleni wants to merge 6 commits into
mainfrom
fix/issue-760-proc-macro-file-inputs

Conversation

@jleni

@jleni jleni commented Aug 18, 2026

Copy link
Copy Markdown
Member

Fixes #760.

What changed

  • Bind every rustc source's stable path identity together with its content hash (cache-key schema v26), so swapping equal content between paths cannot collide.
  • Store Rust dep-info with portable source-root sentinels and expand it for the consuming worktree. Publication now fails closed if dep-info cannot be made portable.
  • Make kache cargo build/check isolate Cargo fingerprints in a workspace-local build directory while retaining the configured shared artifact target (Cargo 1.91+).
  • Cover configured roots, symlink/canonical aliases, Unicode/non-UTF-8 paths, Windows drive/UNC/verbatim paths, and source-root precedence.

Root cause

The reported n00n history did not have byte-identical Rust sources: the relevant change added both a literal builtin entry and an include_dir! invocation. In the exact shared-target reproduction, Cargo marked the old unit Fresh, so it never invoked RUSTC_WRAPPER; Kache could not validate or reject it.

The investigation also found two independent Kache correctness holes:

  • source keys folded a sorted multiset of content hashes without source-path association;
  • cached .d files could retain a live donor-worktree path, allowing Cargo to validate the wrong tree after a relocated hit.

The new kache cargo isolation closes the pre-wrapper Cargo fingerprint boundary, while the key and dep-info changes close the Kache-owned boundaries. Arbitrary undeclared std::fs reads inside proc macros remain outside rustc's observable inputs and still require declared extra_inputs.

Validation

  • cargo fmt --all -- --check
  • cargo check --tests
  • just lint
  • cargo test --workspace --test '*' (all integration tests green)
  • focused cache-key, Cargo proxy, path-normalizer, dep-info, and relocated-worktree tests green
  • full unit run: 1,985/1,988 green; the three unrelated process-inspection tests fail under the shared macOS runner and pass individually

jleni added 6 commits August 18, 2026 09:39
`Test (Windows)` failed on a `clippy::cmp_owned` error in the 8.3
short-name assertion, and the changed-line mutation gate reported 11
missed mutants. Both are fixed here.

- compare the short-name dep-info root as a borrowed `Path` instead of
  building a `PathBuf` just to compare it
- pin the `with_target_dir` splice point from both sides: the new rules
  must land after every higher-ranked root and after an equal-ranked
  `<TARGET>` peer, but ahead of anything ranked below, since `normalize`
  applies rules in list order
- assert `depinfo_source_roots` picks the designated restore spelling
  rather than whichever alias rule happens to come first
- cover every source sentinel's dep-info mapping, including the three
  Windows user dirs, and assert the mappings stay distinct
- assert `configured_rustc_depinfo_roots` reports the workspace, an
  external target, and a configured base dir with their real ranks
- assert `path_normalization_root` reads back the frozen root

The e2e key-divergence diagnostic was one function whose whole body was
stderr I/O, so its parsing could not be tested. Split it into
`parse_keytrace`, `render_key_divergence`, and `key_divergence_report`,
all directly tested; `report_key_divergence` keeps the call site and is
now two lines of printing, excluded with the same justification the
other entries in `.cargo/mutants.toml` use. Dropped the redundant
empty-map early return in the renderer: a crate absent from either map
already contributes no difference, so the guard was an equivalent
mutant.
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.

include_dir asset content is invisible to the cache key: stale rlib served across worktrees

1 participant