S07-20 - Hand-off Sockets
Purpose: The 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.
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”Identity
Section titled “Identity”A hand-off socket carries a VM’s streams and name reports from its
wb-netd to wb-proxyd (S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach.). These values name it:
- the VM slot;
- the VM generation, which a start or restore raises (S04-02-vm-providerS04-02-vm-provider: VM Provider and StreamsHow wb-vmd hands guest connections and the NIC endpoint to other processes, the fixed device set of a VM, and where wb-proxyd takes a stream's identity from., “Restore”);
- the socket number, which
wb-hostdgives each new socket of the VM. It is at least 1, rises with each socket, and isn’t reused whilewb-hostdruns.
Every message about a socket names all three, except on wb-netd’s
control channel, whose VM is its own. Waits and state are keyed by
all three. A replacement in the same generation is a new socket, so
nothing meant for the old one reaches it.
Messages
Section titled “Messages”These are messages of proto/wraithbox/egress/v1/control.proto. The
last column says which ones I728I728 (closed): Hand-off socket contract of S07-20: socket number, HandoffSocketHeld, states, close reports, and a VM's endBuilds the hand-off socket contract of S07-20-handoff-sockets and the end exchange of S07-21-vm-end (#754, PR #758) in one change, before #480. adds, with the socket number in each,
and 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. has the last two.
States
Section titled “States”wb-hostd keeps one state per socket:
| State | Entered when | wb-hostd holds |
|---|---|---|
| offered | it sent HandoffSocket to wb-proxyd |
both ends |
| acknowledged | HandoffSocketAck came, and it sent wb-netd its end |
wb-netd’s end |
| serving | HandoffSocketHeld came |
nothing |
| failed | a deadline passed, or a HandoffSocketClosed came before serving |
nothing |
| closed | HandoffSocketClosed came while serving |
nothing |
| replaced | it offered a newer socket for the VM | nothing |
| ended | its wb-netd exited or was ended, or wb-hostd sent a HandoffSocketEnd that covers it |
nothing |
The last four are final. A VM has at most one socket that isn’t final. A VM starts or resumes only once its socket is serving. The build VM has no hand-off socket (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.).
Each wait from offered and from acknowledged has a deadline in code
(egress.AckTimeout), and wb-hostd holds its copies until then
(S04-12-descriptor-passingS04-12-descriptor-passing: Passing DescriptorsHow one host process passes an open socket to another: who holds it when, how the receiver shows it holds it, when the sender closes its copy, and what a lost or bad acknowledgment does.). When a socket fails, wb-hostd closes
its copies and sends a socket end for 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.), so
wb-proxyd doesn’t keep it open. At a start or restore it refuses the start with
proxyd-setup-failed and the check: ack-timeout, held-timeout, or
handoff-closed. For a running VM, “Who a failure is charged to”
says what it does.
Notices for another socket
Section titled “Notices for another socket”wb-hostd sorts each HandoffSocketAck, HandoffSocketHeld and
HandoffSocketClosed by the socket it names:
- Stale: the socket is in a final state.
wb-hostdlogs it withhandoff-notice-stale, rate-limited per VM, and ignores it. - Refused: the sender wasn’t given the socket under that
generation, the socket is older than the VM’s last 16, or its state
doesn’t wait for it, as for a second one of its kind even on a
final socket (SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.). From
wb-proxydthat is a crash, and it ends awb-netd(S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., “Control channels”).
A notice never fails or ends a socket other than the one it names. So
an old socket’s notice can’t end its replacement’s wb-netd. A socket
that failed by its deadline holds nothing back, as the next one has a
new number. HandoffSocketEnded is never stale (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.).
wb-proxyd’s end
Section titled “wb-proxyd’s end”wb-proxyd checks a HandoffSocket as S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach. (“From
wb-hostd”) says. With the socket it accepts, in this order, it:
- closes the VM’s old socket and every stream that came on it;
- clears the VM’s state when the message is fresh (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., “Lifetime”);
- sends its version record on the new socket;
- sends
HandoffSocketAck; - starts the socket’s reader.
So no HandoffSocketClosed for the socket comes before its
acknowledgment. If step 3 fails, it closes the socket and sends
HandoffSocketClosed instead of the acknowledgment.
A close never waits on a write to a peer. A write in progress on a
stream or a socket that closes ends with an error at once. So the
acknowledgment deadline covers these steps alone, and a wb-netd that
stops reading can’t make another VM’s socket miss it.
A HandoffSocketClosed or HandoffSocketEnded that wb-proxyd can’t
send ends its control channel, as a write that fails does
(S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., “Control channels”). So no socket it closed goes
unreported.
wb-netd’s end
Section titled “wb-netd’s end”wb-netd checks its HandoffSocket as S04-07-supervisionS04-07-supervision: SupervisionWho starts and restarts each host process, what happens when wb-hostd stops or the bundle is upgraded, and daemon outages. (“New
hand-off sockets”) says. Once it holds the end and sent its version
record on it, it sends HandoffSocketHeld with the generation and
number. It sends nothing for an end it refuses or can’t send that
record on. A newer end replaces the old one, whose streams it resets
(handoff-socket-ended).
Isolation between VMs
Section titled “Isolation between VMs”No fault on a socket ends wb-proxyd’s control channel. It ends for a
fault in a message from wb-hostd: its form, its socket type, its VM
slot, its generation or its number, as S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach. (“From
wb-hostd”) lists them (I576I576 (closed): wb-proxyd: one VM's failed hand-off socket ends the control channel for every VMIn wb-proxyd's hand-off receiver (#492, PR #574), a failure on one VM's new hand-off socket ends the whole control channel, and with it every VM's sockets and streams.). wb-hostd is the trusted core, so such
a fault is a bug in it. It also ends for wb-proxyd’s own faults on
the channel: a notice wb-hostd refuses (“Notices for another
socket”), or one it can’t send (“wb-proxyd’s end”).
Anything that goes wrong on a socket after wb-proxyd accepted it
closes that socket only, with its streams. wb-proxyd reports it in
one HandoffSocketClosed, and other VMs’ sockets go on.
Closing a socket
Section titled “Closing a socket”wb-proxyd closes a VM’s socket, with every stream that came on it,
for one of these rules:
| Rule | Check | Cause | Charged to |
|---|---|---|---|
name-report-malformed |
message-form, name-form, synthetic-range |
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., “Malformed reports” | wb-netd |
stream-reset-unsent |
buffer-full, deadline |
a StreamReset it can’t send, for want of room (ENOBUFS, EAGAIN) or by its deadline (S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach., “Resets”) |
wb-netd |
handoff-socket-ended |
peer-closed, control-cut |
wb-netd closed or shut down its end, a StreamReset’s send failed with an error the other rows don’t name (such as EINVAL or EDESTADDRREQ), or wb-netd sent control data that was cut |
wb-netd |
handoff-socket-ended |
receive-failed, version-record |
a receive failed with an error, or step 3 above failed | wb-proxyd |
handoff-socket-ended |
send-failed |
a StreamReset’s send failed with EBADF, ENOMEM, ENOTSOCK or EFAULT, faults of wb-proxyd or the host |
wb-proxyd |
For each, it sends one HandoffSocketClosed with the rule and the
check, for the VM, generation and number. wb-netd resets every
stream of a socket that closed (handoff-socket-ended). A socket that
is replaced or ended sends no HandoffSocketClosed.
Who a failure is charged to
Section titled “Who a failure is charged to”A guest can cause each failure charged to wb-netd, through a
wb-netd it compromised or one it slows down. For one on a running VM,
wb-hostd ends the wb-netd the socket was given to, with
handoff-netd-ended and the
rule or check as the cause. The exit counts toward wb-netd’s restart
limit (S04-07-supervisionS04-07-supervision: SupervisionWho starts and restarts each host process, what happens when wb-hostd stops or the bundle is upgraded, and daemon outages., “Restarting a daemon”). A held-timeout is
charged the same way, as wb-netd withheld its acknowledgment.
A failure charged to wb-proxyd is a fault of wb-proxyd or the host,
which no wb-netd can cause. For one on a running VM, wb-hostd ends
wb-proxyd with handoff-proxyd-ended and the check. An ack-timeout
is charged the same way. The exit counts toward wb-proxyd’s restart
limit, and never toward a wb-netd’s.
wb-proxyd raises its descriptor limit at its start to cover every
descriptor the wb-netds of all VM slots can make it hold at once. Per
slot that is its hand-off socket, three for each stream (DescriptorsPerStream),
one for each message read but not yet decided under S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach. (“Caps”),
and the most descriptors one message holds (S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach., “Message form”).
A margin in code covers its own. If it can’t, it logs proxyd-descriptor-limit and
exits, as wb-netd does for a failed start check (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.). So
one VM at its caps can’t make the other’s records arrive at a full
descriptor table.
Generations and restarts
Section titled “Generations and restarts”| Event | Generation | New socket, with a new number | Fresh |
|---|---|---|---|
| a start that isn’t a restore | new | for the VM | yes |
| a restore | new | for the VM, with a new wb-netd (S04-02-vm-providerS04-02-vm-provider: VM Provider and StreamsHow wb-vmd hands guest connections and the NIC endpoint to other processes, the fixed device set of a VM, and where wb-proxyd takes a stream's identity from., “Restore”) |
no |
a wb-netd restart |
kept | for the VM | no |
a wb-proxyd restart |
kept | for every running VM | no |
| a new active period | kept | none: ActivePeriodStart only |
no |
A socket for a kept generation replaces the old one. After a
wb-proxyd restart it holds no socket, and each VM’s first sets the
generation and number it holds. 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. (“Lifetime”) says
which HandoffSocket is fresh.
Stream bounds
Section titled “Stream bounds”Each stream’s socket is bounded in time where it can stall:
wb-netdkeeps its copy of the end it passed to the hold bound (S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach., “Transport”,stream-hold-expired).wb-netdresets a stream whose guest takes no bytes within a bound in code (guest-write-timeout). That covers a guest that advertises a zero window.wb-proxydbounds each write to a stream’s socket with a deadline in code, longer thanwb-netd’s guest bound. When it passes, it resets the stream and closes its upstream connection (stream-write-timeout). That covers awb-netdthat stops reading.- At the first end of a stream’s socket,
wb-proxydcloses upstream, or half-closes it for the guest’s FIN. A raw or pass relay also waits forwb-netd’s close while it doesn’t read the socket, and drops the bytes not yet relayed (S12-01-platform-interfacesS12-01-platform-interfaces: Platform InterfacesHow platform-specific code is isolated behind interfaces, and what each host OS uses for each., “Socket hang-up”). When the wait fails, it resets the stream.
A stream isn’t bounded in time while neither side sends, or while a raw or pass relay’s write blocks after upstream ended. Inspected streams have their own timeouts, but an inspected host’s WebSocket relay has no write bound upstream (I980I980 (open): wb-proxyd: bound a relay's write upstream once its stream socket's writes are shutIn that state, if the guest has filled the relay toward an upstream that doesn't read, the relay blocks in its write upstream, and wb-netd's close of the socket isn't seen.). Such a stream holds its place under S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach. (“Caps”) and S07-02-packet-pathS07-02-packet-path: Packet PathHow wb-netd carries the guest's frames: the packet transport, the stack, the link filter, its caps, addressing, the MTU and connections. (“Per-VM caps”).
A decision about a stream, a name report or a socket is an egress
decision (SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter., every egress decision is recorded on the host).
The process that makes it sends it on the VM’s event channel with its
rule, rate-limited per rule (S07-02-packet-pathS07-02-packet-path: Packet PathHow wb-netd carries the guest's frames: the packet transport, the stack, the link filter, its caps, addressing, the MTU and connections., “Events and rate
limits”). That includes wb-netd’s hand-off sender. A decision’s record
is queued before the bytes it allows are forwarded.
| Process | Rules it records |
|---|---|
wb-netd |
handoff-send-failed, handoff-unavailable, handoff-socket-refused, stream-refused, stream-reset, guest-write-timeout, guest-write-failed, proxyd-stream-read-failed, handoff-socket-ended, proxyd-message-refused |
wb-proxyd |
handoff-socket-refused, name-report-refused, stream-handoff-refused, fdchan-fd-table-full, address-conflict, stream-write-timeout, stream-hangup-wait-failed, stream-end-unrecorded, and each rule of “Closing a socket” |
wb-hostd |
proxyd-setup-failed, handoff-netd-ended, handoff-proxyd-ended, handoff-end-timeout, handoff-end-read-timeout, proxyd-records-lost |
wb-hostd writes its own decisions to the audit log itself. Some rules go only to the
daemon log of the process that logs them, because they decide nothing about a guest’s
traffic. wb-hostd logs handoff-notice-stale and handoff-stop-end-skipped. wb-netd
logs stream-hold-expired and stream-reset-unknown. wb-proxyd logs
handoff-socket-end, vm-fresh-start, active-period-start, stream-peer-closed and
wildcard-name-rewritten. proxyd-descriptor-limit is a start check of wb-proxyd. Its
log line reaches wb-hostd on the log pipe, and the exit counts toward the restart limit.
Two processes record handoff-socket-ended and
handoff-socket-refused, each with its own meaning. The record’s
sender, which wb-hostd stamps from the channel, tells them apart,
so a reader keys on the sender and the rule together. A wb-netd can
only send records about its own VM. So a compromised one can suppress
its own refusals, but not a decision of wb-proxyd or wb-hostd.
Decisions
Section titled “Decisions”A number for each socket
Section titled “A number for each socket”wb-hostd numbers each hand-off socket, and every message about one
names it.
- Why: a replacement has the same VM and generation as the socket it replaces, so a late notice of the old one could end the new one.
- Rejected: a new generation for each socket. The generation then stops meaning one run of the VM.
- Decided: I728I728 (closed): Hand-off socket contract of S07-20: socket number, HandoffSocketHeld, states, close reports, and a VM's endBuilds the hand-off socket contract of S07-20-handoff-sockets and the end exchange of S07-21-vm-end (#754, PR #758) in one change, before #480. (2026-11-10).
wb-netd acknowledges its end
Section titled “wb-netd acknowledges its end”- Why:
wb-hostdmust keep its copy untilwb-netdholds it (S04-12-descriptor-passingS04-12-descriptor-passing: Passing DescriptorsHow one host process passes an open socket to another: who holds it when, how the receiver shows it holds it, when the sender closes its copy, and what a lost or bad acknowledgment does.), and start the VM only once both ends are held. - Rejected: start the VM once
wb-netd’s end is sent. The end could arrive dead, and the VM would run without egress. - Decided: I729I729 (closed): wb-netd can't acknowledge that it holds its end of the hand-off socketFollow-up from the security review of #727 (F2), for #637. (2026-11-10), built with I728I728 (closed): Hand-off socket contract of S07-20: socket number, HandoffSocketHeld, states, close reports, and a VM's endBuilds the hand-off socket contract of S07-20-handoff-sockets and the end exchange of S07-21-vm-end (#754, PR #758) in one change, before #480..
A socket’s failure stays with its VM
Section titled “A socket’s failure stays with its VM”After wb-proxyd accepts a socket, a failure on it closes that socket
only and is reported. wb-hostd ends the daemon the failure is charged
to. No fault on a socket ends the control channel.
- Why: one
wb-proxydserves every VM (T14-shared-proxydT14-shared-proxyd: One proxy process serves both VMsOne wb-proxyd serves the work VM and the isolated VM (S04-architecture, "Processes").). A socket fault a guest can cause is the doing of one VM’swb-netd. Reporting it letswb-hostdend thatwb-netdinstead of leaving a VM without egress and without a record. - Rejected:
- End the control channel on any socket failure, as for a refused
HandoffSocket(option B). Every VM then loses its network for one VM’s fault. - Close the socket and tell no one (option C).
wb-hostdthen doesn’t know the VM has no egress, and no audit record says why.
- End the control channel on any socket failure, as for a refused
- 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), 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..
I576I576 (closed): wb-proxyd: one VM's failed hand-off socket ends the control channel for every VMIn wb-proxyd's hand-off receiver (#492, PR #574), a failure on one VM's new hand-off socket ends the whole control channel, and with it every VM's sockets and streams. decided the refused
HandoffSocket(2026-11-07), and I571I571 (closed): egress contract: HandoffSocketClosed rule for a StreamReset that can't be sentPR #570 (#491) added a rule to S07-05-stream-hand-off, "Resets": when a StreamReset send fails (ENOBUFS or past its deadline), wb-proxyd closes the VM's hand-off socket before the stream's socket, and wb-netd resets… an unsent reset (2026-11-10).
Status: Draft