carlos / platform Public

gvisor demos: design rev 3 with Paul's A-D rulings

Round 2 (Astra, 1fab79f8) hit stopping rule 2. Paul: A-D as
recommended: exec-sandbox floor instead of a fence, a root
stop-uncertain verb, no generation overlap for gVisor demos, no new
exit record kind. Also fixes the bundle path, refuses agent-side
direct launches in gVisor mode and enumerates build ownership.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 77e2943c959552c152c896e1e2ffaac910e2cc95 parent adcb1dc
2 files changed, +211 −44
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-gvisor-demos-design-R3.md +100 −0
  • docs/superpowers/specs/2026-11-08-gvisor-demos-design.md +111 −44

CI cancelled — superseded by a newer push — run details

diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-gvisor-demos-design-R3.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-gvisor-demos-design-R3.md
new file mode 100644
index 000000000..768bcfb16
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-gvisor-demos-design-R3.md
@@ -0,0 +1,100 @@
+# Review brief: gVisor demos design note, round 3 of 3 (builder-check, LAST)
+
+Repo carlos/platform, branch `gvisor-demos`, the commit named in your prompt.
+Under review: `docs/superpowers/specs/2026-11-08-gvisor-demos-design.md`.
+Authorities: the code on this branch (cut from main 9622c65a). Background
+evidence, not authority: `~/.cache/gvisor-spike/REPORT.md` and
+`~/.cache/gvisor-spike/astra-integration.md` (your own read-only analysis
+from 2026-11-07). Do not review against unmerged branches; if this work
+needs one, say so as a P1 and stop.
+
+You are an independent reviewer and the builder who will implement this.
+Read the note, then the code it names, and check every claim against that
+code. The question is: could you build this as written, and would it be
+safe? Name what is missing or wrong that would stop or mislead an
+implementer.
+
+## Fixed: do not re-argue
+
+- Paul's rulings, §2 of the note (recorded on #527, 2026-11-08). Report
+ only mechanisms that fail to honour them.
+- Scope is demos only (§3). Networked gVisor is out.
+- §4.1 (`auto` resolves to systemd in this build, explicit `gvisor` on the
+ dev demo box) is a sequencing decision to keep flagship demos untouched.
+ Report only if it fails to honour a ruling's end state or the flagship
+ rule.
+
+## What to check
+
+1. Root trust boundary: does the bundle writer (§6.3) or any other new root
+ path read, open, follow or run anything a tenant, an app or a box agent
+ can create, write or name? Is "the trampoline inside the sandbox reads
+ the launch JSON" (§6.4) actually how today's trampoline works
+ (`internal/instanceexec`), and does it run unchanged as uid carlos under
+ runsc with an empty rootfs?
+2. No fallback (ruling 5): is there any start, generation, wake, probe,
+ build, claim-freeze or recovery path that names a native template
+ directly and would bypass `unitFamily` (§7)? List them with file:line.
+3. Agent/root agreement (§4): do activator identity, `unitproc`, names
+ parsing, stop and sweep paths need more than the note says to hold the
+ right unit family for a handle's lifetime?
+4. runsc supply (§5): is the release-asset + pointer + `ensureRunsc` path
+ implementable on today's release, console mirror and box system-update
+ code? Is the pointer change additive for boxes and consoles on older
+ versions? Is "only when effective mode is gvisor" safe for bootstrap
+ ordering on a fresh demo box?
+5. Limits (§6.2) and demo policy readback: do `assertDemoUnit`,
+ `demoSizeShown`, `demoCgroup`, slice sizing and overlap/generation
+ budgeting (`instancectl/gen.go`, `server.go`) all get the +32 MiB
+ consistently, or will one of them refuse every gVisor start?
+6. Stop/exit (§6.5): with MainPID = runsc, do exit records, `observe`,
+ `finaliseGen`, `freezeDemoLocal` and demo cleanup keep their proofs?
+7. Demo build (§9): is the fixed-uid-plus-chown approach compatible with
+ `internal/demobuild` layout, mounts and output validation?
+8. Census and cross-compile: anything in the note that would put cgo,
+ Linux-only types in CLI-linked packages, or an unpinned file in root's
+ scope?
+
+## Round 3 (last)
+
+Earlier rounds: round 1 (Astra, f4ba2170, NOT READY 5 P1 / 5 P2,
+`CODEX-FINDINGS-gvisor-demos-design-R1.md`), round 2 (Astra, 1fab79f8,
+NOT READY 3 P1 / 4 P2, `CODEX-FINDINGS-gvisor-demos-design-R2.md`). Round 2
+triggered stopping rule 2 on four families; Paul ruled "A-D as
+recommended" (note header and §7, §6.2, §6.5). Those rulings are fixed:
+report only mechanisms that fail to honour them, not the choices.
+
+First give one line per P1 and P2 from round 2 (§16 of the note maps
+them): resolved, partly, or not. Carry unresolved ones forward, then add
+new findings. This is the last round without Paul's go: in a NOT READY,
+say whether the P1s share one cause and whether refusing the case up
+front or cutting the feature would remove them.
+
+## Severity
+
+- **P1**: unsafe, would not compile, a test fails, or it would not work.
+ Blocks merge.
+- **P2**: wrong or missing. Fixed without reopening this review. (The
+ census, and review of any newly changed security, root, termination
+ or production-storage behaviour, still check the fix; see AGENTS.md,
+ "Stopping rules".)
+- **P3**: clarity or polish. Goes on a follow-up list; never a reason for
+ another round.
+
+A P1 states its failure scenario and the evidence (file:line). Do not
+raise a P2 to P1 to keep the review open.
+
+## Output
+
+Findings ranked P1, P2, P3. Each gives the section, the problem, the
+evidence (file:line, verified), the failure scenario, a concrete fix and
+the invariant or trust boundary it breaks (that is its fault family). End
+with exactly one verdict:
+
+- **READY**: no P1 and no P2.
+- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another
+ round.
+- **NOT READY**: one or more P1s, listed.
+
+Do not edit files. Do not spawn Anthropic-model reviewers or subagents of
+your own. Do not run the full test suites.
diff --git a/docs/superpowers/specs/2026-11-08-gvisor-demos-design.md b/docs/superpowers/specs/2026-11-08-gvisor-demos-design.md
index 4825f53c3..4a8c76614 100644
--- a/docs/superpowers/specs/2026-11-08-gvisor-demos-design.md
+++ b/docs/superpowers/specs/2026-11-08-gvisor-demos-design.md
@@ -1,11 +1,15 @@
-# gVisor sandbox for anonymous demos: design (2026-11-08, rev 2)
+# gVisor sandbox for anonymous demos: design (2026-11-08, rev 3)
Discussion: amadan carlos/platform #527. Spike: `~/.cache/gvisor-spike/REPORT.md`
and `astra-integration.md` (2026-11-07, runsc release-20261102.0, systrap, t4g).
Branch `gvisor-demos`. This note decides the shape; the plan carries the code.
-Review history: round 1 (Astra, f4ba2170, NOT READY: 5 P1, 5 P2) is answered in
-rev 2; see §15. This is round 2 of 3.
+Review history: round 1 (Astra, f4ba2170, NOT READY: 5 P1, 5 P2) answered in rev 2;
+round 2 (Astra, 1fab79f8, NOT READY: 3 P1, 4 P2) triggered stopping rule 2 on four
+repeated families. Paul ruled 2026-11-08, "A-D as recommended" (via platform-f6):
+A exec-sandbox floor and no fence, B one root stop-uncertain verb, C no generation
+overlap for gVisor demos, D no new exit record kind. Rev 3 applies them; see §15.
+This is round 3 of 3, the last without Paul's go.
## 1. What a user gets, and when
@@ -124,10 +128,12 @@ stop-dependency policy as the native template, and
ExecStartPre=<runsc> --root=/run/carlos-runsc delete -force <id>
ExecStart=<runsc> --root=/run/carlos-runsc --ignore-cgroups --network=none \
- --host-uds=create run --bundle /var/lib/carlos-control/oci/<id> <id>
+ --host-uds=create run --bundle /run/carlos-control/oci/<id> <id>
ExecStopPost=/opt/carlos/carlos instance-exit --sandbox=gvisor run %I
ExecStopPost=<runsc> --root=/run/carlos-runsc delete -force <id>
+One constructor, `execsandbox.BundleDir(id)` = `/run/carlos-control/oci/<id>`, is
+used by the writer, the unit drop-in, the verifier and cleanup (round 2 P1-2).
`<id>` is derived by root from the validated unit instance name (host, role,
generation) and never reused while an older invocation of it may survive. With
`--ignore-cgroups`, runsc, Sentry, gofer and helpers all sit in the unit's cgroup, so
@@ -142,8 +148,15 @@ root runner, then pin it in the verifier); it is not copied from the native temp
`execsandbox.Physical(tier cgroup.Limit) cgroup.Limit`, derives the limits written
to and read back from systemd and the kernel (round 1 P2-7). Every writer and
verifier calls it: the start path's tier lines, the parent slice write, generation
-drop-ins and their readback, overlap budgeting (`OverlapLimit` of two physical
-limits) and restoration, `assertDemoUnit`, `demoSizeShown`, `demoCgroup`. Shares are
+drop-ins and their readback, `assertDemoUnit`, `demoSizeShown`, `demoCgroup`.
+
+No generation overlap in gVisor mode (Paul's ruling C, round 2 P2-5). A gVisor demo
+update stops the running unit, proves it gone, then starts the new one: the agent
+takes its existing stop-then-start swap path whatever `CARLOS_SWAP` says, and root
+refuses (`EXEC-SANDBOX-OVERLAP`) any start for a host that still has an active unit
+or a non-empty cgroup in either family. So a parent slice only ever holds one child,
+parent and child expectations are the same single physical tier, and there is no
+overlap budget or restoration to derive. Cost: about 200 ms of 503 per demo update. Shares are
taken from the logical tier, never from `SharesOf(physical)`. For a gVisor demo unit
and its per-host slice: MemoryMax = small + 32 MiB, MemoryHigh = HighOf(that),
MemorySwapMax = MemoryMax, TasksMax = small + 64 (spike: +30 tasks). CPU and IO stay
@@ -225,16 +238,15 @@ fit.
`KillMode=mixed`: SIGTERM to runsc, which forwards it to the guest init (trampoline),
which forwards to the app; SIGKILL to the cgroup after `TimeoutStopSec`. The root
runner proves graceful stop and the kill path. The trampoline writes the exit record
-by the same host-side hook as native (round 1 P2-8): `ExecStopPost=` runs
+by the same host-side hook as native: `ExecStopPost=` runs
`/opt/carlos/carlos instance-exit run %I` with systemd's invocation and exit
-variables. `runsc run` exits with the guest init's status, and the trampoline
-exits with the app's, so `EXIT_STATUS` is the app's. A runsc failure before the
-guest starts (bad bundle, missing runtime) shows as a runsc exit with a "sandbox"
-journal line; `instance-exit --sandbox=gvisor` records it with kind `runtime`, and
-`unitMainExitOf` reports it as a runtime failure, not an app exit. The hook runs as
-root in this unit, so it opens the record file and `fchown`s it to carlos with the
-native mode before writing; record bytes match native. A guest killed by SIGKILL
-gives a signal status as native does. Records stay advisory. Termination proof
+variables. The hook runs as root in this unit, so it opens the record file and
+`fchown`s it to carlos with the native mode before writing. The record shape is
+unchanged and gains no kind field (Paul's ruling D, round 2 P2-6): it carries the
+status as systemd saw it from runsc. Nothing claims whether the app or the runtime
+produced it. `unitMainExitOf` and status label exits from a gVisor unit (the
+activator knows the family from its handle) "exit status via gVisor". Records stay
+advisory; termination proof is unchanged. Termination proof
stays systemd invocation state plus an empty cgroup. `runsc delete -force` runs before
start and after stop (spike gotcha 2); the generation finaliser also removes the
bundle directory after the proof, before any reuse of the id.
@@ -251,10 +263,16 @@ second place that names a template. In gVisor mode it returns an error for:
`EXEC-SANDBOX-CLAIMS`, so the box never serves in that combination;
- a non-demo box (§4).
-Unit identity (round 1 P2-6): the start response carries the unit name root
-started (additive field); `Client.Start` returns it; the activator's handle stores
-it and every observe, stop and uncertain-start cleanup uses the stored name, never
-one rebuilt from the route. Stops and discovery recognise both families whatever
+Unit identity (round 1 P2-6; Paul's ruling B, round 2 P2-4): the start response
+carries the unit name root started (additive field); `Client.Start` returns it; the
+activator's handle stores it, and every observe and stop on a handle uses the stored
+name, never one rebuilt from the route. A start whose response never arrived has no
+handle, so its cleanup goes through one root verb, `POST /stop-uncertain?host=&role=&gen=`:
+root takes the existing per-unit lock for the validated (host, role, gen), derives
+the unit names of both families from them, stops whichever is loaded, proves each
+inactive with an empty cgroup, and only then answers. The agent's uncertain-start
+paths (`backend_exec.go` generation and original-unit cleanup) call it and never name
+a family. Stops and discovery recognise both families whatever
the configured mode, and keep working while Ready is blocked. The plan carries the
full inventory of dispatch points from round 1's table: main/sidecar start, gen
start/drop-in/stop, seed and its retry, cmd/tty, rootfs roles and probe, native
@@ -270,20 +288,45 @@ comparison. The native demo drop-in (`demo.conf`: PrivateNetwork, AF_UNIX, tmpfs
runsc state. Its offline guarantee is replaced by `--network=none` in the asserted
ExecStart and the probe.
-Rollback fence (round 1 P1-4). A binary older than this build ignores
-`CARLOS_EXEC_SANDBOX`, and recovery can restore `carlos.prev`. So before root
-reports Ready in gvisor mode it writes `95-carlos-exec-sandbox-fence.conf` into the
-drop-in directory of every native instance template (`carlos-instance@`, `-gen@`,
-`-seed@`, `-sidecar@`, `-cmd@`, `-tty@` and the rootfs family), containing
-`ExecStartPre=/bin/false`, and reloads. Any native start then fails before
-ExecStart, whichever binary asks. Old binaries only manage their own
-`90-carlos-demo.conf`, and a rollback restores the update journal's files, not
-runtime drop-ins (the plan checks both against the last releases' code). Ready
-requires the fence present in gvisor mode; root removes it only in systemd mode,
-after the drain check below. gVisor units are `BindsTo=carlos-edge.service`, so a
-rollback's edge restart stops them. A box rolled back to an old binary with gvisor
-set therefore serves no demos until an operator sets `systemd` and restarts: a
-refusal, not a native run.
+Exec-sandbox floor (Paul's ruling A; round 1 P1-4, round 2 P1-1). A binary older
+than this build ignores `CARLOS_EXEC_SANDBOX` and would run demos, builds and
+probes natively. Rather than fence native units, an unaware binary never runs on a
+box whose effective mode is gVisor. This is the moves/seeds floor pattern
+(`rootmovesfloor_boot.go`, `carlos-system-recover.service`), applied to one fact:
+
+- **Aware:** a binary is sandbox-aware when its build carries the exec-sandbox
+ protocol marker (`execsandbox.Protocol = 1`), read from the file without running
+ it, the way `rootFloorBinary` reads a binary's supported floors. This release is
+ the first aware build.
+- **System apply** (this binary as updater, forward or rollback, console-driven or
+ local): when the effective mode is gVisor, it refuses a target binary that is not
+ aware before staging anything, and writes result `refused: exec-sandbox floor`.
+ The box stays on its current build.
+- **Recovery:** this release's `carlos-system-recover.service` adds one test to the
+ existing `&&` chain before `exec /opt/carlos/carlos.prev`:
+ `/opt/carlos/carlos system exec-sandbox-allows-prev /opt/carlos/carlos.prev`. The
+ current binary reads host.env itself; it exits 0 when the effective mode is not
+ gVisor or carlos.prev is aware. Any other result, including the gate failing to
+ run, skips carlos.prev, so the current binary recovers and its own apply-time check
+ refuses to restore an unaware prev, as the moves floor does. The line keeps the
+ unit's rule of no percent or dollar signs.
+- **Bootstrap** installs only the pointer's current binary, which is aware once this
+ release is current; a pointer below this release on a box with gvisor set fails
+ the same apply check.
+- **Below the floor:** an operator sets `CARLOS_EXEC_SANDBOX=systemd`, restarts
+ (root drains and reports systemd), then rolls back. The floor binds only while the
+ effective mode is gVisor.
+
+Agent-side launches (round 2 P1-3). The agent can also start processes itself:
+flat and foreign launches (`backend_exec.go` `startChildAt`/`spawnChildFrom`), flat
+staged generations (`genbackend.go`), seeds and roles. One check,
+`execsandbox.AgentLaunchAllowed(effective, launch)`, runs at the top of
+`Backend.Start` and of every direct-spawn entry point before any process exists. In
+gVisor mode it allows only a nested demo launch through root and refuses everything
+else with `EXEC-SANDBOX-UNSUPPORTED`. A guard test drives each launch kind with a
+fake spawner in gVisor mode and asserts zero spawns, and a source scan fails if a
+new `exec.Cmd` start or `StartChild` call appears in `internal/activator` without
+passing that check.
Mode change: at Ready, root refuses (`EXEC-SANDBOX-DRAIN`) while any unit of the other
family is active or has a non-empty cgroup, and sweeps leftover runsc state and bundle
@@ -309,8 +352,14 @@ writer family (`gvisorBuildBundle`): toolchain and module cache ro, source ro, w
output, cache and tmp rw, cwd `/work/src`, the exact offline argv and environment of
today's `carlos-demo-build@` (GOTOOLCHAIN=local, GOPROXY=off ...), plus
`GOMEMLIMIT` = 90% of the build's memory. The compiler runs as a fixed unprivileged
-uid inside the guest (DynamicUser has no meaning there); root chowns the per-build
-work tree to it before start. `Type=exec` with `RuntimeMaxSec=180`, the same `BuildWindow` the console signs, the
+uid inside the guest (DynamicUser has no meaning there). Ownership, exactly (round 2
+P2-7): root creates `work/out`, `work/tmp` and `work/home` owned by that uid, 0700;
+the source tree, the toolchain, `cache-upper`, `cache-work` and every lower-layer
+file stay root-owned as today. The mounted cache view (`work/cache`, the overlay)
+gets the same directory-permission change `unit.go:168` already makes, with group
+or owner set to the build uid on directories only, after the overlay is mounted, so
+no file is copied up. The guest sees `/work/out`, `/work/tmp`, `/work/home`,
+`/work/cache` (rw) and `/work/src` (ro), never the backing directories. `Type=exec` with `RuntimeMaxSec=180`, the same `BuildWindow` the console signs, the
worker enforces and control bounds (round 1 P1-5): no deadline changes anywhere.
The build cache's lower layer is the toolchain bundle's prebuilt cache
(`unit.go:158`), so a demo build is a warm build: 2.8 to 3.2 s native, 6.9 to 7.8 s
@@ -349,12 +398,16 @@ from the unit family the activator holds). Additive; an old report means unknown
- Unit tests with fake systemctl: parse/resolve table; no-fallback (every refused
combination, and the absence of any native start in gVisor mode); bundle bytes are
a pure function of (host, role, gen); verifier rejects each mutated property;
- limits; status fields; pointer round-trip with and without `Runsc`.
+ limits; status fields; optional runsc asset mirroring (present and absent); runsc-ensure
+installs the target pin and refuses a mismatched object; the floor refuses an unaware
+target and an unaware prev in gVisor mode and allows both in systemd mode;
+stop-uncertain finds either family; overlap refused in gVisor mode.
- Root runner (`//go:build linux && rootrunner`, throwaway arm64 EC2, runsc from the
lock): start and serve over the host socket; SIGTERM graceful stop; kill -9 then
restart with zero acked writes lost; memory overrun oom-kills the whole unit; probe
passes and each probe check fails when its property is broken; demo build output
- matches the native build; claim freeze and snapshot under gVisor; mode drain.
+ matches the native build and finishes under 60 s; recovery with gvisor set and an
+ unaware carlos.prev runs the current binary; claim freeze and snapshot under gVisor; mode drain.
- Dev witness (§13).
- Census: `make census-card` / `census-propose`, Opus verdict on #280.
@@ -370,7 +423,7 @@ from the unit family the activator holds). Additive; an old report means unknown
Rollback: remove the line and restart (the drain check covers leftovers).
5. Flagship: not here.
-## 14. Risks (unchanged from rev 1, plus the fence)
+## 14. Risks
- Root launch authority grows (bundle writer, runsc as root). Contained by §6.3: root
derives every field from the validated host shape and reads no tenant byte.
@@ -378,8 +431,9 @@ from the unit family the activator holds). Additive; an old report means unknown
runsc debug line from the unit journal with the refusal.
- The follow-up flip in §4.1 is a dormant default (rule 5). Its switch-on is the
flagship gVisor window after go-live; the dev box runs it from step 4.
-- The rollback fence (§7) turns an old binary on a gvisor box into a box that serves
- no demos. That is the intended refusal; status shows it as failed native starts.
+- The exec-sandbox floor (§7) blocks rollbacks below this release while gVisor is
+ on. That is the intended refusal; the operator path is set systemd, restart, roll
+ back.
## 15. Round 1 answers
@@ -388,10 +442,23 @@ from the unit family the activator holds). Additive; an old report means unknown
| 1 executable mount | P1 | §6.3: reuse `ensure*ExeAt` + `validateStagedExe`; bind the resolved build at `/opt/carlos/app` and `live/` at `/opt/carlos/live`, as native |
| 2 controller cannot write bundle | P1 | §6.3: config in `/run/carlos-control/oci`; rootfs made by bootstrap/apply; runsc state only inside the workload unit |
| 3 runsc across versions | P1 | §5: content-addressed object, pin in the using binary, `carlos-runsc.service` run by the installed binary on every control start; optional asset; pointer unchanged |
-| 4 rollback restores native | P1 | §7: fence drop-in `ExecStartPre=/bin/false` on every native instance template while gvisor is effective |
+| 4 rollback restores native | P1 | rev 3 §7: exec-sandbox floor (Paul's ruling A); the rev 2 fence is gone |
| 5 build window | P1 | §9: keep 180 s everywhere; warm-cache build measured under 60 s or gVisor builds refused |
-| 6 unit identity | P2 | §7: unit name in the start response, stored on the handle; inventory into the plan |
-| 7 overhead propagation | P2 | §6.2: `Physical(tier)` in every writer/verifier; logical tier and shares unchanged; build slice grows |
-| 8 exit records | P2 | §6.5: host-side `instance-exit` hook as native, runtime kind, fchown to carlos |
+| 6 unit identity | P2 | §7: unit name on the handle; rev 3 adds `stop-uncertain` (ruling B) |
+| 7 overhead propagation | P2 | §6.2: `Physical(tier)` everywhere; rev 3 cuts overlap in gVisor mode (ruling C) |
+| 8 exit records | P2 | §6.5: host-side hook, fchown; rev 3: no new kind, "exit status via gVisor" (ruling D) |
| 9 guest contract | P2 | §6.3 mount list; §6.4 syscall needs; real-trampoline witness |
| 10 snapshot reader | P2 | §10: agent reads, root streams, as today |
+
+## 16. Round 2 answers
+
+| R2 | Sev | Family | Answer |
+|---|---|---|---|
+| 1 fence permits native | P1 | no native fallback in recovery | §7 exec-sandbox floor (ruling A) |
+| 2 bundle path mismatch | P1 | bundle-path agreement | §6.1 one `BundleDir` constructor under `/run/carlos-control/oci` |
+| 3 agent-side native launch | P1 | mandatory sandbox on all launch paths | §7 `AgentLaunchAllowed` + guard test + source scan |
+| 4 lost start response | P2 | unit identity | §7 `stop-uncertain` (ruling B) |
+| 5 overlap budgets | P2 | resource accounting | §6.2 no overlap in gVisor mode (ruling C) |
+| 6 exit attribution | P2 | exit attribution | §6.5 no new kind (ruling D) |
+| 7 build chown | P2 | build-cache ownership | §9 exact ownership list |
+| P3 pointer tests | P3 | doc consistency | §12 rewritten |