Skip to content

test(deferred-cold-path): cross-key contention adversarial test (refs #610) - #651

Merged
zackees merged 1 commit into
mainfrom
test/610-cross-key-contention
Jun 4, 2026
Merged

zackees merged 1 commit into
mainfrom
test/610-cross-key-contention

Conversation

@zackees

@zackees zackees commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds the 4th item from #610's adversarial-test track per DD-025 condition 4: cross-key contention.

distinct_cold_misses_never_cross_contaminate is the cross-key counterpart to the existing same-key concurrent-lookup test. 10 concurrent cold-misses with distinct cache keys run through the miss-store path simultaneously; every task's bytes must equal that task's own expected output, never another key's.

The wrong-hit shapes this guards against once #610's deferred-write path lands:

  • PendingCacheWrite registry keyed wrongly (e.g. by compiler instead of by (context, source-hash)) so a K_Y lookup reuses a K_X registry slot and reads K_X's bytes.
  • DashMap shard collision letting an observer read a half-written entry belonging to a different key.

Pattern + fake-cc shim follow the existing concurrent_lookups_after_cold_miss_return_consistent_content test exactly so the file stays readable as one suite.

Scope discipline

  • Conformance baseline only — passes today on the synchronous-store path, will continue to pass under deferred-write when that lands.
  • refs #610, not Closes — the implementation (PendingCacheWrite registry + bench delta) is still pending.
  • Module docstring's "Future iterations" list trimmed to reflect what's now landed (only notify-timeout + Loom/TSAN remain, and notify-timeout itself is gated on the registry existing).

Test plan

  • Linux CI: soldr cargo test -p zccache --lib daemon::server::tests::deferred_cold_path::distinct_cold_misses_never_cross_contaminate passes
  • macOS CI: same
  • Windows CI: test compiles as #![cfg(unix)] no-op (entire file gated for /bin/sh fake-cc shim)
  • clippy + rustfmt clean

🤖 Generated with Claude Code

…610)

Adds `distinct_cold_misses_never_cross_contaminate` — the cross-key
counterpart to the existing same-key concurrent-lookup test. 10
concurrent cold-misses with distinct cache keys run through the
miss-store path simultaneously; every task's bytes must equal that
task's own expected output, never another key's.

The wrong-hit shapes this guards against (once #610's deferred-write
path lands):
- PendingCacheWrite registry keyed wrongly (e.g. by compiler instead of
  by (context, source-hash)) so a K_Y lookup reuses a K_X registry slot
  and reads K_X's bytes.
- DashMap shard collision letting an observer read a half-written entry
  belonging to a different key.

Passes today against the synchronous-store path (conformance baseline);
must continue to pass when the deferred-write path lands.

This is item 4 of #610's adversarial test track. The remaining item
(notify-timeout fall-through) is gated on the PendingCacheWrite
registry actually existing — module docstring updated to reflect.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 7406b53 into main Jun 4, 2026
26 checks passed
@zackees
zackees deleted the test/610-cross-key-contention branch June 4, 2026 18:44
zackees added a commit that referenced this pull request Jun 4, 2026
Ships #649 (zccache m e s o n configure wrapper, closes #627), #650 (perf: single-pass output-meta build), #651 (test: cross-key contention), #648 (closes #640). The headline payload is #649 — the wrapper was merged 2026-06-04 but the 1.11.11 release was tagged 2026-06-03, so downstream pyproject pins on >=1.11.11 do not currently see it. This release closes that gap. Validated end-to-end against FastLED on Windows.
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.
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.

1 participant