Skip to content

fix(request-cache): scope worktree-bound entries to their originating root - #511

Merged
zackees merged 1 commit into
mainfrom
fix/489-pch-cross-worktree
May 31, 2026
Merged

zackees merged 1 commit into
mainfrom
fix/489-pch-cross-worktree

Conversation

@zackees

@zackees zackees commented May 31, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add worktree_bound: bool to request_cache_entry. When true, force cross_root_shareable = false regardless of path layout — so PCH / GCH / MSVC entries can never be served as cross-worktree HITs even when every captured path is technically root-relative.
  • Derive the flag in pipeline.rs from the same requires_worktree_in_key(family, source_mode) predicate that already gates the depgraph context-key salt. Both cache layers now agree by construction.
  • Plumb through FastHitProbe / DepgraphHitProbe.

Why

A build in worktree fastled10 populated a FastLED.h.pch request-cache entry whose fingerprint then matched a --clean rebuild in sibling worktree fastled7. The HIT replayed a PCH carrying baked fastled10 paths into the fastled7 build, surfacing as compiler diagnostics referencing the wrong worktree + a deterministic set of nine DLLs failing to load with Windows ERROR_MOD_NOT_FOUND (126). The depgraph context-key already handled this via the worktree salt, but the request-level fast path skipped the same gate.

Test plan

  • TDD RED → GREEN with request_cache_entry_worktree_bound_rejects_cross_worktree_match in tests/cache_trim.rs:
    • Pre-fix: doesn't compile (signature mismatch — wired into the call).
    • Post-fix: PCH entry (worktree_bound=true) does NOT match a different root; otherwise-identical non-PCH entry (worktree_bound=false) still matches. The flag is the single discriminator.
  • All 15 cache_trim tests green.
  • All 85 daemon::server::tests green.
  • soldr cargo clippy -p zccache --lib --tests -- -D warnings clean.
  • soldr cargo fmt --all -- --check clean.

Fixes #489

🤖 Generated with Claude Code

… root

PCH (`.pch` / `.gch`) and MSVC compiles bake absolute include paths into
the artifact in a form `-ffile-prefix-map` and friends cannot scrub. The
depgraph context-key layer already accounts for this via
`requires_worktree_in_key` + a worktree-salt term, but the request-level
fast-path cache did not. It computed `cross_root_shareable` purely from
"are all captured paths root-relative?" — which is `true` for a PCH whose
header lives inside the worktree.

Net effect (Windows, issue #489): a build in `C:\...\fastled10` populated
a `FastLED.h.pch` entry whose request fingerprint then matched a fresh
`--clean` rebuild in sibling worktree `C:\...\fastled7`. The HIT replayed
a PCH carrying baked `fastled10` paths into the `fastled7` build, which
surfaced as compiler diagnostics referencing the wrong worktree and a
deterministic set of nine DLLs failing to load with Windows error 126.

Add a `worktree_bound: bool` parameter to `request_cache_entry`; when set,
force `cross_root_shareable = false` regardless of path layout. Plumb it
through `FastHitProbe` / `DepgraphHitProbe` from `pipeline.rs`, where it
is derived from the same `requires_worktree_in_key(family, source_mode)`
predicate already used for the context-key salt — so the two cache layers
agree by construction.

TDD coverage in `tests/cache_trim.rs::request_cache_entry_worktree_bound_rejects_cross_worktree_match`:

- Builds a PCH-flavored entry with `worktree_bound=true` and asserts a
  cross-root lookup via `request_cache_entry_matches_root` returns false.
- Builds an otherwise-identical non-PCH entry (`worktree_bound=false`) and
  asserts the cross-root lookup still succeeds, proving the flag is the
  single discriminator and we have not regressed the worktree-equivalent
  HIT path for normal `.o` artifacts.

Pre-fix the new test would not compile (missing parameter); post-fix all
15 `cache_trim` tests + all 85 `daemon::server::tests` are green. Clippy +
rustfmt clean.

Fixes #489

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@zackees
zackees merged commit 77a652b into main May 31, 2026
26 checks passed
zackees added a commit that referenced this pull request May 31, 2026
Patch release covering the fixes and CI hardening that landed since
1.11.8:

- fix(persist): retry artifact rename through AV-scanner share lock on
  Windows (#509)
- fix(request-cache): scope worktree-bound entries to their originating
  root (#511)
- fix(cli): add `analyze` + `kv` to KNOWN_SUBCOMMANDS to stop wrap-mode
  misroute (#507)
- perf(guard): gate rust-workspace-link Cold ratio (issue #517) (#519)
- perf(bench): emit zccache_rust_miss_profile lines in
  benchmark-stats logs (#521)
- ci(cache-cleanup): switch to count-based policy, broader per-commit
  families, on-demand trigger (#515, #516, #520)
- ci: setup-soldr pin bumps v0.9.21 -> v0.9.38 (#485–#518)

Co-authored-by: Claude Opus 4.7 <[email protected]>
zackees added a commit that referenced this pull request Oct 30, 2026
Maps std::fs write/create_dir*/remove_*/rename/metadata/canonicalize call
sites whose drop-in accessor already ships in the pinned kernal-api
v0.1.35 (facade_burn MAP wave 1). Read-side, read_dir and File/OpenOptions
sites stay for the #510/#511 release; every touched file therefore remains
allowlisted, so the allowlist is unchanged at 63 entries.
zackees added a commit that referenced this pull request Nov 1, 2026
kernal-api v0.1.36 (released 2026-10-31T20:01Z) ships #511's read-side
accessors, which is the release this burn was paused on: read_file,
read_to_string, symlink_metadata, copy, set_permissions and read_dir_paths.

Pin the workspace and the ban_raw_subprocess_in_daemon dev-dependency at
=0.1.36 (they must move together or the dylint lane resolves two kernal-api
copies) and route seven allowlisted files off std::fs, 15 call sites:

  rust_plan/manifest.rs                               read x2
  handle_compile_multi_preflight.rs (test)            read x1
  handle_compile/pch_overlay_aliases.rs               read x5, read_to_string x1
  handle_compile/pch_overlay.rs                       read x1
  handle_compile/pipeline/store_outcome_scan.rs       read x1
  handle_exec.rs                                      read x2
  handle_link.rs                                      read x1

Every mapping is signature- and semantics-identical (io::Result, same
NotFound behaviour), so no error mapping changes. Allowlist 63 -> 56; the
dylint crate goes to 0.1.2 so the cached .so is rebuilt with the new list.

staged_lock.rs stays allowlisted: its remaining std::fs use is File and
OpenOptions (streaming handles), which is kernal-api #510, not the read side.
@zackees
zackees deleted the fix/489-pch-cross-worktree branch November 5, 2026 05:55
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.

Cross-worktree PCH hits with path_remap=off serve stale absolute paths, causing compiler diagnostics + downstream DLL load failures (Windows)

1 participant