S04-07 - Supervision
Purpose: Who starts and restarts each host process, what happens when
wb-hostd stops or the bundle is upgraded, and daemon outages.
Supervision and failure
Section titled “Supervision and failure”The service manager keeps wb-hostd running, and wb-hostd keeps the
other host processes running. A failure stops egress and never opens
it. The work a guest can make the host do is bounded (SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter.,
SEC11-root-gains-nothingSEC11-root-gains-nothing: Guest root is not a privilegeFull control of the guest grants no control over enforcement, secrets, or policy., SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.,
NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.).
Who starts whom
Section titled “Who starts whom”- The service manager (S12-01-platform-interfacesS12-01-platform-interfaces: Platform InterfacesHow platform-specific code is isolated behind interfaces, and what each host OS uses for each., “Service manager”) runs
wb-hostdand no other Wraith Box process. It startswb-hostdat login, and again whenever it exits. On macOS the LaunchAgent setsKeepAliveand doesn’t setAbandonProcessGroup. wb-hostdsupervises every other host process. It decides whenwb-proxydand each VM’swb-vmdandwb-netdstart, and whether one starts again after it exits. On macOS it starts them throughwb-launcher(S04-03-self-sandboxingS04-03-self-sandboxing: Self-SandboxingHow each host daemon confines itself at startup, and the wb-launcher that starts confined programs on macOS., “Each host daemon is self-sandboxed”). Elsewhere it starts them itself.wb-launcheris the parent of the programs it starts, so only it sees their wait status. It reports each exit towb-hostdon its request channel, in one fixed-format message. The message holds the program table entry, the instance ID it returned when it started the process, and the exit code or the signal. An instance ID is never reused while thatwb-launcherruns. It never restarts anything itself. It also sends the kill of awb-diskfmtit started, with its process group, whenwb-hostdasks, and only before it reaps the program (S04-04-vm-processesS04-04-vm-processes: Per-VM ProcessesOne wb-vmd for each VM, the wb-vmd-layer entry of the Claude Code layer build, the wb-vmd-recipe entry of a named image's recipe, and wb-diskfmt, which formats a VM's new data disk., “wb-diskfmt’s kill”).- The programs started for one run are never restarted:
wb-git,wb-prover,wb-guestadmin,wb-build-ssh,wb-diskfmt,wb-release-checkandwb-download.wb-release-checkhas an instance cap of one per build. A run whose program exits before it reports a result fails, and the caller gets the exit reason (S08-workspace-and-gitS08-workspace-and-git: Workspace and Git Round TripHow code gets into the guest and how the agent's work gets back out, without sharing the host filesystem., S09-policy-credentials-auditS09-policy-credentials-audit: Policy, Credentials, Certificates and AuditWhere policy comes from, how secrets are held, how TLS inspection is trusted, and what is recorded., S15-least-privilegeS15-least-privilege: Least Privilege on the HostThe security design for SEC12-least-privilege: which rights Wraith Box takes on the host, where credentials are held, and how each host process gets only the credentials it needs, for only as long as it needs them.).
When wb-hostd stops
Section titled “When wb-hostd stops”VMs stop with wb-hostd, for V1V1-initial: Initial versionThe first version: what it delivers, what it leaves out, and the milestones that get there. (see “Decisions”). wb-launcher,
wb-vmd, wb-netd and wb-proxyd each inherit a control channel to
wb-hostd: a socket, never a path. End of file or an error on that
channel means wb-hostd is gone. Each of them then acts on its own:
- Each
wb-vmdstops its VM at once and exits. It doesn’t ask the guest to shut down, and it doesn’t save the VM. The sessions in that VM are lost. Their worktrees stay on the data disk until recovery at the next connection to the VM (S06-09-session-lifecycleS06-09-session-lifecycle: Session LifecycleA session's states from wb claude to its summary, how it starts and ends, its deadlines, and when its VM may be saved.). Writes the guest flushed are on the disk (S06-05-disksS06-05-disks: DisksA VM's system disk and data disk: how the data disk keeps what the guest flushes, and how the guest mounts it.). wb-netdandwb-proxydclose every stream and exit. The guest’s only network path is gone, so egress stops (SEC05-default-denySEC05-default-deny: Default-deny egress, enforced on the hostOnly allowlisted hostnames are reachable.).wb-launchersendsSIGTERMto every program it started that still runs. It sendsSIGKILLto any left after 5 seconds, waits for them, and exits. So no oldwb-launcher,wb-netdorwb-proxydruns next to the ones a newwb-hostdstarts, and each per-run program ends with thewb-hostdthat asked for it. Awb-diskfmthas nothing to clean up. It getsSIGKILLat once, sent to its process group and to the shim before the reap, which stops eachdiskutilit ran as well.
The per-run programs don’t hold a control channel, and can’t learn
that wb-hostd has gone. wb-launcher ends them. On hosts without
wb-launcher, the service manager ends them with wb-hostd. That is
to be confirmed when those hosts are built (S12-platformsS12-platforms: PlatformsWhich host and guest operating systems Wraith Box targets, how platform-specific code is isolated, what each platform uses, and how wb works inside WSL., I176I176 (open): End per-run programs with wb-hostd on hosts without wb-launcher (Linux, Windows)Follow-up from the code re-review of #171 (#48, finding G).).
On macOS, launchd also kills the processes left in wb-hostd’s process
group when wb-hostd exits (man launchd.plist,
AbandonProcessGroup). That is a second layer. The control channel is
the rule on every host.
A new wb-hostd
Section titled “A new wb-hostd”A new wb-hostd takes over nothing. It:
- starts a new
wb-launcherand new daemons; - marks the sessions it has as starting, running, paused or ending as lost (S06-11-reconnect-and-recoveryS06-11-reconnect-and-recovery: Reconnect, Loss and RecoveryWhat happens when the host-guest link drops, when a session is lost, and how a lost session's work is recovered or discarded., “Lost”);
- starts a VM again only when a session or warm start asks for one (S06-06-devices-and-warm-startS06-06-devices-and-warm-start: Devices, Warm Start and TimeA VM's devices and resources, saving and restoring its state, and how the guest clock follows the host., “Warm start”).
A start that fails because the old VM is still stopping is a temporary
failure. wb-hostd retries it a bounded number of times, as for a
restore.
Upgrades
Section titled “Upgrades”An upgrade takes the same path as a crash:
- the installer replaces the bundle (S17-05-upgrades-and-migrationsS17-05-upgrades-and-migrations: Upgrades and MigrationsHow an upgrade replaces the bundle, and how wb-hostd moves stored data to a new version., “Upgrades”);
- the running
wb-hostdexits; - the service manager starts the new one;
- the running VMs stop, with their sessions lost.
wb-hostd notices a replaced bundle itself and restarts. It reads the
installed bundle’s build version (S17-install-and-upgradeS17-install-and-upgrade: Install, Downloads and UpgradesBuild, install, upgrade and remove a Wraith Box bundle, move its stored data to a new version, and download what an image build needs from the internet.):
- on macOS from the
WBBuildVersionkey of the app bundle’sInfo.plist; - elsewhere from the file
wraithbox-versionnext to the programs.
It reads it when a host peer reports a build version other than its own (S04-08-records-and-boundsS04-08-records-and-bounds: Records, Versions and BoundsThe records daemons send wb-hostd, the build version rules between processes, the bounds on host work a guest can cause, and logs., “Version skew”), and before it starts a daemon. Then:
- The installed version isn’t its own. It logs the rule
bundle-replacedwith both versions and exits. The service manager starts the newwb-hostd. A daemon refused this way doesn’t count as an exit toward the restart limit. - The installed version is its own, and the peer’s isn’t. The peer is refused. A daemon refused this way counts as a failed start.
- It can’t read the installed version. It logs that with the rule
bundle-version-unreadable, treats the installed version as its own, and doesn’t exit.wb statusshows it. So a damaged bundle can’t makewb-hostdexit in a loop.
Restarting a daemon
Section titled “Restarting a daemon”wb-hostd restarts wb-proxyd, and each VM’s wb-netd except the
build VM’s (“A new wb-netd”, below), after an exit it didn’t ask for.
- Backoff. It waits 0.5 seconds before the first restart, and doubles the wait after each one, up to 30 seconds.
- Giving up. After the fifth exit in 10 minutes it stops restarting that process. It logs that it gave up, with the last exit reason. So a crash a guest can cause doesn’t become a stream of fresh processes.
- After giving up. A
wb-netdit gave up on leaves its VM without network until the VM stops, and the VM’s next start gets a new one. Awb-proxydit gave up on is tried once more at the next session start in any VM. - Refusals. Once it gives up, every session start that needs the
process is refused with the rule
daemon-given-up. The refusal names the process, the VM, its last exit reason, and what starts it again: stopping the VM forwb-netd, the next session start forwb-proxyd(NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.). - No path around. The guest sees resets and refusals while a daemon is down, never a path around it. Nothing else on the host forwards guest traffic.
Until V1-M6-release-gateV1-M6-release-gate: Release gateThe Seatbelt profiles of wb-hostd and the sessions, confinement self-checks, warm start and suspend, the full conformance suite and benchmarks, packaging and upgrades. (I480I480 (open): wb-hostd daemon supervision: control channels, restarts with backoff, giving up, and process healthPackage M3.11 of docs/implementation-plan.md, part 3 of 3 (M3.11c).) none is restarted (S04-09-netd-startS04-09-netd-start: Starting `wb-netd`How wb-hostd starts and stops each VM's wb-netd, what the program inherits, its profile, and what it does before its start message., “No restart yet”).
A new wb-netd
Section titled “A new wb-netd”A new wb-netd gets the same start as the first one:
- its VM’s packet transport descriptor;
- the VM’s MAC address and leased address;
- the effective policy;
- the VM’s synthetic name mapping and its counts (“What a restart keeps”, below);
- a new hand-off socket to
wb-proxyd, except for the build VM, whosewb-netdhas none.
The guest keeps its lease, and its cached DNS answers still work.
wb-hostd never restarts the build VM’s wb-netd. When it exits, the
image build fails with its exit reason (S07-18-build-networkS07-18-build-network: Build NetworkThe build VM's network: what its wb-netd serves, the one connection to the guest's port 22, and its refusal for session VMs.).
wb-hostd keeps its copy of each VM’s packet transport descriptor only
to hand it to a new wb-netd. It holds the copy in a type that has no
read or write path. It closes it when the VM stops, and when a restore
hands over a new descriptor for a new VM generation.
What a restart keeps
Section titled “What a restart keeps”A restart doesn’t reset what bounds the guest.
wb-netdchecks and debits the VM’s wildcard budget (S07-03-dnsS07-03-dns: DNSHow wb-netd answers the guest's DNS queries: synthetic addresses, the name form, negative answers and the wildcard budget., “Wildcard budget”).wb-hostdonly keeps the count across restarts.wb-hostdalso keeps every other count S07-egress-gatewayS07-egress-gateway: Egress GatewayThe only path from a guest to any network: a userspace network stack (wb-netd) and a policy-enforcing proxy (wb-proxyd) on the host. haswb-netdorwb-proxydkeep for the active period.wb-hostdkeeps the authoritative count of pending approval requests and the rate of new ones. A newwb-netdgets both at start, with the policy (S09-10-approval-flowS09-10-approval-flow: Approval FlowHow an approval request for a name behaves, from the lookup that raises it to its answer or its expiry.).
The kept name mapping
Section titled “The kept name mapping”wb-hostd keeps each VM’s synthetic name mapping too: every live
entry, with its name, its address, and the time wb-hostd received its
last record.
- It keeps an entry until the entry’s release record arrives. It has
no clock of its own for it.
wb-netddecides when to release an address (S07-03-dnsS07-03-dns: DNSHow wb-netd answers the guest's DNS queries: synthetic addresses, the name form, negative answers and the wildcard budget., “Synthetic pool”). - It learns the mapping the way it learns the wildcard debits, from accounting records (S04-08-records-and-boundsS04-08-records-and-bounds: Records, Versions and BoundsThe records daemons send wb-hostd, the build version rules between processes, the bounds on host work a guest can cause, and logs., “Accounting and event channels”).
wb-netdsends each new or renewed entry before the DNS answer that uses it. It refuses the lookup when the write fails.wb-netdsends each release before it gives the address to another name.wb-hostdlogs a release for an address it doesn’t hold, and ignores it.- A new
wb-netdstarts with the kept entries (NetdStart). It gives none of their addresses to another name until it has released that address.
Without them, an address the guest still has cached for one name could go to another. A raw or pass-mode stream meant for the first would then reach the second.
A new wb-proxyd
Section titled “A new wb-proxyd”A new wb-proxyd has no streams. It fetches binding secrets again when
proxying needs them (S15-least-privilegeS15-least-privilege: Least Privilege on the HostThe security design for SEC12-least-privilege: which rights Wraith Box takes on the host, where credentials are held, and how each host process gets only the credentials it needs, for only as long as it needs them.).
wb-hostd hands it each running VM’s placeholder set on its control
channel, before it creates that VM’s new hand-off socket. So the
placeholder scan has every placeholder before the first stream arrives
(S09-05-credentialsS09-05-credentials: CredentialsHow credentials are stored and bound to requests, and how the model credential reaches the model API without entering the guest., “Model credential”). At each restore of a
suspended VM, wb-hostd hands back the VM’s set the same way, before
it creates the VM’s hand-off socket.
New hand-off sockets
Section titled “New hand-off sockets”A wb-netd restart gives its VM a new hand-off socket, for the same
generation. A wb-proxyd restart gives one to every running VM.
S07-20-handoff-socketsS07-20-handoff-sockets: Hand-off SocketsThe life of one VM's hand-off socket: its identity, the acknowledgments of both ends, how it closes, who a failure is charged to, what each restart does to it, and which of its decisions reach the audit log. (“Generations and restarts”) has the order and
the socket numbers.
Every wb-netd gets its end on its control channel after its start
message (S04-09-netd-startS04-09-netd-start: Starting `wb-netd`How wb-hostd starts and stops each VM's wb-netd, what the program inherits, its profile, and what it does before its start message.), in a message with exactly one descriptor
and the VM, generation and socket number. It refuses the message, with
handoff-socket-refused, when the socket type is wrong, the VM or
generation isn’t its own, or the number isn’t above the one it holds.
It then closes the descriptor and logs the refusal, and the control
channel goes on. A message with another descriptor count than one is of the wrong form:
every descriptor in it is closed, and the control channel ends.
On each new socket, wb-netd first replays the VM’s live mapping, so
that wb-proxyd has it again (S07-06-name-mappingS07-06-name-mapping: Name MappingHow wb-proxyd keeps its own checked copy of the names wb-netd gave synthetic addresses: name reports, releases, replay, lifetime, the second count of the wildcard budget, and the copy wb-hostd keeps., “Replay”).
wb-vmd and wb-vmd-install
Section titled “wb-vmd and wb-vmd-install”- A VM’s
wb-vmdisn’t restarted in a loop. When it exits, its VM has stopped with it, and the VM’s sessions are lost.wb-hostdstarts a newwb-vmdfor that VM when the VM is next needed, with the same backoff and the same limit. wb-vmd-installis never restarted. When it exits during a build, the build fails andwb-hostddeletes the build bundle (S15-04-guest-adminS15-04-guest-admin: The Guest Admin UserHow the host keeps the password of the guest admin user wbadmin, from the image build to each VM's first contact., “The build’s SSH session”). Nothing starts again until the user runs the next build.
Outages
Section titled “Outages”wb-hostd shows a native notification once per outage of a VM’s
wb-netd or wb-proxyd. It asks for nothing (SEC14-no-fake-approvalsSEC14-no-fake-approvals: Approvals cannot be spoofed by the guestApproval prompts are never rendered in the agent's terminal stream.).
It says:
- which process is down, for which VM, and why;
- how many secret store accesses the restarts caused (S15-least-privilegeS15-least-privilege: Least Privilege on the HostThe security design for SEC12-least-privilege: which rights Wraith Box takes on the host, where credentials are held, and how each host process gets only the credentials it needs, for only as long as it needs them.).
Only the 1Password backend, after V1V1-initial: Initial versionThe first version: what it delivers, what it leaves out, and the milestones that get there. (S15-02-secret-storeS15-02-secret-store: The Secret StoreWhere credentials are held: the secret store, its backends, and the guarantees a backend must give.), can prompt for those accesses. The Keychain doesn’t show a dialog in any build (S15-03-access-rulesS15-03-access-rules: Access RulesHow each host process gets only the credentials it needs, for only as long as it needs them, and which process may access which item., access rule 4).
wbin non-interactive use prints the same as onewraith box:line on its standard error.- In interactive use,
wbdoesn’t write into the agent’s terminal. The session’s summary says that its network was down, and for how long (S05-01-agent-commandsS05-01-agent-commands: Agent CommandsHow wb claude passes its arguments to Claude Code, how it runs interactive and non-interactive sessions, and what a session does., “Session behavior”). wb statusshows the outage while it lasts.
One wb-proxyd for both VMs
Section titled “One wb-proxyd for both VMs”One wb-proxyd serves both VMs. These take the network of the other VM
down too:
- a crash that a guest finds in it, until the restart;
- its given-up state;
- a blocked event channel (
event-channel-blocked) at a full audit queue; - a socket fault charged to it (
handoff-proxyd-ended); - a VM’s end it misses in time (
handoff-end-timeout,handoff-end-read-timeout); - once compromised, records of the other VM past the margin, which stop that VM (
event-budget-ignored); - the 1Password prompts its restarts cause, after V1V1-initial: Initial versionThe first version: what it delivers, what it leaves out, and the milestones that get there..
Neither a VM’s normal stop nor its stop for the audit log ends it (S07-21-vm-endS07-21-vm-end: A VM's End in wb-proxydHow wb-hostd ends a VM's hand-off sockets in the one wb-proxyd, and how the VM's last event records reach its stop record without one VM's stop or backlog taking the other VM's network down., S09-13-event-sendersS09-13-event-senders: Event SendersHow wb-hostd tells the senders of event records about the audit budgets, what it holds back, and when it stops a VM for its records.). That is a residual risk to availability, not to egress (T14-shared-proxydT14-shared-proxyd: One proxy process serves both VMsOne wb-proxyd serves the work VM and the isolated VM (S04-architecture, "Processes").).
Decisions
Section titled “Decisions”VMs stop with wb-hostd, for V1
Section titled “VMs stop with wb-hostd, for V1”- Rejected: each
wb-vmdsaves its VM and exits when it loseswb-hostd, and the newwb-hostdrestores them, so sessions pause instead of ending (B48-process-supervisionB48-process-supervision: Who restarts the host processes, and what happens to running VMs when one fails?Recommended that wb-hostd supervises the other daemons, that VMs are saved when wb-hostd stops and restored when it starts, and that every guest-facing handler gets a per-VM limit., option A). It depends on save and restore of a VM with its vsock device and network attachment (X02-warm-startX02-warm-start: Warm startMeasure time to restore a macOS guest from saved state with a vsock device and a file-handle network attachment.). It needs a bounded save on every exit path. A later version may move to it. The guest version rule (S04-08-records-and-boundsS04-08-records-and-bounds: Records, Versions and BoundsThe records daemons send wb-hostd, the build version rules between processes, the bounds on host work a guest can cause, and logs., “Version skew”) then becomes a range. - Rejected: each
wb-vmdkeeps its VM running withoutwb-hostd, and a newwb-hostdtakes them over (option B). That needs a takeover protocol, and awb-vmdoutsidewb-hostd’s process group. An upgrade replaceswb-vmdas well, so it would stop the VMs anyway. - Decided: I48I48 (closed): S04-architecture: process supervision, failure, version skew and host resource limitsS04-architecture names the processes but not how they are supervised, what happens when one fails, or how they are upgraded:, B48-process-supervisionB48-process-supervision: Who restarts the host processes, and what happens to running VMs when one fails?Recommended that wb-hostd supervises the other daemons, that VMs are saved when wb-hostd stops and restored when it starts, and that every guest-facing handler gets a per-VM limit..
Status: Draft