Skip to content

feat(observability): daemon-died / pipe-handover / client-disconnected lifecycle events (#755) - #756

Merged
zackees merged 1 commit into
mainfrom
feat/lifecycle-events-755
Jun 15, 2026
Merged

zackees merged 1 commit into
mainfrom
feat/lifecycle-events-755

Conversation

@zackees

@zackees zackees commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Closes #755.

Extends daemon-lifecycle.log with three new JSONL event types and two new client-meta fields on every spawn-attempt / spawn row, so the two-versions-on-one-pipe wedge — fbuild's bundled 1.12.4 vs. PyPI's 1.12.5, both racing for the same Windows named pipe — becomes reconstructable from a single grep instead of by-hand timestamp matching.

Schema additions (additive; existing tooling keeps working)

event who meaning key fields
daemon-died CLI (on takeover) predecessor was killed and replaced pid (dying daemon), reason: takeover, replaced_by_pid, replaced_by_version, client_pid
pipe-handover CLI new daemon claimed the endpoint a previous daemon held pid (new daemon), inbound_pid, inbound_version, outbound_pid, reason: previous-died, client_pid
client-disconnected client IPC connection broke mid-request endpoint, client_pid, client_version, client_binary_path, cause, detail

Plus client_version + client_binary_path enrichment on every spawn-attempt (CLI-emitted) and spawn (daemon-emitted) row — single source: core::lifecycle::client_meta().

Acceptance (issue checklist)

  • daemon-died with matching reason — emitted by CLI on takeover via emit_takeover_lifecycle_events. Self-emitted died-idle / died-shutdown paths unchanged.
  • Linked daemon-died / pipe-handover with PID join — daemon-died.pid == pipe-handover.outbound_pid, daemon-died.replaced_by_pid == pipe-handover.inbound_pid. See test emit_takeover_lifecycle_events_writes_linked_pair.
  • client-disconnected at point of failure with cause — emitted in run_ephemeral_attempt (per-attempt) and cmd_compile's Failed arm (persistent-session).
  • client_version + client_binary_path on every spawn-attempt and spawn line — wired in 3 call sites (runtime.rs, commands/daemon.rs, bin/zccache-daemon.rs).
  • Schema backward-compatible — additive only; envelope unchanged.
  • Doc block describing schema — module doc in core/lifecycle.rs includes the event table + a six-row forensic walkthrough using the issue's verbatim repro.

TDD trail

5 RED→GREEN unit tests in core/lifecycle.rs::tests:

  • new_event_constants_match_schema — pins wire strings for daemon-died / pipe-handover / client-disconnected.
  • new_reason_and_cause_constants_match_schema — pins all 4 new reasons + 4 new causes.
  • client_meta_returns_version_and_binary_path — binary_path is never empty.
  • write_event_round_trips_new_daemon_died_takeover_event — wire shape of daemon-died including envelope-pid override.
  • emit_takeover_lifecycle_events_writes_linked_pair — pins acceptance Fix cross-platform path handling in linker detection #2's structural join.

Test plan

  • soldr cargo test -p zccache --lib core::lifecycle — 11/11 pass (5 new + 6 existing)
  • soldr cargo test -p zccache --lib cli::commands::wrap::ipc — 11/11 pass (no regressions on the retry/wedge suite)
  • soldr cargo test -p zccache --lib — 1780/1780 pass
  • soldr cargo fmt --all -- --check
  • soldr cargo clippy -p zccache --all-targets -- -D warnings
  • CI green across Linux / macOS / Windows
  • Manual validation (per /clud-fix step 7): inspect ~/.zccache/logs/daemon-lifecycle.log after a zccache stop + spawn cycle and confirm the linked daemon-died + pipe-handover + enriched spawn rows appear with PID join intact.

Out of scope (tracked separately)

  • The structural fix for the underlying collision — hashing (binary_path, version) into the pipe-name suffix so coexisting versions land on distinct pipes — warrants its own issue. This PR makes the collision visible.
  • The duplicated stop_stale_daemon / spawn_and_wait between cli/runtime.rs and cli/commands/daemon.rs is preserved; both arms now emit the linked events identically. Unifying them is a separate refactor.

Refs

🤖 Generated with Claude Code

…d lifecycle events (#755)

Closes #755.

Extends `daemon-lifecycle.log` with three new JSONL event types and
two new client-meta fields on every spawn-attempt / spawn row, so the
two-versions-on-one-pipe wedge — fbuild's bundled 1.12.4 vs. PyPI's
1.12.5, both racing for the same Windows named pipe — becomes
reconstructable from a single `grep` instead of by-hand timestamp
matching.

## Schema additions (all additive; existing tooling keeps working)

* `daemon-died` — emitted by the CLI after `stop_stale_daemon`
  successfully kills a predecessor. Envelope `pid` is overridden to
  the dying daemon's PID; carries `reason: takeover`,
  `replaced_by_pid`, `replaced_by_version`. Self-emitted
  `died-idle` / `died-shutdown` continue to fire from the daemon
  unchanged.
* `pipe-handover` — emitted alongside `daemon-died` when the
  new daemon's PID is observed post-bind. Envelope `pid` is the new
  daemon's PID; carries `inbound_pid`, `inbound_version`,
  `outbound_pid`, `reason: previous-died`.
* `client-disconnected` — emitted at the point a client's IPC
  connection breaks (`cause: comm-error` / `pipe-closed-mid-write`).
  Pre-fix this dropout was only visible one round-trip later as the
  next `spawn-attempt`'s `reason: replaced-comm-error`.
* `client_version` + `client_binary_path` on every `spawn-attempt`
  (CLI-emitted) and `spawn` (daemon-emitted) row — distinguishes
  fbuild's bundled binary from a PyPI install when both share an
  endpoint. Single source: `core::lifecycle::client_meta()`.

## TDD trail

RED before, GREEN after — see `core/lifecycle.rs` tests for the
schema-pinning suite and the `emit_takeover_lifecycle_events` round-
trip that verifies the `outbound_pid` ↔ `inbound_pid` join the
schema doc instructs operators to grep against:

  * `new_event_constants_match_schema` — pins the wire strings.
  * `new_reason_and_cause_constants_match_schema` — pins reason +
    cause strings.
  * `client_meta_returns_version_and_binary_path` — pins the
    helper's contract (binary_path never empty).
  * `write_event_round_trips_new_daemon_died_takeover_event` — pins
    the wire shape of `daemon-died`, including envelope-pid override
    and `replaced_by_*` fields.
  * `emit_takeover_lifecycle_events_writes_linked_pair` — pins
    acceptance #2's structural join (`died.pid == handover.outbound_pid`
    and `died.replaced_by_pid == handover.inbound_pid`).

## Acceptance coverage (issue checklist)

* [x] daemon-died with matching `reason` — emitted by CLI on takeover
  via `emit_takeover_lifecycle_events`. Self-emitted `died-idle` /
  `died-shutdown` paths unchanged.
* [x] Linked daemon-died / pipe-handover with PID join — see the
  round-trip test above.
* [x] client-disconnected at point of failure with `cause` — emitted
  in `run_ephemeral_attempt` and `cmd_compile`'s Failed arm.
* [x] `client_version` + `client_binary_path` on every spawn-attempt
  and spawn line — wired in 3 call sites (runtime.rs, commands/daemon.rs,
  bin/zccache-daemon.rs).
* [x] Schema backward-compatible — additive only; envelope fields
  unchanged; the writer preserves any key the caller passes.
* [x] Doc block describing schema with forensic walkthrough — module
  doc in `core/lifecycle.rs` includes the event table + the six-row
  walkthrough from the issue's repro.

## Out of scope (tracked separately)

* The structural fix for the underlying collision — hashing
  `(binary_path, version)` into the pipe-name suffix so coexisting
  versions land on distinct pipes — warrants its own issue. This PR is
  about making the collision *visible* in the meantime.
* The duplicated `stop_stale_daemon` / `spawn_and_wait` between
  `cli/runtime.rs` and `cli/commands/daemon.rs` is preserved; both
  arms now emit the linked events identically. Unifying them is a
  separate refactor.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit ba34247 into main Jun 15, 2026
26 checks passed
@zackees
zackees deleted the feat/lifecycle-events-755 branch June 15, 2026 04:26
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.

feat(observability): expand daemon-broker JSONL lifecycle log to cover deaths + handovers

1 participant