Skip to content

sandboxd: add read-only catalog volumes - #69

Merged
CMGS merged 27 commits into
mainfrom
codex/issue-66-volumes-v1
Aug 12, 2026
Merged

CMGS merged 27 commits into
mainfrom
codex/issue-66-volumes-v1

Conversation

@CMGS

@CMGS CMGS commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #66.

Summary

Read-only shared-dataset volumes. The operator declares a node-local catalog of
disk images; a claim names up to eight of them with optional guest mount paths;
sandboxd takes a compatible warm VM or provisions one, hot-attaches each image
read-only, resolves the device through sysfs, mounts it read-only, persists the
applied entries, and only then returns the claim.

  • Catalog and access: volumes entries carry a name, an absolute host path,
    a direct-I/O mode, and an optional tenant access list validated at config load.
    A forbidden name and an unknown name return byte-identical errors, so the
    catalog cannot be enumerated by probing.
  • Warm consumption: a volume claim may take an ordinary warm VM — hot-attach
    works on a clone-restored guest. Volume work sits between the warm pop and
    finalize; the volume-less warm path keeps its shape behind an empty-slice
    check. Setup failure destroys the VM and the pool refills normally.
  • Device discovery without udev: the attach name appears as
    /sys/block/<dev>/serial, so discovery scans sysfs under a bounded deadline
    rather than waiting on a udev symlink.
  • Placement: NodeState.Volumes advertises locally available names.
    VolumeCandidates/VolumeOwners require every requested name, never a union;
    a promoted-template volume claim prefers the advertised template∩volume
    intersection and carries require_promoted on its single no_redirect retry
    so a stale name is never reinterpreted as a cold image.
  • Capture and persistence: applied names and mounts persist with the claim;
    hibernate, fork, checkpoint and promote refuse a volume-bearing claim with a
    dedicated sentinel mapped to 409, and the idle sweep skips it. Capture
    decisions read the persisted state, so a catalog or ACL edit cannot make a
    still-attached claim capturable.
  • Surfaces: GET /v1/volumes returns the scope-filtered fleet catalog with
    holder counts and no host paths; the claim usage event and SandboxSummary
    carry applied volume names; Go and Python SDKs expose claim options, discovery,
    and the applied entries on the handle.

Write-enabled catalog images are deliberately out of scope: the hardware round
showed correct writable semantics need clean guest-filesystem shutdown across
release, reap, rollback, pre-finalize failure, and restart reconciliation. That
is a separate lifecycle feature, not a flag on this one. Volumes v1 keeps the
existing lockstep deployment boundary; mixed-version serving is unsupported.

Documentation ships with the change: deploy, API, cluster, security, and both
SDK pages.

Validation

Local gates:

  • go test -race -count=1 ./... across all five Go modules
  • make go-lint on GOOS=linux and GOOS=darwin: 0 issues, no fmt diff
  • go vet ./... and asl ./... per module on both platforms
  • gofmt -l empty, git diff --check clean
  • Python 3.12: ruff check clean, 143 tests passed
  • silkd: cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test
  • bash -n and shellcheck for scripts/sandboxd-e2e.sh

Bare-metal verification on an AMD Ryzen 9700X node (16 cores, kernel
7.0.0-28-generic), cocoon master-07f1d69, Cloud Hypervisor v54.0.0,
template ghcr.io/cocoonstack/sandbox/rt:24.04@sha256:45944ae3363e:

  • the full scripts/sandboxd-e2e.sh with a real ext4 catalog image passed end to
    end, including the existing smoke, reap, and restart re-adoption steps
  • two concurrent claims mounted the same image at different paths, read identical
    bytes, and were refused on write with EROFS; both consumed warm VMs, proven
    per claim by the warm-tier counter
  • the backing image checksum was unchanged after release
  • the volume-less warm claim is unchanged against main: 0.500 ms mean
    (p50 0.5, p90 0.6) before, 0.531 ms mean (p50 0.5, p90 0.6) after, 16
    tier-proven samples per arm, interleaved; the delta is below the harness print
    resolution
  • device discovery served roughly 190 real-guest volume claims with no failures

