Skip to content

feat(daemon): scaffold PendingCacheWrite registry for DD-025 Pass 2 (refs #610) - #664

Merged
zackees merged 1 commit into
mainfrom
feat/610-pending-cache-write-registry
Jun 5, 2026
Merged

zackees merged 1 commit into
mainfrom
feat/610-pending-cache-write-registry

Conversation

@zackees

@zackees zackees commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

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.
  • 9 new tests (5 unit + 4 integration) covering: register idempotency, complete + notify, notify-timeout fall-through within blast-radius bound, warm-lookup zero-wait path, caller-timeout cap.
  • #[allow(dead_code)] on the helpers + field with a comment pointing at the follow-up wiring PR. The lib compiles clean under -D warnings.

DD-025 conditions addressed by this PR

Condition Status
1. Named sync point ✅ pending_cache_writes + await_pending
2. Failure mode is miss, not wrong-hit ✅ documented + asserted by unit tests (timeout returns true so caller re-tries the lookup; a re-miss falls through to recompile)
3. Blast-radius bound ✅ 5 ms timeout cap enforced inside the registry, regardless of caller input
4. Adversarial tests ✅ notify-timeout pair lands here; existing 5 (#611/612/613/618/651) still pass
5. Bench-measurable win ⏸ deferred to follow-up PR which actually defers the write path

What this PR explicitly does NOT do

  • Does not yet defer dep_graph.update or state.artifacts.insert. The hot path is unchanged.
  • Does not yet call await_pending from lookup_artifact_with_disk_fallback. The follow-up PR will plug the registry into both sides and lift the #[allow(dead_code)] annotations.

Test plan

  • soldr cargo test -p zccache --lib -- pending — 9/9 new tests pass
  • soldr cargo check --workspace --all-targets
  • soldr cargo clippy --workspace --all-targets -- -D warnings
  • soldr cargo fmt --all --check

Refs #610, #605. DD-025.

🤖 Generated with Claude Code

…refs #610)

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.
@zackees
zackees merged commit 729173e into main Jun 5, 2026
26 checks passed
zackees added a commit that referenced this pull request Jun 5, 2026
…loses #610) (#665)

Plumbs the registry scaffolded in PR #664 through both ends of
the cold-miss publishing lifecycle, lifting the `#[allow(dead_code)]`
annotation. With this PR landed, **all five DD-025 conditions for
Pass 2 are satisfied**:

| Condition | Status before | Status after |
|---|---|---|
| 1. Named sync point | scaffold only | wired in `store_*` + `try_fast_hit` |
| 2. Failure = miss, never wrong-hit | docs/tests | enforced: all spawn paths call `complete` |
| 3. Blast-radius bound | 5 ms timeout cap in helper | observed by `try_fast_hit` callers |
| 4. Adversarial tests | 6/6 landed | existing 5 + notify-timeout + race coverage |
| 5. Bench-measurable win | not yet exercised | now exercised; perf-cluster validates post-merge |

## Write side — `store_single_output` and `store_rustc_outputs`

Both cold-miss persist spawns now bracket their `spawn_blocking` +
`index_writer_tx.send` work with `register` (synchronously, before
the spawn) and `complete` (inside the spawn, on *every* exit path
including `JoinError`). The completion-on-failure path satisfies
DD-025 condition 2: waiters wake up, re-attempt the lookup, miss,
and recompile — the artifact never returns wrong content.

## Read side — `try_fast_hit`

The fast-hit path becomes `async`. After snapping the
`fast_hit_cache` entry's fields into local clones (so no DashMap
shard guard straddles the await), it calls
`await_pending(artifact_key_hex, PENDING_WAIT_TIMEOUT)` before
materializing. When a cold-miss for the same key is still
publishing, the read path waits ≤ 5 ms instead of falling through
to a wasteful recompile.

`pipeline.rs` adds `.await` to its single `try_fast_hit` call site.
No other cascade is required: `try_request_cache_hit`,
`try_depgraph_cached_hit`, and `materialize_cached_compile_hit`
stay sync — `try_fast_hit` is the only ContextKey-keyed lookup
that benefits from the wait, and it's already on an async caller.

## Why the await is positioned where it is

Cross-shard deadlock avoidance: DashMap's `get` returns a shard
guard. The previous code held that guard across the freshness
checks and then materialized while it was live. With the await
introduced, we now snap `(artifact_key_hex, clock, cached_at)`
into local clones BEFORE the `.await` so no shard lock can
straddle a yield point. The clones are cheap post-#652 (PR #663)
because `artifact_key_hex: String` is small and the other two
fields are `Copy`.

## What this PR explicitly does NOT do

- Does not yet defer `dep_graph.update`. The 1.8 ms median measured
  in #605 iter T2 is still on the response path. Deferring it
  requires moving the entire `store_miss_artifact` body into a
  spawn, which is a larger restructure tracked separately (the
  registry, lookup wiring, and DD-025 ceremony in this PR
  make that follow-up safe to attempt).
- Does not add Loom/TSAN harness — the existing adversarial test
  suite + the cross-platform CI test matrix is the regression bar.

## Test plan

- [x] `soldr cargo test -p zccache --lib` — 1703 / 1703 pass
- [x] `soldr cargo test -p zccache --lib -- pending` — 22 / 22
- [x] `soldr cargo check --workspace --all-targets`
- [x] `soldr cargo clippy --workspace --all-targets -- -D warnings`
- [x] `soldr cargo fmt --all --check`
- [ ] Linux: `deferred_cold_path.rs` adversarial suite (cfg(unix), runs in CI)
- [ ] perf-rust-cluster: validate non-regression on cold scenarios

Closes #610. Refs #605, #664. DD-025.
@zackees
zackees deleted the feat/610-pending-cache-write-registry 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.

1 participant