How to recycle and upgrade a daemon
When you ship a new daemon build, an older one may still be
holding the gate with clients attached. converge() detects the mismatch,
decides what to do by your declared policy, and enacts it through the endpoint.
The client sees no more than a brief reconnect.
1. Declare a policy
A ConvergencePolicy<Cap> holds everything a consumer declares about
convergence: who I am (baked), how I converge per trigger (contract skew
against same-contract build change), and, when drainable, the Cap-gated
drainBudget. Two shapes ship:
recycle-on-skew(kaval): a mismatched daemon is killed and respawned. It has no budget, because a policy that is not drainable cannot spell one.drain-newer-else-refuse(padi): the daemon with the strictly newer contract version wins. It is drained in and replaces the old one; an older or equal contract refuses. The budget survives adopts, so a cross-supervisor fight terminates ascross-supervisorrather than looping.
2. Converge before you connect
State the policy (and probe) on createEndpoint, then call converge(endpoint),
the only boot verb:
// The only boot verb — policy (who I am + how I converge) is fixed on the endpoint.
const outcome = yield* converge(endpoint);
converge runs three steps:
- probe the running identity, over the version-agnostic channel, so a skew cannot hide it;
- decide with the pure
decidefold (no I/O, just the policy table); - enact through the endpoint’s private boot methods, budget-gated when drainable.
It returns a ConvergenceOutcome with an optional ConvergenceAnomaly. Wire
that to your own status surface and logs. Connector arms use convergeAdmit
with the same policy.
probeDaemonIdentity({ capability: "not-drainable" })(socketPath) owns a fresh
local socket dial; the drainable form also requires drainCeilingMs. A
connector that has already dialled a combined client uses
probeDaemonIdentityFrom instead, supplying that client, its disposer, and the
transport’s stronger exit oracle. Both forms assemble the same
ConvergenceProbe, and the client form never turns a lost link into daemon
absence.
3. What a recycle does
When the decision is to recycle, the endpoint:
- reads the gate under the pid-first law (
readGateIdentityplus injectedreadProcessIdentity, with a ±2 s start-time match) to see whether a live survivor holds it. A one-field gate falls back toisHolderLiveand a socket accept. - kills it, then runs
waitForPidGone, so the respawn never races a live gate holder. - calls
driver.spawn(), a survivable spawn (systemd-run --user, or detached+unref). - runs
waitForSocket, thenconnect()and the identity handshake.
A connected client has its daemon replaced underneath, and its session loop
reconnects, re-running converge, with an onStatus(degraded) bridging the
gap. recycle(endpoint, steps) wraps this as
capture → drain → recycle → reattach, so a session can be captured and
re-adopted live across the kill.