S06-07 - Slot Admission
Purpose: How wb-hostd admits every macOS VM it starts against the
limit of two, and lends the isolated VM’s slot to a maintenance VM.
Design
Section titled “Design”macOS runs at most two macOS guests per host (NFR05-two-macos-vmsNFR05-two-macos-vms: Platform limitmacOS permits at most two concurrently running macOS guests per host.).
wb-hostd admits every macOS VM it starts against that limit.
Guests of other operating systems are limited only by resources (NFR05-two-macos-vmsNFR05-two-macos-vms: Platform limitmacOS permits at most two concurrently running macOS guests per host.). These rules don’t apply to them.
What takes a slot
Section titled “What takes a slot”These take a slot:
- the work VM;
- the isolated VM;
- a maintenance VM: one that
wb-hostdstarts for an image rather than for a session.
The maintenance VMs of wb image build are the build VM, under the
wb-launcher entry wb-vmd-install (S06-02-image-buildS06-02-image-build: Image BuildHow wb image build makes a guest image: the build VM, its two provisioning stages, terminfo, sealing, and storage., “Built by
Wraith Box”), the Claude Code layer’s VM under wb-vmd-layer, and a
recipe’s VM under wb-vmd-recipe (S06-17-named-imagesS06-17-named-images: Named Images and RecipesThe build of a named image from a recipe on a clone of the sealed base.). All three run
in the build bundle <data>/images/macos-build.noindex
(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.).
S06-03-image-updatesS06-03-image-updates: Image UpdatesHow a VM gets a new image's system disk while its data disk and project users stay, and the guest admin password of each VM. has no boot that checks a new image before it replaces a system disk. Such a boot would be a maintenance VM too.
Once its state is saved and it has stopped, a VM doesn’t hold a slot. Xcode work takes no slot of its own (S06-04-vms-and-placementS06-04-vms-and-placement: VMs and PlacementThe work VM and the isolated VM, Xcode in them, and which VM a project's sessions run in., “Xcode in the session’s VM”).
The work VM is never moved
Section titled “The work VM is never moved”wb-hostd never saves or stops the work VM to make room. A
maintenance VM never starts while, by wb-hostd’s count, it would take
the slot the work VM needs. That holds even when the work VM isn’t
running.
So a maintenance VM runs only in the isolated VM’s slot, and at most one runs at a time.
Lending the isolated slot
Section titled “Lending the isolated slot”A maintenance VM may start in two cases:
- the isolated VM isn’t running;
- the isolated VM has no session that is starting, running, paused or ending (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., “Idle suspend”).
A debug shell (wb shell) counts as a session here, as for idle
suspend. So one open in the isolated VM blocks a lend.
In the second case, wb-hostd first saves the isolated VM’s state and
stops it, as at the end of its idle period
(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 save isn’t always allowed: when the host is locked, a kill is
pending, or there is a result of processes left
(S06-10-leftover-processesS06-10-leftover-processes: Leftover ProcessesThe results of the kill of a project user, how wb-hostd accepts them, and what it does when processes are left.). wb-hostd then stops the isolated VM
cold instead. Those rules allow that without a session.
An open wb vm admin connection blocks a lend as a session does, and a
VM whose system disk the admin path marked is stopped cold, never
saved (S15-05-admin-pathS15-05-admin-path: The Admin PathHow the person at the host's terminal gets a root shell in their own guest, on a path that no agent, session, or guest process can start or reach., “Marked”).
The return
Section titled “The return”When the maintenance VM stops:
wb-hostdrestores an isolated VM it saved, under the rules of 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”.- An isolated VM it stopped cold stays stopped, until its next session starts it.
- When the isolated VM wasn’t running at the lend,
wb-hostddoesn’t start it afterward. A saved state left from an earlier idle suspend is kept unchanged for the next session.
wb-hostd logs each lend and return with the rule that allowed it.
The lent slot is reserved
Section titled “The lent slot is reserved”The lend starts when wb-hostd decides it, before it saves or stops
the isolated VM. When it ends depends on the case:
- For a VM it saved, the lend ends when the return restore succeeds.
It also ends when
wb-hostdgives up on the restore under 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”. That is after the bounded retries, not at the first temporary failure. - For a VM it stopped cold, and for an isolated VM that wasn’t running at the lend, the lend ends when the maintenance VM stops.
While the lend lasts, wb-hostd refuses every other start or restore
of the isolated VM:
- for a session;
- for a debug shell;
- for the recovery of a lost session;
- for
wb vm start.
The return restore is the one start the lend allows. So a refusal names the build, never a VM outside Wraith Box (“Other software” below).
A maintenance VM gets nothing of a session VM
Section titled “A maintenance VM gets nothing of a session VM”A maintenance VM never gets these of the work VM or the isolated VM:
- the system disk, data disk, saved state or auxiliary storage;
- the machine identifier or MAC address.
It doesn’t get a network grant or credential binding of a project (SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another.). The build makes a new VM with its own network (S06-02-image-buildS06-02-image-build: Image BuildHow wb image build makes a guest image: the build VM, its two provisioning stages, terminfo, sealing, and storage., “Built by Wraith Box”).
Its wb-vmd is confined to the build bundle. So it can’t open the
work VM’s or the isolated VM’s bundle either (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves.).
Lending moves a slot, never a VM’s disks or identity. The isolated
VM’s wb-vmd (wb-vmd-isolated) never runs the build VM.
Refusals
Section titled “Refusals”Each refusal names the rule, what holds the slots, and how to free one
(NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.). wb-hostd refuses:
- a maintenance VM, while the isolated VM has a session that is
starting, running, paused or ending, a debug shell included. The
refusal names each session with its state, the process ID of its
wb, and how it ends. The refusal ofwb vm stopdoes the same (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., “Idle suspend”); - a second maintenance VM while one runs. The refusal names the first, and how long a build takes, about 7 minutes (X17-image-buildX17-image-build: Unattended image buildCan a macOS guest installed from an Apple restore image get past Setup Assistant, with wb-guestd running as a root LaunchDaemon, without SSH, scripted clicks, or MDM?);
- any start or restore of the isolated VM while its slot is lent (“The lent slot is reserved”). The refusal names the maintenance VM, and says that the start works once the lend ends. A session isn’t queued.
Other software
Section titled “Other software”wb-hostd can’t count macOS VMs that other programs run, such as UTM,
Tart, or spike code on a development Mac (I50I50 (closed): Test infrastructure for work that needs a running macOS guestMost v1 work needs a running macOS guest to test: spikes X02-warm-start to X08-data-disk and X17-image-build to X20-shared-homebrew, the conformance suite, and the benchmarks (S11-verification-and-spikes).). It learns of them only
when starting or restoring one of its own VMs fails on the
Virtualization framework’s limit of running VMs
(VZErrorVirtualMachineLimitExceeded in VZError.h).
wb-hostd then refuses the start with vm-limit-other-software. It
matches the limit on the framework error’s code, which wb-vmd passes
on. wb then:
- says that a macOS VM outside Wraith Box holds a slot;
- lists the VMs Wraith Box runs;
- says to quit the other one.
wb-hostd doesn’t retry, and doesn’t stop one of its own VMs to make
room.
Decisions
Section titled “Decisions”The work VM keeps its slot, a maintenance VM borrows the isolated one
Section titled “The work VM keeps its slot, a maintenance VM borrows the isolated one”- Decided: I43I43 (closed): S06-vm-lifecycle: VM slot admission for image builds, updates and GUI work (NFR05-two-macos-vms)NFR05-two-macos-vms allows two running macOS guests per host, and S06-vm-lifecycle uses both: the work VM and the isolated VM. (B43-vm-slot-admissionB43-vm-slot-admission: What gets one of the two macOS VM slots when everything wants one?The work VM keeps its slot.).
Status: Draft