fix(daemon-client): a restart probe cut short by the RPC deadline reports the timeout

Merged
OK
2mo ago
+73-19

Summary

daemon-client-transport.test.ts > "a delayed restart health probe stops at the RPC deadline without retrying" flakes on CI. It failed the Coverage job on #3055 with Remote daemon is unavailable where it expects daemon_transport_timeout, and it fails the same way locally under load.

This is a real race in the client, not just in the test. After a remote_instance_mismatch, retryAfterRemoteInstanceMismatch probes /health with exactly the RPC's remaining budget, then checks performance.now() against the deadline. Node timers start from the event loop's cached clock, which can lag behind real time. So the probe's timer can expire while performance.now() is still short of the deadline. The remaining budget reads positive, and the client reports the daemon as unavailable when the RPC actually timed out.

The fix:

  • readDaemonHttpHealth now marks a result that ran out of time (timedOut: true), from either its socket timeout or its abort signal.
  • The restart retry reports the RPC timeout when the probe timed out and the RPC deadline had capped its budget.
  • A probe that fails fast (for example, connection refused) still reports Remote daemon is unavailable.

Wire ledger: RemoteDaemonHealth and readDaemonHttpHealth got new digests and new acks. timedOut is client-local: it is never read from a /health payload, and the request and the accepted payload fields are unchanged. The two acks it replaces had expired with the digests.

Validation

  • A new test freezes performance.now(), so the probe's timeout lands before the deadline. On main it fails with the exact CI error (Remote daemon is unavailable); with this change it passes.
  • daemon-client-transport.test.ts 20x in a row with one yes per core: 20/20 green.
  • pnpm check:affected --run: passed. pnpm test:coverage:ci: passed. Changed-line gate: passed (100%, 10/10).