perf(daemon-client): reuse remote /health across CLI processes
Closed
TH
1d ago+1531+1531+0123456789012345678901234567890123456789-381-381-012345678901234567890123456789
Summary
Each CLI call to a remote daemon is a new process, so the in-memory health cache never hit. Every command paid GET /health before POST /rpc: one extra network round trip per agent step.
The usable /health answer now also lives in the client state dir. Every RPC from it carries the instance preconditions, so a replaced daemon or proxy upstream answers 409 before dispatch and the client probes again (ADR 0006, amended).
- A cached send whose connection never opened (the client's own evidence, never reply data) drops the entry; after a failure it re-runs a live
/healthcheck and is sent once more, within the remaining budget. Heartbeats included. - Any remote 5xx clears the cache, and so does a timeout whose probe finds the daemon gone. A capability that only the cache lacks is re-probed before refusal.
Before / after
session list, 10 calls through a delay proxy in front of a local HTTP daemon:
requests/call avg wall (RTT 0) avg wall (RTT 100 ms)
base 0b5627d635 2.0 (/health+/rpc) 296 ms 492 ms
head 1771b6c 1.1 (1 /health) 266 ms 378 ms
Security
- The file stores a SHA-256 digest of client version, RPC protocol, URL and token, never the token or URL. Mode 0600, atomic write.
- It is read only from a bounded regular file the user owns that nobody else can write. Links and FIFOs are a miss.
- Auth is unchanged. A client upgrade or token change is a miss.
- Open: a rollback to a release that ignores instance headers (maintainer decision).
Validation
Head 015189f: touched test files and tsc -b packages/daemon-client pass locally. CI pending.
š¤ Generated with Claude Code