carlos / platform Public

host: adopt re-renders the demo build slice after a sandbox flip

carlos-demo-builds.slice is rendered from host.env (build concurrency
and effective exec sandbox), but the adopt pass's already-armed return
never compared it. Switching CARLOS_EXEC_SANDBOX on a demo build box
left the slice at its old sizing and every gVisor build refused at
its budget check (v0.34.35 dev witness on demo box-1).

The pass now compares the installed slice with its rendering and
reinstalls (write loop + daemon-reload) when they differ. Test flips
host.env systemd -> gvisor -> systemd and checks one pass re-renders,
a second pass is quiet. Census re-proposed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 0507790d335264f3dfd98903c81202bfd41f8435 parent 3dd38c0
5 files changed, +167 −2
  • docs/superpowers/notes/census-proposal-demo-slice-adopt.md +19 −0
  • internal/host/demo_slice_adopt_linux_test.go +117 −0
  • internal/host/systemunits.go +25 −2
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-demo-slice-adopt.tsv +5 −0

CI passed — run details

diff --git a/docs/superpowers/notes/census-proposal-demo-slice-adopt.md b/docs/superpowers/notes/census-proposal-demo-slice-adopt.md
new file mode 100644
index 000000000..9c8a2f6d1
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-demo-slice-adopt.md
@@ -0,0 +1,19 @@
+# Census approval: demo-slice-adopt
+
+Ruling `census-ruling-demo-slice-adopt`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/host/systemunits.go` `ensureSystemUnitsWithGuard` | sites | +file:ReadFile ×2 | Read the embedded carlos-demo-builds.slice and the installed one at the fixed unit path (/etc/systemd/system), compare it with its host.env rendering, and treat a difference as a reinstall (the existing write loop and daemon-reload). No new path, input, systemctl verb or write target; the slice is root-owned and rendered only from the already-parsed claim settings. |
+
+Envelopes re-pinned: `internal/host`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Recorded dispositions, which each change must still satisfy:
+
+- `internal/host/systemunits.go` `ensureSystemUnitsWithGuard`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-region-ha-p3b;basis=Move unit-repair body here with existing lock/unit/host.env reads; under lock require operator repair permit on groups before writes and each systemctl effect, preserve root masks/drop-in and omit automatic update/recovery units. New indirect protected marker/permit reads, never agent receipt; fixed repair unchanged.;rev3=census-ruling-gvisor-demos;basis=Create runtime/rootfs directories and repair installer plus three measured workload templates without arming them. Existing unit/host.env reads unchanged.;rev3=census-ruling-gvisor-update-dirs;basis=Create the two live sandbox directories (the same fixed ensureSandboxDirectories paths) before the apply lock and the early returns on non-group boxes; group members still create them only after the maintenance permit. A creation error still ends the pass at the original point. Then call refreshControlSandboxRootfs. No new path, input or systemctl verb beyond the try-restart below.
+
+Seal: `0f7153571df8c1b4b50c31f57efcfdf60c71a12c80fd935fb3ea202fa0201dd5` → `c36402d0312399105904a391eced9f71af8ace17ee82c77d3c7adf830d3d5ea7`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-demo-slice-adopt.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/host/demo_slice_adopt_linux_test.go b/internal/host/demo_slice_adopt_linux_test.go
new file mode 100644
index 000000000..73486055e
--- /dev/null
+++ b/internal/host/demo_slice_adopt_linux_test.go
@@ -0,0 +1,117 @@
+package host
+
+import (
+ "os"
+ "path/filepath"
+ "slices"
+ "strconv"
+ "strings"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/demobuild"
+ "github.com/carlosframework/platform/internal/execsandbox"
+)
+
+// A demo build box switched from systemd to gVisor in host.env changes no
+// unit but the build budget slice. One adopt pass must re-render it and
+// reload systemd; before this, the pass returned as already armed and every
+// gVisor build refused at its budget check (v0.34.35 dev witness).
+func TestAdoptRerendersDemoBuildSliceOnSandboxFlip(t *testing.T) {
+ root := t.TempDir()
+ etc, opt := filepath.Join(root, "etc"), filepath.Join(root, "opt/carlos")
+ unitDir := filepath.Join(etc, "systemd/system")
+ for _, dir := range []string{unitDir, filepath.Join(etc, "carlos")} {
+ if err := os.MkdirAll(dir, 0755); err != nil {
+ t.Fatal(err)
+ }
+ }
+ const demoEnv = "CARLOS_DEMO_BOX=1\nCARLOS_DEMO_ACCOUNT=shop\nCARLOS_DEMO_FLEET=demo\nCARLOS_DEMO_DOMAIN=example.com\nCARLOS_DEMO_BUILD_WORKER=1\nCARLOS_DEMO_BUILD_CONCURRENCY=1\nCARLOS_DEMO_TOOLCHAIN_DIR=/opt/demo-toolchain\n"
+ envPath := filepath.Join(etc, "carlos/host.env")
+ writeEnv := func(mode string) {
+ t.Helper()
+ if err := os.WriteFile(envPath, []byte("CARLOS_EXEC_SANDBOX="+mode+"\n"+demoEnv), 0600); err != nil {
+ t.Fatal(err)
+ }
+ }
+ writeEnv("systemd")
+ settings, err := readClaimUnitSettings(envPath)
+ if err != nil || !settings.demo.BuildWorker {
+ t.Fatalf("settings: %+v %v", settings, err)
+ }
+ // An armed systemd-mode box: every unit as this build renders it.
+ for _, name := range systemUnitFiles {
+ raw, err := unitsFS.ReadFile("units/" + name)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(unitDir, name), claimUnitContent(name, raw, settings), 0644); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if _, err := installDemoUnitsIn(unitDir, settings.demo); err != nil {
+ t.Fatal(err)
+ }
+ probe := func(args ...string) (string, error) {
+ if args[1] == dbReadSocketUnit {
+ if args[0] == "is-active" {
+ return "inactive", systemctlExit(3)
+ }
+ return "disabled", systemctlExit(1)
+ }
+ if args[0] == "is-active" {
+ return "active", nil
+ }
+ return "enabled", nil
+ }
+ var calls [][]string
+ call := func(args ...string) (string, error) {
+ calls = append(calls, args)
+ return "", nil
+ }
+ lock := filepath.Join(systemRootDir(opt), systemLockFile)
+ slicePath := filepath.Join(unitDir, demoBuildsSlice)
+ want := func(family execsandbox.Family) string {
+ p := demobuild.SlicePropertiesFor(1, family)
+ return "MemoryMax=" + strconv.FormatInt(p["MemoryMax"], 10) + "\nMemorySwapMax=0\nTasksMax=" + strconv.FormatInt(p["TasksMax"], 10) + "\n"
+ }
+ if want(execsandbox.FamilySystemd) == want(execsandbox.FamilyGVisor) {
+ t.Fatal("the two families size the slice alike; this test proves nothing")
+ }
+ readSlice := func() string {
+ t.Helper()
+ b, err := os.ReadFile(slicePath)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return string(b)
+ }
+
+ ensureSystemUnits(etc, lock, call, probe, t.Logf)
+ if len(calls) != 0 {
+ t.Fatalf("armed systemd box changed units: %v", calls)
+ }
+ if !strings.Contains(readSlice(), want(execsandbox.FamilySystemd)) {
+ t.Fatalf("baseline slice: %s", readSlice())
+ }
+
+ writeEnv("gvisor")
+ ensureSystemUnits(etc, lock, call, probe, t.Logf)
+ if got := readSlice(); !strings.Contains(got, want(execsandbox.FamilyGVisor)) {
+ t.Fatalf("one pass after the flip left the slice at:\n%s", got)
+ }
+ if !slices.ContainsFunc(calls, func(a []string) bool { return len(a) == 1 && a[0] == "daemon-reload" }) {
+ t.Fatalf("no daemon-reload after re-rendering the slice: %v", calls)
+ }
+
+ calls = nil
+ ensureSystemUnits(etc, lock, call, probe, t.Logf)
+ if len(calls) != 0 {
+ t.Fatalf("second pass on the flipped box changed units again: %v", calls)
+ }
+
+ writeEnv("systemd")
+ ensureSystemUnits(etc, lock, call, probe, t.Logf)
+ if got := readSlice(); !strings.Contains(got, want(execsandbox.FamilySystemd)) {
+ t.Fatalf("rollback pass left the slice at:\n%s", got)
+ }
+}
diff --git a/internal/host/systemunits.go b/internal/host/systemunits.go
index 1c5ba3d06..0f30af552 100644
--- a/internal/host/systemunits.go
+++ b/internal/host/systemunits.go
@@ -34,7 +34,10 @@ var ensureSystemArmed = []string{systemUpdatePathUnit, systemRecoverUnit, instan
// carlos-dbread.socket and its service template are the db-read worker's
// (db region forward spec §8.3): installed and the socket armed here, the
// template never started.
-var systemUnitFiles = []string{"carlos-runsc.service", instancectl.UnitPrefixGVisor + ".service", "carlos-instance-gvisor-probe.service", "carlos-demo-build-gvisor@.service", "carlos-system-update.path", "carlos-system-update.service", systemRecoverUnit, instanceControlSocket, "carlos-instance-control.service", dbReadSocketUnit, "carlos-dbread@.service", "carlos-demo-build@.service", "carlos-demo-builds.slice"}
+// demoBuildsSlice is the demo build budget, rendered per box by claimUnitContent.
+const demoBuildsSlice = "carlos-demo-builds.slice"
+
+var systemUnitFiles = []string{"carlos-runsc.service", instancectl.UnitPrefixGVisor + ".service", "carlos-instance-gvisor-probe.service", "carlos-demo-build-gvisor@.service", "carlos-system-update.path", "carlos-system-update.service", systemRecoverUnit, instanceControlSocket, "carlos-instance-control.service", dbReadSocketUnit, "carlos-dbread@.service", "carlos-demo-build@.service", demoBuildsSlice}
// ensureSystemUnits is the second belt of spec §7: a box the roll script
// forgot to arm is armed within the hour by the root adopt pass. It
@@ -200,6 +203,26 @@ func ensureSystemUnitsWithGuard(etcDir, lockPath string, systemctl, probe func(a
return
}
controlChanged := settingsErr == nil && (claimSettings.enabled || claimSettings.demo.BoxMode() || claimControlRendered(installed)) && (err != nil || !bytes.Equal(installed, claimUnitContent(claimControlUnit, control, claimSettings)))
+ // The demo build budget slice is rendered from host.env too: the build
+ // concurrency and the effective exec sandbox size it. A host.env change
+ // alone (a box switched to gVisor) touches no other unit, so without this
+ // comparison the pass would return as already armed and leave the slice
+ // sized for the old sandbox, and every build would refuse at its budget
+ // check. A missing slice is already a reinstall (missing).
+ sliceChanged := false
+ if settingsErr == nil {
+ sliceRaw, err := unitsFS.ReadFile("units/" + demoBuildsSlice)
+ if err != nil {
+ logf("adopt: system units: %v", err)
+ return
+ }
+ sliceInstalled, err := os.ReadFile(filepath.Join(unitDir, demoBuildsSlice))
+ if err != nil && !os.IsNotExist(err) {
+ logf("adopt: demo build slice: %v", err)
+ return
+ }
+ sliceChanged = err == nil && !bytes.Equal(sliceInstalled, claimUnitContent(demoBuildsSlice, sliceRaw, claimSettings))
+ }
dbrEnabled := parseIsEnabled(dbrEnabledOut)
// Dark: neither listening nor enabled for the next boot.
dbrDark := !*dbrActive && (dbrEnabled == nil || !*dbrEnabled)
@@ -212,7 +235,7 @@ func ensureSystemUnitsWithGuard(etcDir, lockPath string, systemctl, probe func(a
return
}
}
- if !demoChanged && !missing && !controlChanged && *isActive && isEnabled != nil && *isEnabled && *ctlActive && dbrSettled {
+ if !demoChanged && !missing && !controlChanged && !sliceChanged && *isActive && isEnabled != nil && *isEnabled && *ctlActive && dbrSettled {
return
}
if err := os.MkdirAll(unitDir, 0o755); err != nil {
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 4eab739b6..cab410184 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -139,3 +139,4 @@ plan14-root-reads-dns-fresh-lookup-724.tsv 7ac2bde8301c37c7546e9aa19d375f1468fc8
plan14-root-reads-gvisor-update-dirs.tsv 1f1b2fdb569b7be42e75e10d1943d7e512708299364f912c2f72dccf1bd5b678
plan14-root-reads-region-ha-held-build.tsv beb085e4c6cdb3d430d12a8dc3c93f25cc3faf1aa7d62be37698ff9c9c82ecce
plan14-root-reads-fixedbox-health-alarms.tsv 0f7153571df8c1b4b50c31f57efcfdf60c71a12c80fd935fb3ea202fa0201dd5
+plan14-root-reads-demo-slice-adopt.tsv c36402d0312399105904a391eced9f71af8ace17ee82c77d3c7adf830d3d5ea7
diff --git a/internal/provision/testdata/plan14-root-reads-demo-slice-adopt.tsv b/internal/provision/testdata/plan14-root-reads-demo-slice-adopt.tsv
new file mode 100644
index 000000000..9ecae87ed
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-demo-slice-adopt.tsv
@@ -0,0 +1,5 @@
+# Census overlay demo-slice-adopt, written by census-propose (#369). census-ruling-demo-slice-adopt, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-demo-slice-adopt.md.
+# 0 body, 1 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@legacy c2f18832e4429189c15890a43417df4eedff2e0882fdb541ff5cb726ba8b936f internal/host/systemunits.go ensureSystemUnitsWithGuard legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p3b;basis=Move unit-repair body here with existing lock/unit/host.env reads; under lock require operator repair permit on groups before writes and each systemctl effect, preserve root masks/drop-in and omit automatic update/recovery units. New indirect protected marker/permit reads, never agent receipt; fixed repair unchanged.;rev3=census-ruling-gvisor-demos;basis=Create runtime/rootfs directories and repair installer plus three measured workload templates without arming them. Existing unit/host.env reads unchanged.;rev3=census-ruling-gvisor-update-dirs;basis=Create the two live sandbox directories (the same fixed ensureSandboxDirectories paths) before the apply lock and the early returns on non-group boxes; group members still create them only after the maintenance permit. A creation error still ends the pass at the original point. Then call refreshControlSandboxRootfs. No new path, input or systemctl verb beyond the try-restart below.;rev3=census-ruling-demo-slice-adopt;basis=Read the embedded carlos-demo-builds.slice and the installed one at the fixed unit path (/etc/systemd/system), compare it with its host.env rendering, and treat a difference as a reinstall (the existing write loop and daemon-reload). No new path, input, systemctl verb or write target; the slice is root-owned and rendered only from the already-parsed claim settings. file:OpenFile@985,file:ReadFile@5626,file:ReadFile@5759,file:ReadFile@6647,file:ReadFile@6789,file:ReadFile@8096,file:Stat@5535 869800bbcd443b47e0a4462ed39d1051d4a776fc0498791784c19078a3dda7bc
+internal/host/systemunits.go ensureSystemUnitsWithGuard legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p3b;basis=Move unit-repair body here with existing lock/unit/host.env reads; under lock require operator repair permit on groups before writes and each systemctl effect, preserve root masks/drop-in and omit automatic update/recovery units. New indirect protected marker/permit reads, never agent receipt; fixed repair unchanged.;rev3=census-ruling-gvisor-demos;basis=Create runtime/rootfs directories and repair installer plus three measured workload templates without arming them. Existing unit/host.env reads unchanged.;rev3=census-ruling-gvisor-update-dirs;basis=Create the two live sandbox directories (the same fixed ensureSandboxDirectories paths) before the apply lock and the early returns on non-group boxes; group members still create them only after the maintenance permit. A creation error still ends the pass at the original point. Then call refreshControlSandboxRootfs. No new path, input or systemctl verb beyond the try-restart below.;rev3=census-ruling-demo-slice-adopt;basis=Read the embedded carlos-demo-builds.slice and the installed one at the fixed unit path (/etc/systemd/system), compare it with its host.env rendering, and treat a difference as a reinstall (the existing write loop and daemon-reload). No new path, input, systemctl verb or write target; the slice is root-owned and rendered only from the already-parsed claim settings. file:OpenFile@985,file:ReadFile@5626,file:ReadFile@5759,file:ReadFile@6647,file:ReadFile@6789,file:ReadFile@8096,file:Stat@5535 869800bbcd443b47e0a4462ed39d1051d4a776fc0498791784c19078a3dda7bc
+@coverage internal/host 6f798596db0d2800638875314233378edea1a127c18c1337669f8518bdf59b9e