The daemon spine
A surface in a browser tab dies with the tab. A surface in a daemon outlives every client that connects to it, and outlives its own code. You ship a new build while a client is mid-session, and the old process still holds the socket.
The daemon stratum makes that moment safe.
ensure() and a live restart(). The frozen control-core identity is read before the versioned handshake — the version-agnostic probe that survives a skew.What a daemon must answer that a page does not
A page never has to say which version of itself you are talking to. There is one version, and it reloads. A daemon has to say it constantly, because the process a client is attached to and the build you just shipped can be different things. A client that cannot tell them apart either drops every session on an upgrade, or serves stale behaviour under the new build’s name.
So a daemon needs two things a page does not. It needs a way to say which build it is, which is what How to bake an identity covers. And it needs a small part of itself that never changes shape, so the question can be asked across a version mismatch. That part is the spine.
Why the control core is frozen
Identity is read over a version-agnostic channel, before the versioned handshake. That ordering is the whole trick. If reading a daemon’s identity required speaking its current contract, you could not read it in the one situation where you need it most. Freezing the control core and probing it before connecting lets a supervisor learn what it is looking at, then decide whether to talk to it, recycle it, or drain it.
Everything behind the spine is free to churn. The surface can grow cells, the handlers can change, the build can be replaced whole. The frozen core still answers the same question the same way. The fields it answers with are listed in the daemon reference.
What a frozen contract survives, and what it does not
The frozen contract holds within one protocol epoch, not across a change of framing. Version negotiation happens inside the protocol being replaced, so a peer from an earlier epoch cannot be asked anything at all. Its first frame does not decode. A supervisor reports that as an unspeakable protocol, never as an incompatible version, because a value carried inside a frame cannot describe a break in the frame itself.
That is why the control core’s version number stays put when the framing moves. It versions the hello payload, and the payload’s fields have not changed. A framing change is a declared flag day: you stop every old process once, and from there the frozen contract holds again.
Recycling a daemon without lying to its clients
With a stable identity and a version-agnostic probe, a live upgrade is a
decision rather than a gamble. converge reads the running identity, compares it
to the build you baked, and acts by a declared policy. The client sees a brief
reconnect, not a dropped session.
The contract is the promise the daemon keeps across that swap. A recycle may replace every byte of the process, but it must not change what the wire says without saying so. This is reactive honesty one layer down: a recovered connection must not quietly be talking to something else.
A peer whose protocol cannot be spoken is taken over, whatever the policy says. Refusing instead looks principled, because the drain verb really is unreachable. It is the wrong act: a cross-epoch upgrade then stays unconverged until a person stops the old daemon by hand.
Why a runtime fault kills the process
Every shutdown reason the daemon reports is a success except one. When the served runtime dies, the process tears down in order and then exits non-zero, because the exit code is the supervisor’s only channel for “that was a crash, not a stop”.
Logging the fault and serving on is the tempting alternative, and it produces a zombie: the process alive, the single-instance gate held, the socket answering, the runtime behind it dead. A failed poll read is already cell-local at every tick, so a dead runtime can only be structural wiring death, which does not heal by waiting.
kolu met the zombie once. A padi logged a probe timeout, kept its gate and socket, and needed an operator, where a crash would have been respawned and restored in about two seconds (kolu#2101).
Why the supervisor is a separate package
The daemon code and the supervising code are split into two packages, and the split is load-bearing. A supervisor runs in the client and must never be able to change what a daemon restart loads, so it is kept out of the daemon’s hashed closure. The package boundary is the hash boundary. A supervisor edit cannot look like a new daemon build, because the supervisor is not in the build id.
A supervisor is also written in Effect with no Promise-shaped twin. It composes its boot, its recycle and its drain into one fiber tree. A boot that loses a race, a restart you abandoned and a drain past its ceiling each tear their own work down instead of running on unobserved.
Why the framework takes values, not loose fields
Three small shapes in this stratum follow one rule: make the wrong combination impossible to write rather than forbidden in prose.
- A daemon’s home is a primitive, not a convenience. The daemon and the supervisor both take a home and derive the gate and the socket from it, so loose path strings never cross from your code into the framework. A command line override is absorbed into the home, never sprinkled at call sites.
- Launch mode and environment inheritance are one union field, so “inherit the parent environment on a normal launch” is a type error instead of an invariant you have to remember.
- A drain hook that refuses is a defect rather than a member error. The frozen fragment declares no error schema, because its shape is not a consumer’s to widen, and an undeclared throw stays a defect instead of posing as something a supervisor could narrow on and handle.
A daemon is not a fleet
Long-lived and runs-on-other-machines look like they travel together. They do not. kaval is a daemon on your own machine: one process, no ssh, no map. It needs everything in this stratum and none of the multi-host one. The spine is what a daemon needs in order to be recycled honestly. Where the daemon runs is a separate question.
What freezing costs you
Freezing a control core commits you to a shape for good, because the recycle story depends on old and new builds agreeing how to ask who they are. Change that, and you break the one channel meant to survive change.
The stratum takes a small permanent rigidity at the core in exchange for freedom to replace everything around it. For a process upgraded under load without dropping its clients, that is the trade worth making, and the narrowness of the frozen part keeps the price low.