Skip to content

fix(wrap): auto-retry link/compile-ephemeral on lost-connection (#752) - #754

Merged
zackees merged 1 commit into
mainfrom
fix/link-auto-retry-752
Jun 15, 2026
Merged

zackees merged 1 commit into
mainfrom
fix/link-auto-retry-752

Conversation

@zackees

@zackees zackees commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Closes #752. Cross-ref: FastLED/FastLED#3011.

This PR is the relief layer for lost connection to daemon on the burst-link path. It does not address the underlying wedge-guard-vs-legitimate-work distinction tracked at #753 (filed separately). After #753 lands, this retry becomes defense-in-depth for non-wedge connection-loss modes (daemon OOM, OS network glitch).

Why (sharpened reframe)

Original symptom: under FastLED's all-with-examples ninja target (~341 concurrent linker invocations), individual link clients hit lost connection to daemon, ninja marks the target FAILED, the prior build's .dll is left on disk, FastLED's #3011 stale-artifact detector flags it, false test failures cascade. The error message itself says to fix it with zccache stop + retry — this PR makes that automatic.

After investigating: the failure shape is NOT a daemon segfault and NOT a connection-refusal thundering herd. It's the client-side wedge guard killing a busy-but-alive daemon (Request::Shutdown) when one client's 180 s recv budget expires under the burst-write load. ~40 other in-flight workers then see their connection close. The retry recovers that follow-on; the wedge-guard misfire itself is tracked at #753.

How

  • link_with_retry — generic async helper. Runs attempt(); on CompileRecvOutcome::Failed runs recover() and re-runs attempt(). Bounded by max_recoveries. Wedge outcomes bypass retry (ephemeral arms intentionally fail-fast per Daemon stops responding after ~1h uptime — all clients hit recv timed out after 300s (1.11.14, Windows) #666).
  • Production recovery is retry_backoff_with_jitter (50–250 ms randomized sleep), NOT a daemon kill. ensure_daemon's next call already handles a dead daemon (probe → CommError → stop + respawn), and unconditionally killing here would race a healthy daemon another worker just spawned.
  • Retry budget defaults to 1. Override via ZCCACHE_DISABLE_LINK_RETRY=1 (mirrors the ZCCACHE_WEDGE_RECV_TIMEOUT_SECS=0 shape).
  • run_ephemeral_attempt folds ensure-daemon → connect → send → recv into one closure so a single retry covers ALL pre-recv failure modes uniformly.

TDD trail (5 new unit tests, all RED on main, GREEN here)

Test Asserts
link_retry_returns_done_when_first_attempt_succeeds first-attempt success doesn't invoke recovery
link_retry_recovers_after_one_transport_failure the symptom this PR fixes — Failed then Done → outcome Done, recoveries=1
link_retry_surfaces_failure_after_exhausting_budget bounded — two Failed surface as Failed with attempts=2, no infinite loop
link_retry_does_not_retry_on_wedge Wedged outcomes bypass recovery (ephemeral wedge stays fail-fast)
link_retry_disabled_when_budget_is_zero env-var override behaves as documented

Caveats audited

  • Thundering-herd amplification: recovery is sleep+jitter, NOT a kill — N parallel workers all retrying won't pile a spawn storm.
  • Healthy-daemon protection: ensure_daemon probes the version endpoint before any kill; we don't pre-emptively kill a daemon another worker just spawned.
  • Cap at 1: budget is hard-bounded; two Failed in a row surface to caller.

Test plan

  • soldr cargo test -p zccache --lib cli::commands::wrap::ipc::tests — 11/11 pass
  • soldr cargo fmt --all -- --check
  • soldr cargo clippy -p zccache --all-targets -- -D warnings
  • CI green across Linux / macOS / Windows
  • Manual: FastLED bash test --cpp cold-daemon run succeeds without zccache stop

Refs

🤖 Generated with Claude Code

Closes #752. Cross-ref FastLED/FastLED#3011.

## Why

`cmd_link_ephemeral` and `cmd_compile_ephemeral` used to bail with
`ExitCode::FAILURE` on any `CompileRecvOutcome::Failed` — including
the FastLED-burst-link symptom where one client's wedge guard
triggered a `Request::Shutdown` of a busy-but-alive daemon, and the
~40 other in-flight workers then got `lost connection to daemon`.
Stale DLLs from prior builds remained, FastLED's #3011 stale-artifact
detector flagged them, false test failures cascaded.

This PR is the **relief layer**: it makes the recovery the error
message itself recommends (`zccache stop` + retry) automatic on the
client side. It does NOT address the underlying wedge-guard-vs-
legitimate-work distinction tracked at #753 (filed separately).
After #753 lands, this retry becomes defense-in-depth for non-wedge
connection-loss modes (daemon OOM, OS network glitch).

## How

* `link_with_retry` — generic async helper that runs an `attempt`
  closure and on `CompileRecvOutcome::Failed` runs a `recover`
  closure and retries up to `max_recoveries` times. Wedge outcomes
  bypass retry (intentionally fail-fast on ephemeral arms per #666).
* Production recover closure is `retry_backoff_with_jitter` — a
  jittered 50–250 ms sleep, NOT a daemon kill. `ensure_daemon` on
  the next attempt already handles a dead daemon (probe → CommError
  → stop + respawn), and unconditionally killing here would race a
  healthy daemon another worker just spawned.
* Retry budget is 1 by default, controlled by `link_retry_budget()`.
  `ZCCACHE_DISABLE_LINK_RETRY=1` opts back into pre-fix fail-fast
  behavior (mirrors the `ZCCACHE_WEDGE_RECV_TIMEOUT_SECS=0` shape).
* `run_ephemeral_attempt` extracts the ensure-daemon → connect →
  send → recv cycle so a retry covers ALL pre-recv failures
  (daemon spawn error, connect error, send error) uniformly — any
  of these can manifest as the burst-link spawn-storm shape.

## TDD trail (5 new unit tests)

All RED on `main` before the helper existed, GREEN after:

* `link_retry_returns_done_when_first_attempt_succeeds` —
  first-attempt success does not invoke recovery.
* `link_retry_recovers_after_one_transport_failure` —
  the symptom this PR fixes: first `Failed`, second `Done` → outcome
  is `Done` and recovery was invoked exactly once.
* `link_retry_surfaces_failure_after_exhausting_budget` —
  bounded: two `Failed` in a row surface as `Failed` with attempts=2,
  recoveries=1 (no infinite loop).
* `link_retry_does_not_retry_on_wedge` —
  `Wedged` outcomes bypass recovery so the ephemeral wedge path
  stays fail-fast.
* `link_retry_disabled_when_budget_is_zero` — env-var override.

## Caveats audited

* No thundering-herd amplification: recovery is sleep+jitter, NOT
  a daemon kill, so N parallel workers all retrying don't pile a
  spawn storm.
* Cap at 1 spawn-respawn per worker (budget=1 default).
* Healthy-daemon detection is delegated to `ensure_daemon` which
  probes the version endpoint before any kill.

## Refs

* #752 — this fix's tracking issue.
* #753 — sibling root-cause issue (wedge guard kills legitimate
  in-flight work). This retry is the relief layer; #753 is the cure.
* #666, #669 — wedge detection design + pool-replenishment fix that
  the retry complements.
* #726 — closed root-cause issue this PR re-opens as #753 with
  sharper framing.
* #745 — env-race lesson: the unit tests use closure-captured
  `AtomicU32` counters, not process-global env mutation.
* FastLED/FastLED#3011 — downstream stale-DLL detection (consumer side).
* FastLED/FastLED#3048 — adjacent native-file lifecycle bug (fixed
  in 1.12.5 via #750).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit f013072 into main Jun 15, 2026
26 checks passed
@zackees
zackees deleted the fix/link-auto-retry-752 branch June 15, 2026 00:50
@zackees zackees mentioned this pull request Jun 15, 2026
1 of 3 tasks
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.

link path: client should auto-retry on lost connection to daemon instead of failing the link step (refs FastLED/FastLED#3011)

1 participant