Repository navigation
sandbox/v1: a Release frame frees a workspace key on the worker (part of #338) - #949
Conversation
…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]>
|
Release on real Firecracker: the KVM gates pass on a bare-metal KVM host.
|
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
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.releaseis field 5 andWorkerFrame.release_resultfield 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-v1is 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
trySendat once (release_unsupported,busy), an admitted call off the receive loop throughsendLate; the result carries the runner's error with outcome UNSPECIFIED, andframeRefnames 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);
detachLockedtreats 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.muwith the refusals, andrunAtLockedre-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.pendingReleaseskeeps the per-ExecreleaseIfPendinglock-free when nothing is pending, and every path that drops a run goes throughdropRunLocked, 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 andStats.Releasesare 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 |
There was a problem hiding this comment.
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.
…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]>
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]>
…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]>
remote-worker: a container Release whose rename fails answers an error, not RELEASED (follow-up to #949)
Summary
The worker half of #338's explicit release, per the answers on #338: a dedicated
Releaseframe (not the lease opsandbox_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
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 advertisessbx:release-v1inHello.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_unsupportedand a refused key: don't retry;busyand 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 asworkspace_keyand a release before then locks a resumable session out forWorkspaceIdle. Stubs regenerated withbuf generate;buf breakingagainst main passes.Releaserrunner interface. A release runs off the receive loop likeLeaseControl(bounded at 32 in flight,busy:past it) and is answered asrelease_result; a runner without it answersrelease_unsupported:.vmpool).Pool.Releasefrees 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: atExecPhased'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.released.kept_busy. Its standbys go at once, and no standby is restored for it (scheduleReplenishLockedandreplenishOneskip 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 atWorkspaceIdle.unknown_key, refused all the same (a release that overtakes a session's first Exec still stops it).released: …(counted asRefuseReleased). Releases are counted by outcome inStats.Releases; a refused Release call (an invalid key) is the call's error, not counted as an Exec refusal.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 isunknown_keyand 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.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 timesWorkspaceIdle.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.Tests
The new tests exercise new API, so before this change they do not build; with it:
kept_busy), the first ends, pastReplenishDelay: 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: refusedreleased, no run re-created (all four fail without the fix)released, workspace gone, Exec refusedreleased(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 forWorkspaceIdle, then accepted and pruned; invalid and empty keys refused; a live lease →kept_busy, freed by the sweep after the lease ends;Runner.Releasemaps outcomes to the wirekept_busy, removed when it returns; unknown key leaves an untracked directory alone and is refused; idempotent, bounded byIdle, invalid key refused; a symlinked session directory: the link goes, its target's files survive (fails if the release resolved the link first)Releaserwith its key and is acked under itsctl_id; aReleasererror goes back aserrorwith outcomeUNSPECIFIED; a runner without it answersrelease_unsupportedreleased), then an Exec refusedreleased:with nothing re-made in the workspace rootReleaseFrame,ReleaseResultand the oneof members round-trip;ServerFrame.releaseis field 5 andWorkerFrame.release_resultfield 8; the outcome valuessbx:release-v1once, never passing on a manifest's copy; the container worker advertises it afterworkspace-subdirgo vet ./...andgo test ./...pass inremote-worker/andgen/go/;go test -racepasses oninternal/vmpool,internal/exec,internal/session,cmd/workerandcmd/microvm-worker;buf lintpasses andbuf generateleaves no drift;sandbox-client,k8s-sandboxandsandbox-relaytypecheck against the new stubs.Not run yet: Release on real Firecracker. The KVM gates (
gates_*_kvm_test.go) need/dev/kvmand 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
kept_busyfor a live lease frees the workspace at the next sweep after the lease ends (withinReclaimScanInterval), not at the lease end itself. Without asandbox_deletedto end it, a leased workspace waits for the lease's own idle expiry before that sweep frees it.WorkspaceIdleon 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 longWorkspaceIdle(8 h on the installers) keeps too many keys.Part of #338
Part of #879
Assisted-By: Claude Code