fix(daemon-client): decide that a daemon is unresponsive with the same three probes on every path

Merged
TH
7d ago
+54-32

Problem

Two paths end a daemon because it answers nothing, and they required different evidence:

  • ensureDaemon() asks three liveness probes (1 s each, 200 ms apart) before it force-retires a daemon.
  • A timed-out reset-eligible request (daemon-client-timeout.ts) asked one probe, then sent SIGKILL.

One missed probe is the weaker evidence on the path that kills without a grace period. On an overloaded shared host a healthy daemon can miss a single 1 s window.

Change

answersLivenessProbe moves from daemon-client-ensure.ts into daemon-client-liveness-probe.ts, with its probe count and gap, and takes the same session parameter as one probe. Both paths call it. The copy and its two constants in daemon-client-ensure.ts are deleted.

Cost: a timed-out request against a daemon that answers nothing reports its error up to 2.4 s later (three windows and two gaps, 3.4 s in total, was 1 s). A daemon that answers the first probe costs the same as before. The verdict stays far under the shortest reset-eligible request envelope (90 s default).

Evidence

  • daemon-client-timeout-route.test.ts: the rows "resets a daemon that answers no probe endpoint" and "an attach client leaves a daemon that answers no probe running" now observe 4 connections (the request and three probes). They fail on main's code, which makes 2.
  • packages/daemon-client: 39 files, 348 tests pass. Typecheck, lint, the production-exports audit, the eager-closure gate and the layering scan pass. No allowlist, baseline or budget rows.
  • The pin test still holds one probe window an order of magnitude under the envelope. I did not export the whole verdict budget to pin it directly: the production-exports audit refuses an export that only a test reads.

Size

Production: +24 āˆ’16, net +8 lines (the helper's doc comment and the session parameter). No new module on an entry closure, so the built CLI startup cost does not change.

Note: this touches lines next to #4806 in daemon-client-ensure.ts; whichever merges second needs a trivial rebase.

Part of #4649.

šŸ¤– Generated with Claude Code


Autofix with [code]smith
Open in [code]smith Ā· Need help on this PR? Tag @codesmith-bot with what you need.