carlos / platform Public

gvisor demos: design rev 2 answering builder-check round 1

Round 1 (Astra, f4ba2170): NOT READY, 5 P1 and 5 P2. Rev 2 reuses the
native executable preparation, moves the bundle into the controller's
writable tree, installs a content-addressed runsc from the installed
binary's pin, fences native templates against rollback, and keeps the
180 s build window.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 1fab79f82f3a0fee489459c08a65ce9f076123c1 parent f4ba217
3 files changed, +412 −53
  • docs/superpowers/reviews/CODEX-FINDINGS-gvisor-demos-design-R1.md +143 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-gvisor-demos-design-R2.md +99 −0
  • docs/superpowers/specs/2026-11-08-gvisor-demos-design.md +170 −53

CI cancelled — superseded by a newer push — run details

diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-gvisor-demos-design-R1.md b/docs/superpowers/reviews/CODEX-FINDINGS-gvisor-demos-design-R1.md
new file mode 100644
index 000000000..833f806fa
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-FINDINGS-gvisor-demos-design-R1.md
@@ -0,0 +1,143 @@
+Round 1 of 3, reviewed at `f4ba21704e2a8efdc016cd1f048e91bb8ab83d34`. No files changed; no tests run.
+
+1. **P1 — §6.3: the executable mount rejects normal launches and loses generation pinning.**
+
+ The proposed source, `/opt/carlos/live/<host>`, is a symlink, which the proposed writer must reject. Native units instead mount root’s prepared executable view. For a generation, that view can name a validated staged build different from the live link.
+
+ Evidence: [hardening.go:45](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/hardening.go:45), [stagedexe.go:105](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/stagedexe.go:105), [gen.go:44](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/gen.go:44). The trampoline validates the pathname in `argv[0]`; it does not independently pin the executable: [exec.go:158](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instanceexec/exec.go:158).
+
+ **Failure:** ordinary starts fail the symlink check. Relaxing that check and mounting the live target makes a staged generation run the wrong build.
+
+ **Fix:** preserve `validateStagedExe` and the per-role/per-generation executable preparation. Define how the bundle mounts the verified regular executable while retaining the guest pathname `/opt/carlos/live/<host>`. Validate source resolution through the actual bind operation, including ancestor components.
+
+ **Fault family:** executable identity and privileged mount-source authority.
+
+2. **P1 — §§6.3, 7: the controller cannot write the proposed bundle directory.**
+
+ The root controller runs with `ProtectSystem=strict`. Its base writable paths are `/run/carlos-control` and `/run/systemd/system`; the demo additions do not include `/var/lib/carlos-control` or `/run/carlos-runsc`.
+
+ Evidence: [carlos-instance-control.service:41](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/host/units/carlos-instance-control.service:41), [claimunit.go:121](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/host/claimunit.go:121).
+
+ **Failure:** the first bundle write fails with a read-only-filesystem error. Controller-side cleanup of the separate runtime-state tree is also outside its writable scope.
+
+ **Fix:** specify creation, ownership and narrowly scoped writable access for the bundle and runtime-state directories, through bootstrap, unit rendering and system-update installation. Keep runsc execution and its resource charges in the workload unit.
+
+ **Fault family:** controller filesystem authority.
+
+3. **P1 — §5: runsc installation lacks a target-version and bootstrap handoff.**
+
+ The updater continues executing the old binary while staging and installing the candidate. Candidate bootstrap runs against a newly emptied staging directory; bootstrap reads `host.env` beneath that directory. It therefore cannot discover the live box’s explicit gVisor setting there.
+
+ Evidence: [systemapply.go:605](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/host/systemapply.go:605), [systemapply.go:1318](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/host/systemapply.go:1318), [bootstrap.go:408](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/host/bootstrap.go:408). Control restarts before the edge at [systemapply.go:697](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/host/systemapply.go:697).
+
+ **Failure:** when a release changes the runsc pin, `ensureRunsc` in the old updater compares the new artifact against the old compiled pin. Moving it into candidate bootstrap without an explicit handoff instead resolves the absent setting to systemd and skips installation. The new controller then refuses readiness. A fresh box that receives its gVisor setting after bootstrap has the same missing-runtime problem.
+
+ **Fix:** specify which verified binary checks the **target** pin, how it receives the authenticated artifact and live configuration, and when installation completes before control starts. Cover initial enablement, pin changes, fresh bootstrap and same-version retries.
+
+ The pointer field itself can be additive: signature verification precedes ordinary `json.Unmarshal`, which tolerates unknown fields ([systempointer.go:227](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/release/systempointer.go:227)). Also specify console-first deployment and historical-release handling: unconditional fetching of runsc assets would make older releases fail `Feed.Asset` when their checksum lists contain none ([feed.go:111](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/publicrelease/feed.go:111)).
+
+ **Fault family:** authenticated runtime installation across version transitions.
+
+4. **P1 — §§7, 13: automatic rollback can silently restore native execution.**
+
+ The mode-drain check exists only in the proposed new binary. Existing recovery can execute `carlos.prev`, restore its units and restart its controller and edge. A pre-gVisor binary does not interpret `CARLOS_EXEC_SANDBOX=gvisor`.
+
+ Evidence: [carlos-system-recover.service:41](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/host/units/carlos-system-recover.service:41), [systemapply.go:1893](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/host/systemapply.go:1893), [server.go:835](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/server.go:835).
+
+ **Failure:** a failed roll or interrupted installation restores an older binary while host.env still requires gVisor. Subsequent demos start through native templates without executing the new refusal or drain checks.
+
+ **Fix:** establish a rollback fence before enabling gVisor, including the unit-level choice to execute `carlos.prev`. Either require a sandbox-aware recovery baseline in both slots or refuse restoration to an unaware binary until an explicit drained switch to systemd.
+
+ **Fault family:** no native fallback during recovery.
+
+5. **P1 — §9: `RuntimeMaxSec=300` does not give builds 300 seconds.**
+
+ `BuildWindow` remains 180 seconds. The console signs that deadline, the worker enforces it, and the control client/server impose their own bounds from the same constant.
+
+ Evidence: [job.go:23](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/demobuild/job.go:23), [demo_jobs.go:356](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/console/demo_jobs.go:356), [worker.go:179](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/demobuild/worker.go:179), [worker.go:201](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/demobuild/worker.go:201), [demo_build.go:123](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/demo_build.go:123).
+
+ **Failure:** a valid build taking four minutes is cancelled after three minutes despite the new unit limit. Increasing only the signed deadline makes existing worker validation reject the job.
+
+ **Fix:** define the complete gVisor build deadline contract across console grants, agent validation, control transport, worker initialization, execution and result acceptance. Preserve the flagship’s native behavior and define mixed-version handling.
+
+ **Fault family:** bounded build authorization and deadline agreement.
+
+6. **P2 — §§4, 7, 10–11: selected unit identity and the migration inventory are incomplete.**
+
+ Adding the mode to JSON responses is insufficient: current clients return only `InvocationID`, and `newUnitProcFor` derives a native unit name from the route. Stops similarly reconstruct the target.
+
+ Evidence: [client.go:161](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/client.go:161), [unitproc.go:140](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/activator/unitproc.go:140), [unitproc.go:232](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/activator/unitproc.go:232).
+
+ **Failure:** incomplete plumbing observes or stops the native sibling of a running gVisor unit; cleanup can examine the wrong cgroup or leave the actual unit running.
+
+ **Fix:** carry root-selected family/unit identity through the client, start result and handle, including uncertain-start cleanup. Stops must remain usable while readiness is blocked by a mode change. Discovery must recognize both families independently of the current configured mode.
+
+ The implementation inventory must include these existing paths:
+
+ | Path | Verified selection or dispatch |
+ |---|---|
+ | Main/sidecar start | [server.go:835](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/server.go:835) |
+ | Generation start, drop-in and stop | [gen.go:85](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/gen.go:85), [gen.go:316](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/gen.go:316), [gen.go:488](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/gen.go:488) |
+ | Seed, including retry | [server.go:964](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/server.go:964), [server.go:994](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/server.go:994) |
+ | Cmd/tty | [cmd.go:71](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/cmd.go:71) |
+ | Rootfs roles and probe | [rootfs.go:573](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/rootfs.go:573), [rootfs.go:1271](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/rootfs.go:1271) |
+ | Native readiness probe | [server.go:1421](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/server.go:1421) |
+ | Host-claim start | [claimunit.go:200](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/claimunit.go:200) |
+ | Egress-triggered restart | [egress.go:496](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/egress.go:496) |
+ | Build naming and recovery | [unit.go:39](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/demobuild/unit.go:39), [unit.go:389](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/demobuild/unit.go:389) |
+ | Claim-freeze/purge discovery | [demo_cleanup.go:177](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/demo_cleanup.go:177) |
+ | General sweep and generation leftovers | [server.go:1140](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/server.go:1140), [gen.go:605](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/gen.go:605) |
+
+ Unsupported starts need explicit refusals at their dispatch boundaries; stop and discovery paths need recognition, not refusal.
+
+ **Fault family:** unit identity throughout launch, observation and termination.
+
+7. **P2 — §§6.2, 9: overhead must be separate from the platform tier and propagated through parent budgets.**
+
+ The note updates three demo checks but omits other writers and readers. Demo starts and parent writes forcibly select the unadjusted small tier; generation readback compares against `req.tier`. Passing 288 MiB as a tier also fails tier validation, and `SharesOf` assigns standard shares to an unknown limit.
+
+ Evidence: [server.go:718](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/server.go:718), [server.go:774](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/server.go:774), [gen.go:267](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/gen.go:267), [gen.go:716](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/gen.go:716), [cgroup.go:143](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/cgroup/cgroup.go:143).
+
+ **Failure:** partial implementation either fails readback, restores the old cap, or changes CPU/IO shares. Leaving the aggregate build slice unchanged also caps each fully occupied slot at 1 GiB/128 tasks despite the larger child limits ([runner.go:29](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/demobuild/runner.go:29), [unit.go:401](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/demobuild/unit.go:401)).
+
+ **Fix:** keep the logical small tier unchanged and derive physical sandbox limits separately. Use that derivation in all writers, verifiers and kernel readbacks. Explicitly define generation overlap/restoration budgeting and whether build-parent budgets increase with their children.
+
+ **Fault family:** consistent hierarchical resource accounting.
+
+8. **P2 — §§6.4–6.5: today’s trampoline does not write exit records.**
+
+ `runInitChecked` exits with the supervised child’s status. A separate `instance-exit` invocation in native `ExecStopPost` writes the record using systemd’s invocation and exit environment.
+
+ Evidence: [init_linux.go:123](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instanceexec/init_linux.go:123), [carlos-instance@.service:28](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/host/units/carlos-instance@.service:28), [exit.go:79](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instanceexec/exit.go:79).
+
+ **Failure:** the proposed delete-only post-hook leaves no record. Merely calling the existing writer inside the guest supplies neither the systemd invocation ID nor its stop-result variables. A killed guest cannot write a final record.
+
+ **Fix:** design invocation propagation and a guest-status writer explicitly. Specify runtime failure, guest exit and missing-record behavior, including changes to [unitMainExitOf](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/activator/unitproc.go:524). Records must remain advisory; termination still requires host evidence.
+
+ **Fault family:** exit attribution across the runtime boundary.
+
+9. **P2 — §§6.3–6.4, 8: the empty-rootfs guest contract is underspecified.**
+
+ The probe requires `/proc/version` and process-security information, but the mount list does not specify a guest proc filesystem. The real trampoline additionally depends on `openat2` resolution restrictions, `PR_SET_CHILD_SUBREAPER`, fork/session creation and signal/reaping behavior.
+
+ Evidence: [instancefs_linux.go:20](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancefs/instancefs_linux.go:20), [init_linux.go:99](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instanceexec/init_linux.go:99). The spike explicitly mounted guest proc: [box.sh:255](/home/paulca/.cache/gvisor-spike/payload/box.sh:255).
+
+ **Failure:** reproducing only the listed mounts cannot satisfy the specified proc checks; reproducing the spike’s direct app launch does not establish that the platform trampoline works.
+
+ **Fix:** enumerate the virtual filesystems/devices and numeric guest identity, then require a witness using the actual trampoline, launch JSON, safe opens and child supervision. Unsupported calls must cause refusal, not weakened path validation.
+
+ **Fault family:** guest runtime compatibility and filesystem isolation.
+
+10. **P2 — §10: the snapshot description assigns host DB reads to the wrong process.**
+
+ `wireDemoClaimSnapshot` runs in the agent. It opens the host-visible DB/WAL and streams them to `SnapshotDemo`; root’s freeze operation explicitly does not read database files.
+
+ Evidence: [demo_claim_snapshot.go:30](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/host/demo_claim_snapshot.go:30), [demo_claim_snapshot.go:38](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/host/demo_claim_snapshot.go:38), [demo_claim.go:70](/home/paulca/amadan.net/carlos/platform-gvisor-demos/internal/instancectl/demo_claim.go:70).
+
+ **Failure:** implementing “root snapshots the host DB” literally introduces a new privileged read of tenant-writable paths that the existing design avoids.
+
+ **Fix:** retain the existing agent-read/streamed-snapshot boundary. Extend stop-and-prove to the gVisor family and runtime cleanup before those agent reads begin.
+
+ **Fault family:** privileged access to tenant database files.
+
+**NOT READY**
\ No newline at end of file
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-gvisor-demos-design-R2.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-gvisor-demos-design-R2.md
new file mode 100644
index 000000000..d7c019a8a
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-gvisor-demos-design-R2.md
@@ -0,0 +1,99 @@
+# Review brief: gVisor demos design note, round 2 of 3 (builder-check)
+
+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 2
+
+Earlier rounds: round 1, Astra, at f4ba2170: NOT READY, 5 P1 and 5 P2,
+findings in `docs/superpowers/reviews/CODEX-FINDINGS-gvisor-demos-design-R1.md`.
+The note's §15 says how rev 2 answers each. The round number counts every
+earlier review of this design under any file name or reviewer; this is
+round 2 of 3, and round 3 is the last without Paul's go.
+
+First give one line per P1 and P2 from round 1: resolved, partly, or not.
+Carry every unresolved or partly resolved finding forward at its current
+severity, then add new findings. The verdict covers everything
+outstanding, round 1 included. Name the fault family beside each finding;
+a second round of findings in one family stops fixing (AGENTS.md rule 2).
+
+## 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 681a62929..4825f53c3 100644
--- a/docs/superpowers/specs/2026-11-08-gvisor-demos-design.md
+++ b/docs/superpowers/specs/2026-11-08-gvisor-demos-design.md
@@ -1,9 +1,12 @@
-# gVisor sandbox for anonymous demos: design (2026-11-08, rev 1)
+# gVisor sandbox for anonymous demos: design (2026-11-08, rev 2)
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.
+
## 1. What a user gets, and when
Code a stranger hands the /start demo runs under gVisor: its syscalls are served by
@@ -55,7 +58,7 @@ New package `internal/execsandbox`:
`EXEC-SANDBOX-UNSUPPORTED` (networked instances are not built). Not a fallback: the
operator asked for gVisor, so nothing runs natively.
-### 4.1 `auto` in this build (deviation for the flagship rule, flagged to platform-f6)
+### 4.1 `auto` in this build (sequencing for the flagship rule; agreed by platform-f6, 2026-11-08)
Ruling 3 says `auto` means gVisor on demo boxes. Shipped as-is, the next flagship box
roll would switch flagship demos to gVisor, which the go-live owners forbid. So this
@@ -68,31 +71,44 @@ its test.
## 5. runsc supply (ruling 4)
-- **Pin in the tree:** `internal/execsandbox/runsc.lock.json`, embedded: gVisor release
- name, upstream tarball sha512 per arch, and the sha256 of the extracted `runsc`
- binary for `linux-arm64` and `linux-amd64`. Changing runsc is a reviewed commit to
- this file and nothing else.
-- **Release assets:** the release cut fetches the upstream tarballs, checks sha512
- against the lock, extracts `runsc`, checks its sha256 against the lock, and attaches
- `runsc-linux-arm64` and `runsc-linux-amd64` to the GitHub release, listed in the
- signed SHA256SUMS like every other asset. A release-check test reads the lock so a
- cut cannot attach a different binary.
-- **Mirror and pointer:** `carlos system update` (console `runSystemUpdate`) mirrors
- `runsc-<plat>` for each platform it mirrors `carlos-<plat>` for, to
- `bootstrap/router/<tag>/runsc-<plat>`, and records it in the signed pointer:
- `SystemRelease.Runsc map[string]SystemArtifact` (additive, omitempty; old pointers
- parse; boxes ignore it when absent). Uploads by `--file` carry no runsc.
-- **Install on the box:** the root system-update path and bootstrap call one function,
- `ensureRunsc`, but only when the box's effective mode is gvisor. It downloads the
- pointer's artifact, requires pointer sha == compiled pin sha, and installs it
- root-owned 0755 at `/opt/carlos/runsc/<sha256>/runsc` by write-to-temp, fsync,
- rename. The directory name is the hash, so an upgrade with a new pin installs a new
- path beside the old one and never rewrites a binary in use. Old directories go once
- no unit references them.
-- **Use:** root checks the installed file's sha256 against its own compiled pin at
- Ready (and caches by dev/inode/size/mtime). Missing or mismatched: Ready fails with
- `EXEC-SANDBOX-RUNSC` and every start is refused. Units reference the path through a
- root-written drop-in, so the template stays fixed.
+The authority is a pin compiled into the binary that will use runsc. That binary
+was itself delivered by the signed system pointer, so a runsc file whose sha256
+matches the pin is authentic wherever it was fetched from.
+
+- **Pin in the tree:** `internal/execsandbox/runsc.lock.json`, embedded: gVisor
+ release name, upstream tarball sha512 per arch, and the sha256 of the extracted
+ `runsc` binary for `linux-arm64` and `linux-amd64`. Changing runsc is a reviewed
+ commit to this file. It is in root's census scope.
+- **Content-addressed object:** `bootstrap/runsc/<sha256>/runsc-<plat>`. The key
+ names the hash, so no release, pointer or version string is involved, an old
+ release never needs the asset, and two releases with the same pin share one
+ object. `SystemPointer` does not change.
+- **Who uploads it:** the release cut fetches the upstream tarball, checks sha512
+ against the lock, extracts `runsc`, checks sha256 against the lock, and attaches
+ `runsc-linux-<arch>` to the GitHub release (in the signed SHA256SUMS). The
+ console's `runSystemUpdate` mirrors it to the content-addressed key when the
+ release has the asset; the asset is optional, so historical tags and `--file`
+ uploads mirror exactly as today. A console older than this build mirrors nothing;
+ the release agent then copies the object once by hand (dev only here). Trust does
+ not depend on the uploader: boxes check the hash.
+- **Who installs it:** a new root oneshot, `carlos-runsc.service`
+ (`ExecStart=/opt/carlos/carlos system runsc-ensure`, no RemainAfterExit),
+ pulled in by `carlos-instance-control.service` with `Wants=` and `After=`. It
+ runs the binary that is now installed, so the pin it checks is always the target
+ pin, after adoption, on every control start: fresh bootstrap, roll, rollback,
+ same-version retry, or a host.env change followed by a control restart. It reads
+ host.env itself and resolves the mode with §4's code; in systemd mode it exits 0
+ and touches nothing. In gvisor mode: if `/opt/carlos/runsc/<sha256>/runsc` exists,
+ is root-owned 0755, a single-link regular file, and hashes to the pin, done.
+ Otherwise it fetches the content-addressed object with the box's own bucket
+ credentials and the fetch code system-update already uses, checks the hash,
+ writes temp, fsyncs, renames, fsyncs the directory. The unit has
+ `ReadWritePaths=/opt/carlos/runsc` and nothing else writable.
+- **Use:** root controller checks the file against its compiled pin at Ready
+ (cached by dev/inode/size/mtime). Missing or mismatched: Ready fails with
+ `EXEC-SANDBOX-RUNSC` and every start is refused; Ready retries by starting
+ `carlos-runsc.service` on a backoff. Directories for other pins are removed by
+ runsc-ensure once no unit's ExecStart names them.
## 6. Units and the bundle
@@ -109,6 +125,7 @@ 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>
+ ExecStopPost=/opt/carlos/carlos instance-exit --sandbox=gvisor run %I
ExecStopPost=<runsc> --root=/run/carlos-runsc delete -force <id>
`<id>` is derived by root from the validated unit instance name (host, role,
@@ -120,7 +137,14 @@ root runner, then pin it in the verifier); it is not copied from the native temp
### 6.2 Limits (ruling 2)
-`execsandbox.GVisorOverhead = 32 MiB` (spike: +25 to 30 MB). For a gVisor demo unit
+`execsandbox.GVisorOverhead = 32 MiB` (spike: +25 to 30 MB). The logical tier stays
+`small` everywhere it is named (route, policy, shares, billing); one function,
+`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
+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
the small tier's. `GOMEMLIMIT` = 90% of the small tier's 256 MiB is set in the guest
@@ -131,21 +155,48 @@ gVisor mode and the native values otherwise.
### 6.3 Bundle writer: root derives everything
`internal/instancectl/ocibundle.go`: one typed constructor, `gvisorBundle(host, role,
-gen)`, run by root before `systemctl start`, writing
-`/var/lib/carlos-control/oci/<id>/config.json` (0600 root, parent 0700) with an empty
-read-only rootfs shared at `/var/lib/carlos-control/oci/rootfs` (not under `/run`:
-noexec breaks the gofer, spike gotcha 1).
-
-Inputs are the validated host shape, role and generation. No tenant-writable byte is
-read by root to build it: not the launch JSON, not the app's files.
-
-- Process: the platform's own trampoline, the same argv the native template's
- ExecStart uses today, plus `--sandbox=gvisor`. uid/gid carlos, no capabilities,
- `noNewPrivileges`, cwd the instance data dir.
-- Mounts: the root-owned carlos binary (ro), `/opt/carlos/live/<host>` (ro), the
- instance's nested data dir and run dir (rw), tmpfs `/tmp`. Nothing else from the
- host. Sources are derived from the host shape exactly as the native template's
- paths are; the writer refuses if any source is a symlink or not owned as expected.
+gen)`, run by root before `systemctl start`.
+
+Where things live (round 1 P1-2):
+
+- `config.json` goes in `/run/carlos-control/oci/<id>/` (0700 root), inside the
+ controller's existing writable `/run/carlos-control`. Nothing in the bundle
+ directory is executed, so `/run`'s noexec does not matter for it.
+- The rootfs is `root.path` = `/var/lib/carlos/oci-rootfs`, one empty directory,
+ root-owned 0755, created by bootstrap and by system apply, never written by the
+ controller. It is on the root filesystem, not noexec (spike gotcha 1).
+- runsc state is `--root=/run/carlos-runsc`, written only by runsc inside the
+ workload unit (its `RuntimeDirectory=carlos-runsc`, preserved). The controller
+ never reads or deletes runsc state; leftovers go through the unit's own
+ `ExecStartPre=runsc delete -force` and through stopping the unit.
+
+Inputs are the validated host shape, role and generation. No byte a tenant or app
+can write is read by root to build it: not the launch JSON, not the app's files.
+
+Executable (round 1 P1-1): the bundle reuses root's existing executable
+preparation unchanged: `ensureHostExeAt` / `ensureGenExeAt` with
+`validateStagedExe`, which lays out `<ExeRoot>/<key>/app` (a link to the live
+build or a validated staged build) and `<ExeRoot>/<key>/live/<host>` -> `../app`.
+The native unit binds those two with `BindReadOnlyPaths=` and systemd follows the
+`app` link at bind time. The bundle does the same work at write time: root resolves
+`app` with the same rules (no new kind of source: the live link or a validated
+staged build, both already followed by root today), requires a regular file, and
+writes that resolved path as the source of the `/opt/carlos/app` bind; it binds
+`<ExeRoot>/<key>/live` at `/opt/carlos/live`. Inside the guest
+`/opt/carlos/live/<host>` therefore names the same build the native unit would run,
+including a generation's staged build. A later deploy repoints the live link for
+the next start, as today.
+
+- Process: the trampoline at `/opt/carlos/carlos` (the platform binary, bound
+ read-only), argv `instance-exec run <instance>` exactly as the native ExecStart,
+ plus `--sandbox=gvisor`. Numeric uid/gid of `carlos` (read by root from the host's
+ root-owned passwd at bundle write), no capabilities, `noNewPrivileges`, cwd the
+ instance data dir, rlimits as the native unit's.
+- Mounts, complete list (round 1 P2-9): gVisor's own `/proc` (proc), `/dev` (runsc's
+ minimal device set: null, zero, full, random, urandom, tty, pts, shm as tmpfs),
+ `/tmp` tmpfs, `/opt/carlos/carlos` ro, `/opt/carlos/app` ro, `/opt/carlos/live` ro,
+ the instance's nested data dir and run dir rw at the same paths as native. No
+ `/sys`, no other host path.
- Network: none (`--network=none`, loopback only).
- The writer writes then reads back and compares bytes; `assertGVisorUnit` (§7)
rebuilds the expected bytes and compares again before start.
@@ -163,13 +214,27 @@ records, and:
the launch's;
- is PID 1 of the guest, so it keeps reaping and signal forwarding.
+It needs `openat2` with `RESOLVE_*` restrictions (`internal/instancefs`),
+`PR_SET_CHILD_SUBREAPER`, fork, setsid and signal delivery. The root-runner witness
+runs the real trampoline with a real launch JSON under runsc. If gVisor lacks a call
+the trampoline needs, the start is refused; path validation is never weakened to
+fit.
+
### 6.5 Stop, exit and stale state
`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
-inside the guest as uid carlos, as today, so the activator's exit reading is
-unchanged; systemd's own result describes runsc and is advisory. Termination proof
+by the same host-side hook as native (round 1 P2-8): `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
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.
@@ -186,6 +251,17 @@ 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
+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
+probe, host-claim start, egress restart, build naming and recovery, claim-freeze and
+purge discovery, general sweep and gen leftovers. Each unsupported start refuses at
+its own dispatch boundary.
+
`assertDemoUnit` gains a gVisor branch, `assertGVisorUnit`: `systemctl show` readback
of User=root, the exact ExecStart/ExecStartPre/ExecStopPost, runsc path and pin
directory, Slice, limits from §6.2, no pending reload, plus the bundle byte
@@ -194,6 +270,21 @@ 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.
+
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
directories for units that are inactive and empty. An operator flips the switch with
@@ -219,20 +310,29 @@ output, cache and tmp rw, cwd `/work/src`, the exact offline argv and environmen
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=300` (native 180; the
-spike's cold build took 1.5x as long), MemoryMax 1 GiB + 32 MiB, TasksMax 128 + 64,
-CPU as today, `KillMode=control-group`. `internal/demobuild` `prepareUnit`, `runUnit`,
+work tree to it before start. `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
+under gVisor in the spike. The root-runner witness builds the demo starter under
+gVisor with the real toolchain bundle and must finish under 60 s; if it does not,
+gVisor builds are refused and this section comes back, rather than the window
+moving. Limits come from `execsandbox.Physical`: MemoryMax 1 GiB + 32 MiB, TasksMax
+128 + 64, and `carlos-demo-builds.slice` grows by the overhead per allowed concurrent
+build. CPU as today, `KillMode=control-group`. `internal/demobuild` `prepareUnit`, `runUnit`,
`assertUnit`, `cleanUnit` and recovery branch on the family; output validation,
diagnostics and the aggregate build slice are unchanged. The build probe runs the
gVisor build unit when the box is in gVisor mode.
## 10. Demo claims keep working
-A claim freezes the demo (`freezeDemoLocal`: stop and prove), then root snapshots the
-host DB and WAL (`wireDemoClaimSnapshot`). In gVisor mode the stop-and-prove covers
+A claim freezes the demo (`freezeDemoLocal`: root stops and proves), then the agent
+reads the DB and streams it to root for the snapshot. In gVisor mode the stop-and-prove covers
the gVisor unit family, waits for the cgroup to empty and for `runsc delete` to
-finish, then the snapshot reads the host-visible files, which are the same files the
-guest wrote through the gofer. Demo instances hold a local lease with no replicator,
+finish, and only then does the agent's `wireDemoClaimSnapshot` open the host-visible DB and
+WAL and stream them to root's `SnapshotDemo`, exactly as today (round 1 P2-10): root
+still reads no database file. The files are the same ones the guest wrote through
+the gofer. Demo instances hold a local lease with no replicator,
so no host process reads the DB while the guest writes it. A root-runner test runs a
demo under gVisor, writes rows, freezes, snapshots and checks integrity and content.
@@ -270,7 +370,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
+## 14. Risks (unchanged from rev 1, plus the fence)
- 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.
@@ -278,3 +378,20 @@ 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.
+
+## 15. Round 1 answers
+
+| R1 | Sev | Answer |
+|---|---|---|
+| 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 |
+| 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 |
+| 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 |