Performance

Measured back-to-back on one host against a provision-only build of the same
feature: 420.9 ms mean per volume claim before, 79.3 ms mean after (5.3x). Two
changes contribute: replacing the udev device wait with the sysfs serial scan —
which alone takes the provision path to 167.5 ms mean — and consuming a warm VM
instead of always provisioning.

Absolute claim latency is load-dependent: a claim landing on the previous
claim's teardown and pool refill ranges 26–150 ms. With the pool settled it is
38.1 ms mean (sd 1.3, n=16, every claim warm-tier proven); the quiet end-to-end
path measures 25.6 ms and 33.3 ms for the two concurrent claims. Per additional
volume in one claim, attach and mount are sequential and cost 60–90 ms.

Review

The branch includes a quality pass over the whole repository — style
walkthroughs, simplification lenses, comment tightening, and a production-LOC
audit whose verified cut-list was applied. That pass is net-negative on
production lines (−35 prod, +14 test) and behavior-preserving; the hardware
round above was re-run at its final commit to confirm no regression.

CMGS added 27 commits August 12, 2026 00:55
@CMGS
CMGS merged commit a424f76 into main Aug 12, 2026
3 checks passed
@CMGS
CMGS deleted the codex/issue-66-volumes-v1 branch August 12, 2026 03:21
CMGS added a commit that referenced this pull request Nov 4, 2026
* silkd: a client hang-up reaps an attached language server

The pump only watched the server's stdout, so a silent server that ignored stdin EOF pinned its memory after the client left. A request frame during the stream ends it the same way, as a pty does.

* silkd: git_branch list names an unborn branch

rev-parse --abbrev-ref fails on an unborn HEAD and printed HEAD, while git_status on the same repo reports the branch. A detached HEAD still reads HEAD.

* review: silkd docs: attach never ends in done, a dropped port_forward can linger

* review: silkd and sandbox-init borrow what they only read

claim_env keeps its one read buffer and parses into borrowed pairs, so an exec, pty or session drops 2N String allocations. BootCfg and IpParam borrow the cmdline, read_manifest returns its text, apply_config sets literals, pty and upload signatures take plain borrows, and scan_serials formats a path only when it reads it. Tests changed only where a literal's type or a temporary's lifetime named the old owned form.

* review: silkd drops code that cannot run

Child::id is Some right after spawn, a session body is never empty, Path::file_name is never empty, abort on a finished task is a no-op, and the exec rebinds did nothing. Table::new and Broker::new only aliased Default; git hand-rolled error_frame; the imds consts and handle, DEFAULT_INIT and PROTO_VERSION had no outside user; the ignored bench asserted nothing.

* review: silkd statics and test helpers follow the file layout

Function-local statics and consts move to the top-of-file block, and the one-caller proxy_vars and silkd_net wrappers go with them; test helpers move above the tests and private below public.

* review: silkd comments shrink to what the code cannot carry

Module narratives go to one line, the imds token fact moves to its const, a history comment goes, make_controlling_tty becomes safe because it has no memory precondition, and find's at_root stops shadowing the root param.

* review: silkd tests use the shared request and assert_error helpers

* sdk/python: ship the PEP 561 py.typed marker

The package is fully annotated and mypy-strict, but the wheel carried no marker, so a
consumer's type checker treated every cocoonsandbox import as untyped (reveal_type gave
Any). Add the marker and the setuptools package-data entry; a scratch wheel now lists
cocoonsandbox/py.typed and mypy on a consumer reveals cocoonsandbox.sandbox.Sandbox.

* review: one-line docstrings where several lines restated the signature or sibling docs

* review: drop duplicate test fixtures and a subset test; share FakeConn through conftest

