carlos / platform Public

demobuild: the build worker reconciles the slice budget (option A)

Rule 2 stop after Astra R2. Paul (via 8a3d302) chose option A: one
reconciler in the build worker, and no live budget changes in the
adopt or apply paths.

- Removed set-property, the runtime override, and the slice change in
  the apply path (systemapply.go is back to main).
- Adopt keeps only the R1 re-render + daemon-reload, plus the
  loaded-budget check, which retries a failed reload.
- Before admitting a build, Worker.Build checks the slice's kernel
  limits (memory.max, memory.swap.max, pids.max, cpu.max) against the
  rendered budget. If they differ, it stops the slice only when it
  holds buildPurge exclusively, the slice is unpopulated and no build
  or slice job is queued. Otherwise it defers with a retryable
  DEMO-BUILD. A stale loaded config is left for the adopt pass.
- Root witness TestRootBuildBudgetReconcile passed both directions on
  systemd 257 (run 20261109T184214-8ef716). A busy slice defers
  untouched, an empty stale slice is stopped, and the next unit starts
  on the loaded budget. The witness also found that systemd re-applies
  the loaded budget itself when the last unit leaves the slice.

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 b0c4d51ddaddb77c994ba8b3f5f27d3baa93e9c8 parent 532ebcf
12 files changed, +457 −289
  • docs/superpowers/notes/census-proposal-demo-slice-adopt.md +11 −6
  • internal/demobuild/budget.go +128 −0
  • internal/demobuild/budget_rootrunner_linux_test.go +146 −0
  • internal/demobuild/budget_test.go +137 −0
  • internal/demobuild/worker.go +19 −6
  • internal/demobuild/worker_test.go +2 −2
  • internal/host/demo_slice_adopt_linux_test.go +1 −99
  • internal/host/demo_slice_reload_rootrunner_linux_test.go +0 −116
  • internal/host/systemapply.go +0 −16
  • internal/host/systemunits.go +0 −37
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −1
  • internal/provision/testdata/plan14-root-reads-demo-slice-adopt.tsv +12 −6

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
index 0ffbcd986..7ffe363fe 100644
--- a/docs/superpowers/notes/census-proposal-demo-slice-adopt.md
+++ b/docs/superpowers/notes/census-proposal-demo-slice-adopt.md
@@ -1,21 +1,26 @@
# 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).
+Ruling `census-ruling-demo-slice-adopt`. The independent reviewer approves or rejects every change below, 2 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
| unit | change | read sites | what changed |
|---|---|---|---|
-| `internal/host/systemapply.go` `systemApplier.installUnits` | sites | +file:ReadFile ×2 | Read the installed carlos-demo-builds.slice before the install (fixed root unit path); when the installed slice changed, set its rendered budget on the live slice (systemctl set-property --runtime, fixed name) and on failure write the earlier bytes back. No new path or input; values come from the rendering this function already wrote. |
-| `internal/host/systemunits.go` `ensureSystemUnitsWithGuard` | sites | +file:ReadFile ×2 | Compare the installed carlos-demo-builds.slice (fixed root unit path, embedded unit) with its host.env rendering, and ask systemd for the slice's loaded MemoryMax/TasksMax (systemctl show on the fixed slice name); a definite difference is a reinstall. Before writing, put the rendered budget on the live slice with systemctl set-property --runtime on that fixed name, through the same permit-wrapped systemctl. No new path, input or write target; values come only from the already-parsed claim settings. |
+| `internal/demobuild/worker.go` `Worker.Build` | body | unchanged (1) | Before admission, call the admit hook (nil = reconcileBudget). reconcileBudget reads the fixed build slice's systemctl show budget, its cgroup limit files and cgroup.events under the fixed root cgroup path, and list-jobs; only with buildPurge held exclusively, the slice empty and no build or slice job queued does it run systemctl stop on the fixed slice name. Otherwise it defers with DEMO-BUILD. No tenant, app or agent input names a path or unit. |
+| `internal/host/systemunits.go` `ensureSystemUnitsWithGuard` | sites | +file:ReadFile ×2 | Compare the installed carlos-demo-builds.slice (fixed root unit path, embedded unit) with its host.env rendering, and ask systemd for the slice's loaded MemoryMax/TasksMax (systemctl show on the fixed name). A definite difference is a reinstall (existing write loop + daemon-reload). No live budget change, no new path, input or write target. |
-Envelopes re-pinned: `internal/host`.
+Envelopes re-pinned: `internal/demobuild`, `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/systemapply.go` `systemApplier.installUnits`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-agent-start-demo-1;basis=Renders the staged build slice against live root host configuration; preserves it when settings cannot be parsed.;rev3=census-ruling-region-ha-p3b;basis=Require group apply/rollback permit, preserve root Restart=no/nftables drop-in and masks, and skip automatic update/recovery units. Existing staged unit and host.env reads remain; new indirect marker/permit reads are protected and agent receipts are excluded.;rev3=census-ruling-gvisor-demos;basis=Create rootfs/runtime parent directories before controller restart. Existing staged unit and root-owned host.env reads unchanged.
+- `internal/demobuild/worker.go` `Worker.Build`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-agent-start-demo-1;basis=Holds the build/purge read lock through cleanup; existing bounded source read remains.
- `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` → `c793523d694cd0ddd20b9562bd61b69093b613b5faa4a262d5cb3f0c82efa0b5`.
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- new `internal/demobuild/budget.go:budgetSlicePopulated`: reads +file:ReadFile; written legacy, accepted-legacy, frozen
+- new `internal/demobuild/budget.go:kernelBudgetMatches`: reads +file:Lstat, +file:ReadFile; written legacy, accepted-legacy, frozen
+
+Seal: `0f7153571df8c1b4b50c31f57efcfdf60c71a12c80fd935fb3ea202fa0201dd5` → `762577dd5e472a076779f5e9dfd697034293a4f52667c42002671f5f887e474a`.
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/demobuild/budget.go b/internal/demobuild/budget.go
new file mode 100644
index 000000000..caba9407e
--- /dev/null
+++ b/internal/demobuild/budget.go
@@ -0,0 +1,128 @@
+package demobuild
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "os"
+ "path/filepath"
+ "strconv"
+ "strings"
+
+ "github.com/carlosframework/platform/internal/execsandbox"
+)
+
+// budgetSlice holds every native and gVisor build unit.
+const budgetSlice = "carlos-demo-builds.slice"
+
+// reconcileBudget runs before a build is admitted. It is the only place a
+// build budget reaches the kernel after the slice was first started.
+//
+// systemd sets a slice's cgroup limits when the slice starts. daemon-reload
+// after the adopt pass re-renders the unit (a sandbox switch, a concurrency
+// change) updates systemd's view only, and the running slice keeps its old
+// limits (root-runner witness, systemd 257). So, when the kernel limits
+// differ from the rendered budget:
+// - with builds, snapshots or purges running, or anything left in the
+// slice, the build is deferred (ErrBuild, retryable): a running build
+// never has its budget changed under it;
+// - otherwise the empty slice is stopped, and the next build unit starts
+// it again on the budget systemd now has loaded.
+//
+// A slice whose loaded configuration is itself stale (no adopt pass since
+// host.env changed) fails assertBudget first and is left alone: stopping it
+// would only restart it on the same stale budget.
+func (w *Worker) reconcileBudget(ctx context.Context) error {
+ if err := w.assertBudget(ctx); err != nil {
+ return err
+ }
+ n, family := cap(w.slots), w.SandboxFamily()
+ if ok, err := kernelBudgetMatches(n, family); err != nil || ok {
+ return err
+ }
+ // Builds hold buildPurge for reading; snapshots and purges hold it
+ // outright. Holding it here means none of them is in flight in this
+ // process, and processLock means no other worker process exists.
+ if !w.buildPurge.TryLock() {
+ return fmt.Errorf("%w: build budget change waits for running builds", ErrBuild)
+ }
+ defer w.buildPurge.Unlock()
+ if ok, err := kernelBudgetMatches(n, family); err != nil || ok {
+ return err
+ }
+ populated, err := budgetSlicePopulated()
+ if err != nil {
+ return err
+ }
+ if populated {
+ return fmt.Errorf("%w: build budget change waits for an empty build slice", ErrBuild)
+ }
+ jobs, err := systemctl(ctx, "list-jobs", "--no-legend", "--no-pager")
+ if err != nil {
+ return err
+ }
+ for _, line := range strings.Split(jobs, "\n") {
+ if f := strings.Fields(line); len(f) >= 2 && (f[1] == budgetSlice || strings.HasPrefix(f[1], "carlos-demo-build@") || strings.HasPrefix(f[1], "carlos-demo-build-gvisor@")) {
+ return fmt.Errorf("%w: build budget change waits for queued %s", ErrBuild, f[1])
+ }
+ }
+ if _, err := systemctl(ctx, "stop", budgetSlice); err != nil {
+ return err
+ }
+ out, err := systemctl(ctx, "show", budgetSlice, "-p", "ActiveState")
+ if err != nil {
+ return err
+ }
+ if state := showProperties(out)["ActiveState"]; state != "inactive" {
+ return fmt.Errorf("%w: build slice %s after stop", ErrBuild, state)
+ }
+ return nil
+}
+
+// kernelBudgetMatches compares the build slice's cgroup limits with the
+// budget for n slots of family. No cgroup (the slice is not running) is a
+// match: the next start applies whatever systemd has loaded.
+func kernelBudgetMatches(n int, family execsandbox.Family) (bool, error) {
+ p := SlicePropertiesFor(n, family)
+ if p == nil {
+ return false, ErrBuild
+ }
+ if _, err := os.Lstat(buildCgroupRoot); errors.Is(err, os.ErrNotExist) {
+ return true, nil
+ } else if err != nil {
+ return false, err
+ }
+ want := map[string]string{
+ "memory.max": strconv.FormatInt(p["MemoryMax"], 10),
+ "memory.swap.max": "0",
+ "pids.max": strconv.FormatInt(p["TasksMax"], 10),
+ "cpu.max": strconv.FormatInt(p["CPUQuota"]*1000, 10) + " 100000",
+ }
+ for name, value := range want {
+ b, err := os.ReadFile(filepath.Join(buildCgroupRoot, name))
+ if err != nil {
+ return false, err
+ }
+ if strings.TrimSpace(string(b)) != value {
+ return false, nil
+ }
+ }
+ return true, nil
+}
+
+// budgetSlicePopulated reads the slice's cgroup.events. No cgroup is empty.
+func budgetSlicePopulated() (bool, error) {
+ b, err := os.ReadFile(filepath.Join(buildCgroupRoot, "cgroup.events"))
+ if errors.Is(err, os.ErrNotExist) {
+ return false, nil
+ }
+ if err != nil {
+ return false, err
+ }
+ for _, line := range strings.Split(string(b), "\n") {
+ if f := strings.Fields(line); len(f) == 2 && f[0] == "populated" {
+ return f[1] != "0", nil
+ }
+ }
+ return false, fmt.Errorf("%w: build slice cgroup.events has no populated line", ErrBuild)
+}
diff --git a/internal/demobuild/budget_rootrunner_linux_test.go b/internal/demobuild/budget_rootrunner_linux_test.go
new file mode 100644
index 000000000..a3b6bdcc6
--- /dev/null
+++ b/internal/demobuild/budget_rootrunner_linux_test.go
@@ -0,0 +1,146 @@
+//go:build linux && rootrunner
+
+package demobuild
+
+import (
+ "context"
+ "errors"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "strconv"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/execsandbox"
+)
+
+// TestRootBuildBudgetReconcile: on real systemd, the build worker's
+// reconciler brings an active build slice with a stale kernel budget to the
+// loaded one, in both directions of a sandbox switch. It defers (retryable
+// DEMO-BUILD) while anything runs in the slice and never touches a running
+// one; once the slice is empty it stops it, and the next unit in the slice
+// starts it on the new budget.
+func TestRootBuildBudgetReconcile(t *testing.T) {
+ if os.Geteuid() != 0 {
+ t.Fatal("needs root")
+ }
+ if _, err := os.Lstat(filepath.Join("/etc/systemd/system", budgetSlice)); err == nil {
+ t.Fatal("refusing: a real build slice is installed here")
+ }
+ unitPath := filepath.Join("/run/systemd/system", budgetSlice)
+ run := func(args ...string) string {
+ t.Helper()
+ out, err := exec.Command(args[0], args[1:]...).CombinedOutput()
+ if err != nil {
+ t.Fatalf("%v: %v: %s", args, err, out)
+ }
+ return strings.TrimSpace(string(out))
+ }
+ install := func(family execsandbox.Family) {
+ t.Helper()
+ p := SlicePropertiesFor(1, family)
+ body := "[Unit]\nDescription=carlos offline demo build budget\n\n[Slice]\nMemoryMax=" + strconv.FormatInt(p["MemoryMax"], 10) + "\nMemorySwapMax=0\nTasksMax=" + strconv.FormatInt(p["TasksMax"], 10) + "\nCPUQuota=" + strconv.FormatInt(p["CPUQuota"], 10) + "%\nCPUWeight=10\n"
+ if err := os.WriteFile(unitPath, []byte(body), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ run("systemctl", "daemon-reload")
+ }
+ const sleeper = "carlos-rr-build-sleeper"
+ startSleeper := func() {
+ t.Helper()
+ run("systemd-run", "--unit="+sleeper, "--slice="+budgetSlice, "--property=Type=exec", "/bin/sleep", "600")
+ time.Sleep(500 * time.Millisecond)
+ }
+ stopSleeper := func() {
+ t.Helper()
+ run("systemctl", "stop", sleeper+".service")
+ time.Sleep(500 * time.Millisecond)
+ }
+ kernel := func() string {
+ t.Helper()
+ var parts []string
+ for _, f := range []string{"memory.max", "memory.swap.max", "pids.max", "cpu.max"} {
+ b, err := os.ReadFile(filepath.Join(buildCgroupRoot, f))
+ if err != nil {
+ t.Fatalf("%s: %v", f, err)
+ }
+ parts = append(parts, f+"="+strings.TrimSpace(string(b)))
+ }
+ return strings.Join(parts, " ")
+ }
+ t.Cleanup(func() {
+ _ = exec.Command("systemctl", "stop", sleeper+".service", budgetSlice).Run()
+ _ = os.Remove(unitPath)
+ _ = exec.Command("systemctl", "daemon-reload").Run()
+ })
+ ctx := context.Background()
+
+ install(execsandbox.FamilySystemd)
+ startSleeper()
+ if ok, err := kernelBudgetMatches(1, execsandbox.FamilySystemd); err != nil || !ok {
+ t.Fatalf("baseline: %v %v (%s)", ok, err, kernel())
+ }
+ for _, step := range []struct{ from, to execsandbox.Family }{
+ {execsandbox.FamilySystemd, execsandbox.FamilyGVisor},
+ {execsandbox.FamilyGVisor, execsandbox.FamilySystemd},
+ } {
+ w := &Worker{family: step.to, slots: make(chan struct{}, 1)}
+ install(step.to) // the adopt pass: file + daemon-reload
+ before := kernel()
+ t.Logf("%s -> %s, after reload only: %s", step.from, step.to, before)
+ if ok, _ := kernelBudgetMatches(1, step.to); ok {
+ t.Fatalf("reload alone moved the kernel budget; the witness premise is gone: %s", before)
+ }
+
+ // A build (here the sleeper) still runs in the slice: defer.
+ err := w.reconcileBudget(ctx)
+ if !errors.Is(err, ErrBuild) {
+ t.Fatalf("busy slice: want a DEMO-BUILD deferral, got %v", err)
+ }
+ if kernel() != before || run("systemctl", "is-active", sleeper+".service") != "active" {
+ t.Fatalf("busy slice was touched: %s", kernel())
+ }
+ t.Logf("busy slice deferred: %v", err)
+
+ // The slice empties. systemd may re-apply the loaded budget itself
+ // when the last unit leaves (seen on 257); either way the
+ // reconciler must leave the slice on the loaded budget.
+ stopSleeper()
+ ok, _ := kernelBudgetMatches(1, step.to)
+ t.Logf("slice emptied: kernel %s (already on the new budget: %v)", kernel(), ok)
+ if err := w.reconcileBudget(ctx); err != nil {
+ t.Fatalf("empty slice: %v", err)
+ }
+ // The stop branch on real systemd: an empty, active slice whose
+ // kernel limits are stale (the state the reload left on the box).
+ startSleeper()
+ stopSleeper()
+ old := SlicePropertiesFor(1, step.from)
+ for name, v := range map[string]string{"memory.max": strconv.FormatInt(old["MemoryMax"], 10), "pids.max": strconv.FormatInt(old["TasksMax"], 10)} {
+ if err := os.WriteFile(filepath.Join(buildCgroupRoot, name), []byte(v), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if ok, _ := kernelBudgetMatches(1, step.to); ok {
+ t.Fatalf("could not stage stale limits: %s", kernel())
+ }
+ if err := w.reconcileBudget(ctx); err != nil {
+ t.Fatalf("empty stale slice: %v", err)
+ }
+ if out, _ := exec.Command("systemctl", "is-active", budgetSlice).CombinedOutput(); strings.TrimSpace(string(out)) != "inactive" {
+ t.Fatalf("empty stale slice not stopped: %s", out)
+ }
+ t.Logf("empty stale slice stopped")
+ startSleeper()
+ if ok, err := kernelBudgetMatches(1, step.to); err != nil || !ok {
+ t.Fatalf("restarted slice: %v %v (%s)", ok, err, kernel())
+ }
+ t.Logf("restarted on the %s budget: %s", step.to, kernel())
+ // Converged: a further admission check changes nothing.
+ if err := w.reconcileBudget(ctx); err != nil || run("systemctl", "is-active", sleeper+".service") != "active" {
+ t.Fatalf("converged slice: %v", err)
+ }
+ }
+}
diff --git a/internal/demobuild/budget_test.go b/internal/demobuild/budget_test.go
new file mode 100644
index 000000000..4cd50b0fc
--- /dev/null
+++ b/internal/demobuild/budget_test.go
@@ -0,0 +1,137 @@
+package demobuild
+
+import (
+ "context"
+ "errors"
+ "os"
+ "path/filepath"
+ "strconv"
+ "strings"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/execsandbox"
+)
+
+// budgetFixture: a worker with one slot in family, a fake build slice cgroup
+// holding kernel limits for kernelFamily, and a fake systemctl whose loaded
+// budget is the rendered one for loadedFamily.
+type budgetFixture struct {
+ w *Worker
+ calls []string
+ jobs string
+ active string
+ stopErr error
+}
+
+func newBudgetFixture(t *testing.T, family, loadedFamily execsandbox.Family, kernelFamily execsandbox.Family, populated bool) *budgetFixture {
+ t.Helper()
+ f := &budgetFixture{active: "inactive"}
+ f.w = &Worker{family: family, slots: make(chan struct{}, 1)}
+ oldRoot, oldCtl := buildCgroupRoot, systemctl
+ t.Cleanup(func() { buildCgroupRoot, systemctl = oldRoot, oldCtl })
+ buildCgroupRoot = filepath.Join(t.TempDir(), "carlos-demo-builds.slice")
+ if kernelFamily != "" {
+ if err := os.MkdirAll(buildCgroupRoot, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ k := SlicePropertiesFor(1, kernelFamily)
+ pop := "0"
+ if populated {
+ pop = "1"
+ }
+ for name, v := range map[string]string{
+ "memory.max": strconv.FormatInt(k["MemoryMax"], 10), "memory.swap.max": "0",
+ "pids.max": strconv.FormatInt(k["TasksMax"], 10), "cpu.max": "50000 100000",
+ "cgroup.events": "populated " + pop + "\nfrozen 0\n",
+ } {
+ if err := os.WriteFile(filepath.Join(buildCgroupRoot, name), []byte(v+"\n"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ }
+ }
+ loaded := SlicePropertiesFor(1, loadedFamily)
+ systemctl = func(_ context.Context, args ...string) (string, error) {
+ f.calls = append(f.calls, strings.Join(args, " "))
+ switch {
+ case args[0] == "show" && strings.Contains(strings.Join(args, " "), "MemoryMax"):
+ return "MemoryMax=" + strconv.FormatInt(loaded["MemoryMax"], 10) + "\nMemorySwapMax=0\nTasksMax=" + strconv.FormatInt(loaded["TasksMax"], 10) + "\nCPUQuotaPerSecUSec=500ms\n", nil
+ case args[0] == "show":
+ return "ActiveState=" + f.active + "\n", nil
+ case args[0] == "list-jobs":
+ return f.jobs, nil
+ case args[0] == "stop":
+ if f.stopErr != nil {
+ return "", f.stopErr
+ }
+ // Stopping the slice removes its cgroup.
+ if err := os.RemoveAll(buildCgroupRoot); err != nil {
+ t.Fatal(err)
+ }
+ }
+ return "", nil
+ }
+ return f
+}
+
+func (f *budgetFixture) stopped() bool {
+ for _, c := range f.calls {
+ if c == "stop "+budgetSlice {
+ return true
+ }
+ }
+ return false
+}
+
+func TestReconcileBudget(t *testing.T) {
+ gv, sd := execsandbox.FamilyGVisor, execsandbox.FamilySystemd
+ for _, tc := range []struct {
+ name string
+ family, loaded, kn execsandbox.Family
+ populated, busy bool
+ jobs string
+ active string
+ stopErr error
+ wantErr, wantStop bool
+ }{
+ {name: "kernel matches", family: gv, loaded: gv, kn: gv},
+ {name: "slice not running", family: gv, loaded: gv},
+ {name: "stale kernel, empty slice is stopped", family: gv, loaded: gv, kn: sd, wantStop: true},
+ {name: "stale kernel back to systemd", family: sd, loaded: sd, kn: gv, wantStop: true},
+ {name: "stale config is left for adopt", family: gv, loaded: sd, kn: sd, wantErr: true},
+ {name: "builds running defer", family: gv, loaded: gv, kn: sd, busy: true, wantErr: true},
+ {name: "populated slice defers", family: gv, loaded: gv, kn: sd, populated: true, wantErr: true},
+ {name: "queued build defers", family: gv, loaded: gv, kn: sd, jobs: "12 carlos-demo-build@aa_1.service start waiting\n", wantErr: true},
+ {name: "queued slice job defers", family: gv, loaded: gv, kn: sd, jobs: "13 carlos-demo-builds.slice stop running\n", wantErr: true},
+ {name: "stop fails", family: gv, loaded: gv, kn: sd, stopErr: errors.New("bus"), wantErr: true, wantStop: true},
+ {name: "still active after stop", family: gv, loaded: gv, kn: sd, active: "active", wantErr: true, wantStop: true},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ f := newBudgetFixture(t, tc.family, tc.loaded, tc.kn, tc.populated)
+ f.jobs, f.stopErr = tc.jobs, tc.stopErr
+ if tc.active != "" {
+ f.active = tc.active
+ }
+ if tc.busy {
+ f.w.buildPurge.RLock()
+ defer f.w.buildPurge.RUnlock()
+ }
+ err := f.w.reconcileBudget(context.Background())
+ if (err != nil) != tc.wantErr {
+ t.Fatalf("err %v, calls %v", err, f.calls)
+ }
+ if tc.wantErr && !errors.Is(err, ErrBuild) && tc.stopErr == nil {
+ t.Fatalf("a deferral must be a retryable DEMO-BUILD: %v", err)
+ }
+ if f.stopped() != tc.wantStop {
+ t.Fatalf("stopped=%v, calls %v", f.stopped(), f.calls)
+ }
+ if !tc.wantStop && tc.stopErr == nil {
+ for _, c := range f.calls {
+ if strings.HasPrefix(c, "stop") || strings.HasPrefix(c, "set-property") {
+ t.Fatalf("changed the slice: %v", f.calls)
+ }
+ }
+ }
+ })
+ }
+}
diff --git a/internal/demobuild/worker.go b/internal/demobuild/worker.go
index e6b531f97..fc27ac43f 100644
--- a/internal/demobuild/worker.go
+++ b/internal/demobuild/worker.go
@@ -44,12 +44,16 @@ type Worker struct {
proof func(context.Context) error
prepare func(context.Context, string, Source) (func() error, error)
run func(context.Context, string, Lock) (BuildOutput, error)
- processLock *os.File
- mu sync.Mutex
- poisoned bool
- ready bool
- initMu sync.Mutex
- initDone bool
+ // admit runs before a build is admitted; nil is reconcileBudget, the
+ // production check. Unit tests that stand in prepare and run stand this
+ // in too.
+ admit func(context.Context) error
+ processLock *os.File
+ mu sync.Mutex
+ poisoned bool
+ ready bool
+ initMu sync.Mutex
+ initDone bool
snapshotPoisoned bool
}
@@ -209,6 +213,15 @@ func (w *Worker) Build(ctx context.Context, wire []byte, source io.Reader) (out
if err != nil {
return out, err
}
+ // Before admission: a budget the kernel does not have yet reaches the
+ // slice only while nothing runs in it (budget.go).
+ admit := w.admit
+ if admit == nil {
+ admit = w.reconcileBudget
+ }
+ if err := admit(ctx); err != nil {
+ return out, err
+ }
w.buildPurge.RLock()
defer w.buildPurge.RUnlock()
ctx, cancel := context.WithDeadline(ctx, j.Deadline)
diff --git a/internal/demobuild/worker_test.go b/internal/demobuild/worker_test.go
index 45890f632..e0cc2ba04 100644
--- a/internal/demobuild/worker_test.go
+++ b/internal/demobuild/worker_test.go
@@ -31,7 +31,7 @@ func workerFixture(t *testing.T) (*Worker, Job, ed25519.PrivateKey, []byte) {
if err != nil {
t.Fatal(err)
}
- w := &Worker{removeSandbox: func(string) error { return nil }, ready: true, cfg: demo.Config{Account: "shop", Fleet: "demo", Domain: "example.com", BuildConcurrency: 1}, box: "box-1", pub: pub, lock: testLock(t), digest: strings.Repeat("b", 64), root: t.TempDir(), slots: make(chan struct{}, 1), proof: func(context.Context) error { return nil }}
+ w := &Worker{removeSandbox: func(string) error { return nil }, ready: true, cfg: demo.Config{Account: "shop", Fleet: "demo", Domain: "example.com", BuildConcurrency: 1}, box: "box-1", pub: pub, lock: testLock(t), digest: strings.Repeat("b", 64), root: t.TempDir(), slots: make(chan struct{}, 1), proof: func(context.Context) error { return nil }, admit: func(context.Context) error { return nil }}
w.prepare = func(context.Context, string, Source) (func() error, error) { return func() error { return nil }, nil }
w.run = func(context.Context, string, Lock) (BuildOutput, error) { return BuildOutput{}, nil }
j := Job{ID: base64.RawURLEncoding.EncodeToString(bytes.Repeat([]byte{1}, 32)), DemoID: base64.RawURLEncoding.EncodeToString(bytes.Repeat([]byte{2}, 16)), Account: "shop", App: "tmp-demo-bright-otter-42", Host: "bright-otter-42.example.com", Lifetime: "life-1", Fleet: "demo", Box: "box-1", SourceSHA256: v.SHA256, BundleSHA256: w.digest, Generation: 1, Attempt: 1, Deadline: time.Now().UTC().Add(time.Minute)}
@@ -142,7 +142,7 @@ func TestDemoBuildSlotsAndReplay(t *testing.T) {
t.Fatal("replayed completed attempt")
}
// A new process reads the same durable marker before it opens source.
- w2 := &Worker{ready: true, cfg: w.cfg, box: w.box, pub: w.pub, lock: w.lock, digest: w.digest, root: w.root, slots: make(chan struct{}, 1), proof: w.proof, prepare: w.prepare, run: w.run}
+ w2 := &Worker{ready: true, cfg: w.cfg, box: w.box, pub: w.pub, lock: w.lock, digest: w.digest, root: w.root, slots: make(chan struct{}, 1), proof: w.proof, prepare: w.prepare, run: w.run, admit: w.admit}
if _, err := w2.Build(context.Background(), wire, neverRead{t}); err == nil {
t.Fatal("replayed after root restart")
}
diff --git a/internal/host/demo_slice_adopt_linux_test.go b/internal/host/demo_slice_adopt_linux_test.go
index 113c831e1..0fcefa7bc 100644
--- a/internal/host/demo_slice_adopt_linux_test.go
+++ b/internal/host/demo_slice_adopt_linux_test.go
@@ -85,12 +85,9 @@ func TestAdoptRerendersDemoBuildSliceOnSandboxFlip(t *testing.T) {
return "enabled", nil
}
var calls [][]string
- reloadFails, setFails := false, false
+ reloadFails := false
call := func(args ...string) (string, error) {
calls = append(calls, args)
- if args[0] == "set-property" && setFails {
- return "", errors.New("set-property failed")
- }
if len(args) == 1 && args[0] == "daemon-reload" {
if reloadFails {
return "", errors.New("daemon-reload failed")
@@ -132,16 +129,6 @@ func TestAdoptRerendersDemoBuildSliceOnSandboxFlip(t *testing.T) {
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)
}
- // The live slice gets the budget too (daemon-reload leaves an active
- // slice's kernel limits alone), before the file is written.
- g := demobuild.SlicePropertiesFor(1, execsandbox.FamilyGVisor)
- setArgs := []string{"set-property", "--runtime", demoBuildsSlice, "MemoryMax=" + strconv.FormatInt(g["MemoryMax"], 10), "MemorySwapMax=0", "TasksMax=" + strconv.FormatInt(g["TasksMax"], 10), "CPUQuota=" + strconv.FormatInt(g["CPUQuota"], 10) + "%"}
- setAt := slices.IndexFunc(calls, func(a []string) bool { return slices.Equal(a, setArgs) })
- reloadAt := slices.IndexFunc(calls, func(a []string) bool { return len(a) == 1 && a[0] == "daemon-reload" })
- if setAt < 0 || setAt > reloadAt {
- t.Fatalf("want %v before the reload, got %v", setArgs, calls)
- }
-
calls = nil
ensureSystemUnits(etc, lock, call, probe, t.Logf)
if len(calls) != 0 {
@@ -182,89 +169,4 @@ func TestAdoptRerendersDemoBuildSliceOnSandboxFlip(t *testing.T) {
t.Fatalf("converged box changed units again: %v", calls)
}
- // A live budget that cannot be applied leaves the file as it was, so
- // the next pass still sees the difference and tries again.
- writeEnv("systemd")
- setFails = true
- calls = nil
- ensureSystemUnits(etc, lock, call, probe, t.Logf)
- if got := readSlice(); !strings.Contains(got, want(execsandbox.FamilyGVisor)) {
- t.Fatalf("slice written although its budget could not be applied:\n%s", got)
- }
- setFails = false
- ensureSystemUnits(etc, lock, call, probe, t.Logf)
- if got := readSlice(); !strings.Contains(got, want(execsandbox.FamilySystemd)) {
- t.Fatalf("retry pass left the slice at:\n%s", got)
- }
-}
-
-// The apply path installs the slice too. A changed budget reaches the live
-// slice; when it cannot, the old file goes back for the adopt pass.
-func TestApplyPutsChangedDemoSliceBudgetOnLiveSlice(t *testing.T) {
- writeEnv := func(etc string, n int) {
- t.Helper()
- if err := os.MkdirAll(filepath.Join(etc, "carlos"), 0755); err != nil {
- t.Fatal(err)
- }
- raw := "CARLOS_DEMO_BOX=1\nCARLOS_DEMO_ACCOUNT=shop\nCARLOS_DEMO_FLEET=demo\nCARLOS_DEMO_DOMAIN=example.com\nCARLOS_DEMO_BUILD_WORKER=1\nCARLOS_DEMO_TOOLCHAIN_DIR=/opt/demo-toolchain\nCARLOS_DEMO_BUILD_CONCURRENCY=" + strconv.Itoa(n) + "\n"
- if err := os.WriteFile(filepath.Join(etc, "carlos/host.env"), []byte(raw), 0600); err != nil {
- t.Fatal(err)
- }
- }
- memLine := func(n int) string { return "MemoryMax=" + strconv.FormatInt(int64(n)*1073741824, 10) + "\n" }
- stage := t.TempDir()
- writeEnv(filepath.Join(stage, "etc"), 1)
- if err := bootstrap(stage, nil); err != nil {
- t.Fatal(err)
- }
- f := newApplyFixture(t, "stable", "v1.0.0")
- slicePath := filepath.Join(f.a.etcDir, "systemd/system", demoBuildsSlice)
- readSlice := func() string {
- t.Helper()
- b, err := os.ReadFile(slicePath)
- if err != nil {
- t.Fatal(err)
- }
- return string(b)
- }
- setCalls := func() []string {
- var out []string
- for _, c := range f.calls {
- if strings.HasPrefix(c, "systemctl set-property") {
- out = append(out, c)
- }
- }
- return out
- }
- writeEnv(f.a.etcDir, 1)
- if err := f.a.installUnits(t.Context(), stage, nil); err != nil {
- t.Fatal(err)
- }
- if got := setCalls(); len(got) != 0 {
- t.Fatalf("first install set a budget with no slice before it: %v", got)
- }
-
- writeEnv(f.a.etcDir, 3)
- f.calls = nil
- if err := f.a.installUnits(t.Context(), stage, nil); err != nil {
- t.Fatal(err)
- }
- if got := setCalls(); len(got) != 1 || !strings.Contains(got[0], "--runtime "+demoBuildsSlice+" "+strings.TrimSpace(memLine(3))) {
- t.Fatalf("changed budget not put on the live slice: %v", got)
- }
-
- writeEnv(f.a.etcDir, 1)
- inner := f.a.ops.systemctl
- f.a.ops.systemctl = func(args ...string) (string, error) {
- if args[0] == "set-property" {
- return "", errors.New("set-property failed")
- }
- return inner(args...)
- }
- if err := f.a.installUnits(t.Context(), stage, nil); err != nil {
- t.Fatalf("a budget that cannot be applied must not fail the apply: %v", err)
- }
- if got := readSlice(); !strings.Contains(got, memLine(3)) {
- t.Fatalf("old slice not put back for the adopt pass:\n%s", got)
- }
}
diff --git a/internal/host/demo_slice_reload_rootrunner_linux_test.go b/internal/host/demo_slice_reload_rootrunner_linux_test.go
deleted file mode 100644
index 3c1e3ccdc..000000000
--- a/internal/host/demo_slice_reload_rootrunner_linux_test.go
+++ /dev/null
@@ -1,116 +0,0 @@
-//go:build linux && rootrunner
-
-package host
-
-import (
- "os"
- "os/exec"
- "path/filepath"
- "strconv"
- "strings"
- "testing"
- "time"
-
- "github.com/carlosframework/platform/internal/demo"
- "github.com/carlosframework/platform/internal/demobuild"
- "github.com/carlosframework/platform/internal/execsandbox"
-)
-
-// TestRootDemoSliceBudgetReachesActiveSlice: on real systemd, an active
-// carlos-demo-builds.slice keeps its kernel limits across a unit-file
-// rewrite plus daemon-reload. applyDemoSliceBudget (set-property --runtime)
-// must move them, in both directions of a sandbox flip, and the rendered
-// file plus reload must then agree with the kernel.
-func TestRootDemoSliceBudgetReachesActiveSlice(t *testing.T) {
- if os.Geteuid() != 0 {
- t.Fatal("needs root")
- }
- unitPath := filepath.Join("/run/systemd/system", demoBuildsSlice)
- if _, err := os.Lstat(filepath.Join("/etc/systemd/system", demoBuildsSlice)); err == nil {
- t.Fatal("refusing: a real carlos-demo-builds.slice is installed here")
- }
- run := func(args ...string) string {
- t.Helper()
- out, err := exec.Command(args[0], args[1:]...).CombinedOutput()
- if err != nil {
- t.Fatalf("%v: %v: %s", args, err, out)
- }
- return strings.TrimSpace(string(out))
- }
- systemctl := func(args ...string) (string, error) {
- out, err := exec.Command("systemctl", args...).CombinedOutput()
- return string(out), err
- }
- raw, err := unitsFS.ReadFile("units/" + demoBuildsSlice)
- if err != nil {
- t.Fatal(err)
- }
- render := func(family execsandbox.Effective) []byte {
- cfg := claimUnitSettings{demo: demo.Config{Account: "shop", Fleet: "demo", Domain: "example.com", BuildWorker: true, BuildConcurrency: 1}, sandbox: family}
- return claimUnitContent(demoBuildsSlice, raw, cfg)
- }
- kernel := func() map[string]string {
- t.Helper()
- group := strings.TrimPrefix(run("systemctl", "show", "-p", "ControlGroup", "--value", demoBuildsSlice), "/")
- if group == "" {
- t.Fatal("slice has no control group")
- }
- m := map[string]string{}
- for _, f := range []string{"memory.max", "memory.swap.max", "pids.max", "cpu.max"} {
- b, err := os.ReadFile(filepath.Join("/sys/fs/cgroup", group, f))
- if err != nil {
- t.Fatalf("%s: %v", f, err)
- }
- m[f] = strings.TrimSpace(string(b))
- }
- return m
- }
- expect := func(family execsandbox.Family, when string) {
- t.Helper()
- p := demobuild.SlicePropertiesFor(1, family)
- k := kernel()
- t.Logf("%s: kernel %v", when, k)
- if k["memory.max"] != strconv.FormatInt(p["MemoryMax"], 10) || k["pids.max"] != strconv.FormatInt(p["TasksMax"], 10) || k["memory.swap.max"] != "0" {
- t.Fatalf("%s: kernel %v, want %s budget", when, k, family)
- }
- }
- install := func(b []byte) {
- t.Helper()
- if err := os.WriteFile(unitPath, b, 0644); err != nil {
- t.Fatal(err)
- }
- run("systemctl", "daemon-reload")
- }
- t.Cleanup(func() {
- _ = exec.Command("systemctl", "stop", "carlos-rr-budget-sleeper.service", demoBuildsSlice).Run()
- _ = os.Remove(unitPath)
- _ = os.RemoveAll(filepath.Join("/run/systemd/system.control", demoBuildsSlice+".d"))
- _ = exec.Command("systemctl", "daemon-reload").Run()
- })
-
- install(render(execsandbox.EffectiveSystemd))
- run("systemd-run", "--unit=carlos-rr-budget-sleeper", "--slice="+demoBuildsSlice, "--property=Type=exec", "/bin/sleep", "600")
- time.Sleep(time.Second)
- expect(execsandbox.FamilySystemd, "active slice, systemd budget")
-
- // The failure the dev witness hit: file + reload alone.
- install(render(execsandbox.EffectiveGVisor))
- time.Sleep(time.Second)
- t.Logf("file + reload only: kernel %v (show %s)", kernel(), run("systemctl", "show", demoBuildsSlice, "-p", "MemoryMax,TasksMax"))
-
- for _, step := range []struct {
- sandbox execsandbox.Effective
- family execsandbox.Family
- }{{execsandbox.EffectiveGVisor, execsandbox.FamilyGVisor}, {execsandbox.EffectiveSystemd, execsandbox.FamilySystemd}, {execsandbox.EffectiveGVisor, execsandbox.FamilyGVisor}} {
- want := render(step.sandbox)
- if err := applyDemoSliceBudget(systemctl, want); err != nil {
- t.Fatal(err)
- }
- install(want)
- time.Sleep(time.Second)
- expect(step.family, "after applyDemoSliceBudget + file + reload ("+string(step.family)+")")
- if sliceLoadedDiffers(run("systemctl", "show", demoBuildsSlice, "-p", "MemoryMax,TasksMax"), want) {
- t.Fatalf("systemd's loaded budget differs from the file after %s", step.family)
- }
- }
-}
diff --git a/internal/host/systemapply.go b/internal/host/systemapply.go
index 8cfa542c0..0d1814c2d 100644
--- a/internal/host/systemapply.go
+++ b/internal/host/systemapply.go
@@ -1,7 +1,6 @@
package host
import (
- "bytes"
"context"
"crypto/ed25519"
"encoding/json"
@@ -1514,9 +1513,6 @@ func (a *systemApplier) installUnits(ctx context.Context, stagedRoot string, rem
}
os.Remove(filepath.Join(unitDir, u))
}
- // The slice before this install, so a budget that cannot reach the live
- // slice can be put back for the adopt pass (below).
- beforeSlice, beforeSliceErr := os.ReadFile(filepath.Join(unitDir, demoBuildsSlice))
beforeControl, err := os.ReadFile(filepath.Join(unitDir, claimControlUnit))
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
@@ -1615,18 +1611,6 @@ func (a *systemApplier) installUnits(ctx context.Context, stagedRoot string, rem
if _, err = a.ops.systemctl("daemon-reload"); err != nil {
return err
}
- // The reload does not move an active slice's kernel limits; a changed
- // demo build budget goes onto the live slice too. A failure is logged,
- // not fatal: the old slice file goes back, so the next adopt pass sees
- // the file differ from its rendering and applies the budget itself.
- if afterSlice, err := os.ReadFile(filepath.Join(unitDir, demoBuildsSlice)); err == nil && beforeSliceErr == nil && !bytes.Equal(beforeSlice, afterSlice) {
- if err := applyDemoSliceBudget(a.ops.systemctl, afterSlice); err != nil {
- a.ops.logf("system apply: demo build slice: %v; left for the adopt pass", err)
- if err := writeFileDurable(filepath.Join(unitDir, demoBuildsSlice), beforeSlice, 0o644); err != nil {
- a.ops.logf("system apply: demo build slice: restore: %v", err)
- }
- }
- }
afterControl, err := os.ReadFile(filepath.Join(unitDir, claimControlUnit))
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
diff --git a/internal/host/systemunits.go b/internal/host/systemunits.go
index 965a9dd24..79e480172 100644
--- a/internal/host/systemunits.go
+++ b/internal/host/systemunits.go
@@ -3,7 +3,6 @@ package host
import (
"bytes"
"errors"
- "fmt"
"github.com/carlosframework/platform/internal/instancectl"
"os"
"os/exec"
@@ -211,7 +210,6 @@ func ensureSystemUnitsWithGuard(etcDir, lockPath string, systemctl, probe func(a
// sized for the old sandbox, and every build would refuse at its budget
// check. A missing slice is already a reinstall (missing).
sliceChanged := false
- var sliceWant []byte
if settingsErr == nil {
sliceRaw, err := unitsFS.ReadFile("units/" + demoBuildsSlice)
if err != nil {
@@ -224,7 +222,6 @@ func ensureSystemUnitsWithGuard(etcDir, lockPath string, systemctl, probe func(a
return
}
want := claimUnitContent(demoBuildsSlice, sliceRaw, claimSettings)
- sliceWant = want
sliceChanged = err == nil && !bytes.Equal(sliceInstalled, want)
// Matching bytes are not enough: a pass that wrote the slice and then
// failed its daemon-reload (or lost its group permit before it) leaves
@@ -254,16 +251,6 @@ func ensureSystemUnitsWithGuard(etcDir, lockPath string, systemctl, probe func(a
logf("adopt: system units: %v", err)
return
}
- // daemon-reload changes systemd's view of an active slice but not its
- // kernel limits (root-runner witness, systemd 257), so the new budget
- // goes onto the live slice first. A failure here returns before the
- // file is written, and the next pass still sees the difference.
- if sliceChanged {
- if err := applyDemoSliceBudget(systemctl, sliceWant); err != nil {
- logf("adopt: demo build slice: %v", err)
- return
- }
- }
for _, u := range systemUnitFiles {
if group && groupAutomaticUnit(u) {
continue
@@ -364,27 +351,3 @@ func sliceLoadedDiffers(show string, rendered []byte) bool {
}
return loaded["MemoryMax"] != want["MemoryMax"] || loaded["TasksMax"] != want["TasksMax"]
}
-
-// applyDemoSliceBudget puts the rendered slice's budget onto the live slice
-// with `systemctl set-property --runtime`, which reaches the kernel cgroup
-// at once; daemon-reload alone leaves an active slice's limits as they were.
-// The runtime drop-in it leaves carries the same values as the file and goes
-// at reboot. A rendering without all four properties is refused.
-func applyDemoSliceBudget(systemctl func(args ...string) (string, error), rendered []byte) error {
- props := map[string]string{}
- for _, line := range strings.Split(string(rendered), "\n") {
- k, v, ok := strings.Cut(strings.TrimSpace(line), "=")
- if ok && (k == "MemoryMax" || k == "MemorySwapMax" || k == "TasksMax" || k == "CPUQuota") {
- props[k] = v
- }
- }
- args := []string{"set-property", "--runtime", demoBuildsSlice}
- for _, k := range []string{"MemoryMax", "MemorySwapMax", "TasksMax", "CPUQuota"} {
- if props[k] == "" {
- return fmt.Errorf("rendered slice has no %s", k)
- }
- args = append(args, k+"="+props[k])
- }
- _, err := systemctl(args...)
- return err
-}
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 79e83eaa3..7d1eba50c 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -139,4 +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 c793523d694cd0ddd20b9562bd61b69093b613b5faa4a262d5cb3f0c82efa0b5
+plan14-root-reads-demo-slice-adopt.tsv 762577dd5e472a076779f5e9dfd697034293a4f52667c42002671f5f887e474a
diff --git a/internal/provision/testdata/plan14-root-reads-demo-slice-adopt.tsv b/internal/provision/testdata/plan14-root-reads-demo-slice-adopt.tsv
index ac526e51d..4f484b755 100644
--- a/internal/provision/testdata/plan14-root-reads-demo-slice-adopt.tsv
+++ b/internal/provision/testdata/plan14-root-reads-demo-slice-adopt.tsv
@@ -1,7 +1,13 @@
# 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, 2 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
-@legacy c290bc9443ed6ec58d6efb9b5c13ade24fe912e502c2968046862f37dbd557ca internal/host/systemapply.go systemApplier.installUnits legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-agent-start-demo-1;basis=Renders the staged build slice against live root host configuration; preserves it when settings cannot be parsed.;rev3=census-ruling-region-ha-p3b;basis=Require group apply/rollback permit, preserve root Restart=no/nftables drop-in and masks, and skip automatic update/recovery units. Existing staged unit and host.env reads remain; new indirect marker/permit reads are protected and agent receipts are excluded.;rev3=census-ruling-gvisor-demos;basis=Create rootfs/runtime parent directories before controller restart. Existing staged unit and root-owned host.env reads unchanged.;rev3=census-ruling-demo-slice-adopt;basis=Read the installed carlos-demo-builds.slice before the install (fixed root unit path); when the installed slice changed, set its rendered budget on the live slice (systemctl set-property --runtime, fixed name) and on failure write the earlier bytes back. No new path or input; values come from the rendering this function already wrote. file:ReadDir@1722,file:ReadFile@1197,file:ReadFile@1273,file:ReadFile@2313,file:ReadFile@5637,file:ReadFile@6134,file:Stat@2971,file:Stat@4264 2b1a266dd3712e28288d42264e77601cd07bc863c201017958c81daa1e2362a3
-@legacy 7af53abdda5e401d17624a209ca155f9bc7a79d5172bed15b3789d16cc2408b9 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=Compare the installed carlos-demo-builds.slice (fixed root unit path, embedded unit) with its host.env rendering, and ask systemd for the slice's loaded MemoryMax/TasksMax (systemctl show on the fixed slice name); a definite difference is a reinstall. Before writing, put the rendered budget on the live slice with systemctl set-property --runtime on that fixed name, through the same permit-wrapped systemctl. No new path, input or write target; values come only from the already-parsed claim settings. file:OpenFile@985,file:ReadFile@5626,file:ReadFile@5759,file:ReadFile@6669,file:ReadFile@6811,file:ReadFile@9018,file:Stat@5535 cbc353a08921fb509543f92c870a601793a03bad1147bcde8517e0bc30359438
-internal/host/systemapply.go systemApplier.installUnits legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-agent-start-demo-1;basis=Renders the staged build slice against live root host configuration; preserves it when settings cannot be parsed.;rev3=census-ruling-region-ha-p3b;basis=Require group apply/rollback permit, preserve root Restart=no/nftables drop-in and masks, and skip automatic update/recovery units. Existing staged unit and host.env reads remain; new indirect marker/permit reads are protected and agent receipts are excluded.;rev3=census-ruling-gvisor-demos;basis=Create rootfs/runtime parent directories before controller restart. Existing staged unit and root-owned host.env reads unchanged.;rev3=census-ruling-demo-slice-adopt;basis=Read the installed carlos-demo-builds.slice before the install (fixed root unit path); when the installed slice changed, set its rendered budget on the live slice (systemctl set-property --runtime, fixed name) and on failure write the earlier bytes back. No new path or input; values come from the rendering this function already wrote. file:ReadDir@1722,file:ReadFile@1197,file:ReadFile@1273,file:ReadFile@2313,file:ReadFile@5637,file:ReadFile@6134,file:Stat@2971,file:Stat@4264 2b1a266dd3712e28288d42264e77601cd07bc863c201017958c81daa1e2362a3
-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=Compare the installed carlos-demo-builds.slice (fixed root unit path, embedded unit) with its host.env rendering, and ask systemd for the slice's loaded MemoryMax/TasksMax (systemctl show on the fixed slice name); a definite difference is a reinstall. Before writing, put the rendered budget on the live slice with systemctl set-property --runtime on that fixed name, through the same permit-wrapped systemctl. No new path, input or write target; values come only from the already-parsed claim settings. file:OpenFile@985,file:ReadFile@5626,file:ReadFile@5759,file:ReadFile@6669,file:ReadFile@6811,file:ReadFile@9018,file:Stat@5535 cbc353a08921fb509543f92c870a601793a03bad1147bcde8517e0bc30359438
-@coverage internal/host 2bc84d2163f54b05258d0e3520b50452bb3c0c3b0e90982c6b1d1b79f308557d
+# 1 body, 1 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 2 new dispositions: 0 reads re-frozen at their disposition with the claim, 2 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other.
+@legacy 3dbd76d6a8ba1381c12f564779a73a78b8221b4beebc16b67617f148fb047e54 internal/demobuild/worker.go Worker.Build legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-1;basis=Holds the build/purge read lock through cleanup; existing bounded source read remains.;rev3=census-ruling-demo-slice-adopt;basis=Before admission, call the admit hook (nil = reconcileBudget). reconcileBudget reads the fixed build slice's systemctl show budget, its cgroup limit files and cgroup.events under the fixed root cgroup path, and list-jobs; only with buildPurge held exclusively, the slice empty and no build or slice job queued does it run systemctl stop on the fixed slice name. Otherwise it defers with DEMO-BUILD. No tenant, app or agent input names a path or unit. file:ReadAll@796 dc3a42e025fa666182ba082ac7af6866e2ed755979ea15da3f5412971e4bd4c6
+@legacy bf0fab994b0fd42b2af18b70e21c4b8cbe3b4dfe8e0e9988f246f0ea9275afb6 internal/demobuild/budget.go budgetSlicePopulated legacy accepted-legacy accepted-legacy;rev3=census-ruling-demo-slice-adopt;basis=New. Reads cgroup.events under the fixed build slice cgroup path (buildCgroupRoot); absent = empty; a file without a populated line refuses. file:ReadFile@55 60e72229ce907ec9eb953caf4d35c56416153a10f9e73520b55571c2e11b7ca2
+@legacy 4b52c494b53f26d262697e10cfd31bad182f2c54c1b56e529b9b930fa439c936 internal/demobuild/budget.go kernelBudgetMatches legacy accepted-legacy accepted-legacy;rev3=census-ruling-demo-slice-adopt;basis=New. Reads memory.max, memory.swap.max, pids.max and cpu.max under the fixed build slice cgroup path and compares them with SlicePropertiesFor; absent cgroup = slice not running = match; read errors refuse. file:Lstat@168,file:ReadFile@591 fc138916d7510dd62066c8bafa97c8c4b7bf9a108537862f73f9bfbdcd2853c8
+@legacy 55e6adc18f848f6049ffc4504debbacd1f5704dc1f9eac798bc74d2d09b83196 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=Compare the installed carlos-demo-builds.slice (fixed root unit path, embedded unit) with its host.env rendering, and ask systemd for the slice's loaded MemoryMax/TasksMax (systemctl show on the fixed name). A definite difference is a reinstall (existing write loop + daemon-reload). No live budget change, no new path, input or write target. file:OpenFile@985,file:ReadFile@5626,file:ReadFile@5759,file:ReadFile@6647,file:ReadFile@6789,file:ReadFile@8548,file:Stat@5535 134e8105086fb29df32933f0ef26e664c0f08b7b8667a909838f2bde0c0fecfb
+internal/demobuild/worker.go Worker.Build legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-1;basis=Holds the build/purge read lock through cleanup; existing bounded source read remains.;rev3=census-ruling-demo-slice-adopt;basis=Before admission, call the admit hook (nil = reconcileBudget). reconcileBudget reads the fixed build slice's systemctl show budget, its cgroup limit files and cgroup.events under the fixed root cgroup path, and list-jobs; only with buildPurge held exclusively, the slice empty and no build or slice job queued does it run systemctl stop on the fixed slice name. Otherwise it defers with DEMO-BUILD. No tenant, app or agent input names a path or unit. file:ReadAll@796 dc3a42e025fa666182ba082ac7af6866e2ed755979ea15da3f5412971e4bd4c6
+internal/demobuild/budget.go budgetSlicePopulated legacy accepted-legacy accepted-legacy;rev3=census-ruling-demo-slice-adopt;basis=New. Reads cgroup.events under the fixed build slice cgroup path (buildCgroupRoot); absent = empty; a file without a populated line refuses. file:ReadFile@55 60e72229ce907ec9eb953caf4d35c56416153a10f9e73520b55571c2e11b7ca2
+internal/demobuild/budget.go kernelBudgetMatches legacy accepted-legacy accepted-legacy;rev3=census-ruling-demo-slice-adopt;basis=New. Reads memory.max, memory.swap.max, pids.max and cpu.max under the fixed build slice cgroup path and compares them with SlicePropertiesFor; absent cgroup = slice not running = match; read errors refuse. file:Lstat@168,file:ReadFile@591 fc138916d7510dd62066c8bafa97c8c4b7bf9a108537862f73f9bfbdcd2853c8
+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=Compare the installed carlos-demo-builds.slice (fixed root unit path, embedded unit) with its host.env rendering, and ask systemd for the slice's loaded MemoryMax/TasksMax (systemctl show on the fixed name). A definite difference is a reinstall (existing write loop + daemon-reload). No live budget change, no new path, input or write target. file:OpenFile@985,file:ReadFile@5626,file:ReadFile@5759,file:ReadFile@6647,file:ReadFile@6789,file:ReadFile@8548,file:Stat@5535 134e8105086fb29df32933f0ef26e664c0f08b7b8667a909838f2bde0c0fecfb
+@coverage internal/demobuild e00826f4e089661ac629756bc8daabd9cb7642ac6ca25790f30f58f98ac6a3d0
+@coverage internal/host 88889b9888f3bec0a97e22581c486a81cd33951a8b2148299788ce5abe0512f6