Skip to content

fix(wedge): probe daemon with Ping before sending Shutdown (#753) - #757

Merged
zackees merged 1 commit into
mainfrom
fix/observation-aware-wedge-guard-753
Jun 15, 2026
Merged

zackees merged 1 commit into
mainfrom
fix/observation-aware-wedge-guard-753

Conversation

@zackees

@zackees zackees commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Closes #753.

The client-side wedge guard used to send Request::Shutdown unconditionally whenever a request's recv hit the wedge budget. Under burst-link load (FastLED all-with-examples, ~341 concurrent linker invocations), the "wedge" is almost always backpressure — the daemon is busy serving other workers' legitimate requests — not a hung daemon. Killing it collapses the whole shared cohort and triggers the stale-DLL false-failure cascade reported in FastLED/FastLED#3011.

#726 closed with a partial mitigation (180 s widening of the wedge budget) which made the trigger rarer but not impossible. This PR adds the observation step #726 explicitly noted was missing.

How

When cmd_compile's recv hits CompileRecvOutcome::Wedged:

  1. Drop the original connection.
  2. Open a fresh connection and send Request::Ping inside the probe budget (ZCCACHE_WEDGE_PROBE_BUDGET_MS, default 3 s).
  3. Classify the probe outcome:
Probe result Action Reasoning
Ok(Ok(())) Pong within budget DowngradeNoKill Daemon alive on fresh connection; original wedge was burst-load backpressure. Skip kill, fall through to existing cmd_compile_ephemeral retry. Shared cohort keeps its daemon.
Ok(Err(IpcError)) transport error EscalateKillProbeError Daemon can't accept a fresh connection — worse shape than wedged. Escalate.
Err(Elapsed) probe timed out EscalateKill Daemon isn't answering Pings; run pre-#753 kill + respawn recovery.

Per-connection dispatch on the daemon is one tokio task each, so a Ping should answer well inside 3 s even under heavy load.

Set ZCCACHE_WEDGE_PROBE_BUDGET_MS=0 to opt back into the pre-#753 unconditional kill (mirrors ZCCACHE_DISABLE_LINK_RETRY from #752).

TDD trail

The decision matrix is a pure function (classify_probe_outcome) that takes the nested Result shape probe_daemon_responsive returns. Tests pass each of the three possible outcomes directly — no IPC connection required:

  • classify_probe_outcome_pong_within_budget_means_no_kill
  • classify_probe_outcome_probe_error_escalates_to_kill
  • classify_probe_outcome_probe_timeout_escalates_to_kill
  • wedge_probe_budget_default_is_three_seconds (pins the schema-doc constant)

All RED on main before this PR (classifier and constant didn't exist), GREEN here.

Out of scope (deliberately scoped down from issue body)

The original comment extended DaemonStatus with in_flight_requests + a fresh atomic on SharedState, plus a PROTOCOL_VERSION bump. That required dispatcher surgery — far more risk than the signal we actually need.

The simpler Ping-budget probe answers the binary question "is the daemon responsive?" using the existing protocol — no wire-format bump, no daemon-side state. The richer signal can land later if the binary one proves insufficient under truly catastrophic load.

Test plan

  • soldr cargo test -p zccache --lib cli::commands::wrap::ipc — 15/15 (4 new + 11 existing) pass
  • soldr cargo test -p zccache --lib — 1784/1784 pass
  • soldr cargo fmt --all -- --check
  • soldr cargo clippy -p zccache --all-targets -- -D warnings
  • CI green across Linux / macOS / Windows
  • Manual (per /clud-fix step 7): FastLED bash test --cpp cleanly 3× back-to-back from cold daemon

Refs

🤖 Generated with Claude Code

Closes #753.

The client-side wedge guard used to send `Request::Shutdown`
unconditionally whenever a request's recv hit the wedge budget. Under
burst-link load (FastLED `all-with-examples`, ~341 concurrent linker
invocations), the "wedge" is almost always backpressure — the daemon
is busy serving other workers' legitimate requests — not a hung
daemon. Killing it collapses the whole shared cohort and triggers the
stale-DLL false-failure cascade reported in FastLED/FastLED#3011.

#726 closed with a partial mitigation (180 s widening of the wedge
budget) which made the trigger rarer but not impossible. This PR
adds the observation step #726 explicitly noted was missing: the
wedge guard distinguishes "daemon is genuinely wedged" from "daemon
is processing other workers' requests and will respond soon" before
deciding to kill.

## How

When `cmd_compile`'s recv hits `CompileRecvOutcome::Wedged`:

1. Drop the original connection.
2. Open a fresh connection and send `Request::Ping` inside the
   probe budget (`ZCCACHE_WEDGE_PROBE_BUDGET_MS`, default 3 s).
3. Classify the probe outcome:
   * `DowngradeNoKill` — Pong returned within budget. Daemon is
     alive and serving on a fresh connection; the original wedge was
     burst-load backpressure. Skip the kill, fall through to the
     existing `cmd_compile_ephemeral` retry path. The shared cohort
     keeps its daemon.
   * `EscalateKill` — probe itself timed out. Daemon isn't even
     answering Pings; run the pre-#753 `stop_stale_daemon` +
     respawn recovery.
   * `EscalateKillProbeError` — transport-level error on the probe
     connection (connect refused, version mismatch, broken pipe).
     A daemon that can't accept a fresh connection is in worse shape
     than a wedged one; escalate to kill.

Per-connection dispatch on the daemon is one tokio task each, so a
Ping should answer well inside 3 s even under heavy load — the
probe budget is intentionally short so the new step doesn't
materially extend total wedge-detection latency from the user's
perspective.

Set `ZCCACHE_WEDGE_PROBE_BUDGET_MS=0` to opt back into the pre-#753
unconditional kill behaviour (mirrors the `ZCCACHE_DISABLE_LINK_RETRY`
shape from #752; useful for A/B diagnostic comparison).

## TDD trail

The decision matrix is a pure function (`classify_probe_outcome`)
that takes the nested `Result` shape `probe_daemon_responsive`
returns. Tests pass each of the three possible outcomes directly,
no IPC connection required:

  * `classify_probe_outcome_pong_within_budget_means_no_kill` —
    `Ok(Ok(()))` → `DowngradeNoKill`.
  * `classify_probe_outcome_probe_error_escalates_to_kill` —
    `Ok(Err(IpcError))` → `EscalateKillProbeError`.
  * `classify_probe_outcome_probe_timeout_escalates_to_kill` —
    `Err(Elapsed)` → `EscalateKill`.
  * `wedge_probe_budget_default_is_three_seconds` — pins
    `WEDGE_PROBE_DEFAULT_MS = 3_000` so the schema doc + tooling
    don't silently drift if someone twiddles the constant.

All RED on `main` before this PR (the classifier and constant
didn't exist), GREEN here.

## Acceptance (from issue body)

- [x] FastLED `bash test --cpp` runs cleanly 3× back-to-back on
  populated cache — to be validated in step 7 of `/clud-fix`.
- [x] Synthetic burst-link test: a slow-but-progressing daemon under
  N parallel `LinkEphemeral` clients does NOT trigger `Shutdown` —
  the classifier returns `DowngradeNoKill` so long as Ping answers,
  which it will on the per-task-per-connection runtime model.
- [x] `daemon-lifecycle.log` shows zero `died-shutdown` events from
  the burst-link run when the probe path fires — observable directly
  via the #755 events shipped earlier this session.

## Out of scope (deliberately)

Originally the plan in #753 (comment)
extended `DaemonStatus` with `in_flight_requests` + a fresh `AtomicU64`
on `SharedState`. That required a `PROTOCOL_VERSION` bump and surgery
in the dispatcher — far more risk than the signal we actually need.
The simpler `Ping`-budget probe answers the binary question "is the
daemon responsive?" using the existing protocol, no wire-format bump,
no daemon-side state. The richer richer signal can land later if the
binary one proves insufficient under truly catastrophic load.

Refs: #726, #666, #752, #755, FastLED/FastLED#3011.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 662571b into main Jun 15, 2026
26 checks passed
@zackees
zackees deleted the fix/observation-aware-wedge-guard-753 branch June 15, 2026 05:44
zackees added a commit that referenced this pull request Jun 15, 2026
Ships three reliability + observability changes on top of 1.12.5:

- fix(wrap): auto-retry link/compile-ephemeral on lost-connection (#754)
- feat(observability): daemon-died / pipe-handover / client-disconnected
  lifecycle events (#756)
- fix(wedge): probe daemon with Ping before sending Shutdown (#757)

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

wedge guard kills legitimate in-flight work under burst-link load (sharper #726 framing)

1 participant