* review: tests before helpers in test_stream and test_client

* review: adapters floor the SDK at 0.1.13, where the in-guest kill after a timeout cut first shipped

* review: silkdtest's default arm calls serveStateless

The arm re-spelled serveStateless byte for byte.

* review: trim multi-line comments on unexported decls, capitalise own-line comments

Own-line comments start uppercase per /code Comment Style; multi-line godocs on unexported names cut to one line.

* review: guestserver keeps its report utility below the halfCloseSink block

Layout only: /code File Organization puts utility funcs below the type's methods.

* review: volumesmoke rejects non-local probes with filepath.IsLocal

Same verdict as the hand-rolled path test on 15 inputs.

* review: harness owns the guest proxy address, RelayConn and a package-level Request

The proxy address was declared in four drivers. Dial returns RelayConn so portsmoke calls CloseWrite directly. PortRelay.Request never read its receiver. credsmoke's expectPlaceholder locals stop shadowing the entry and header consts.

* docs: deploy's upgrade notes name the release each starts from

At v0.1.21 "this release" read as every upgrade needing a drain, a fresh data dir and an emptied bucket. Releases come from the first tag holding each commit: #81 v0.1.6 (the pool key's engine axis went), #364 v0.1.18, #59 v0.1.5, #69 v0.1.5 and #72 v0.1.6, #171 and #169 v0.1.11.

* docs: deploy and egress samples load and name a pulled image by its full ref

A pulled image is keyed by its whole ref, so template base:24.04 fails the golden build with image not found, as the README already fixed in #425. The deploy sample's cluster_key and the egress sample's missing egress_ca failed config.Load.

* docs: deploy states what the code requires of a failed claim, a golden and a dump

A wake of a failed egress-lane or volume claim answers 409, tenants get 403 on two more root routes, golden dumps queue, an idle default acts on running claims at the next sweep, and an adopted replica always wakes on a read; none of these had a line.

* docs: deploy gives the archive registry's DDL

A role without CREATE could not enable archive_failover from the docs: the other three shared tables have a pre-create DDL and this one had none.

* docs: deploy keeps the S3 layout and the replica bound in one place each

The checkpoint_store row repeated the Reclaiming S3 storage section, which takes the facts only the row carried (lineage scope, marker order, re-stamped manifests); the TTL, replica-loss, tenant-outage and cluster-invariant passages become links to the pages that own them.

* docs: cluster lists registered volumes and the TTL, and says when the digest covers secrets

An operator rebuilding data_dir from config.json lost runtime-volumes.json silently, and gauge 0 read as a check of two secrets a keyless digest never covers.

* docs: security names the TLS edge, the re-admitted prefix and the shared usage table

Stated as hard constraints these ruled out what deploy ships: a TLS edge for SDK clients, egress_internal_allow, and meta_store.usage.

* docs: benchmarks and performance keep each caveat once

* docs: api states redirects, operator tokens, fork env and the checkpoint list as the server does

The mint endpoint never answers the 503 and 429 its paragraph listed: the browser request does. A template another node deleted stays in tplSet, so the cluster page's never-fires claim was false for that entry.

* docs: api lists the errors of a call that reaches a guest once

Wake, agent, ports and exec carried the same four tails. Restore failures, 409s, release, hibernate and the preview listener differ, so they keep their own lines.

* docs: sdk, silkd, langchain and android match what the code does

Go Exec runs the argv given, with no implicit shell; every control-plane verb returns APIError; the checkpoint option refusals and a fork child's env were incomplete.

* docs: the sdk pages link the volume and deadline rules the api page owns

Go-specific and Python-specific names stay. The settled-entry sentence stays on the Go page, its only source.

* sandboxd: a preview listener that cannot bind is fatal

A taken preview_listen was logged and ignored: the node stayed healthy while the preview endpoint kept minting URLs for a dead port. The main listener already exits on the same failure, and systemd Restart= is the retry loop. http.ErrServerClosed stays clean.

