Skip to content

sandbox/v1: a Release frame frees a workspace key on the worker (part of #338) - #949

Merged
pdettori merged 3 commits into
rossoctl:mainfrom
webchang:pr/i338-release-frame
Nov 20, 2026
Merged

pdettori merged 3 commits into
rossoctl:mainfrom
webchang:pr/i338-release-frame

Conversation

@webchang

Copy link
Copy Markdown
Member

Summary

The worker half of #338's explicit release, per the answers on #338: a dedicated Release frame (not the lease op sandbox_deleted) with an ack from the worker; the busy rule kept, but the workspace freed when the Exec ends; new Execs for a released key refused. Who sends it (the relay, on a sandbox's or session's end) comes in follow-up PRs, so this one changes no behavior until a relay sends the frame.

What changes

  • Wire (additive). ServerFrame.release = ReleaseFrame{ctl_id, workspace_key}; WorkerFrame.release_result = ReleaseResult{ctl_id, outcome, error}; ReleaseOutcome = RELEASED | KEPT_BUSY | UNKNOWN_KEY. A worker that serves it advertises sbx:release-v1 in Hello.capabilities (both tiers), so a relay can send it only where it is understood. The proto comments give the error forms a sender acts on (release_unsupported and a refused key: don't retry; busy and anything else: retry, idle reclaim stays the backstop) and the sender contract: send it only at the owner's terminal end, since the harness uses the session id as workspace_key and a release before then locks a resumable session out for WorkspaceIdle. Stubs regenerated with buf generate; buf breaking against main passes.
  • Session. A Releaser runner interface. A release runs off the receive loop like LeaseControl (bounded at 32 in flight, busy: past it) and is answered as release_result; a runner without it answers release_unsupported:.
  • microVM worker (vmpool). Pool.Release frees the run's standbys and workspace (Reclaim's steps, under one lock hold) and marks the key released in the same critical section. An Exec racing it is either already using the run (kept_busy, below) or refused: at ExecPhased's early check, or, if it passed that check before the release, where it would create the run again (runAtLocked), so it cannot re-create a released run with an empty workspace. The destroys and the tree removal go to the reclaim goroutine, off both the relay's call and an Exec's unwind; with that queue full (or the pool closed) the batch runs inline after the lock is released, as the sweep's does.
    • An idle run: released.
    • A busy run (an Exec in flight, a warming, a live lease): kept_busy. Its standbys go at once, and no standby is restored for it (scheduleReplenishLocked and replenishOne skip a released run; a warming in flight at the release destroys its VM, and a warming that fails frees the run at once). Its workspace goes when the run is no longer busy, from the Exec's own unwind (after its VM is destroyed and its gate opened; a no-lock check when no release is pending) or, after a lease ends, the next sweep. Not at WorkspaceIdle.
    • A key the pool holds nothing for: unknown_key, refused all the same (a release that overtakes a session's first Exec still stops it).
    • An Exec for a released key is refused released: … (counted as RefuseReleased). Releases are counted by outcome in Stats.Releases; a refused Release call (an invalid key) is the call's error, not counted as an Exec refusal.
  • Container worker (WorkspaceRunner). The same outcomes and refusal, with its detach-then-remove pattern (tombstone naming shared with the sweep; the removal after a busy command runs off the Exec's goroutine). A key this process has not run is unknown_key and its directory is left alone, for the reason the sweep does not adopt directories (Root is also the shared workspace); the startup sweep is a separate follow-up. A release skips the sweep's live-cwd check (fix(remote-worker): remove an empty per-session workspace no process is in #872) on purpose: that check protects a session still going, and the release says its owner has ended. A symlinked session directory loses the link, never its target.
  • How long a released key is refused: WorkspaceIdle (SH_WORKSPACE_IDLE), on both tiers. By then idle reclaim would have removed the workspace anyway, so a later Exec is in the same position as one after an idle reclaim (and the harness's reset marker reports it). The released set is pruned by the sweep, so it is bounded by the release rate times WorkspaceIdle.
  • Pool.Reclaim's comment no longer says reclaiming "costs a re-converge, never data"; P4 microVM tier: WorkspaceIdle=30min deletes a HITL session's workspace mid-session, silently #338 showed it can cost the workspace.
  • The P4 spec's §4.4 and §9 note the worker half.

Tests

The new tests exercise new API, so before this change they do not build; with it:

vmpool, review regressions two Execs in flight, a release (kept_busy), the first ends, past ReplenishDelay: no VM restored; a release during a replenishment's warm: the warmed VM is destroyed and the run freed; a release during a warm that then fails: the run is freed at once, with no sweep tick; an Exec that passed the early check with the release landing before its acquire: refused released, no run re-created (all four fail without the fix)
vmpool idle release → released, workspace gone, Exec refused released (counted); release during an Exec → kept_busy, workspace kept, freed when the Exec returns with no clock advance; unknown key → unknown_key, still refused; second release → unknown_key; refused only for WorkspaceIdle, then accepted and pruned; invalid and empty keys refused; a live lease → kept_busy, freed by the sweep after the lease ends; Runner.Release maps outcomes to the wire
container tier idle release removes the directory and refuses the key without re-creating it; release during a running command → kept_busy, removed when it returns; unknown key leaves an untracked directory alone and is refused; idempotent, bounded by Idle, invalid key refused; a symlinked session directory: the link goes, its target's files survive (fails if the release resolved the link first)
session the frame reaches the Releaser with its key and is acked under its ctl_id; a Releaser error goes back as error with outcome UNSPECIFIED; a runner without it answers release_unsupported
end to end over the Attach contract on the microVM worker: an Exec, a release (released), then an Exec refused released: with nothing re-made in the workspace root
wire ReleaseFrame, ReleaseResult and the oneof members round-trip; ServerFrame.release is field 5 and WorkerFrame.release_result field 8; the outcome values
capabilities every vmpool worker advertises sbx:release-v1 once, never passing on a manifest's copy; the container worker advertises it after workspace-subdir

go vet ./... and go test ./... pass in remote-worker/ and gen/go/; go test -race passes on internal/vmpool, internal/exec, internal/session, cmd/worker and cmd/microvm-worker; buf lint passes and buf generate leaves no drift; sandbox-client, k8s-sandbox and sandbox-relay typecheck against the new stubs.

Not run yet: Release on real Firecracker. The KVM gates (gates_*_kvm_test.go) need /dev/kvm and a golden snapshot, which CI's runners and macOS don't have, so this PR's tests use the fake launcher; the release path on a real microVM host is untested here.

For review

  • A released lease. kept_busy for a live lease frees the workspace at the next sweep after the lease ends (within ReclaimScanInterval), not at the lease end itself. Without a sandbox_deleted to end it, a leased workspace waits for the lease's own idle expiry before that sweep frees it.
  • The refusal window is WorkspaceIdle on both tiers, which is why the sender contract above matters: a release sent before a session's terminal end would lock it out for that long. A fixed, shorter tombstone time is the alternative if a long WorkspaceIdle (8 h on the installers) keeps too many keys.

Part of #338
Part of #879

Assisted-By: Claude Code

…h tiers

The worker half of rossoctl#338's explicit release. pdettori's answer on rossoctl#338: a dedicated
Release frame (not the lease op sandbox_deleted), with an ack from the worker; keep
the busy rule but free the workspace when the Exec ends; refuse new Execs for a
released key.

- proto (additive): ServerFrame.release = ReleaseFrame{ctl_id, workspace_key};
  WorkerFrame.release_result = ReleaseResult{ctl_id, outcome, error};
  ReleaseOutcome RELEASED | KEPT_BUSY | UNKNOWN_KEY. A worker that serves it
  advertises sbx:release-v1 in Hello (both tiers). The comments give the error
  forms a sender acts on and the sender contract (only at the owner's terminal
  end: the harness's workspace_key is the session id). Stubs regenerated (buf).
- session: a Releaser runner interface; Release runs off the receive loop like
  LeaseControl (releaseCap 32, busy past it) and is acked as release_result; a
  runner without it answers release_unsupported.
- vmpool: Pool.Release frees the run's standbys and workspace (Reclaim's steps,
  under one lock hold) and marks the key released in the same critical section.
  An Exec racing it either already uses the run (kept_busy) or is refused, at
  ExecPhased's early check or where it would create the run again (runAtLocked),
  so it cannot re-create a released run. A kept_busy run gets no new standby
  (scheduleReplenishLocked, replenishOne; a warming in flight destroys its VM,
  and one that fails frees the run at once),
  and its workspace is freed when it is no longer busy (the Exec's own unwind,
  a no-lock check when no release is pending; or the next sweep after a lease
  ends), not at WorkspaceIdle. Destroys and tree removal go to the reclaim
  goroutine (inline after the lock is released if its queue is full, as the
  sweep's are). An Exec for a released key is refused "released: ..."
  (RefuseReleased) for WorkspaceIdle; the set is pruned by the sweep. Releases
  are counted by outcome in Stats.Releases.
- container tier (WorkspaceRunner): the same outcomes and refusal; the removal
  after a busy command runs off the Exec's goroutine; tombstone naming shared
  with Sweep; a key this process has not run is unknown_key and its directory
  is left alone (Root is also the shared workspace); a symlinked session
  directory loses the link, never its target.
- Pool.Reclaim's and the sweep's comments no longer say reclaiming "never"
  costs data (rossoctl#338).
- The P4 spec's §4.4 and §9 note the worker half.

Part of rossoctl#338
Part of rossoctl#879

Assisted-By: Claude Code
Signed-off-by: Rong Chang <[email protected]>
Four manual-only gates for rossoctl#338's worker-side Release, on the lease-pool gate's
real Firecracker launcher (pooled VM cgroups under a gate-private parent whose
cleanup reports a leaked VM), with the sweep and idle timers set an hour out so
only a Release, or an Exec's unwind after one, can free anything:

- TestGateReleaseOfAnIdleRunFreesItsVMsAndWorkspace: both standbys' jail,
  sockets, cgroup and VMM, and the workspace and its image, gone within 10 s;
  Stats ActiveRuns 0, StandbysResident 0, Releases[released] 1.
- TestGateReleaseDuringAnExecIsKeptBusyThenFreed: kept_busy with a command
  running; the standbys go, the workspace and the running VM stay, the command
  ends normally (exit 0, "done"), then its unwind frees the VM and workspace.
- TestGateExecAfterReleaseIsRefused: Execs after a release (and on an unknown
  key released first) are refused released, restore no VM and re-create no
  workspace; Refusals[released] 2.
- TestGateKeptBusyReleaseRestoresNoStandby (review M1 on real VMs): A running,
  B queued on the run's gate, a kept_busy release; StandbysResident stays 0 and
  restores grow by at most B's own, through 5 x ReplenishDelay after A ends.

Each starts with requireKVM and is listed in manualOnlyGates; without /dev/kvm
they skip.

Part of rossoctl#338

Assisted-By: Claude Code
Signed-off-by: Rong Chang <[email protected]>
… empty

On bm1 two Release gates failed only on "lease cgroup .../pool-0 still present":
a per-exec VM's cgroup is a POOLED slot that cgroupPool returns to the idle pool,
empty but kept, unlike a lease's retired cgroup, so requireLeaseVMGone's "cgroup
absent" check doesn't apply to standbys. requirePooledVMGone keeps the VMM-pid,
jail and socket checks and requires the cgroup empty (cgroup.procs has no pid)
or absent, naming the leftover cgroup's pids when it fails.

Part of rossoctl#338

Assisted-By: Claude Code
Signed-off-by: Rong Chang <[email protected]>
@webchang

Copy link
Copy Markdown
Member Author

Release on real Firecracker: the KVM gates pass on a bare-metal KVM host.

  • Two test-only commits on top: 088a521c adds gates_release_kvm_test.go, four gates (each requireKVM(t), listed in manualOnlyGates, so CI skips them), and 97ff67c5 makes the two standby gates accept a pooled cgroup that's emptied and kept for reuse (a per-exec VM's slot goes back to the cgroup pool, unlike a lease's retired cgroup); on failure they name the leftover cgroup and its cgroup.procs.
  • At 97ff67c5, all four pass on real VMs: TestGateReleaseOfAnIdleRunFreesItsVMsAndWorkspace, TestGateReleaseDuringAnExecIsKeptBusyThenFreed, TestGateExecAfterReleaseIsRefused, TestGateKeptBusyReleaseRestoresNoStandby (VMM pids, jails, sockets and the workspace gone; no standby restored for a released key).
  • The existing vmpool KVM gates also pass on this branch's code (29 pass, one expected skip with no CA). Without -race there (no compiler on the host); the race detector runs cover vmpool, exec, session and both worker commands locally.

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — sandbox/v1: a Release frame frees a workspace key on the worker (part of #338)

The wire change is additive and both tiers implement the same contract, which is what makes this reviewable as one thing rather than two.

  • Proto. ServerFrame.release is field 5 and WorkerFrame.release_result field 8, and the contract test pins the tags (0x2a/0x42) and the enum values, so a renumbering cannot slip through. A worker that predates it drops the unknown oneof member; a relay that never sends it leaves idle reclaim as the only release. sbx:release-v1 is stripped from any manifest copy and added by both Hello builders (cmd/worker, vmpool.HelloCapabilities), so a relay has one thing to gate on.
  • Session layer. One bounded slot pool (32) across the connection, refusals answered through trySend at once (release_unsupported, busy), an admitted call off the receive loop through sendLate; the result carries the runner's error with outcome UNSPECIFIED, and frameRef names the ctl_id so a late or duplicate answer is visible in a log.
  • Container tier. The released marker is refused before the Exec takes the run's slot; the busy case marks the run and the Exec's own unwind detaches and removes off its goroutine (so a big tree does not delay the End); detachLocked treats a vanished directory as already free; the sweep prunes the same markers, so the set is bounded by rate × Idle.
  • microVM tier. The released map lives under p.mu with the refusals, and runAtLocked re-checks it where a run would be created — the race the early check cannot cover — so an Exec that passed the fast path cannot re-create an empty workspace. pendingReleases keeps the per-Exec releaseIfPending lock-free when nothing is pending, and every path that drops a run goes through dropRunLocked, so the count stays exact. Warmers are stopped, a VM a Release raced during a warm is destroyed rather than kept as a standby, and the sweep reclaims a marked run regardless of either idle threshold. Counters and Stats.Releases are additive.
  • Tests pin the interesting races: the ExecPhased/Release interleaving with the test seam, a lease-held run freed when the lease ends, a warming run, a failed warming, and the KVM gates listed as manual with their prerequisites, as the pool's other gates are.

The inline comment is about the container tier's release error path, where a failed detach is reported as RELEASED.

Checks 18/18 green. Author: webchang (MEMBER — maintainer). Three commits, signed off.

tomb := w.detachLocked(key, dir)
w.mu.Unlock()
removeTomb(tomb)
return pb.ReleaseOutcome_RELEASE_OUTCOME_RELEASED, nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. detachLocked returns "" for a rename that failed for any reason other than ENOENT (it logs and keeps the key tracked, so the sweep retries), and Release then answers RELEASE_OUTCOME_RELEASED. The wire contract says RELEASED means "the standbys and the workspace are freed", and lists a filesystem error under the generic error string ("the worker failed …; retry"). pool.Release in vmpool already does the other thing — detachRunLocked's error is returned and the runner maps it to UNSPECIFIED + error — so the two tiers disagree on the same failure. Returning the detach error here (with the outcome left UNSPECIFIED, as release() already does for any error) would make the answer honest without giving up the retry: the key is refused either way, and the sweep still finishes the job.

@pdettori
pdettori merged commit 39cbf76 into rossoctl:main Nov 20, 2026
18 checks passed
pdettori pushed a commit that referenced this pull request Nov 20, 2026
…kspace at its end

The client half of #338's release, on the worker Release frame (stacked on #949):

- sandbox/v1: SandboxExec.Release(ReleaseRequest{sandbox_id}) -> ReleaseResponse{outcome},
  additive. Its errors are gRPC statuses a client can act on (release_unsupported and a refused
  key: don't retry; busy, a timeout, unavailable: retry; idle reclaim stays the backstop).
- sandbox-relay: authorized as an Exec is, for sandbox-token callers only: the token's worker,
  and the token's own workspace key, never one the caller names. The harness exec token is
  refused (it is unrestricted; the control plane's release comes with its own bearer). A
  ReleaseFrame goes only to a worker that advertises sbx:release-v1 (an older one drops it
  unread: FAILED_PRECONDITION release_unsupported, nothing sent); every call ends at the
  worker's answer, a 15 s timeout, or the worker going away; at most 2 in flight per sandbox.
  One audit line per call, marker sandbox_workspace_release.
- sandbox-client: SandboxExecConn.release(), under the sandbox token with the lease calls'
  token-refusal retry, not counted as use.
- mocactl: sbx rm releases every sandbox's workspace before its DELETE (after a lease
  sandbox's sandbox_deleted), best effort within the existing 15 s bound; the token for it is
  minted with activity false.
- docs: the direct-API guide's Release section, the client guide's sbx rm row, the runbook's
  audit markers.

Part of #338
Part of #879

Assisted-By: Claude Code
Signed-off-by: Rong Chang <[email protected]>
@pdettori pdettori added this to the v0.11.0 milestone Nov 20, 2026
webchang added a commit to webchang/moca that referenced this pull request Nov 20, 2026
Carries rossoctl#941-rossoctl#946, rossoctl#948, rossoctl#950 and rossoctl#338's rossoctl#949/rossoctl#951 (API 1.33.0).
One conflict: docs/operate/sandbox-service/install.md's settings
table; upstream's table kept (its rossoctl#945 SBX_STORAGE_CLASS wording,
the OIDC and proxy-hop rows) plus the fork's SBX_GATE_RECORD_SCHEMA
row. The fork-only set is unchanged: the same 30 files.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit that referenced this pull request Nov 20, 2026
…r, not RELEASED

Follow-up to #949 (#338): the container tier's detachLocked logged a rename that failed
for any reason other than ENOENT and returned "", so Release answered RELEASED with the
directory still there. The wire contract says RELEASED means the workspace is freed, and
a filesystem error is the error string a sender retries on; vmpool's Release already
answers that failure so. detachLocked now logs the detail (path and OS error, as before)
and returns a fixed, path-free error, since it travels to the client and the relay's
audit: Release answers UNSPECIFIED plus it (the key is refused all the same, and stays
tracked, so a later Release or the sweep finishes the job), and the release after a busy
Exec logs it, as vmpool does.

Assisted-By: Claude Code
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit that referenced this pull request Nov 20, 2026
remote-worker: a container Release whose rename fails answers an error, not RELEASED (follow-up to #949)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants