Skip to content

S06-09 - Session Lifecycle

Purpose: A session’s states from wb claude to its summary, how it starts and ends, its deadlines, and when its VM may be saved.

A session runs from wb claude to its summary.

Closing the terminal ends the session. V1V1-initial: Initial versionThe first version: what it delivers, what it leaves out, and the milestones that get there. has no detach and no wb attach. A session has one client, the wb process that started it.

starting worktree, carry-in running wb relays ending WIP commit, push ended summary, exit status paused processes stopped lost wb exits 255 start refused, fails, link drops, or deadline: wb exits 255 claude starts claude exits, or hangup done, or deadline link drops back, wb there: resume back, wb gone: finish VM, wb-guestd or wb-hostd stops, or paused past 30 s VM or daemon stops recovery, discard, or deadline
Session states. A session starts, runs, and ends with a WIP commit and push. A start that fails or times out ends at once. A dropped host-guest link pauses a running session, which resumes or finishes when the link returns. A stopped VM or daemon, or a pause past 30 seconds, loses a session, and a lost session ends by recovery, by wb discard, or at its deadline.
State What holds Link drops VM or daemon stops Other exits
starting wb-hostd admits the session, starts or restores the VM, and wb-guestd creates the worktree and applies the carry-in (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.) ended, as a failed start lost running when claude starts. ended, as a failed start, on a refusal, a failure or the deadline
running claude runs, and wb relays its terminal or its streams (S05-cliS05-cli: Command Line InterfaceSpecify wb, the single user-facing command.) paused lost ending when claude exits or the client goes
paused the link is down, and the guest’s project processes are stopped (S13-01-process-hardeningS13-01-process-hardening: Layer 1: Process Hardening (v1)How wb-guestd hardens every process it starts for a project user, and how it stops and kills a project user's processes.) stays paused lost running or ending when the link returns. lost at the pause limit
ending claude has exited or was killed, and wb-guestd commits WIP and pushes (S08-03-pushesS08-03-pushes: PushesWhere the guest's pushes land, the settings receive-pack runs with, which refs a push may write, and the push at session end., “Session end”) stays ending, and finishes again when the link returns lost ended when done, or as a failure at the deadline
lost the session’s VM, its wb-guestd, or wb-hostd stopped under it ended by recovery, wb discard, wb project rm, or the deadline
ended the exit status and the summary are in wb sessions, and the returned work stays until wb land or wb discard

wb-hostd logs these in the audit log, with the rule that made each one (SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter.):

wb-hostd refuses an open out of its form with session-open-form: an agent other than claude, over 4096 arguments or 1 MiB of them, or a NUL byte. It refuses a flag not built yet with session-flag-unavailable, naming when it comes. Admission checks 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.) first. The cap of 64 sessions and shells per VM comes next, then the isolated VM’s one project. The VM’s state, the mount, and the unlock come last. Once the record exists, a refusal ends the session as a failed start. wb project place is refused with project-place-has-session, naming the live session.

Every operation under a project user’s home runs in a child process as that user, with the session’s environment allowlist (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.). These operations are:

wb-guestd, running as root, never opens a path under a project user’s home. So a project user’s .git/config or hooks never run as root.

wb-guestd starts each session through a small helper that runs as the project user. The helper:

  1. starts a new POSIX session (setsid);
  2. in interactive use, makes the PTY its controlling terminal;
  3. starts claude in a process group of its own, as the terminal’s foreground group, as a shell does for a job;
  4. waits with WUNTRACED, so it sees claude stop;
  5. reports that, and claude’s exit status, to wb-guestd.

It ignores the SIGHUP it gets when the PTY’s other end closes. So it can still report claude’s exit after a hangup.

wb shell uses the same helper, with a login zsh (zsh -l) in place of claude.

The helper is wb-guestd’s own executable, started with the one argument session-helper. wb-guestd checks that argument before any other start-up code, so a helper never updates, listens or stops processes. It starts as the project user, with the user’s ID, primary group, and no other group. It refuses to run as root. Its program starts in the user’s home directory.

Before it starts the helper, wb-guestd checks the data mount (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., “Before every session start”) and that the user is a project user it knows, not root and not in admin or wheel (SEC12-least-privilegeSEC12-least-privilege: Least privilege on the hostNo root or administrator rights at run time and no extra host user accounts.), and not locked.

The helper reports to wb-guestd, and takes its commands, in the records of S06-12-guest-agentS06-12-guest-agent: Guest AgentWhat wb-guestd, the service in the guest, does for the host, and how it updates itself. (“Session helper records”).

The session’s processes are the processes in the helper’s POSIX session. wb-guestd records that POSIX session ID in a root-owned directory on the data disk, outside every project user’s home. It uses a recorded ID only for processes whose user ID is this session’s project user. A process that leaves the POSIX session with setsid is out of the session (S13-02-filesystem-profileS13-02-filesystem-profile: Layer 2: Seatbelt Filesystem Profile (v1)The Seatbelt profile each session's process tree runs under, where it comes from, its exceptions for Xcode builds, and its known gaps., “Known gaps”).

V1-M2-walking-skeletonV1-M2-walking-skeleton: Walking skeletonwb-vmd boots a fixture VM bundle in its confined process, wb-guestd answers over vsock, a data disk made on the host holds the homes, and wb shell opens a PTY as a project user, with its output through the terminal fi… keeps the ID in memory only. The record on the data disk comes with the reports kept in the guest (below). Until then, a wb-guestd that starts again stops the project users’ processes at start (S13-01-process-hardeningS13-01-process-hardening: Layer 1: Process Hardening (v1)How wb-guestd hardens every process it starts for a project user, and how it stops and kills a project user's processes., “When the link drops”), and knows no session’s ID.

wb-hostd has wb-guestd hang up the session when:

  • wb gets SIGHUP;
  • wb’s connection to wb-hostd closes for any reason, as when wb was killed or crashed.

wb-hostd detects this by the closed connection, never by a missed heartbeat. So a wb stopped with job control keeps its session.

The hangup works like this:

  • In interactive use, wb-guestd closes its end of the session’s PTY. The guest kernel sends SIGHUP, as it does for a closed terminal.
  • Otherwise wb-guestd closes claude’s standard input.
  • Either way, wb-guestd sends the helper the hangup command, and the helper sends SIGHUP to claude’s process group.
  • A stopped group also gets SIGCONT, so the hangup is delivered.

When claude hasn’t exited 10 seconds later, wb-guestd kills the session’s processes. It kills the project user’s other processes as S13-01-process-hardeningS13-01-process-hardening: Layer 1: Process Hardening (v1)How wb-guestd hardens every process it starts for a project user, and how it stops and kills a project user's processes. says.

Either way, the session goes on to ending, as on a normal exit.

wb claude --continue then starts a new session at the host’s HEAD. It resumes the conversation (S06-08-projects-and-sessionsS06-08-projects-and-sessions: Projects and Sessions Inside a VMHow projects map onto guest users and sessions onto worktrees, and how Claude Code runs in the guest., “Conversation history”). The files the old session left uncommitted are only in its WIP commit, on its session branch.

The session ends when claude exits, or after a hangup. wb-guestd:

  1. commits and pushes WIP (S08-03-pushesS08-03-pushes: PushesWhere the guest's pushes land, the settings receive-pack runs with, which refs a push may write, and the push at session end., “Session end”);
  2. reports claude’s exit status: an exit code, or the signal that ended it.

The report is guest input (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.). wb-hostd accepts an exit code from 0 to 255, or a signal number from 1 to 64. Anything else is recorded as a failure with the rule. wb then exits as for a Wraith Box failure (S05-02-exit-status-and-signalsS05-02-exit-status-and-signals: Exit Status and SignalsWhat wb claude exits with, and what it does with each signal.).

When wb is still connected, it prints the summary and exits.

wb-guestd keeps each finished session’s report in its root-owned directory, until wb-hostd acknowledges it. The report has the exit status, and whether the WIP commit and push succeeded. wb-guestd sends it again after a reconnect. So a report lost in a dropped link still ends the session normally, not as lost.

wb-guestd deletes:

So the directory holds at most the 64 sessions of one VM.

The session’s client can go when no session of its project user is left. The report then also has a cleanup field: the result of the kill loop that followed (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.). That is clean, or the count of processes left, capped at 1001.

The summary’s commit count and its ”(+ WIP)” mark come from landing.git, not from the report.

  • A report can claim a push that wb-hostd’s receive-pack didn’t accept for that session’s branch. It is recorded as a failed push. wb exits with 255, and the rule is logged.
  • A report of nothing to commit is taken as reported.

A session’s changes stay in the guest worktree when it ends at a deadline, or when its WIP commit or push failed. The summary and wb sessions then (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.):

  • give the worktree’s path in the guest;
  • give wb shell --project P to reach it;
  • say that wb discard deletes it.

Each state that waits on the guest has a deadline on the host, counted in host time awake:

Past its deadline, wb-hostd:

  1. has wb-guestd end the session (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., “Reconnect”);
  2. records it as ended with a Wraith Box failure. wb exits with 255.

The worktree keeps its changes until wb discard. So a guest that never reports can’t hold a session, or its VM, past the deadline (SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.).

A kill of a project user (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.) has 7 minutes. They count from the kill, or from the start of ending for a kill that follows a client that went. Past that deadline, without an accepted clean result, the kill counts as 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., “Failing closed”).

The VM sleeps with the host. On wake, wb-hostd updates the guest clock (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., “Time and sleep”).

The session runs on as long as wb still has its terminal. When the host-guest link drops across the sleep, the session pauses and resumes as 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. (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., “Reconnect”) says.

wb over SSH gets SIGHUP when the SSH connection drops, and that ends the session.

The idle period 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”, runs only while the VM has no session that is starting, running, paused or ending, debug shells included. A lost or ended session doesn’t count. An open wb vm admin connection stops the idle period too (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”). So a VM is never saved for idleness with such a session in it, and no restore has a session to resume.

While a kill of a project user in the VM is pending, and after a result of processes left, the idle period doesn’t run. wb vm suspend is then refused with the reason (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 vm suspend and wb vm stop are refused while the VM has a starting, running, paused or ending session. The refusal names each such session with (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.):

  • its state;
  • the process ID of its wb;
  • how it ends: close its terminal for a running or paused session, or wait for its deadline for a starting or ending one.

wb sessions lists them.

A terminal left open on a session keeps its VM running (NFR03-footprintNFR03-footprint: FootprintIdle VMs suspend after a configurable period.). It also holds the VM’s slot (NFR05-two-macos-vmsNFR05-two-macos-vms: Platform limitmacOS permits at most two concurrently running macOS guests per host.).

Each session has its own ID, worktree, client, exit status, and summary (FR05-parallel-sessionsFR05-parallel-sessions: Parallel sessionsSeveral sessions can run at once, in the same project and across projects.). Ending one session doesn’t touch the others.

The one exception is the end of its project’s last session. Then all the project user’s processes are killed, and the user is locked (S13-01-process-hardeningS13-01-process-hardening: Layer 1: Process Hardening (v1)How wb-guestd hardens every process it starts for a project user, and how it stops and kills a project user's processes.).

Closing the terminal ends the session, and V1V1-initial: Initial versionThe first version: what it delivers, what it leaves out, and the milestones that get there. has no wb attach.

  • Rejected: saving a VM whose sessions have been quiet. That needs a restore on the next keystroke, and turns every restore into a pause.

Status: Draft