* tenants: the contract replaces the set with no tenants

An empty Replace must delete every tenant on both backends: pgx sends a nil slice as NULL, so a Collect-built name list would delete nothing on pg.

* review: one owner for the max fork default, the routable-host test, the s3 store test and the tenant claim mapping

config.DefaultMaxForkCount replaces the second literal in pool, config.RoutableHost replaces the copy in server.New, Config.S3Checkpoints replaces three spellings of the kind test, and forTenant replaces the tenant-to-options mapping written in both claim paths. Behaviour-preserving, net zero lines.

* review: store package docs fit the comment budget, constant errors use errors.New

Package docs of store, s3 and peer shrink to one line (docs/deploy.md owns the key layout); the SweepStaging godoc and the redirectCacheEntry comment restate their names; three message-only fmt.Errorf become errors.New; VolumePatch is decode-only, so its slices follow the omitempty rule.

* pool: a fenced node captures no replicated claim

Fork, Checkpoint and Promote reached captureAllowed with no fence gate, so a node past its lease window could hand out children, a checkpoint or a template from a claim a peer may already own. ErrLeaseLost maps to 503 through the error table and is benign to the archive and replicate sweeps.

* pool: consumeArchive reads the row epoch under the manager lock

An unfence rewrites ArchiveEpoch holding only m.mu, and a release or replica retirement read it holding only Transition, so the two raced. The stale read cost at most a refused Consume and a settle round trip.

* review: pool comments name what the code does now

Two field comments named fields that moved to configView, checkTemplateOwner never deletes, HasPromotedTemplate's cache can go stale, and poolSeedHash's field list drifted against the lines below it.

* review: checkpoint.go keeps const and var above its types

* review: fold pool helpers with one caller

archiveDeleteFor, unpooledTemplates, archiveFetchErr, dropStaleRow, hasRegularFile, deliverGuestEnv and TenantRecords each had one caller. reputArchive's held parameter was dead: its only caller guards a non-zero epoch.

* review: one owner for pool facts stated twice

replicaPools repeated view.poolReplicate, whose key set a reload cannot change and PUT /v1/pools cannot set. The view's map guards bought nothing, since every reader takes the zero value. env and replicable spelled out runningShaped, AgentSocket spelled out isFenced, and the two reader teardowns stripped a cancel that removeVM strips itself. addClaimLocked gains one atomic load on nodes with archives and nothing elsewhere.

* review: pool sweeps and wakes carry what they have

commitWake logged its persist failure at Warn and its caller rebuilt the error with the cause dropped; it now returns the error. idleOnce copied id and token so idleHibernate could look the claim up again, and hibernateLocked's setIfLive already answers ErrUnknownSandbox for a released claim. Fork and Checkpoint no longer wait on Transition for a usage field, since every write of VMName after publication holds m.mu; lockedVMName stays for tests, which read under Transition.

* review: types.go splits into env.go and volume.go

Pure move: the env types, limits and patterns go to env.go and the volume types, modes and mount validation to volume.go, matching the existing env_test.go and volume_test.go. envView and namedVar stay beside the Sandbox that owns them. No line changes beyond imports and gofmt alignment.

* egress: an upstream dying mid-body truncates the guest's response

relay dropped the copy error, so net/http wrote the terminating chunk and the guest read a partial body as complete. Hijack and close the conn on a copy error, which leaves the chunked stream unterminated. Success costs one nil check.

* outbound: ArmProxy closes a displaced door before it binds

The close unlinks the socket path, so a re-arm that bound first left the guest with no door while Route reported relay. A re-arm with no policy left now closes the door too, which makes the Disarm in restartLocked dead. The claim path pays one map delete under a lock it already holds.

* engine: a restore gets the dump budget

