S07-21 - A VM's End in wb-proxyd
Purpose: How 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.
Requirements: SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another., SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter., SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.
Tests: C02-streams-and-tlsC02-streams-and-tls: Streams, TLS, and the Inspection CAThe test cases for the streams wb-proxyd takes over: the hand-off from wb-netd, the first-byte and TLS checks, upstream addresses, the HTTP request form, and the inspection CA's leaves, rotation, and keys., C11-host-daemonsC11-host-daemons: Host Daemons, Audit, and DisksThe test cases for the host daemons' own checks: wb-vmd's device set and slots, the image build bundle, supervision, the accounting and event channels, the daemon log pipes, the audit writer, free space, and the data…
Design
Section titled “Design”The end exchange
Section titled “The end exchange”HandoffSocketEnd names the VM, the generation, a socket number, and
whether the VM stops. wb-proxyd closes every socket of the VM and
generation whose number is at or below the one named, with every
stream that came on them. It answers HandoffSocketEnded with the same
four values, also when it holds none of those sockets.
There are two kinds, and wb-hostd sends each at most once:
- A socket end doesn’t stop the VM.
wb-hostdsends it for a socket that wasn’t final before one of these: it fails by a deadline, or itswb-netdexits or is ended. It names that socket.wb-proxydruns step 1 of “Order at a VM stop” only, and its answer has the sequence 0.wb-hostdrefuses any other value. - A stop end says the VM stops.
wb-hostdsends it once for the generation when the VM stops, is saved, or its start is refused. It names the highest numberwb-hostdoffered for the generation, whatever each socket’s state.wb-proxydruns every step.
wb-hostd keeps one wait for each end it sent, keyed by VM,
generation, number and the stop flag, apart from the socket states of
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.. So a socket end and a stop end for the same
number have their own waits. That covers these cases:
- a socket fails, and then the VM stops;
- a start’s socket fails, and the start is refused;
- a
wb-netdexits just before its VM’s stop end is sent.
When an end is sent, each socket it covers that isn’t final becomes
ended. A socket already final keeps its state. A socket end is sent
only for a socket that wasn’t final before, so a wb-netd that exits
after the stop end causes none. HandoffSocketEnded is never stale. One that matches no
wait is refused, as a crash of wb-proxyd (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., “Control
channels”).
Order at a VM stop
Section titled “Order at a VM stop”wb-hostd sends the stop end before it stops the VM’s wb-netd
(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., “Stop”). A HandoffSocketClosed for peer-closed
that the stop then causes names an ended socket, so it is stale and
charges no one. wb-netd sees its socket close first, so an honest
wb-netd records handoff-socket-ended at each stop. The stop record
after it tells that apart from a failure. No socket of the generation
follows its stop end: wb-hostd refuses one with vm-stopped.
wb-proxyd then, in this order:
- closes the VM’s sockets and streams up to the number, and cancels each of their handlers’ upstream dial, name lookup and secret fetch in progress;
- waits for every running handler of the VM and generation to queue its last event record, those of streams an earlier socket end closed included, at most a bound in code shorter than the answer’s deadline;
- counts each handler that didn’t in a run with the rule
stream-end-unrecorded, and queues the counts of the VM’s open runs; - answers
HandoffSocketEndedwith the sequence number of its last queued event record that names the VM and generation, or 0 when it sent none.
Step 2 can’t wait on a peer, because a close ends every write in
progress (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., “wb-proxyd’s end”). No step waits
on the event channel’s delivery or on room in its queue. The records
of a close go into the queue even at its cap, as 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.
(“The hold”) bounds them. So an honest wb-proxyd answers within the
deadline whether or not wb-hostd reads its channel.
After its stop answer, wb-proxyd queues no record that names the VM
and generation, and it records nothing for an ended generation. A
handler that finishes late drops its record, and the
stream-end-unrecorded count stands for it. After wb-hostd sends the
stop end, it sends wb-proxyd no PolicyChange or ActivePeriodStart
for the VM, and no message that names the ended generation. The
placeholder set, CaIssue and CaRemove name no generation, and
CaSet and CaAccept name a newer one, so they stay allowed.
Events in band
Section titled “Events in band”Each event record has a sequence number (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.,
“Event records”). wb-hostd reads wb-proxyd’s channel up to the
sequence the stop answer names, then ends the VM’s events (Hub.End).
So the VM’s stop record has every count wb-proxyd sent, and no record
of the VM comes after its end.
wb-hostd refuses a stop answer whose sequence is below the one of
the last record that names the VM and generation it read from that
wb-proxyd. A refused answer is a crash of wb-proxyd. A high
sequence isn’t refused, because the read below ends at its own bound.
That read runs under the stop allowance of 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. (“At a VM’s
stop”). It reads past the hold. Its bound is as many records as the
allowance gives a wb-netd, plus the records the closes of every VM’s
sockets may queue past the cap. So the read’s last sequence is the last one read when the
answer came plus that bound. Records of another VM read under it count
toward that VM’s budget as usual. The read ends at the first of:
- the named sequence;
- the read’s last sequence, logged with
event-stop-allowance; - the end of
wb-proxyd’s channel; - a deadline in code, which ends
wb-proxydwithhandoff-end-read-timeout. The exit counts toward its restart limit.
wb-hostd then ends the VM’s events. When the read stopped short, the
stop record names the rule, the named sequence and the last one read,
so a reader knows the records between them are missing.
When wb-proxyd may name a generation
Section titled “When wb-proxyd may name a generation”wb-proxyd may name a VM and generation on its event channel from
before the first HandoffSocket of that generation up to the sequence
its stop answer names. wb-hostd opens the window before it sends that
HandoffSocket.
A record that names a generation above its slot’s last ended
generation that doesn’t run, as one whose window hasn’t opened, ends
wb-proxyd with event-record-invalid.
A record that names a generation at or below its slot’s last ended
generation is late: it comes after a read that stopped short, or above
the named sequence. wb-hostd keeps only the last ended generation of
each slot, so a lower generation that never ran is late too. So is a
record of a VM whose stop wb-hostd decided for the margin
(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., “The margin”).
A late record doesn’t end wb-proxyd, because that would cost every
other VM its network (T14-shared-proxydT14-shared-proxyd: One proxy process serves both VMsOne wb-proxyd serves the work VM and the isolated VM (S04-architecture, "Processes").). wb-hostd writes it as its
own record, and logs it with event-vm-ended. Per end of the VM’s slot
it writes at most the stop allowance of late records, and drops each
one past that, logged with event-vm-ended. It writes the count of the
drops as one audit record at the slot’s next end (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.,
“Late records”).
A late record gets no budget notice and counts toward no margin. So a late record fails closed for its own VM only, and a high named sequence gives no open license to name a stopped VM.
Deadline
Section titled “Deadline”The answer has the same deadline as an acknowledgment (egress.AckTimeout).
It covers steps 1 to 3, which close sockets and streams and queue
records. If it passes, wb-hostd ends wb-proxyd with
handoff-end-timeout, and the exit counts toward its restart limit.
When wb-proxyd exits
Section titled “When wb-proxyd exits”A wait ends with the wb-proxyd it was sent to. When wb-proxyd exits
or is ended, every wait for an end it didn’t answer ends too. For a
stop end, wb-hostd reads what is left on the channel under the
allowance and ends the VM’s events. A new wb-proxyd never gets an end
for a socket it wasn’t given: wb-hostd logs
handoff-stop-end-skipped and sends none. While no wb-proxyd runs, a
VM’s stop sends no end and ends the VM’s events at once.
When wb-proxyd exits or is ended with records unsent, those records
are lost. wb-hostd writes one audit record for each VM it served,
with the rule proxyd-records-lost, the exit’s rule, and the last
sequence it read. A VM’s stop record names the same.
One VM doesn’t wait on another
Section titled “One VM doesn’t wait on another”wb-proxyd decides the messages about one VM in order. It runs each
VM’s end and each socket’s steps apart from its control loop. So a wait
for one VM never delays a message about another VM.
wb-hostd keeps each wait on its own as well. After a wb-proxyd
restart, each running VM’s new socket goes through its states alone.
A wb-netd that withholds HandoffSocketHeld fails only its own VM’s
socket.
No hold for a budget
Section titled “No hold for a budget”A VM’s budget never holds wb-proxyd’s channel: a sender that ignores
it has its own VM stopped (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., “The margin”). Only a
full audit queue holds the channel, and the end doesn’t depend on that
hold. wb-proxyd queues the end’s records past its cap and answers
without waiting on delivery, and wb-hostd reads past the hold under
the allowance.
Decisions
Section titled “Decisions”A VM’s end is acknowledged
Section titled “A VM’s end is acknowledged”- Why: a
wb-proxydrecord for a VM whose events have ended can’t be attributed. Ending them after the answer keeps every count in the stop record. - Rejected: end the VM’s events at once. A record
wb-proxydstill queued for the VM would then name a VM that isn’t running. - Decided: I512I512 (closed): wb-proxyd: the program, its confinement and start, hand-off sockets per VM, and restartsPackage M3.12 of docs/implementation-plan.md, part 3 of 4 (M3.12c)., decision 4 (2026-10-31).
The end is its own exchange, before wb-netd stops
Section titled “The end is its own exchange, before wb-netd stops”- Why: an end that waits on a socket’s state is lost when that
socket was closed or failed first.
wb-hostdthen ends the sharedwb-proxydfor a VM that stopped normally (I754I754 (closed): S07-05-stream-hand-off and S04: settle the hand-off contract end to end (descriptor passing, acks, identity, close, restarts, audit)The hand-off of sockets and streams between host processes keeps getting patched one review at a time:, code and security reviews). - Rejected: answer the end only for a socket that is serving. A
malformed report or a refused start then ends
wb-proxydat the stop. - Decided: I754I754 (closed): S07-05-stream-hand-off and S04: settle the hand-off contract end to end (descriptor passing, acks, identity, close, restarts, audit)The hand-off of sockets and streams between host processes keeps getting patched one review at a time: (2026-11-11), with option A of B754-handoff-contractB754-handoff-contract: What happens to one VM's hand-off socket, from its creation to its end?S04-12-descriptor-passing, S07-20-handoff-sockets and S07-21-vm-end settle the hand-off contract in one place..
The stop flag keys the wait
Section titled “The stop flag keys the wait”- Why: a socket end and the stop end can name the same number at once. With the flag in the key and the answer, each answer finds its own wait.
- Rejected: let the stop end take over a pending socket end. Then
wb-hostdmust tell which answer came for which, and the late one is a refused answer that endswb-proxyd. - Decided: I754I754 (closed): S07-05-stream-hand-off and S04: settle the hand-off contract end to end (descriptor passing, acks, identity, close, restarts, audit)The hand-off of sockets and streams between host processes keeps getting patched one review at a time: (2026-11-11), round 3 of the reviews.
The answer names the last event record
Section titled “The answer names the last event record”- Why: the control channel and the event channel have no order
between them. Naming the sequence puts the end in the event stream,
so
wb-hostdends the VM’s events after its last record and not before. - Rejected:
- Answer once the counts are queued, and end the VM’s events at the
answer. A queued record then names a stopped VM, and
event-record-invalidendswb-proxyd. - Answer once the counts are delivered. A held channel then delays
the answer, and
handoff-end-timeoutendswb-proxyd.
- Answer once the counts are queued, and end the VM’s events at the
answer. A queued record then names a stopped VM, and
- Decided: I754I754 (closed): S07-05-stream-hand-off and S04: settle the hand-off contract end to end (descriptor passing, acks, identity, close, restarts, audit)The hand-off of sockets and streams between host processes keeps getting patched one review at a time: (2026-11-11), with option A of B754-handoff-contractB754-handoff-contract: What happens to one VM's hand-off socket, from its creation to its end?S04-12-descriptor-passing, S07-20-handoff-sockets and S07-21-vm-end settle the hand-off contract in one place..
The end’s records may pass the queue’s cap
Section titled “The end’s records may pass the queue’s cap”- Why: at its cap, a queue waits for
wb-hostdto read. A hold for a full audit queue would then make an honestwb-proxydmiss the answer’s deadline. The per-VM caps bound what the end adds. - Rejected: read past the hold from when the end is sent. Records of the other VM could still fill the queue first.
- Decided: I754I754 (closed): S07-05-stream-hand-off and S04: settle the hand-off contract end to end (descriptor passing, acks, identity, close, restarts, audit)The hand-off of sockets and streams between host processes keeps getting patched one review at a time: (2026-11-11), round 3 of the reviews.
A late record is written, not refused
Section titled “A late record is written, not refused”- Why: a queued record of a VM that was just stopped would
otherwise end
wb-proxydwithevent-record-invalid, and with it every other VM’s network (T14-shared-proxydT14-shared-proxyd: One proxy process serves both VMsOne wb-proxyd serves the work VM and the isolated VM (S04-architecture, "Processes").). Writing it keeps the record, and the stop allowance per end of the slot bounds what a buggy or compromisedwb-proxydadds. - Rejected: drop late records at once. An honest
wb-proxydthat queued them after a short read would lose them for no reason. - Decided: I741I741 (closed): Audit event holds: one VM's budget can hold the shared wb-proxyd channel for every VMFollow-up from the reviews of #740 (#541): code review F3, security review F1. (2026-11-10).
Status: Draft