Repository navigation
test(cold-path): source-edit invalidation race for #610 - #613
Merged
Merged
Conversation
Third installment of #610's adversarial test track. `source_edit_invalidates_cached_artifact` guards the worst-case defer-vs-invalidation race: a cold-miss compile starts publishing v1 in the background; before the publish lands the source is edited (v2); a subsequent lookup must reflect v2's content, never v1's. The fake cc shim here echoes source CONTENT (not path) so the assertion is direct: v1 bytes must start with v1's source text; v2 bytes must start with v2's source text. Because cache keys include the source's content hash, v1's entry — even if its deferred publish completes after v2's lookup arrives — cannot satisfy v2's lookup key. This invariant must hold under both the sync-store path (today) and the deferred path (#610). Bumps source mtime forward to defeat any stat-based fast paths. Refs #605, #610, DD-025. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Closed
Co-Authored-By: Claude Opus 4.7 <[email protected]>
zackees
added a commit
that referenced
this pull request
Jun 5, 2026
…refs #610) (#664) Adds the `pending_cache_writes` registry on `SharedState` and the `pending_writes` helper module (`register` / `complete` / `await_pending`). This is the **named sync point** required by DD-025 condition 1 — the bridge between the daemon's response-return and the deferred publication of a cold-miss artifact into `state.artifacts` that the follow-up PR will introduce in `store_*` (see `daemon/server/handle_compile/miss_store.rs`). Lands the **notify-timeout fall-through** adversarial test pair (unit + `SharedState`-integration) — the remaining DD-025 condition 4 item identified in PR #618. The wiring follows the existing #610 "tests first, wiring second" cadence (PRs #611, #612, #613, #618, #651). ## What this PR does - Adds `SharedState.pending_cache_writes: DashMap<String, Arc<Notify>>` (keyed by artifact_key_hex), initialized empty at bind time. - Adds `daemon/server/pending_writes.rs` with three helpers: - `register(pending, key) -> Arc<Notify>` — idempotent: repeat calls for the same key return the same handle. - `complete(pending, key)` — notify waiters + remove entry. - `await_pending(pending, key, timeout) -> bool` — caps the caller-supplied timeout at `PENDING_WAIT_TIMEOUT` (5 ms) so a buggy caller cannot blow the DD-025 condition-3 blast radius. Returns `true` if a pending entry was observed (caller should re-attempt the lookup), `false` if not (caller should fall through to its normal miss path). - Unit tests (5) in the module + integration tests (4) in `tests/pending_cache_writes.rs` covering: - `register` idempotency for the same key - `complete` wakes waiters and removes the entry - notify-timeout fall-through within blast-radius bound - warm lookup (no pending entry) pays zero wait - caller-supplied timeout is capped at the blast-radius bound - `#[allow(dead_code)]` on the helpers + field with a comment pointing at the follow-up wiring PR. The lib compiles clean under `-D warnings`. ## What this PR explicitly does NOT do - It does not yet defer `dep_graph.update` or `state.artifacts.insert`. The hot path is unchanged. - It does not yet call `await_pending` from `lookup_artifact_with_disk_fallback` (the lookup function is sync; routing it through the registry requires the follow-up PR's async refactor or a thin async wrapper at the call site). The follow-up PR will plug the registry into both sides and lift the `#[allow(dead_code)]` annotations. ## Test plan - [x] `soldr cargo test -p zccache --lib -- pending` — 9/9 new tests pass (+13 unrelated `pending` tests already green) - [x] `soldr cargo check --workspace --all-targets` - [x] `soldr cargo clippy --workspace --all-targets -- -D warnings` - [x] `soldr cargo fmt --all --check` Refs #610, #605. DD-025.
5 of 7 tasks
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
Third installment of #610's adversarial test track. Builds on #611 and #612.
source_edit_invalidates_cached_artifactguards the worst-case defer-vs-invalidation race:evolving.c@v1returns; daemon publishes v1's artifact in the background.evolving.c@v2.Why this passes today and must keep passing tomorrow
Cache keys are derived from the source's content hash (DD-005). So v1's cache entry — even if its deferred publish completes after v2's lookup arrives at the daemon — cannot satisfy v2's lookup because the keys are derived from different content hashes.
This test asserts that invariant directly by using a custom fake
ccshim that echoes the source's CONTENT into the object output. v1's bytes start with v1's source text; v2's bytes start with v2's source text; if v2 ever returns v1's bytes the test fails loudly.Source mtime is bumped forward by 5s to defeat any stat-based fast path.
Refs
Test plan
🤖 Generated with Claude Code