A dump may take 15 minutes while an eager-copy restore of the same image had 2, so a slow page cache could fail the wake it had just made possible. cocoon gives vm.restore the same limit as vm.snapshot. Clone and cold boot keep the command budget.

* review: drop checks and fields the code already guarantees

ReadSlice caps a line at the reader's buffer, IsGlobalUnicast already excludes link-local and multicast, UnixListener.Close already unlinks, marshalCA's public key is its PEM key's, and interDER copied interCert.Raw.

* review: DialFunc's Router methods serve only tests

The only production egress.New takes a claim as its router, so the two methods move to the egress test file.

* review: a CA key error names the key its caller parsed

parseECKey said intermediate key while parsing the root, so IssueIntermediate reported root key: intermediate key. validHostName takes the package's maxHostLen for the same DNS limit.

* review: cut a restating godoc and fold the engine package doc to one line

* review: layout: silkd helpers live in silkd.go, tcpAddrPort beside proxy.go's other address helpers

installca.go kept the generic guest write and exec helpers every other engine file uses; installOutputMax becomes guestOutputMax since it caps every guest exec.

* docs: name the capture fence, the restore budget, a preview bind failure and a cut upstream

* review: VolumePatch keeps the SDK's omitzero tags, as the wire parity test requires

* engine: a clone restores memory like a restore, so it gets the dump budget

cocoon's vm clone and vm restore share restoreVM and its 10 minute memory transfer, and an archived wake and a fork go through clone. A hung refill clone now holds its slot for up to 18 minutes, which stays bounded and loud.

* review: silkd's language server feed needs no flag or channel, and one helper sets the claim env

* review: refill.go keeps the refill loop; golden builds go to golden.go, VM provisioning to provision.go, destroyAll and dropSnap beside destroy, runBounded to pool.go with its callers across the package

* review: the reaper leaves claim.go for reap.go, since expiry handling is not claim admission

* review: claim and authed resolve a credential, so they sit in operator.go with resolve and byID

* review: the pool type joins its watermark methods in watermark.go, so its type block is atomic

* review: rewriteArchiveRow writes an archive row, so it sits in failover.go beside refusedReplace

* review: NewManager delegates template and volume seeding to loadTemplates in template.go and seedVolumes in volume_catalog.go, keeping the order

* review: the catalog owns its entries and holders, so catalogVolume, catalogSnapshot and the holder bookkeeping move to volume_catalog.go as volumeCatalog methods

* review: the seven single-flight sweep guards group into one sweeps field on Manager

* review: recordLocks owns the per-record lock maps and their mutex, and recLock's doc says it returns the lock without taking it

* review: healVetoes owns the heal veto maps and their mutex, replacing the three Manager methods and fields

* review: ckMarkers owns the archive delete markers, and the delete and retry chain moves with it to archive_delete.go

* pool: an uncordon during an evacuation's drain stops it

Evacuate waits for the warm VMs to go before it starts its run. A DELETE /v1/drain in that wait found nothing to stop, and the run then moved every claim off an uncordoned node.

* pool: a tier claim woken past its lease before the export gets a fresh lease

The reaper archives a hibernated claim of a tier pool at its lease end, and the same call a moment after the export restores it with a fresh lease. A call in between woke it with the past deadline, so the next reap tick destroyed it.

* pool: a running claim that moved to a peer closes its egress doors

forgetAdopted removes the VM with no sandbox id, so the removal never disarms. The doors, their listeners and their goroutines stayed until the next restart, one set per moved claim, unlogged.

* docs: a moved claim's token, its first wake, and the 503s an evacuation and the tenant store answer

* sdk: Close follows a sandbox that moved off a retired node

Close looked the sandbox up only on a 404 from its old owner. Once that node is retired, the first release fails to connect, so the claim stayed on the adopter until its deadline, and every retry hit the same dead address. A connection failure now looks it up too, and keeps its error when no node answers.
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.

volumes v1: read-only shared dataset disks (M7-1 scope cut)

1 participant