rootfs apps plan 3: amendment round 4 (Astra plan review R3)
Group A: resident gate I/O runs in reserved jobs off the sweeper with the Service's lifetime ctx; retention requires a report for resident records; rootfs admission stays closed until a startup sweep proves no rootfs leftover runs, retried with a rootfs-only sweep. Group R: only a failed release answers SwapDown, tested through the real scheduler; release admission refuses beside an unfinished generation operation. Gates: per-group copy sets and a declared-name inventory replace the grep; the later instancectl checks pass on an empty diff. W inherits the proof.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+94
−45
docs/superpowers/plans/2026-10-24-rootfs-apps-3-lifecycle.md+94 −45
diff --git a/docs/superpowers/plans/2026-10-24-rootfs-apps-3-lifecycle.md b/docs/superpowers/plans/2026-10-24-rootfs-apps-3-lifecycle.md| index 78fdc72e7..75e3bce4d 100644 |
| --- a/docs/superpowers/plans/2026-10-24-rootfs-apps-3-lifecycle.md |
| +++ b/docs/superpowers/plans/2026-10-24-rootfs-apps-3-lifecycle.md |
| @@ -6,7 +6,7 @@ |
| **Architecture:** One immutable column, `routes.runtime` (Plan 2 Task 2), decides everything on the box. `registry.Route.ActivatorOwned()` replaces every `Kind == "instance" && Hibernate` test, so a non-hibernating rootfs row is the activator's, nested, lease-held and activator-replicated. Every start of a rootfs row, the overlap successor, the hold pin and the planned wake included, goes through Plan 2's rootfs start (Task N1), and every refusal comes before the lease (Task 7). A 2-second rootfs tick inside the activator's sweeper goroutine starts resident rows (four at a time, per-host backoff) and notices crashes. The `release` process (Group R, after A) is one service-owned operation in the rootfs cmd unit from the new image: before an overlap swap is admitted, under the incumbent's lease, the swap then running only on a proven pass; and inside a wake (planned, hold, or onto a build the row has not served), under the wake's lease. A failure is the build's failure, so the incumbent keeps serving; losing the lease stops it and proves it gone before the lease's safety deadline, and is never the build's failure. Until Group R lands, an app migrates in its own web command (`db:prepare` before the server, as Rails 8's Docker entrypoint does). Workers (Group W, after A) are `RoleWorker` units started after `web` is healthy and stopped first. |
| -**Tech Stack:** Go 1.26; `internal/registry`, `internal/provision`, `internal/activator` (state machine, `ExecBackend`, cmd unit), `internal/rollout`, `internal/edge`, `internal/ops`, `internal/layout`, `internal/host`, `internal/console`, `internal/runs`, `internal/rolloutwords`, `internal/status`, `internal/release`; systemd through `instancectl` (Plan 3 changes only `internal/instancectl/client.go` there). |
| +**Tech Stack:** Go 1.26; `internal/registry`, `internal/provision`, `internal/activator` (state machine, `ExecBackend`, cmd unit), `internal/rollout`, `internal/edge`, `internal/ops`, `internal/layout`, `internal/host`, `internal/console`, `internal/runs`, `internal/rolloutwords`, `internal/status`, `internal/release`; systemd through `instancectl` (Plan 3 changes only `client.go` there, and `server.go`'s sweep, for a rootfs-only variant). |
| **Spec:** `docs/superpowers/specs/2026-10-24-rootfs-apps-design.md` rev 5: §5.0 (record half), §5.2 (environment and deploy half), §5.2.1, §5.4, §5.5, §5.6, §7 C5, C7, C8. Index and shared contract: `docs/superpowers/plans/2026-10-24-rootfs-apps-0-index.md`. Prior design used for residency semantics only: `implementation/always-awake-exec.md`. Run design for the cmd unit: `docs/superpowers/specs/2026-10-08-carlos-run-design.md`. |
| @@ -24,7 +24,7 @@ They come from where Plan 2 spun. Plan 2's Task 11 rounds 1 to 5 and its final w |
| - **INV-2. No rootfs file goes before the proof.** Agent side: a worker's launch file, exit records and stray entry, a run's hold, and (Group R) a release's record, go only after `RootfsWorkerGone`, or after the cmd unit's `StopAndSettle`, returned nil. Root side: Plan 3 adds no removal owner, and `TestRootfsRemovalGuard`'s allowlist is unchanged. |
| - *Guard (Task 1):* `TestRootfsRemovalOwnersUnchanged` pins `rawRemovalOwners` and `rootfsRemovalOwners` unchanged. |
| - *Behaviour (Task 12, W1, Group R):* an unproven stop keeps the obligation that owns it: a run's hold stays in `e.cmdLeft` with its pin until `retryCmdSettlesLocked` proves it (Task 12, `TestRootfsRunPollsAndStopsTheRootfsUnit`); a worker's stray keeps `launch.worker.<name>.json`, its exit records and its pin (W1); a release's record keeps its lease, pin and wake latch (Group R's INV-R1 and INV-R2). Each test's mutation (drop the hold, the stray or the record on the failure path) makes it fail [Astra R1 11]. |
| -- **INV-3. Refuse before the lease.** A rootfs row on a box that refuses rootfs is refused before `Acquire`, `Restore`, `LiveIdentity`, `recordBuild` or any entry state. That covers each of Plan 2's gate reasons, unarmed, and an unknown runtime. |
| +- **INV-3. Refuse before the lease.** A rootfs row on a box that refuses rootfs is refused before `Acquire`, `Restore`, `LiveIdentity`, `recordBuild` or any entry state. That covers each of Plan 2's gate reasons, unarmed, an unknown runtime, and a startup sweep not yet proven (Task 7). |
| - *Behaviour (Task 7, with Task 8's rows):* `TestRootfsRefusalPrecedesTheLease`, a table over every reason through `doWake`, `begin` and `rootfsTick`, asserting `acquires == restores == materialized == 0`. No guard passes on main here: the gap this invariant closes is the pre-flight's finding [pf 2.1]. |
| - **INV-4. A refusal is never a build failure.** Every pre-start refusal is classified gateNoOwnership or stale, and never reaches `OnGen`, `SwapFailed`, the failure book or the resident failure count. That covers `errRootfsRefused`, `ErrStagedImage` and `ErrStartRefused` on `/start` and `/cmd`, unarmed, and `errSwapBusy`; Group R's INV-R3 classifies every release result on top of it. |
| - *Guard (Task 1):* `TestRootfsRefusalsAreNotBuildFailures`, a `verdictOf`/`classifyStep` table pinning today's rootfs sentinels. |
| @@ -101,7 +101,7 @@ Each is a name this plan consumes, checked against main at the amendment (a912a3 |
| - **A5 (Plan 2).** For a rootfs row, `ExecBackend.BuildIdentity` (`backend_exec.go:1842`) and `LiveIdentity` (`:1793`) name the staged image (it sits at `VersionPath`), `Start` and `StartGenExe` dispatch to Plan 2's `startRootfsGen` (`rootfs.go:189`), and a one-off command from an image goes through `RootfsControl.CmdRootfs(ctx, host, memoryMax, img instancectl.StagedImage) (string, error)` (`control.go:59`), never `CmdExe`. `StartStaged` has no rootfs arm on main; Task N1 adds it [pf 1.1]. `CmdRootfs` types only a 403 (`internal/instancectl/client.go:484-506`); Task N1 types the rest [pf 1.7]. Task 12 adds `stagedImageOf(id release.StagedIdentity, process string, argv []string) instancectl.StagedImage` (`Path: id.StagedPath, Version: id.Version, Digest: id.Digest`) beside `stagedExeOf` (`identity.go:98`). |
| - **A6 (Plan 2).** The rootfs `web` start is Plan 2's own function, `(*ExecBackend).startRootfs` in `internal/activator/rootfs.go:227`, not a branch of `spawnUnitFrom`; it composes the web environment with Plan 2's `rootfsVars(vars map[string]string, sock, dbPath string) map[string]string` (`rootfs.go:83`). The 120 s health bound is Plan 2's `rootfsHealthTimeout` (`rootfs.go:40`, from `release.RootfsHealthTimeout`); Task N1 adds `healthBoundFor(rt registry.Route) time.Duration` (`rootfsHealthTimeout` for a rootfs row, `spawnHealthTimeout`, 30 s, otherwise) and uses it wherever a successor's health is bounded [pf 1.2]. The tier is answered by `b.tier(rt)` (`backend_exec.go:434`) and `GenTier` (`genbackend.go:283`), whose base for a rootfs row is Plan 2's `rootfsTier` (`cgroup.TierChildren`, R9) and which #328 wraps with `SizedLimit` (`rootfs.go:42-47`). Plan 3 code never reads `rootfsTier` directly [pf 1.8]. |
| - **A7 (Plan 2).** The box-side placement refusal (`host.RootfsPlacementAllowed`) runs on every rootfs start, inside Plan 2's `rootfsGates` (`rootfs.go:128-162`). Plan 3 adds no placement check of its own; Task 7 asks the same gates earlier, before the lease [pf 2.1]. |
| -- **A8 (Plan 2, Astra R1 finding 1).** The cmd unit of a rootfs row is polled, stopped and proven gone as `RootfsUnitName(RoleCmd, host)`, never as the binary `carlos-instance-cmd@`: Plan 2's runtime-aware `cmdUnit` (names under "Cross-plan changes"). Every `CmdUnit` this plan returns for a rootfs row (Task 12's run, R1's release) is that unit, and each task's backend tests go through the real control handler (Task 12's `rootfsCtlHarness`), not a scripted `CmdStatus`. |
| +- **A8 (Plan 2, Astra R1 finding 1).** The cmd unit of a rootfs row is polled, stopped and proven gone as `RootfsUnitName(RoleCmd, host)`, never as the binary `carlos-instance-cmd@`: Plan 2's runtime-aware `cmdUnit` (names under "Cross-plan changes"). Every `CmdUnit` this plan returns for a rootfs row (Task 12's run, R1's release) is that unit, and each task's backend tests go through the real control handler (Task 7's `rootfsCtlHarness`), not a scripted `CmdStatus`. |
| ## Global Constraints |
| @@ -118,7 +118,7 @@ Each is a name this plan consumes, checked against main at the amendment (a912a3 |
| - Diagnostics (log lines, `ValidateShape` errors, test messages) are not copy and are not in the table. |
| - CI cross-compiles darwin and windows: linux-only code needs `//go:build linux` and a `!linux` stub. Nothing in this plan adds a syscall. |
| - Tests: locally only the touched packages, `go test ./internal/<pkg>/ -run 'TestX|TestY' -count=1`; CI runs the full suite. Leave `GOCACHE` at its default. Socket tests need a short `TMPDIR` (the repo's recipe: a short directory the runner creates and removes by name). Race-bearing tests are named in their task and run once with `-race` before the task's commit. New `internal/host` tests call `t.Parallel()` unless they set env, cwd, umask, log output or package vars. |
| -- No census task: main's census runs at merge (Paul, 2026-10-25) [pf 4.1]. The two invariants the census stood in for are tests: root reads SQLite only through the service-user child (Task 15), and Plan 3's diff touches no `internal/instancectl` file except `client.go` (gate A) [pf 4.2]. |
| +- No census task: main's census runs at merge (Paul, 2026-10-25) [pf 4.1]. The two invariants the census stood in for are tests: root reads SQLite only through the service-user child (Task 15), and Plan 3's diff touches no `internal/instancectl` file except `client.go` and `server.go`'s rootfs-only sweep (gate A) [pf 4.2; Astra R3 3]. |
| - Claims: host lifecycle claims are shelved. Plan 3 adds no reader of `Config.HostWrites` [pf 3.1]. While the switch exists, Plan 2's `rootfsGates` still refuses under it (`rootfs.go:155`), and Task 7's early gate inherits that, so nothing goes unrefused. |
| - Commits end with `Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>`. |
| @@ -144,6 +144,9 @@ Each is a name this plan consumes, checked against main at the amendment (a912a3 |
| |---|---|---| |
| | `internal/activator/rootfs_invariants_test.go` (new) | the INV-1, INV-2, INV-4 guards and INV-5's launch-env table | 1, rows added by N1, 6, 12, R1, W1 | |
| | `internal/activator/binary_golden_test.go`, `testdata/binary_golden/` (new) | INV-6's binary goldens | 1 | |
| +| `plan3_groups_test.go` (new, root package) | per-group copy sets, the started and landed lists, the release and worker machinery inventory | 1, gates | |
| +| `internal/host/retention.go` | resident records need a box report before retention deletes | 5 | |
| +| `internal/host/agent.go`, `rootfs_sweep.go` (new), `rootfsplacement.go` | `MarkRootfsSwept` after a clean startup sweep; the rootfs-only retry; ctx-bounded gate I/O | 7 | |
| | `internal/registry/runtime.go` (new) | `Route.Rootfs`, `ActivatorOwned`, `Resident`, `ErrRuntimeFixed` (Plan 2 owns `RuntimeRootfsV1`, `ValidRuntime` and the column) | 2 | |
| | `internal/registry/registry.go`, `remote.go`, `remote_dispatch.go` | `Upsert`'s hibernate and replication arms, `normalizeRoute`, `SetHibernate`'s refusal, `ResidentInstances`; `ErrRuntimeFixed` over the remote registry | 2 | |
| | `cli.go` | `carlos add` refuses an existing rootfs host (a diagnostic) | 2 | |
| @@ -154,7 +157,7 @@ Each is a name this plan consumes, checked against main at the amendment (a912a3 |
| | `internal/release/pins.go` | `BuildStateKept` on `ActivatorOwned` | 5 | |
| | `internal/activator/rootfsenv.go` (new) | `rootfsCmdVars` (Task 6), `rootfsWorkerVars` (W1), on Plan 2's `rootfsVars` | 6, W1 | |
| | `internal/activator/genbackend.go`, `swap.go`, `wakeplan.go`, `backend_exec.go` | `StartStaged`'s rootfs arm; `KillHost`/`EmptyHost` refuse rootfs; the health bound in `genHealthy` and the verdict floor; `HasSidecar` false for rootfs | N1 | |
| -| `internal/instancectl/client.go` | `CmdRootfs` types root's pre-start refusals (the only `instancectl` file Plan 3 changes) | N1 | |
| +| `internal/instancectl/client.go`, `server.go` | `CmdRootfs` types root's pre-start refusals (N1); `SweepRootfs` and `handleSweep`'s `runtime=rootfs` filter (7); the only `instancectl` files Plan 3 changes | N1, 7 | |
| | `internal/activator/rootfs_service.go` (new; Plan 2 owns `rootfs.go`) | `healthBoundFor` (N1); start gates, `ArmRootfs`, first-wake budget (7); residency state and `rootfsTick` (8); the wake ceiling (R3) | N1, 7, 8, R3 | |
| | `internal/activator/rootfsdb.go` (new) | `ExecBackend.PlaceRootfsDB`, the empty SQLite database of D7 | 7 | |
| | `internal/activator/backend_rootfs.go` (new) | `Processes` (D); `stagedImageOf` (12); `StartRelease`, `ReleaseEnv` (R1); `LaunchRootfsWorker`, `RootfsWorkerGone` (W1) | D, 12, R1, W1 | |
| @@ -162,7 +165,7 @@ Each is a name this plan consumes, checked against main at the amendment (a912a3 |
| | `internal/activator/maintenance.go`, `opset.go` | the failed wake hands an unproven release's lease to its record; `releasable` waits on the record | R1, R3 | |
| | `internal/activator/backend_unit.go`, `production_backend_test.go` (new) | `SplitBackend` forwarding of every new interface; the production composition and its test | 7, D, R1, W1 | |
| | `internal/release/layoutintent.go` | `RootfsLifecycleFloor` | 15 | |
| -| `internal/activator/rootfs_ctl_harness_test.go` (new) | `rootfsCtlHarness`: the real `instancectl.Server` handler and client behind an `ExecBackend` | 12, used by R1 | |
| +| `internal/activator/rootfs_ctl_harness_test.go` (new) | `rootfsCtlHarness`: the real `instancectl.Server` handler and client behind an `ExecBackend` | 7, used by 12 and R1 | |
| | `internal/activator/cmd.go`, `cmdunit.go`, `swaphold.go`, `generations_file.go` | run integration (12), release integration (R1 to R3), the stop proof, the generations pins | 12, R1, R2, R3 | |
| | `internal/activator/rootfsworkers.go` (new), `prepare.go`, `unitproc.go`, `opset.go` | worker identity, lifecycle, supervision, handover, stop proof, `RootfsWorkers` | W1, W2 | |
| | `internal/edge/edge.go`, `internal/ops/litestream.go`, `internal/ops/hibernate_verify.go`, `internal/rollout/policy.go`, `internal/host/socket_advice.go`, `internal/host/probes.go`, `internal/host/schedule_wiring.go`, `internal/layout/pass.go` | the consumer inventory | 5 | |
| @@ -185,7 +188,7 @@ No later task writes a string of this plan until this one has merged with the ro |
| **Files:** |
| - Verify only: `docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md`, `approved_rootfs_copy_test.go` (the amendment already rewrote the RFS-3 file cells and struck RFS-3-C13 there, with `rootfsCopyStruck` [pf 8.3, 3.1]) |
| -- Create: `internal/activator/rootfs_invariants_test.go`, `internal/activator/binary_golden_test.go`, `internal/activator/testdata/binary_golden/` (golden files), `internal/activator/testdata/rootfs_verb_guard/` (guard fixtures) |
| +- Create: `plan3_groups_test.go` (root package), `internal/activator/rootfs_invariants_test.go`, `internal/activator/binary_golden_test.go`, `internal/activator/testdata/binary_golden/` (golden files), `internal/activator/testdata/rootfs_verb_guard/` (guard fixtures) |
| **Interfaces:** |
| - Consumes: Plan 1 Task 1's gate (A1); main's activator as Plan 2 left it. |
| @@ -200,6 +203,7 @@ The guards (each passes on main and fails on a violation; fixtures prove each re |
| - **`TestRootfsRefusalsAreNotBuildFailures` (INV-4).** A table over today's rootfs sentinels, each wrapped as the code wraps it: `refuseRootfs(errors.New("x"))`, `errRootfsRefused`, `errRootfsBinaryLaunch`, `errNoRootfsControl`, `fmt.Errorf("%w: x", instancectl.ErrStagedImage)`, `refuseRootfs(fmt.Errorf("%w: x", instancectl.ErrStartRefused))` (the marking `rootfs.go:322` does), `errBuildStateUnwritten`. Each: `verdictOf(err) == gateNoOwnership` (`swap.go:228`) and `classifyStep(nil, err) == stepStale` (`swap.go:134`), never a failure outcome. Later tasks add their sentinels to this table (Task 7's and Task 12's; R1's release sentinels, through `classifyRelease`). |
| - **`TestRootfsLaunchFilesCarryOnlyComposedEnv` (INV-5), web row.** `t.Setenv("PATH", "/agent/bin")` and `t.Setenv("HOME", "/agent")`; production-wired (`nestedBackend`, `unitproc_test.go:225`, with `fakeControl`), a rootfs row with a `.env` holding `SHOP_MODE=live`: `StartGenExe` for generation 7; the launch file `GenLaunchFileName(7)` decodes to schema 2, no argv, `Env == rootfsLaunchEnv(<the vars startRootfs composed>)`, and neither `PATH` nor `HOME` is in it. A table keyed by process, so Tasks 6, 10 and 12 and W1 add `release`, `run` and `worker` rows. |
| - **`TestEveryRootfsProofNamesTheRootfsUnit` (INV-1 behaviour), main's rows.** Production-wired (`nestedBackend` with `fakeControl` and a cgroup fixture whose `cgroup.events` the test sets; no binary unit in any answer, every rootfs unit's group `populated 1`): a rootfs generation's `unitProc` (Stop asks `StopRootfs` for that generation, never `Stop`/`StopGen`, and stays unproven), and the rootfs `cmdUnit` (`Poll` asks `CmdStatusRootfs`; `StopAndSettle` asks `StopRootfs` with `RoleCmd` and fails while `RootfsUnitName(RoleCmd, host)`'s group is populated). A table keyed by handle, so N1, Tasks 10 and 12 and W1 add rows. |
| +- **The group inventory** (`plan3_groups_test.go`, root package) [Astra R3 6]. Three pinned copy sets, `plan3CopyA` (C11, C12, C14 to C28), `plan3CopyR` (C01 to C07, C29) and `plan3CopyW` (C08 to C10), and two pinned lists, `plan3GroupsStarted` and `plan3GroupsLanded`, both empty at Task 1. `TestPlan3CopyGroups`: the three sets are disjoint and their union is exactly the deck's live RFS-3 rows (C13 struck); each landed group's set is in `rootfsCopyBuilt`; no id of a group not started is. `TestPlan3MachineryInventory`: parses `internal/activator`'s non-test files and collects every declared name (functions, methods, types, vars, consts, struct fields and interface methods). Names matching the release inventory (`(?i)release(Op|Due|Timeout|Passed|BeforeSwap|Env|Backend)|runRelease|classifyRelease|leaseWatch|ReleaseError|errRelease|wakeCeiling|StartRelease`) are refused unless `"R"` is started, and names matching the worker inventory (`(?i)rootfsWorker|RootfsWorker|LaunchRootfsWorker|workerGate|workerWakeGate|startRootfsWorkers|stopRootfsWorkers|handOverRootfsWorkers|WorkerReport|prepareWorker|writeRootfsWorkerLaunch|rootfsUnitFor`) unless `"W"` is started. Two pinned allowances: main's baseline matches at a912a342, read once at Task 1 (for example `RootfsControl.StartRootfsWorker`, `control.go:55`, and Plan 2's worker drop-in names), and A's shared seams, which look related but belong to A (`Processes`, `ProcessReader`, `rootfsProcessesHook`, `superviseRootfsLocked`, `startCmdUnit`, `stagedImageOf`, `stagedIdentityOf`, `rootfsCmdVars`, `residentFailure`). A fixture with one added release name and one added worker name proves each refusal. The first task of Group R adds `"R"` to `plan3GroupsStarted` and the R gate adds it to `plan3GroupsLanded`; Group W does the same with `"W"`. |
| - **INV-6 goldens** (`binary_golden_test.go`, each byte-compared with a file under `testdata/binary_golden/`, written once from main at Task 1; a later change to a golden file needs its own reason in review): |
| - `TestBinaryStartCmdLaunchGolden`: a binary nested row's `StartCmd` (`cmdunit.go:172`): `launch.cmd.json`'s bytes, and the `Control.Cmd` or `CmdExe` call `fakeControl` records (host, `b.tier(rt).MemoryMax`, the staged exe). |
| - `TestBinaryStartStagedGolden`: `StartStaged` (`genbackend.go:230`) on a binary nested row and a binary flat row: the returned `Gen` and the start request `fakeControl` records. |
| @@ -208,12 +212,12 @@ The guards (each passes on main and fails on a violation; fixtures prove each re |
| - `TestHasSidecarBinaryGolden`: `HasSidecar` (`backend_exec.go:2985`) on a binary row: a planted `<host>-sidecar.env` answers true, none false. |
| - [ ] **Step 1:** `grep -c '^| RFS-3-' docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md` is 29: 28 `approved`, RFS-3-C13 `struck`; every RFS-3 file cell is a bare path with an optional note in parentheses; `rootfsCopyStruck` is `{"RFS-3-C13"}`. Run `go test . -run 'TestRootfsCopy|TestRootfsBuilt' -count=1` (PASS). If a row was added after 2026-10-24 and is `pending`, invoke the `copy-review` skill on those rows only, apply Paul's edits verbatim to the deck and to this plan's string table, and mark them `approved` (read `result.json` before any restart of the review server). |
| -- [ ] **Step 2:** Write the guards and goldens above. Run `go test ./internal/activator/ -run 'TestRootfsFilesNameNoBinaryVerb|TestRootfsRemovalOwnersUnchanged|TestRootfsRefusalsAreNotBuildFailures|TestRootfsLaunchFilesCarryOnlyComposedEnv|TestEveryRootfsProofNamesTheRootfsUnit|TestBinary.*Golden|TestGenHealthyBoundBinary' -count=1` under the short `TMPDIR`. Expected: PASS on main. |
| +- [ ] **Step 2:** Write the guards and goldens above. Run `go test ./internal/activator/ -run 'TestRootfsFilesNameNoBinaryVerb|TestRootfsRemovalOwnersUnchanged|TestRootfsRefusalsAreNotBuildFailures|TestRootfsLaunchFilesCarryOnlyComposedEnv|TestEveryRootfsProofNamesTheRootfsUnit|TestBinary.*Golden|TestGenHealthyBoundBinary' -count=1` under the short `TMPDIR`, and `go test . -run 'TestPlan3' -count=1`. Expected: PASS on main. |
| - [ ] **Step 3:** Mutation evidence, in scratch edits reverted by hand before the commit (never `git checkout`): add `_ = b.Control.Stop` to `rootfs.go` (INV-1 guard FAILS); add `"x": true` to a copy of `rawRemovalOwners` in a fixture (INV-2 FAILS); swap `rootfsLaunchEnv` for `childEnv` in `startRootfs`'s launch (INV-1 and INV-5 FAIL); in the shared dispatch files the guard does not scan, make `cmdUnit.Poll`'s rootfs test (`cmdunit.go:261`) false, and make `stopRole` (`unitproc.go:165`) take its binary arm for a rootfs row (INV-1 behaviour FAILS for each); change `spawnHealthTimeout` to 31 s (INV-6 FAILS). Record each in the report. |
| - [ ] **Step 4:** Commit. |
| ```bash |
| -git add internal/activator/rootfs_invariants_test.go internal/activator/binary_golden_test.go internal/activator/testdata/ |
| +git add plan3_groups_test.go internal/activator/rootfs_invariants_test.go internal/activator/binary_golden_test.go internal/activator/testdata/ |
| git commit -m "rootfs apps plan 3: invariant guards INV-1, 2, 4, 5 and the binary goldens (INV-6)" |
| ``` |
| @@ -421,6 +425,7 @@ The rule for every row: a change only widens a site by residents (INV-6). A site |
| | `internal/host/socket_advice.go:83`; `internal/host/probes.go:310`; `internal/host/schedule_wiring.go:342` | `r.Kind == "instance" && r.Hibernate` | `r.ActivatorOwned()` (the same answer for every binary row) | |
| | `internal/host/socket_advice.go:42`, `:121` | `rt.Hibernate` (no kind check) | `rt.ActivatorLeased()`. At `:121` it picks the diagnostic: a resident is activator-managed, so it gets the stray-supervisor line, never the "set hibernate=1" advice [pf 1.13, Astra R1 1] | |
| | `internal/release/pins.go:236` `BuildStateKept` | `rt.Hibernate && rt.Socket != "" && ...` | `rt.ActivatorOwned() && rt.Socket != "" && ...` (a registry predicate, so the package can import it). It must agree with the host's `keepsBuildState` (`internal/host/buildstate.go:367-376`), which reads `ActivatorManaged` and so widens with the first row [pf 1.13] | |
| +| `internal/host/retention.go:396` (`settingsProtected`, `:346`, the record-side completeness check) | `r.KindOrDefault() != "instance" \|\| r.Unit != "" \|\| !r.HibernateOrDefault()` skips every non-hibernating record, so a resident whose box report is absent protects nothing and refuses nothing, and `retentionPass` (`:36`) can reach `release.DeleteVersion` (`:102`) for a build only its unreported build state names [Astra R3 2] | `... \|\| (!r.HibernateOrDefault() && r.Runtime != provision.RuntimeRootfsV1)`: a resident record needs a fresh, complete report like a hibernating one, and retention refuses (deletes nothing) when any is absent, stale or incomplete. The unit, kind and binary exclusions stay as on main | |
| | `internal/layout/pass.go:264` | every `ActivatorManaged` row converges | a rootfs row is skipped with `Result{Host, "kept", "rootfs instances are always nested"}` in both modes; `restoreHold` (`:529`) and the recheck it runs (`recheck`, `:559`) refuse one the same way | |
| Deliberately unchanged, each for the reason given (the implementer adds a one-line comment at each): |
| @@ -461,6 +466,10 @@ func TestBuildStateKeptCoversResident(t *testing.T) // BuildStateKept(reside |
| func TestSocketAdvisoryLeavesOwnedResident(t *testing.T) // warnExternalSockets(owns true) returns nothing for it; not owned, the |
| // activator-managed diagnostic is the one logged; a hibernating sidecar with a socket answers as on main |
| func TestCurrentSocketProbeFollowsResident(t *testing.T) |
| +func TestRetentionRefusesWithoutAResidentReport(t *testing.T) // [Astra R3 2] an app with a resident rootfs record and an otherwise |
| + // eligible build named only by its build state: the resident's report absent, older than buildStateReportMaxAge, and not |
| + // Complete each make settingsProtected refuse; through retentionPass with a recording store, zero DeleteVersion calls; |
| + // a binary always-on record and a unit record are still not required (as on main) |
| func TestResidentSettingsRefsWaitForBuildState(t *testing.T) // a resident's held settings refs refuse while its build state is unread: |
| // the sweep never reads them as complete before keepsBuildState's read, so a pinned build is not swept |
| // internal/layout/rootfs_pass_test.go |
| @@ -469,7 +478,7 @@ func TestPassNeverMovesRootfsRows(t *testing.T) // flat mode, nested ro |
| - [ ] **Step 2:** Run each package's tests with `-run` on the names above. Expected: FAIL. |
| - [ ] **Step 3:** Make the changes in the table. Do not touch `keepsBuildState`'s `claims` parameter; the cleanup removes it [pf 3.3]. |
| -- [ ] **Step 4:** Run Step 2's commands, then each touched package's existing tests on the families touched (`-run 'Reload|FleetDBs|Hibernating|Managed|Advisory|SocketProbe|Pass|ActivatorManaged|WakeRoute|BuildState|Pins|Sidecar|Drill'`). Expected: PASS. |
| +- [ ] **Step 4:** Run Step 2's commands, then each touched package's existing tests on the families touched (`-run 'Reload|FleetDBs|Hibernating|Managed|Advisory|SocketProbe|Pass|ActivatorManaged|WakeRoute|BuildState|Pins|Sidecar|Drill|Retention|SettingsProtected'`). Expected: PASS. |
| - [ ] **Step 5: Commit** |
| ```bash |
| @@ -622,9 +631,12 @@ git commit -m "activator: StartStaged starts rootfs generations; the rootfs heal |
| - Create: `internal/activator/rootfsdb.go`, `internal/activator/rootfsdb_test.go` (D7, Astra R1 finding 8) |
| - Modify: `internal/activator/activator.go`: `doWake` (`:2114`: the gate after step 0's refresh and before step 0.5 at `:2161`; after step 2 at `:2302` the served-never-empty check and the placeholder; after step 5 at `:2616` the placeholder's first sync, in step 5b's shape at `:2628`), `begin` (`:1484`, the gate before an entry is made), `serveWakeError` (`:5494`) |
| - Modify: `internal/activator/backend_unit.go` (beside `SplitBackend.SeedPlaced`, `:316`): `SplitBackend.PlaceRootfsDB` and `SplitBackend.rootfsStartable`, each forwarding to `b.Exec` for an exec-backed row whose `Exec` implements the interface and refusing otherwise (`errNoRootfsDB`; `refuseRootfs(errNoRootfsControl)`). Production builds the service over a `SplitBackend` (`internal/host/agent.go:524`), whose fields promote nothing, so an interface only `ExecBackend` implements is invisible in production [Astra R1 4] |
| +- Create: `internal/activator/rootfs_ctl_harness_test.go` (`rootfsCtlHarness`, below) |
| - Create: `internal/activator/production_backend_test.go`: `productionBackend(t, eb *ExecBackend) *SplitBackend`, the composition `agent.go:524` builds (`&SplitBackend{Exec: eb, Unit: &UnitBackend{OptDir: ...}}`), and `TestProductionBackendImplementsRootfsSeams`, which asserts the production composition satisfies every interface Plan 3 adds (this task: `rootfsStartable`, `rootfsDBPlacer`; Task D: `ProcessReader`; R1: `ReleaseBackend`; W1: `RootfsWorkerBackend`) and that a unit-backed row is refused by each |
| - Modify: `internal/activator/wakeplan.go:381` and `awaitWake` (`activator.go:1606`, its deadline at `:1621`): `firstWakeBudgetFor(rt)` |
| - Modify: `internal/host/rollout.go:406`: `svc.ArmRootfs()` once the manager has armed (not in `refuseManaged`, `:210`) |
| +- Modify: `internal/activator/rootfs.go` (Plan 2's `rootfsGates` and `rootfsGateCheck`, `:128-162`, take a `ctx`) and the two `ExecBackend` hooks they call, `RootfsOK` and `RootfsPlacement` (`backend_exec.go:218-219`, wired at `host/rootfsplacement.go:360-361`), which become `func(context.Context) error` and `func(context.Context, registry.Route) error`; `internal/host/rootfsplacement.go`: the readiness ask (`ready`, `:345-353`) and the fleet owner read (`read`, `:228-231`) derive their deadlines from that `ctx` instead of `context.Background()` [Astra R3 1] |
| +- Modify (the startup proof, Astra R3 3): `internal/host/agent.go` (the `Sweep` wrapper, `:660-668`); new `internal/host/rootfs_sweep.go` (`retryRootfsSweep`); `internal/instancectl/server.go` (`handleSweep`, `:934`, a `runtime=rootfs` query that lists only the four rootfs unit patterns, `:939`, and keeps only rootfs units from the job list); `internal/instancectl/client.go` (`SweepRootfs`) |
| **Interfaces:** |
| - Consumes: `a.gens`, `runs.MaxTimeout`, `firstWakeKillReserve` (`wakeplan.go:232`), N1's `healthBoundFor`, Plan 2's `rootfsGates` (`rootfs.go:128`) and `refuseRootfs`. |
| @@ -635,10 +647,17 @@ git commit -m "activator: StartStaged starts rootfs generations; the rootfs heal |
| // SplitBackend forwards to its exec side and refuses a unit-backed row. A backend without it refuses a rootfs row |
| // (refuseRootfs(errNoRootfsControl)): there is no unchecked path. It may do I/O (the control service's readiness, |
| // a cached owner read), so it is never called with a.mu held [Astra R1 8]. |
| - type rootfsStartable interface{ rootfsStartable(rt registry.Route) error } |
| + type rootfsStartable interface{ rootfsStartable(ctx context.Context, rt registry.Route) error } // ctx bounds every I/O it does |
| // Two halves, so nothing slow runs under a.mu [Astra R1 8]: |
| func (a *Service) rootfsRefusalLocked(rt registry.Route) error // cheap, under a.mu: nil for a binary row with a valid |
| - // runtime; !registry.ValidRuntime(rt.Runtime) -> errRuntimeUnknown; !a.gens || !a.rootfsArmed.Load() -> errRootfsUnarmed |
| + // runtime; !registry.ValidRuntime(rt.Runtime) -> errRuntimeUnknown; !a.gens || !a.rootfsArmed.Load() -> errRootfsUnarmed; |
| + // !a.rootfsSwept.Load() -> errRootfsUnswept (the startup proof below) |
| + func (a *Service) MarkRootfsSwept() // a.rootfsSwept.Store(true); only internal/host calls it, once a sweep proved every |
| + // rootfs unit a previous agent left is gone; never cleared for the Service's life |
| + var errRootfsUnswept = errors.New("activator: rootfs instances wait for the startup sweep to prove every leftover rootfs unit gone") |
| + // internal/instancectl: func (c *Client) SweepRootfs(ctx context.Context) (SweepResponse, error) // POST /sweep?runtime=rootfs |
| + // internal/host: func retryRootfsSweep(ctx context.Context, sweep func(context.Context) (instancectl.SweepResponse, error), |
| + // mark func()) // 5 s doubling to 60 s, until a sweep answers with no error and no failed unit; then mark() |
| func (a *Service) rootfsStartRefusal(ctx context.Context, rt registry.Route) error // never with a.mu held: the locked half |
| // (taking a.mu briefly), then the backend's rootfsStartable(rt), shared per host (a singleflight, so a request storm on a |
| // cold host asks the gates once). Every non-nil answer of either half is marked with refuseRootfs (errRootfsRefused). |
| @@ -654,11 +673,14 @@ git commit -m "activator: StartStaged starts rootfs generations; the rootfs heal |
| // sql.Open("sqlite", path), "PRAGMA busy_timeout=5000", "PRAGMA journal_mode=WAL" (writes page 1), Close, read, remove |
| ``` |
| +`rootfsCtlHarness` (`rootfs_ctl_harness_test.go`, created here; Task 12 and Group R reuse it) is the real control handler behind an `ExecBackend` (Astra R1 finding 1): a real `instancectl.Server` (`Handler()`, `internal/instancectl/server.go:380`) on a unix socket under the short `TMPDIR`, with `PeerOK` returning nil; `Systemctl` a fake keyed by unit name (each unit's `show` answer, and `start`/`stop` recorded in order and changing that unit's state); `CgroupRoot` a fixture tree whose `cgroup.events` per unit the test sets; `OptDir` with build B staged at `release.VersionPath` and its root-written staged manifest (Plan 2's rootfs server fixture shape); `HostApp` answering the row's account and app; `ExeRoot` and `DropInDir` under `t.TempDir()`; a switch that makes the handler answer `/cmd` with a chosen pre-start status. The `ExecBackend` is `nestedBackend` with `Control: instancectl.NewClient(sock)` and `CgroupEvents` reading the same fixture tree. The binary `carlos-instance-cmd@<host>.service` exists in no answer: `show` reports it with no invocation and inactive, and its cgroup is absent, so a test passes only if every poll, stop and proof names the rootfs unit. It also answers `/sweep` (plain and `runtime=rootfs`) from the same systemctl fake, with a switch for a unit that will not stop. |
| + |
| The method is `rootfsStartRefusal`, not `rootfsRefusal`, because Plan 2's `rootfsRefusal` is the wrapper type `refuseRootfs` builds (`rootfs.go:58`). The first draft's `errRootfsClaim` and its claim reason are struck: Plan 3 reads no claim switch, and Plan 2's gates still refuse under it (`rootfs.go:155`), which this gate inherits [pf 3.1]. |
| Rules: |
| - **Refuse before the lease (INV-3)** [pf 2.1]: `doWake` and `begin` refuse a rootfs row before `Acquire`, `Restore`, `LiveIdentity`, `recordBuild` or any entry state: `acquires == restores == materialized == 0`. Where each half runs [Astra R1 8]: `begin` asks `rootfsRefusalLocked` under its lock; on the path that would make a new entry (no live entry for the host) it drops `a.mu`, asks `rootfsStartRefusal`, retakes `a.mu` and re-checks from the top of its loop (an entry made meanwhile is coalesced on, as today), so an awake instance's requests never pay the gates and a cold one's pay them once per wake attempt; `doWake` asks `rootfsStartRefusal` off `a.mu` before step 0.5, for wakes that did not come through `begin` (due wakes, planned wakes, the tick); Task 8's tick asks it off `a.mu` for each candidate before it takes the lock to start one. Plan 2's `rootfsGates` still runs inside `Backend.Start`, after `Acquire`, `Restore` and `LiveIdentity` (which materializes the live link); asking it here first means a refused row pays none of that. The wake's member event is `RFS-3-C12` with the fragment `RFS-3-C14` for unarmed. An unknown runtime and a backend gate refusal log only (no member can cause the first; the second carries Plan 2's reason in the log). `serveWakeError` answers these 503 "instance failed to wake" (today's text). Task 8 asks the same gate in `rootfsTick`. |
| - `errRuntimeUnknown` is also returned for a binary-looking row whose `Runtime` is not valid, so no future value degrades to a binary launch. |
| +- **The startup proof** [Astra R3 3]. After an agent restart the old Service's obligations (a run's hold, Group R's release record, a worker's stray) are gone from memory, and `BindsTo` asks systemd to stop the old units but supplies no proof. On main `startActivator` (`internal/host/layoutleg.go:354`) calls `start()` whether or not the startup sweep succeeded, root keeps a unit's files when it cannot prove termination (`instancectl/server.go:986-995`), and `ReadyRootfs` (`instancectl/rootfs.go:1303`) reports only the probes, not that result. So rootfs admission is closed until a sweep has proven every leftover rootfs unit gone: `rootfsRefusalLocked` answers `errRootfsUnswept` until `MarkRootfsSwept`. The `Sweep` wrapper (`agent.go:660`) calls `svc.MarkRootfsSwept()` when the startup sweep answers with no error (`instancectl.Client.Sweep` already joins "some instance units would not stop" on a 502, `client.go:339-345`); otherwise it starts `retryRootfsSweep` with the agent's context. The retry must not re-run the full sweep, which stops every instance unit (`handleSweep`'s patterns, `server.go:937-939`) and would stop this agent's own binary units started after `Start`. It asks `SweepRootfs`, which stops only rootfs units: while admission has never opened on this Service, no rootfs unit is this agent's, so every one it finds is a leftover. Binary rows are unaffected (INV-6). This is the refuse-up-front shape main already uses for seeds, which trust an unproven stop only after a successful startup sweep (`seedSweptAtStart`, `agent.go:636-640`). It covers Group A's runs and residents and Groups R and W alike, since every rootfs start passes `rootfsRefusalLocked`. |
| - **Request budget** [pf 2.1]: the early gate's placement read is Plan 2's coalesced owner cache (at most 12 GET an hour per account with a record, 120 without). Residency adds no S3 read beyond a cache miss, and D7 adds one sync per first boot. A refused resident costs no lease cycle. |
| - The first-wake budget: a planned first wake of a rootfs build gets the rootfs health bound plus the kill reserve, so a 120 s Rails boot is judged on its own bound, not the binary 55 s. N1 already sizes the verdict floor to the same bound. |
| - Served never boots empty (Review Focus 4): after `Restore` reports `fresh` for a rootfs row whose `GoodVersion != ""`, the wake refuses with `errRootfsReplicaMissing` (member event `RFS-3-C15`), gives the lease back and starts nothing, and no placeholder is written. A first boot (`GoodVersion == ""`) proceeds. This check runs before the placeholder below and is not changed by it: the placeholder is only ever written for a row that has never served. |
| @@ -671,8 +693,15 @@ Rules: |
| ```go |
| func TestRootfsRefusalPrecedesTheLease(t *testing.T) // INV-3. table over every reason: unknown runtime; gens off; ArmRootfs not |
| // called; and each of Plan 2's gate reasons through rootfsStartable (not nested-ready, layout flat, layout fenced, probe not |
| - // passed, no probe, placement refused, no placement check, claim switch on, no rootfs control half). Through doWake and |
| + // passed, no probe, placement refused, no placement check, claim switch on, no rootfs control half); the startup sweep not yet proven (`MarkRootfsSwept` not called). Through doWake and |
| // begin: acquires == restores == materialized == 0, no recordBuild, no entry left; ServeHTTP 503. Task 8 adds rootfsTick rows. |
| +func TestRootfsAdmissionWaitsForTheStartupProof(t *testing.T) // [Astra R3 3] a replaced Service over a rootfsCtlHarness whose sweep |
| + // answers Failed for a leftover rootfs cmd unit (its cgroup populated): the readiness probes pass, yet a request, the tick and a |
| + // RunCmd cause no Acquire, no Restore and no launch (errRootfsUnswept); the rootfs-only retry sweep keeps failing while the unit |
| + // lives and never stops a binary unit (the harness's systemctl log); once the cgroup empties the retry succeeds, |
| + // MarkRootfsSwept runs, and the next request wakes the instance |
| +func TestRootfsSweepIsRootfsOnly(t *testing.T) // internal/activator, through the harness: POST /sweep?runtime=rootfs lists and |
| + // stops only carlos-instance-rootfs*@ units; a plain /sweep is unchanged |
| func TestRootfsGatesRunOffTheLock(t *testing.T) // [Astra R1 8] rootfsStartable blocks on a channel for host A: a request to |
| // binary host B and to awake host C completes meanwhile, and Shutdown is not held up by A beyond its ctx; awake host C's |
| // requests never call rootfsStartable; 20 concurrent cold requests to A call it once |
| @@ -705,14 +734,14 @@ func TestRootfsAppWithoutSQLiteRestarts(t *testing.T) // Review Focus 8. A web |
| INV-4's table gains `errRootfsUnarmed` and `errRuntimeUnknown`, each marked by `refuseRootfs`. |
| -- [ ] **Step 2:** Run `go test ./internal/activator/ -run 'TestRootfsRefusalPrecedesTheLease|TestRootfsGatesRunOffTheLock|TestRootfsGatesThroughTheProductionBackend|TestProductionBackendImplementsRootfsSeams|TestRootfsWakeRefused|TestBinaryWakeNotGated|TestUnknownRuntimeNeverWakes|TestServedRootfsNeverBootsEmpty|TestFirstRootfsWakeMayBootFresh|TestServedRootfsPlacesNoPlaceholder|TestBinaryFreshWakePlacesNothing|TestRootfsPlaceholderFailureStartsNothing|TestPlaceRootfsDB|TestRootfsAppWithoutSQLiteRestarts' -count=1` (the production-wired ones need the short `TMPDIR` of the Global Constraints). Expected: FAIL. |
| +- [ ] **Step 2:** Run `go test ./internal/activator/ -run 'TestRootfsRefusalPrecedesTheLease|TestRootfsAdmissionWaitsForTheStartupProof|TestRootfsSweepIsRootfsOnly|TestRootfsGatesRunOffTheLock|TestRootfsGatesThroughTheProductionBackend|TestProductionBackendImplementsRootfsSeams|TestRootfsWakeRefused|TestBinaryWakeNotGated|TestUnknownRuntimeNeverWakes|TestServedRootfsNeverBootsEmpty|TestFirstRootfsWakeMayBootFresh|TestServedRootfsPlacesNoPlaceholder|TestBinaryFreshWakePlacesNothing|TestRootfsPlaceholderFailureStartsNothing|TestPlaceRootfsDB|TestRootfsAppWithoutSQLiteRestarts' -count=1` (the production-wired ones need the short `TMPDIR` of the Global Constraints). Expected: FAIL. |
| - [ ] **Step 3:** Implement; write `RFS-3-C12`, `C14` and `C15` from the deck and add their ids to the built list. |
| -- [ ] **Step 4:** Run Step 2's command, Task 1's guards, the restore and seed families the new step sits beside (`go test ./internal/activator/ -run 'Restore|Seed|Fresh' -count=1`), and `go test ./internal/host/ -run 'TestRollout' -count=1`. Expected: PASS. |
| +- [ ] **Step 4:** Run Step 2's command, Task 1's guards, the restore and seed families the new step sits beside (`go test ./internal/activator/ -run 'Restore|Seed|Fresh' -count=1`), `go test ./internal/host/ -run 'TestRollout|TestRetryRootfsSweep|Placement|Sweep' -count=1` (with `TestRetryRootfsSweep` there: backoff, no full sweep, mark only on a clean answer, stops on ctx), and `go test ./internal/instancectl/ -run 'Sweep' -count=1`. Expected: PASS. |
| - [ ] **Step 5: Commit** |
| ```bash |
| -git add internal/activator internal/host/rollout.go approved_rootfs_copy_test.go |
| -git commit -m "activator: rootfs rows refused before the lease unless overlap swaps are armed and the box's rootfs gates pass; first boot places an empty database; never boot empty after serving" |
| +git add internal/activator internal/host internal/instancectl/server.go internal/instancectl/client.go approved_rootfs_copy_test.go |
| +git commit -m "activator: rootfs rows refused before the lease, and until the startup sweep proves no rootfs leftover runs; unless overlap swaps are armed and the box's rootfs gates pass; first boot places an empty database; never boot empty after serving" |
| ``` |
| --- |
| @@ -744,7 +773,9 @@ git commit -m "activator: rootfs rows refused before the lease unless overlap sw |
| refused string // the current refusal's text, "" when none: logged once per change |
| } |
| type errResidentBackoff struct{ retryAfter time.Duration } |
| - func (a *Service) rootfsTick() |
| + func (a *Service) rootfsTick() // reserves; never does I/O |
| + func (a *Service) residentJob(ctx context.Context, rt registry.Route) // the gates off the sweeper, then the re-checked start |
| + // Service.lifeCtx: cancelled as Shutdown begins |
| func (a *Service) superviseRootfsLocked(e *actEntry) // a no-op in group A; W1 fills it with worker supervision |
| func (a *Service) noteResidentWakeLocked(e *actEntry, err error) |
| func (a *Service) noteResidentStopLocked(e *actEntry) |
| @@ -755,7 +786,7 @@ git commit -m "activator: rootfs rows refused before the lease unless overlap sw |
| 1. Off `a.mu`: `routes, err := lister.ResidentInstances()`. An error logs and ends the tick. It is never read as "no residents": nothing is stopped and nothing forgotten (incomplete discovery is not retirement). |
| 2. Under `a.mu`, return if `a.shuttingDown`. For every awake rootfs entry (resident or not) whose `e.proc.Exited()`: `e.unexpectedExit = true; a.beginStopLocked(e, StopExited)`, the sweep's own crash arm (`:4614`), so a crash is seen within 2 s rather than the sweep's 30. Then `a.superviseRootfsLocked(e)` for every awake rootfs entry: one hook, a no-op until W1 [pf 6.1]. |
| -3. Forget `a.residents[host]` for hosts no longer listed. For each listed route, in host order, skip when: `a.fences[host] != 0`; any live entry; `a.unprovenWakes[host]` or `a.straySidecars[host]` (the uncertainty latches; Group R adds its release record); `st.starting`; `a.now().Before(st.retryAt)`; `a.residentStarting >= residentStartCeiling` (stop the loop). A route that passes every skip is a candidate. Candidates are collected under `a.mu`, and the lock is dropped to ask `rootfsStartRefusal(ctx, rt)` for each (off `a.mu`, Astra R1 8); then, under `a.mu` again, every skip is re-checked before anything starts. A refusal sets `st.refused` and skips, counting no failure, with one log line per change of `st.refused` and, for unarmed, one `RFS-3-C12` event (fragment `RFS-3-C14`) per change [pf 2.1]. Otherwise make `e := &actEntry{host, route: rt, state: actWaking, ready: make(chan struct{}), resident: true}`, publish it, set `st.starting`, `a.residentStarting++`, and `go a.wake(e)`. |
| +3. Forget `a.residents[host]` for hosts no longer listed. For each listed route, in host order, skip when: `a.fences[host] != 0`; any live entry; `a.unprovenWakes[host]` or `a.straySidecars[host]` (the uncertainty latches; Group R adds its release record); `st.starting`; `a.now().Before(st.retryAt)`; `a.residentStarting >= residentStartCeiling` (stop the loop). A route that passes every skip and `rootfsRefusalLocked` is a candidate. The tick reserves it under `a.mu` (`st.starting = true`, `a.residentStarting++`, so the four-job ceiling bounds gate checks and starts together) and hands it to `go a.residentJob(a.lifeCtx, rt)`. The tick never does a gate's I/O: it runs inside the sweeper goroutine, whose lease check (`activator.go:4606`) every awake entry depends on, and which Shutdown waits for before stopping anything (`:5222-5224`) [Astra R3 1]. `residentJob`, off the sweeper: `rootfsStartRefusal(ctx, rt)` with `ctx` the Service's lifetime context (cancelled when Shutdown begins), so a blocked readiness ask or owner read ends with it; then under `a.mu` it re-checks admission from the top (no fence, no live entry, no latch, not shutting down, still reserved by this job, `rootfsRefusalLocked`) before it publishes anything. A refusal clears the reservation, sets `st.refused` and counts no failure, with one log line per change of `st.refused` and, for unarmed, one `RFS-3-C12` event (fragment `RFS-3-C14`) per change [pf 2.1]. Otherwise it makes `e := &actEntry{host, route: rt, state: actWaking, ready: make(chan struct{}), resident: true}`, publishes it and runs `a.wake(e)`. Shutdown does not wait for a job that is still in its gates: a job whose re-check finds `a.shuttingDown` starts nothing. |
| Outcome and stop accounting, both under `a.mu`: |
| - `noteResidentWakeLocked` (in `wake`'s final critical section, for any wake of a resident row, proactive or by request): a proactive wake clears `starting` and decrements `residentStarting`. A failed wake counts a failure only when `residentFailure(err)`: `failures++`, `retryAt = now + residentBackoff(failures, jitter())`. Otherwise `retryAt = now` and nothing is counted [Astra R1 11]. |
| @@ -768,7 +799,7 @@ Idle: in `sweepOnce`, `hibernates := !e.worker || e.route.Hibernate` gains `if e |
| What stops a resident, and nothing else does (spec §5.6): its row going away (`RetireExcept`), a fence (maintenance or a move's, which Task 13 makes unreachable), a lost lease (restarted under a fresh lease after the backoff), the agent's shutdown, and the stops it restarts from (crash, release cycle, bounce). |
| -- [ ] **Step 1: Write the failing tests.** `fakeBackend` with a lister seam (`fakeDue` gains `ResidentInstances`), `a.now` faked, `residentPoll` shrunk to 10 ms, `residentJitter` returning 0, `ArmRootfs()` and generations on. |
| +- [ ] **Step 1: Write the failing tests.** `fakeBackend` with a lister seam (`fakeDue` gains `ResidentInstances`), `a.now` faked, `residentPoll` shrunk to 10 ms, `residentJitter` returning 0, `ArmRootfs()`, `MarkRootfsSwept()` and generations on. |
| ```go |
| func TestResidentStartsAtBootWithNoRequest(t *testing.T) // Start, close Startup: fb.starts == 1 within 1 s; no ServeHTTP call made |
| @@ -791,6 +822,10 @@ func TestResidentRefusalCountsNoFailure(t *testing.T) // rootfsStartable ref |
| func TestResidentFailureClassification(t *testing.T) // [Astra R1 11] table over residentFailure: each INV-4 case false (a refusal, |
| // errSwapLeaseLost, errSwapBusy, errWakeUnproven, ErrFenced, shutdown); a health failure and an Acquire store error true; and through the tick: a wake failing with each false case |
| // leaves failures == 0 |
| +func TestSlowResidentGateNeverStallsTheSweeper(t *testing.T) // [Astra R3 1] through the real Start: rootfsStartable blocks for one |
| + // resident; another awake entry's replica reports lease loss and is stopped StopLeaseLost on the next sweep, on time; ten |
| + // blocked residents never put more than four jobs in flight; Shutdown with a 200 ms deadline returns within it, the blocked |
| + // job's ctx is cancelled, and nothing starts after |
| func TestResidentRequestAndTickRaceOneWake(t *testing.T) // RACE: 50 goroutines ServeHTTP a cold resident while the tick runs every |
| // 1 ms; fb.acquires == 1 and fb.starts == 1. Run with -race. |
| func TestResidentCrashDuringStopIsOneStop(t *testing.T) // RACE: proc exits while a Bounce stops the entry: one stop, one restart |
| @@ -798,7 +833,7 @@ func TestResidentCrashDuringStopIsOneStop(t *testing.T) // RACE: proc exits wh |
| INV-3's table gains its `rootfsTick` rows: every reason, `acquires == restores == materialized == 0`. |
| -- [ ] **Step 2:** Run `go test ./internal/activator/ -run 'TestResident|TestRootfsRefusalPrecedesTheLease' -count=1`. Expected: FAIL. |
| +- [ ] **Step 2:** Run `go test ./internal/activator/ -run 'TestResident|TestSlowResidentGate|TestRootfsRefusalPrecedesTheLease' -count=1`. Expected: FAIL. |
| - [ ] **Step 3:** Implement to the rules; write `RFS-3-C11` and `RFS-3-C16`, add their ids to the built list. |
| - [ ] **Step 4:** Run Step 2's command, then `go test -race ./internal/activator/ -run 'TestResidentRequestAndTickRaceOneWake|TestResidentCrashDuringStopIsOneStop' -count=3`, then the families the hooks touch: `-run 'Sweep|Idle|Converge|Bounce|Retire|Shutdown|Wake'`, and Task 1's guards. Expected: PASS. |
| - [ ] **Step 5: Commit** |
| @@ -873,7 +908,6 @@ git commit -m "activator: read a rootfs build's declared processes from its own |
| **Review:** cross-model (pre-flight §7): the rootfs run's cmd unit proof. |
| **Files:** |
| -- Create: `internal/activator/rootfs_ctl_harness_test.go` (`rootfsCtlHarness`, below; Group R reuses it) |
| - Modify: `internal/activator/backend_rootfs.go` (`stagedImageOf`, beside Task D's `Processes`) |
| - Modify: `internal/activator/cmdunit.go`: `StartCmd`'s body (`:172`) becomes `startCmdUnit`, shared by both runtimes, which builds Plan 2's runtime-aware `cmdUnit` (A8; Group R's release reuses it); its rootfs arm replaces the `nestedGate` refusal at `:179` for rootfs rows only [pf 8.7]; `CmdSpec` (`:38`); `internal/activator/cmd.go` `RunCmd` (`:449`, `spec.serving` at `:600-602`); `internal/activator/generations_file.go:177` (a run's build pinned) |
| - Modify: `internal/runs/runs.go` (`Meta` `:146`, `Request` `:174`, `RefusedVersion` beside `RefusedFlat` `:47`); `internal/console/apiruns.go` (`runClassRefusal` `:268`, the version check beside `runMetaRefusal` `:286`); `internal/host/runexec.go:77` (`runResultForLaunch`, the spec's `Build`), `internal/host/runevents.go:70` (`runRefusedWords`); `run.go` (`:30` usage, the flag beside `--timeout` at `:71`, `:740` `runExit`) |
| @@ -897,7 +931,7 @@ git commit -m "activator: read a rootfs build's declared processes from its own |
| var runCopySuperseded = map[string]string{"RUN-C47": "RFS-3-C18"} |
| ``` |
| -`rootfsCtlHarness` (`rootfs_ctl_harness_test.go`) is the real control handler behind an `ExecBackend` (Astra R1 finding 1): a real `instancectl.Server` (`Handler()`, `internal/instancectl/server.go:380`) on a unix socket under the short `TMPDIR`, with `PeerOK` returning nil; `Systemctl` a fake keyed by unit name (each unit's `show` answer, and `start`/`stop` recorded in order and changing that unit's state); `CgroupRoot` a fixture tree whose `cgroup.events` per unit the test sets; `OptDir` with build B staged at `release.VersionPath` and its root-written staged manifest (Plan 2's rootfs server fixture shape); `HostApp` answering the row's account and app; `ExeRoot` and `DropInDir` under `t.TempDir()`; a switch that makes the handler answer `/cmd` with a chosen pre-start status. The `ExecBackend` is `nestedBackend` with `Control: instancectl.NewClient(sock)` and `CgroupEvents` reading the same fixture tree. The binary `carlos-instance-cmd@<host>.service` exists in no answer: `show` reports it with no invocation and inactive, and its cgroup is absent, so a test passes only if every poll, stop and proof names the rootfs unit. |
| +`rootfsCtlHarness` is Task 7's (the real control handler behind an `ExecBackend`, no binary cmd unit in any answer). |
| Rules: |
| - `StartCmd` on a rootfs row: the tenant launch file is Plan 2's schema 2 with `Process: "cmd"` and no argv, its env `rootfsLaunchEnv(rootfsCmdVars(rt, spec.genEnv, p.dbPath, spec.RunID, spec.RunDir))` [pf 1.6]; the argv is `spec.Args` as given (no live-link prefix), sent to root as `StagedImage.Argv` through `RootfsControl.CmdRootfs(ctx, host, b.tier(rt).MemoryMax, stagedImageOf(id, "", spec.Args))` (A3, A5, the sized tier [pf 1.8]); the image identity is required (a rootfs command always names its image; none refuses with `errNoCmdExe`). An `ErrStagedImage` or `ErrStartRefused` answer is marked with `refuseRootfs` [pf 1.7]. The `CmdUnit` it returns, on success and on a failed start alike, is Plan 2's runtime-aware unit (A8, through this task's `startCmdUnit`): `RunCmd`'s `Poll`, its `Stop`, `interruptCmdsLocked` (`cmd.go:377`), `settleCmds` (`:415`) and the sweep's `retryCmdSettlesLocked` (`:399`) all reach `RootfsUnitName(RoleCmd, host)` and prove that unit's cgroup empty, never the binary cmd unit's (Astra R1 finding 1). A binary row is unchanged (INV-6). No egress step: #328 checks in root's `startRootfsCmd` [pf 2.5]. |
| @@ -1062,8 +1096,8 @@ git commit -m "system apply: a box with rootfs instances refuses a platform rele |
| - [ ] **Step 2:** `GOOS=darwin go build ./... && GOOS=windows go build ./... && GOOS=linux GOARCH=arm64 go build ./...`. Expected: clean. |
| - [ ] **Step 3:** Every touched package once, without `-run`: `go test ./internal/registry/ ./internal/provision/ ./internal/rollout/ ./internal/ops/ ./internal/layout/ ./internal/runs/ ./internal/rolloutwords/ ./internal/release/ -count=1`, then `go test ./internal/activator/ ./internal/edge/ ./internal/host/ ./internal/console/ -count=1` under `nice`, one package at a time, then the root package's `TestRun|TestRootfsCopy|TestRootfsBuilt|TestDocsite|TestAddRefuses` group. Expected: PASS. |
| - [ ] **Step 4:** `go test -race ./internal/activator/ -run 'TestResidentRequestAndTickRaceOneWake|TestResidentCrashDuringStopIsOneStop' -count=1`. Expected: PASS. |
| -- [ ] **Step 5:** The invariants hold: `go test ./internal/activator/ -run 'TestRootfsFilesNameNoBinaryVerb|TestRootfsRemovalOwnersUnchanged|TestRootfsRefusalsAreNotBuildFailures|TestRootfsLaunchFilesCarryOnlyComposedEnv|TestEveryRootfsProofNamesTheRootfsUnit|TestRootfsRefusalPrecedesTheLease|TestResidentFailureClassification|TestProductionBackendImplementsRootfsSeams|TestRootfsHealthWindowIsTheRootfsBound|TestBinary.*Golden|TestGenHealthyBoundBinary' -count=1` and `go test ./internal/ops/ -run 'TestFleetDBsStillExcludesHibernatingSidecars' -count=1` (PASS). Plan 3's diff touches no `internal/instancectl` file except `client.go` [pf 4.2]: `git diff --name-only origin/main...HEAD -- internal/instancectl` prints exactly `internal/instancectl/client.go`. |
| -- [ ] **Step 6:** Group A contains no release machinery: `grep -n 'releaseOp\|runRelease\|ReleaseError\|leaseWatch' internal/activator/*.go` finds nothing. Every live `RFS-3-C` id except W1's (`C08`, `C09`, `C10`) and Group R's (`C01` to `C07`, `C29`) is in the gate's built list, and C13 is in none: `go test . -run 'TestRootfsCopy|TestRootfsBuilt' -count=1`. Expected: PASS. The controller pushes the branch to amadan; CI runs the full suite; main's census runs at merge [pf 4.1]. |
| +- [ ] **Step 5:** The invariants hold: `go test ./internal/activator/ -run 'TestRootfsFilesNameNoBinaryVerb|TestRootfsRemovalOwnersUnchanged|TestRootfsRefusalsAreNotBuildFailures|TestRootfsLaunchFilesCarryOnlyComposedEnv|TestEveryRootfsProofNamesTheRootfsUnit|TestRootfsRefusalPrecedesTheLease|TestResidentFailureClassification|TestProductionBackendImplementsRootfsSeams|TestRootfsHealthWindowIsTheRootfsBound|TestBinary.*Golden|TestGenHealthyBoundBinary' -count=1` and `go test ./internal/ops/ -run 'TestFleetDBsStillExcludesHibernatingSidecars' -count=1` (PASS). Plan 3's diff touches no `internal/instancectl` file but `client.go` (N1's typed refusal, Task 7's `SweepRootfs`) and `server.go` (Task 7's rootfs-only sweep) [pf 4.2, Astra R3 3]: `git diff --name-only origin/main...HEAD -- internal/instancectl | grep -vx -e internal/instancectl/client.go -e internal/instancectl/server.go` prints nothing (an empty diff passes too). |
| +- [ ] **Step 6:** Add `"A"` to `plan3GroupsLanded` (Task 1's `plan3_groups_test.go`). Then `go test . -run 'TestPlan3|TestRootfsCopy|TestRootfsBuilt' -count=1`: Group A's copy set is built, Group R's and W's sets are not, and Task 1's inventory finds no release or worker machinery in `internal/activator` beyond main's baseline and A's allowed shared seams [Astra R3 6]. Expected: PASS. The controller pushes the branch to amadan; CI runs the full suite; main's census runs at merge [pf 4.1]. |
| --- |
| @@ -1101,7 +1135,7 @@ Each has its enforcing test; R1 lands the tests and R2 and R3 add their rows. Gr |
| - Modify: `internal/activator/rootfs_invariants_test.go` (INV-1, INV-4 and INV-5 release rows); `internal/activator/rootfs_processes_test.go` (Task D's release log line goes) |
| **Interfaces:** |
| -- Consumes: Task D's `Processes`; Task 12's `startCmdUnit`, `stagedImageOf` and `rootfsCtlHarness`; N1's `stagedIdentityOf` and typed `CmdRootfs`; Task 6's `rootfsCmdVars`; `CmdUnit` (`cmdunit.go:95`), `cmdHold` (`cmd.go:91`, `newCmdHold` `:140`), `cmdBusyLocked` (`cmd.go:284`), `runPendingRecord` (`beforeexec.go:319`), `recordBuild` (`beforeexec.go:45`), `withExecGate`/`runExecGate` (`genbackend.go:80`, `:96`), `leaseLost`'s shape (`activator.go:357`), `errSwapLeaseLost` (`swapadmit.go:12`), `cmdStopBound` (`cmd.go:68`), `publishBeforeExec` (`generations_file.go:250`), `lease.Held.SafeUntil`/`Lost` and `lease.Replicator.SafeUntil`/`Lost` (`internal/lease/lease.go:237-241`, `:476-480`). |
| +- Consumes: Task D's `Processes`; Task 12's `startCmdUnit` and `stagedImageOf`, Task 7's `rootfsCtlHarness`; N1's `stagedIdentityOf` and typed `CmdRootfs`; Task 6's `rootfsCmdVars`; `CmdUnit` (`cmdunit.go:95`), `cmdHold` (`cmd.go:91`, `newCmdHold` `:140`), `cmdBusyLocked` (`cmd.go:284`), `runPendingRecord` (`beforeexec.go:319`), `recordBuild` (`beforeexec.go:45`), `withExecGate`/`runExecGate` (`genbackend.go:80`, `:96`), `leaseLost`'s shape (`activator.go:357`), `errSwapLeaseLost` (`swapadmit.go:12`), `cmdStopBound` (`cmd.go:68`), `publishBeforeExec` (`generations_file.go:250`), `lease.Held.SafeUntil`/`Lost` and `lease.Replicator.SafeUntil`/`Lost` (`internal/lease/lease.go:237-241`, `:476-480`). |
| - Produces: |
| ```go |
| type ReleaseBackend interface { |
| @@ -1180,7 +1214,7 @@ own := func() error { |
| `runRelease`, in order: |
| 1. Under `a.mu`, before anything else, the open-release check (INV-R4) [Astra R2 N4]: a record for `rt.Host` in any state refuses with `errReleaseOpen`. Then `procs, err := Processes(rt, id)` off the lock. Any error is a refusal to start, marked with `refuseRootfs`, never "no release process, not due": nothing starts, `web` included [pf 1.9]. Not due: return nil. `held == nil`: `errReleaseNoLease`, marked with `refuseRootfs`, nothing started (a caller whose `Lease` or `Rep` is not a `leaseWatch` passes nil). |
| -2. `own()`; a refusal returns it and starts nothing. Under `a.mu`: refuse with `errSwapBusy` when `cmdBusyLocked(e)` (a member's run holds the host's one cmd unit), and with `errReleaseOpen` when a record appeared meanwhile; else create the record (`build: id`, `hold: newCmdHold("release", cancel, a.now)` with `starting` set, `owner: e`, `state: opRunning`, `busy: true`). Then, off `a.mu`, `a.publishBeforeExec()`: the record's build is in the generations file before anything runs, and a failed write removes the record and returns `errStagedBuildNotPublished` (a refusal) [Astra R1 9]. |
| +2. `own()`; a refusal returns it and starts nothing. Under `a.mu`, in the same critical section that creates the record: refuse with `errSwapBusy` when `cmdBusyLocked(e)` (a member's run holds the host's one cmd unit); for an awake owner (R2), also with `errSwapBusy` when swap admission would refuse (`swap.go:476-486`): an operation-set member is outstanding or the parent is still raised (`len(e.ops.members) > 0 || e.ops.raised`, which a `SwapDone` with its retiring generation unproven leaves behind, `swap.go:685-689`), or a run's start is in flight (`cmdStartInFlightLocked(e)`), so no migration runs for a swap that could not then be admitted [Astra R3 5]; and with `errReleaseOpen` when a record appeared meanwhile. The reciprocal holds: swap admission refuses while a record exists (R2); else create the record (`build: id`, `hold: newCmdHold("release", cancel, a.now)` with `starting` set, `owner: e`, `state: opRunning`, `busy: true`). Then, off `a.mu`, `a.publishBeforeExec()`: the record's build is in the generations file before anything runs, and a failed write removes the record and returns `errStagedBuildNotPublished` (a refusal) [Astra R1 9]. |
| 3. `recordBuild(ctx, rt.Host, id.Version)`: the build state names the release's build before it touches the data (settings §4.2). `StartRelease` then runs `runPendingRecord(ctx)` and `runExecGate(ctx)` immediately before `CmdRootfs`, as the exec seam does, so a cold wake's pending record is written before `release` runs, not at `web`'s exec, and ownership is checked at the last moment before root is asked. (No egress step: #328 checks on root's side, in `startRootfsCmd` [pf 2.5].) |
| 4. Event `RFS-3-C03`. `rctx, trip := context.WithCancelCause(ctx)` with `releaseTimeout(procs[release.ProcessRelease])` over it. |
| 5. `StartRelease(withExecGate(rctx, own), rt, id, ReleaseEnv(rt), out)`: Task 12's `startCmdUnit` with Plan 2's `writeRootfsLaunchFor(p, RoleCmd, 0, rt.Host, release.ProcessRelease, rootfsLaunchEnv(env))` (A3: schema 2, no argv, nothing of the agent's environment [pf 1.6]) and `RootfsControl.CmdRootfs(ctx, host, b.tier(rt).MemoryMax, stagedImageOf(id, release.ProcessRelease, nil))` (A5, the sized tier [pf 1.8]). An `ErrStagedImage` or `ErrStartRefused` answer is marked with `refuseRootfs`: root refused before anything ran, so it is a refusal, never the build's failure (INV-4) [pf 1.7]. The unit it returns, with or without an error, is Plan 2's runtime-aware `cmdUnit` (A8): it polls `RootfsUnitName(RoleCmd, host)` and stops and proves that unit, never the binary `carlos-instance-cmd@`. `out` is a line writer into the app log sink (`b.logEmitter(rt)`, `prepare.go:259`), both streams, at most `runs.MaxOutputBytes`, after which lines are dropped and one diagnostic logged. A `launchRefused` start returns the gate's error and the record is removed: nothing ran. |
| @@ -1191,15 +1225,19 @@ own := func() error { |
| **Every result, classified (INV-R3)** [Astra R2 N6]. `classifyRelease(host, err)` reads the record first, so "the unit may still run" is never confused with "this build failed": |
| +`executed` below means the release's unit may have started: `StartRelease` reached root and did not come back with a pre-start refusal. The scheduler reads `SwapDown` as a failure, always: it builds a failure record and holds a hold attempt down (`internal/rollout/scheduler.go:237`, the cohort failure at `:331`), so no row below that is not the build's failure may answer `SwapDown` [Astra R3 4]. An abandoned hold that may have run answers `SwapAbandoned` with `Executed` true, which for an adoption sets the hold-ran marker (`scheduler.go:310-321`), so no later wake boots the good build over a database B's release may have migrated. |
| + |
| | result | record after the call | outcome | R2 (overlap) | R3 planned first wake | R3 hold | R3 other pinned wake | resident accounting | |
| |---|---|---|---|---|---|---|---| |
| -| any error | still there (`opUnproven`) | unproven | `SwapAbandoned`; nothing more runs; the record blocks the host (INV-R4) | the wake fails; its lease goes to the record (`owed`); no fallback, B not failed | `SwapDown` with no build failure recorded; lease to the record | the wake fails; lease to the record | no failure counted (the record latches the host) | |
| +| any error | still there (`opUnproven`) | unproven | `SwapAbandoned`, `Executed` true; nothing more runs; the record blocks the host (INV-R4) | the wake fails; its lease goes to the record (`owed`); no fallback, B not failed | `SwapAbandoned`, `Executed` true (the hold-ran marker, no failure record); lease to the record | the wake fails; lease to the record | no failure counted (the record latches the host) | |
| | nil | gone | passed | the swap may be admitted with `releasePassed` | `web` starts | the pinned start runs | `web` starts | n/a | |
| -| `*ReleaseError` | gone | failed | `SwapFailed`, `Executed` true, reason "release: ..." or "release timed out: ..." | B's failure: fallback to the good build, `w.failed` | `SwapDown`, `markPinExec` | the wake fails with B's failure | counts | |
| -| lease loss (`errSwapLeaseLost`) | gone | cancelled | `SwapAbandoned` | the wake fails, no fallback, B not failed | `SwapDown`, no build failure | the wake fails | no failure | |
| -| `ctx.Err()`, a fence, shutdown | gone | cancelled | `SwapAbandoned` | as lease loss | as lease loss | as lease loss | no failure | |
| -| `errReleaseOpen`, `errSwapBusy` | (another's, or none) | refused | `SwapAbandoned`; the scheduler retries after its deferral | refused before anything ran (the wake latch, INV-R4) | `SwapAbandoned` (Swap's admission) | refused | no failure | |
| -| `errRootfsRefused` (a `Processes` refusal, `errReleaseNoLease`, root's `ErrStagedImage`/`ErrStartRefused`), `errStagedBuildNotPublished`, a gate refusal | gone | refused | `SwapAbandoned` | the wake fails, B not failed, no fallback | `SwapAbandoned` | the wake fails | no failure | |
| +| `*ReleaseError` | gone | failed | `SwapFailed`, `Executed` true, reason "release: ..." or "release timed out: ..." | B's failure: fallback to the good build, `w.failed` | `SwapDown`, `markPinExec`: the build's failure and its hold-down, as a hold build that ran and failed is today | the wake fails with B's failure | counts | |
| +| lease loss (`errSwapLeaseLost`) | gone | cancelled | `SwapAbandoned`, `Executed` = executed | the wake fails, no fallback, B not failed | `SwapAbandoned`, `Executed` = executed (the hold-ran marker when true) | the wake fails | no failure | |
| +| `ctx.Err()`, a fence, shutdown | gone | cancelled | `SwapAbandoned`, `Executed` = executed | as lease loss | as lease loss | as lease loss | no failure | |
| +| `errReleaseOpen`, `errSwapBusy` | (another's, or none) | refused | `SwapAbandoned`, `Executed` false; the scheduler retries after its deferral | refused before anything ran (the wake latch, INV-R4) | `SwapAbandoned`, `Executed` false (Swap's admission) | refused | no failure | |
| +| `errRootfsRefused` (a `Processes` refusal, `errReleaseNoLease`, root's `ErrStagedImage`/`ErrStartRefused`), `errStagedBuildNotPublished`, a gate refusal | gone | refused | `SwapAbandoned`, `Executed` false | the wake fails, B not failed, no fallback | `SwapAbandoned`, `Executed` false | the wake fails | no failure | |
| + |
| +This table is a contract on both sides: R2 and R3 return exactly these `SwapResult`s (`TestReleaseSwapResultsAreTheContract`), and the rollout scheduler handles each one as stated (`TestReleaseOutcomesThroughTheScheduler`, R3), with no change to `scheduler.go`. |
| R2 and R3 map the outcome with this table and never pass a release error to `classifyStep`, whose default is `stepFailed` (`swap.go:162`). `residentFailure` (Task 8) is true for a release result only when the outcome is failed. |
| @@ -1222,7 +1260,7 @@ R2 and R3 map the outcome with this table and never pass a release error to `cla |
| | a member run's retries | `retryCmdSettlesLocked` (`cmd.go:399`) | untouched: a release is not a run and never sits in `e.cmd` or `e.cmdLeft` | |
| | a worker start (if Group W has landed) | W1's `workerGate` and `workerWakeGate` | refused while a record exists (whichever of R and W lands second adds this line) | |
| -- [ ] **Step 1: Write the failing tests.** The backend half goes through Task 12's `rootfsCtlHarness`, not a scripted fake (Astra R1 finding 1). The Service half uses `fakeBackend` implementing `ReleaseBackend`, with `fakeLease` and `fakeRep` implementing `leaseWatch` (a `lost` channel the test closes, an `until` the test sets or advances). |
| +- [ ] **Step 1: Write the failing tests.** The backend half goes through Task 7's `rootfsCtlHarness`, not a scripted fake (Astra R1 finding 1). The Service half uses `fakeBackend` implementing `ReleaseBackend`, with `fakeLease` and `fakeRep` implementing `leaseWatch` (a `lost` channel the test closes, an `until` the test sets or advances). |
| ```go |
| func TestReleaseDue(t *testing.T) // table: rootfs, B != good: due; B == good (version and digest): not; |
| @@ -1295,7 +1333,7 @@ func TestStopSettlesARunningRelease(t *testing.T) // RACE: Bounce while t |
| The invariant tables gain this task's rows: INV-1, the release `cmdUnit` (Stop and Poll through the harness, no binary unit, populated reported group: unproven); INV-4, the release sentinels with `classifyRelease`'s outcome; INV-5, the release launch file under `t.Setenv("PATH", "/agent/bin")`; `TestRootfsCmdVarsFollowTheRunRule` gains the release case (runID "" carries no `CARLOS_RUN_ID` or `CARLOS_RUN_DIR`). |
| - [ ] **Step 2:** Run `go test ./internal/activator/ -run 'TestReleaseDue|TestReleaseTimeout|TestRelease|TestUnprovenReleaseOnAnAwakeIncumbent|TestShutdownDrainsReleaseOps|TestEveryReleaseResult|TestStopSettlesARunningRelease|TestProductionBackend|TestEveryRootfsProof|TestRootfsRefusalsAreNot|TestRootfsLaunchFilesCarry|TestRootfsCmdVars' -count=1` under the short `TMPDIR`. Expected: FAIL. |
| -- [ ] **Step 3:** Implement; write `RFS-3-C03` to `C07` and `RFS-3-C29`, add their ids to the built list. |
| +- [ ] **Step 3:** Implement; write `RFS-3-C03` to `C07` and `RFS-3-C29`, add their ids to the built list, and add `"R"` to `plan3GroupsStarted`. |
| - [ ] **Step 4:** Run Step 2's command, `go test -race ./internal/activator/ -run 'TestStopSettlesARunningRelease|TestReleaseLeaseLossRacesExit|TestReleaseStopsOnLostLease|TestShutdownDrainsReleaseOps' -count=3`, the families the consumers touch (`-run 'Cmd|RunCmd|Sweep|Idle|Shutdown|Releasable|Disabled|MaxRun'`), and Task 1's guards and goldens. Expected: PASS. |
| - [ ] **Step 5: Commit** |
| @@ -1370,6 +1408,9 @@ func TestIncumbentNeverIdlesThroughAMigration(t *testing.T) // [Astra R1 6, Astr |
| // past cfg.Idle of fake time and past an installed maxRunFor ceiling: sweepOnce stops it for neither (C8); after the |
| // release ends the ceiling fires on the next sweep |
| func TestNoReleaseForADisabledRoute(t *testing.T) // the route plan-disabled: no release starts, SwapAbandoned |
| +func TestNoReleaseBesideAnUnfinishedOperation(t *testing.T) // [Astra R3 5] a swap to B returns SwapDone with its retiring generation |
| + // unproven (members outstanding, parent raised); an attempt for C: no release starts (errSwapBusy, Executed false) until the |
| + // retiring generation is proven and the parent restored; then C's release runs and its swap is admitted |
| func TestReleaseRerunsAfterAnAgentRestart(t *testing.T) // the release passed, then the Service is replaced before the swap: a new |
| // Service over the same registry runs release(B) again before admitting B (D3) |
| // internal/rollout/rootfs_reason_test.go |
| @@ -1395,7 +1436,7 @@ git commit -m "rootfs: release runs before an overlap swap is admitted; the swap |
| **Files:** |
| - Modify: `internal/activator/swaphold.go:352` `startPinnedChecked`; `internal/activator/wakeplan.go:370` `spawnPlanned`; `internal/activator/activator.go`: `wake` (`:1760`, the ceiling), `doWake` step 4 (`:2421`; the planned and pinned branches at `:2540`, `:2544`, the identity branch `ib != nil` at `:2546`) and its start-error switch (`:2571`); `internal/activator/maintenance.go` (`cleanupFailedWake`, `:360`); `internal/activator/rootfs_service.go` (`wakeCeilingFor`) |
| -- Create: `internal/activator/rootfs_wake_release_test.go` |
| +- Create: `internal/activator/rootfs_wake_release_test.go`, `internal/rollout/rootfs_release_outcomes_test.go` |
| **Interfaces:** |
| - Consumes: R1's operation, record and `classifyRelease`; N1's `healthBoundFor` and `stagedIdentityOf`; Task 7's placeholder order; each site's existing ownership gate: `startPinnedChecked`'s `gate` (`swaphold.go:353`), `planGate(ctx, e, lease, plan, build string)` (`wakeplan.go:145`, called with `plan.Boot.Version`), and for `doWake`'s pinned branch `leaseLost(lease)` then `a.wakeOwned(ctx, e)`. |
| @@ -1408,7 +1449,7 @@ Where `release` runs inside a wake, under the wake's own lease (`held` is `watch |
| | path | where | lease (`held`) and `gate` | failure | |
| |---|---|---|---| |
| -| hold swap | `startPinnedChecked`, after its gate, before `startPinnedAt`, on `stagedIdentityOf(pin)` | the wake's `lease`; its `gate` | the old build is already stopped; `markPinExec(e)` (`swaphold.go:378`) when the release ran, so the hold reports down, as a hold build that ran and failed does today. The lease-loss error and a refusal are the gate's NoOwnership refusal, as `leaseLost(lease)` there already is | |
| +| hold swap | `startPinnedChecked`, after its gate, before `startPinnedAt`, on `stagedIdentityOf(pin)` | the wake's `lease`; its `gate` | the old build is already stopped. A failed release (`*ReleaseError`, proven): `markPinExec(e)` (`swaphold.go:378`) and `SwapDown`, as a hold build that ran and failed does today. Every other outcome is `SwapAbandoned`, never `SwapDown`, with `Executed` as R1's table says [Astra R3 4] | |
| | planned wake (asleep row, or a resident's restart, scheduler choosing B) | `spawnPlanned`, after `checkPlan` and before `healthBy` is computed, on `plan.Boot`, already a full `StagedIdentity` with its digest (`wakeplan.go:25`); `healthBy` is then measured from the release's end, and the verdict floor uses `healthBoundFor(rt)` (N1) | the wake's `lease`; `planGate(ctx, e, lease, plan, plan.Boot.Version)` | treated as B failing at its start: `executed` and `crashed` include `*ReleaseError`, so a first wake with a fallback boots the good build and records B's failure (`w.failed`, `w.fellBack`). The lease-loss error and a refusal are not B's failure: they are gateNoOwnership like every `planGate` refusal, nothing more is started, and no fallback runs | |
| | other wakes with a pinned identity | `doWake`, right before the `ib != nil` branch, on `id` | the wake's `lease`; `leaseLost(lease)` then `a.wakeOwned(ctx, e)` | the wake fails with the error | |
| @@ -1448,17 +1489,24 @@ func TestReleaseObligationRetriedUntilProven(t *testing.T) // the same, then the |
| // request wakes |
| func TestNoWorkerAfterAFailedRelease(t *testing.T) // only when Group W has landed: a cold wake whose release ends in lease loss, |
| // refusal or failure, and an overlap whose release fails, start no worker of B and leave gen 1's workers untouched |
| +func TestReleaseSwapResultsAreTheContract(t *testing.T) // [Astra R3 4] for R2 and the R3 hold path, each classification row returns |
| + // exactly its SwapResult (Outcome and Executed); no row but failed answers SwapDown or SwapFailed |
| +// internal/rollout/rootfs_release_outcomes_test.go |
| +func TestReleaseOutcomesThroughTheScheduler(t *testing.T) // [Astra R3 4] the real scheduler and failure book, a fake activator |
| + // answering each row's SwapResult for an overlap and a hold adoption: failed writes a failure record (a hold is held down); |
| + // cancelled, unproven and refused write none; an executed hold abandonment sets the hold-ran marker and a non-executed one |
| + // does not; a non-executed abandonment does not spend a retried host's allowance |
| func TestUnprovenWakeReleaseIsNotABuildFailure(t *testing.T) // INV-R3. planned first wake, release(B) exits 1 and its settle fails: the |
| // wake fails, B is not recorded failed, no fallback to A runs beside the unproven unit |
| ``` |
| -- [ ] **Step 2:** Run `go test ./internal/activator/ -run 'TestHoldReleaseFailure|TestAsleepRowRunsRelease|TestFirstWakeReleaseFailure|TestRestartDoesNotRerunRelease|TestReleaseRerunsAfterInterruptedWake|TestRootfsWakeCeiling|TestColdWakeRelease|TestReleaseRefusedWhenOwnershipEnds|TestReleaseObligation|TestUnprovenWakeRelease' -count=1` (under the short `TMPDIR`). Expected: FAIL. |
| +- [ ] **Step 2:** Run `go test ./internal/rollout/ -run TestReleaseOutcomesThroughTheScheduler -count=1` and `go test ./internal/activator/ -run 'TestReleaseSwapResultsAreTheContract|TestHoldReleaseFailure|TestAsleepRowRunsRelease|TestFirstWakeReleaseFailure|TestRestartDoesNotRerunRelease|TestReleaseRerunsAfterInterruptedWake|TestRootfsWakeCeiling|TestColdWakeRelease|TestReleaseRefusedWhenOwnershipEnds|TestReleaseObligation|TestUnprovenWakeRelease' -count=1` (under the short `TMPDIR`). Expected: FAIL. |
| - [ ] **Step 3:** Implement to the table. |
| - [ ] **Step 4:** Run Step 2's command, the wake-plan families (`-run 'Hold|Planned|FirstWake|Wake|Restore|Seed'`), and Task 1's guards. Expected: PASS. |
| - [ ] **Step 5: Commit** |
| ```bash |
| -git add internal/activator |
| +git add internal/activator internal/rollout |
| git commit -m "rootfs: release runs inside the wake's lease before web; an unproven release keeps the lease, the pin and the host latched" |
| ``` |
| @@ -1469,7 +1517,7 @@ git commit -m "rootfs: release runs inside the wake's lease before web; an unpro |
| - [ ] **Step 1:** Merge `origin/main` (Group A merged, and Group W if it has), keeping the claims cleanup's deletions on conflict. Gate A's Steps 1 and 2. Expected: clean. |
| - [ ] **Step 2:** `go test ./internal/activator/ ./internal/rollout/ ./internal/rolloutwords/ ./internal/status/ -count=1` under `nice`, one package at a time. Expected: PASS. |
| - [ ] **Step 3:** `go test -race ./internal/activator/ -run 'TestStopSettlesARunningRelease|TestReleaseLeaseLossRacesExit|TestReleaseStopsOnLostLease|TestSwapReleaseLeaseLossRacesTheSweep|TestShutdownDrainsReleaseOps' -count=1`. Expected: PASS. |
| -- [ ] **Step 4:** Gate A's Step 5, plus Group R's invariants: `-run 'TestReleaseOpConsumersReadTheRecord|TestUnprovenReleaseOnAnAwakeIncumbentIsRetried|TestShutdownDrainsReleaseOps|TestEveryReleaseResultIsClassified|TestOpenReleaseBlocksEveryTransition|TestSwapAdmittedOnlyOnAProvenPass'`. `RFS-3-C01` to `C07` and `C29` are in the built list: `go test . -run 'TestRootfsCopy|TestRootfsBuilt' -count=1`. Expected: PASS. The controller pushes; CI runs the full suite. |
| +- [ ] **Step 4:** Gate A's Step 5, plus Group R's invariants: `-run 'TestReleaseOpConsumersReadTheRecord|TestUnprovenReleaseOnAnAwakeIncumbentIsRetried|TestShutdownDrainsReleaseOps|TestEveryReleaseResultIsClassified|TestOpenReleaseBlocksEveryTransition|TestSwapAdmittedOnlyOnAProvenPass'`. Add `"R"` to `plan3GroupsLanded` (R1 added it to `plan3GroupsStarted`); `go test . -run 'TestPlan3|TestRootfsCopy|TestRootfsBuilt' -count=1`: Group R's copy set (`C01` to `C07`, `C29`) is built, and W's is built only if W has landed. Group R changes no `instancectl` file: `git diff --name-only origin/main...HEAD -- internal/instancectl` prints nothing. Expected: PASS. The controller pushes; CI runs the full suite. |
| --- |
| @@ -1545,8 +1593,8 @@ Rules: |
| - **Start after `web` is healthy** (spec §5.4): Task D's hook in `doWake` after step 6 starts the workers (`startRootfsWorkers`) for a rootfs row, on the wake's generation `w.gen`: one `LaunchRootfsWorker` per name, from that generation's staged image and its launch env, off `a.mu`, under the wake's context, each through `workerWakeGate(e, w.gen, w.rep)` (below). A worker that fails to start is not a wake failure (members before bots, the co-spawn rule); it is installed as exited so the tick restarts it. The declaration is read through `Processes(rt, stagedIdentityOf(w.gen))`, from the build the generation runs, never from the live link. A `Processes` refusal starts no worker and logs once; `web` serves. More than 4 names, or an invalid one, starts no worker and logs once; `web` serves. |
| - **Supervision** in Task 8's `superviseRootfsLocked`, for each awake rootfs entry: a worker whose `proc.Exited()` and that is not `starting` is a crash whatever its exit status (Review Focus 3: a worker's record says it runs). Before a restart its unit is proven gone (`RootfsWorkerGone`); unproven, it moves to `strayRootfsWorkers` and no restart runs beside it. Backoff is the sidecar's (Global Constraints). A worker whose backoff has reached `sidecarRestartMax` is in crash loop: event `RFS-3-C10` once on entry, then `RFS-3-C09` at most once a minute. Every other exit emits `RFS-3-C09`. A start emits `RFS-3-C08`. The restart runs off `a.mu` and re-checks entry identity (`a.entries[host] == e0`) and `e0.state == actAwake` before it installs, the sidecar restart's shape (`activator.go:4873-4920`); a start that lost its entry stops what it started and proves it gone before `startDone` closes. |
| - **The worker exec gates** [Astra R1 7; Astra R2 N5]: every worker start passes a gate immediately before root is asked, riding in on the context (`withExecGate`) as a generation's gate does, and `LaunchRootfsWorker` asks `runExecGate(ctx)` after its preparation and before `StartRootfsWorker`. There are two gates, because a cold wake's first start and a later start see different state: |
| - - `workerWakeGate(e, g Gen, rep Rep)`, for the first start inside `doWake` after step 6. On main the waking entry has neither its generation nor its replica yet: `wake()` installs `e.gen` (`activator.go:1895`) and `e.rep` (`:1863`) only after `doWake` returns, and `ownedLocked(e, true)` skips the lease check for a waking entry by design (`swapadmit.go:94`). So the gate receives the wake's own generation (`w.gen`) and its replica (`w.rep`, which step 5 made, `activator.go:2621-2622`) and refuses unless, under `a.mu`: `ownedLocked(e, true)` (the entry is the host's, no fence, no shutdown); `e.state == actWaking`; `rep != nil && rep.Err() == nil` (the wake's lease is still held); the worker's `gen` is `g.N`; and no stray of that worker's name is unproven. |
| - - `workerGate(e, w)`, for every later start (a restart, W2's handover): `ownedLocked(e, false)` (`swapadmit.go:88`: awake, its replica's lease held, no fence, no shutdown); `e.gen.N == w.gen` (the generation the worker belongs to is still the serving one, so a swap that switched meanwhile starts none of the old set); no stray of that worker's name is unproven. |
| + - `workerWakeGate(e, g Gen, rep Rep)`, for the first start inside `doWake` after step 6. On main the waking entry has neither its generation nor its replica yet: `wake()` installs `e.gen` (`activator.go:1895`) and `e.rep` (`:1863`) only after `doWake` returns, and `ownedLocked(e, true)` skips the lease check for a waking entry by design (`swapadmit.go:94`). So the gate receives the wake's own generation (`w.gen`) and its replica (`w.rep`, which step 5 made, `activator.go:2621-2622`) and refuses unless, under `a.mu`: `ownedLocked(e, true)` (the entry is the host's, no fence, no shutdown); `a.rootfsSwept` (Task 7's startup proof) [Astra R3 3]; `e.state == actWaking`; `rep != nil && rep.Err() == nil` (the wake's lease is still held); the worker's `gen` is `g.N`; and no stray of that worker's name is unproven. |
| + - `workerGate(e, w)`, for every later start (a restart, W2's handover): `a.rootfsSwept`; `ownedLocked(e, false)` (`swapadmit.go:88`: awake, its replica's lease held, no fence, no shutdown); `e.gen.N == w.gen` (the generation the worker belongs to is still the serving one, so a swap that switched meanwhile starts none of the old set); no stray of that worker's name is unproven. |
| - Group R, if it lands, adds "no release record open for the host" to both (its consumer table). The backend's own rootfs gates run in `LaunchRootfsWorker` before its preparation, as `rootfsGates` does for web. This is `startSidecar`'s shape (`activator.go:2828`), which checks ownership before and after its preparation. A refused start starts nothing and is not a crash; the post-start identity check (below) stays, for a start that raced a stop after the gate. |
| - **Pins** [Astra R1 9]: a worker's `build` is set before its start, `entryGenerationsLocked` adds every worker's and every stray's `build`, and the start calls `a.publishBeforeExec()` off `a.mu` before `LaunchRootfsWorker`; a failed write starts nothing (`errStagedBuildNotPublished`) and retries on the next tick. The pin is the worker's own identity, not its generation's member entry, so it survives `dropMember` of the retiring generation (`swap.go:685`), which W2's handover runs after. |
| - **Through the production backend** [Astra R1 4]: `SplitBackend.LaunchRootfsWorker` and `SplitBackend.RootfsWorkerGone` forward to `b.Exec` for an exec-backed row and refuse a unit-backed one; `production_backend_test.go` gains the `RootfsWorkerBackend` row, and the worker tests below run once through `productionBackend`. |
| @@ -1598,7 +1646,7 @@ func TestRootfsWorkersReport(t *testing.T) // the four states |
| The invariant tables gain the worker rows: INV-1, the worker handle's Stop and Poll (no binary unit, populated reported group: unproven); INV-5, the worker launch file under `t.Setenv("PATH", "/agent/bin")`. |
| - [ ] **Step 2:** Run `go test ./internal/activator/ -run 'TestRootfsWorker|TestCleanExitingWorker|TestTooManyWorkers|TestWorkerProcessesRefusal|TestWorkerImagePinned|TestWorkerGate|TestColdWakeWorkerGate|TestWorkersThroughTheProductionBackend|TestProductionBackend|TestEveryRootfsProof|TestRootfsLaunchFilesCarry' -count=1` under the short `TMPDIR`. Expected: FAIL. |
| -- [ ] **Step 3:** Implement; write `RFS-3-C08` to `C10`, add their ids to the built list. |
| +- [ ] **Step 3:** Implement; write `RFS-3-C08` to `C10`, add their ids to the built list, and add `"W"` to `plan3GroupsStarted`. |
| - [ ] **Step 4:** Run Step 2's command, `go test -race ./internal/activator/ -run 'TestRootfsWorkerStartRacesStop|TestRootfsWorkersStopFirst' -count=3`, `-run 'Stop|Sidecar|Releasable|Generations|Prepare|UnitProc'`, and Task 1's guards and goldens. Expected: PASS. |
| - [ ] **Step 5: Commit** |
| @@ -1701,7 +1749,7 @@ git commit -m "rollout: the box reports each rootfs instance's worker states" |
| - [ ] **Step 1:** Merge `origin/main` as gate A did; Steps 1 and 2 of gate A. Expected: clean. |
| - [ ] **Step 2:** `go test ./internal/activator/ ./internal/rollout/ ./internal/status/ -count=1` under `nice`, one package at a time. Expected: PASS. |
| - [ ] **Step 3:** `go test -race ./internal/activator/ -run 'TestRootfsWorkerStartRacesStop|TestOverlapHandsOverWorkersNeverTwoSets' -count=1`. Expected: PASS. |
| -- [ ] **Step 4:** Gate A's Step 5 (the invariants, the `instancectl` diff). Every live `RFS-3-C` id, C08 to C10 included, is in the built list: `go test . -run 'TestRootfsCopy|TestRootfsBuilt' -count=1`. Expected: PASS. The controller pushes; CI runs the full suite. |
| +- [ ] **Step 4:** Gate A's Step 5's tests. Add `"W"` to `plan3GroupsLanded` (W1 added it to `plan3GroupsStarted`); `go test . -run 'TestPlan3|TestRootfsCopy|TestRootfsBuilt' -count=1`: Group W's copy set (`C08` to `C10`) is built, and R's is built only if R has landed [Astra R3 6]. Group W changes no `instancectl` file: `git diff --name-only origin/main...HEAD -- internal/instancectl` prints nothing. Expected: PASS. The controller pushes; CI runs the full suite. |
| --- |
| @@ -1758,7 +1806,7 @@ None open. The one this plan raised, `carlos run` on fleet boxes (D4), Paul answ |
| - Spec coverage. §5.0 record half: Tasks 2 to 4 (and the mint helper for Plan 4). §5.2 environment: Task 6, W1 and R1; deploy overlap: N1, with R2's release before it; worker handover: W2. §5.2.1: Group R (R2 overlap, R3 hold, hibernating wake and first boot; rollback leaves the schema; distinct from seeds by D5); until it lands, the app's web command migrates (D8). §5.4: W1 (start after healthy, stop first, cap 4, crash restart, crash loop in logs and status, W3). §5.5 `carlos run` and `--version`: Task 12; moves: Task 13; seeds: D5. §5.6: Tasks 7 and 8 (boot, crash, adoption, no idle, replication with the activator, Task 5's ops change), R3's wake ceiling, the version floor (Task 15 and Plans 2 and 4), no local database (every rootfs row keeps its SQLite path, Task 4), plans-caps (hand-off). §7 C5: every process is a unit (Tasks 12, R1, W1); C7: release and workers run under the incumbent's or the wake's lease, and a release is gated on ownership and stopped and proven gone before the lease's safety deadline (R1); C8: N1's swap tests and R2's (the incumbent is never touched by a release, and never idle-stopped or ceiling-stopped during one). B1-4's empty SQLite file: D7, Task 7. |
| - What a claim-armed box does: Plan 3 reads no claim switch; Plan 2's `rootfsGates` refuses every rootfs start under it, and Task 7 asks those gates before the lease, so residency, wake, release and run all refuse there with the reason in `carlos logs`. |
| -- Names used across tasks: `ActivatorOwned`, `ActivatorLeased`, `Resident`, `Rootfs` (Task 2) in Tasks 4, 5, 7, 8; `RuntimeRootfsV1` in `registry` and `provision`; Plan 2's `rootfsVars` with Task 6's `rootfsCmdVars` in Task 12 and R1 and W1's `rootfsWorkerVars`; `healthBoundFor` and `stagedIdentityOf` (N1) in Tasks 7, 12, D, R1 to R3, W1; `rootfsStartRefusal`, `rootfsStartable` and `productionBackend` (Task 7) in Tasks 8, D, R1, W1; Task D's `Processes` and `rootfsProcessesHook` in R1 and W1, W2; Task 12's `startCmdUnit`, `stagedImageOf` and `rootfsCtlHarness` in R1 and W1; Task 8's `superviseRootfsLocked` and `residentFailure` filled by W1 and extended by R1; R1's `releaseOp`, `runRelease`, `classifyRelease`, `leaseWatch`, `ReleaseError` in R2 and R3; R2's `releasePassed` in `swapOverlap`; `rootfsDBPlacer`, `PlaceRootfsDB` (Task 7) in R3's first-boot order; `RootfsWorkers`, `WorkerReport` (W1) in W3; `stopRootfsWorkers`, `rootfsWorkersGone`, `workerGate`, `workerWakeGate`, `handOverRootfsWorkers` in W1 and W2. |
| +- Names used across tasks: `ActivatorOwned`, `ActivatorLeased`, `Resident`, `Rootfs` (Task 2) in Tasks 4, 5, 7, 8; `RuntimeRootfsV1` in `registry` and `provision`; Plan 2's `rootfsVars` with Task 6's `rootfsCmdVars` in Task 12 and R1 and W1's `rootfsWorkerVars`; `healthBoundFor` and `stagedIdentityOf` (N1) in Tasks 7, 12, D, R1 to R3, W1; `rootfsStartRefusal`, `rootfsStartable` and `productionBackend` (Task 7) in Tasks 8, D, R1, W1; Task D's `Processes` and `rootfsProcessesHook` in R1 and W1, W2; Task 12's `startCmdUnit` and `stagedImageOf`, Task 7's `rootfsCtlHarness` in R1 and W1; Task 8's `superviseRootfsLocked` and `residentFailure` filled by W1 and extended by R1; R1's `releaseOp`, `runRelease`, `classifyRelease`, `leaseWatch`, `ReleaseError` in R2 and R3; R2's `releasePassed` in `swapOverlap`; `rootfsDBPlacer`, `PlaceRootfsDB` (Task 7) in R3's first-boot order; `RootfsWorkers`, `WorkerReport` (W1) in W3; `stopRootfsWorkers`, `rootfsWorkersGone`, `workerGate`, `workerWakeGate`, `handOverRootfsWorkers` in W1 and W2. |
| - Proportion: decisions, signatures and test assertions; bodies only where the order of steps is the decision (`rootfsTick`, `runRelease`). |
| - **Who owns a running `release`, admission to proof (Group R, round 3).** One owner: the Service, through one operation record per host, `a.releaseOps[host]` (R1). One obligation record: it holds the build's full identity (the pin), the cmd unit's hold (the stop and settle), the cancel, the entry it runs beside while that entry lives, the lease it must give back if a wake's entry went, and its state (running, or finished with proof outstanding). One retry path: `runRelease` settles while it runs; once it returns unproven, only `reapReleaseOpsLocked` retries, in `finishPendingStops`, the pass the sweep and Shutdown share, whatever the owner's state, and Shutdown counts the records in its drain and names any left at exit. Admission refuses while a record exists, before any decision about whether a release is due, and publishes the pin before root is asked; the proof is the only thing that removes the record. Every consumer reads that record and nothing else (R1's table: runs, other releases, every swap admission, the plan-disabled stop, idle, the instance awake ceiling, the owner's stop and `releasable`, wakes, the failed wake's lease, pins, worker starts). Every result has one classification (R1's table), and only a `*ReleaseError` with its unit proven gone is the build's failure. |
| - **Release is decoupled from the overlap swap (Paul, 2026-10-26; Astra round-2 review).** The round-2 view was that decoupling would be simpler for the swap and not for the cold wake, at the cost of a durable "release passed" marker. Astra's review showed the marker is unnecessary: an attempt-scoped, in-memory pass handed straight to the swap, with attempt, target and ownership rechecked, is enough, and an agent restart reruns the release, which D3 already allows. Paul chose that design and moved `release` out of Group A into its own Group R, built after A: R2 runs the release as its own operation before the swap is admitted, and `swapOverlap` contains no release step; R3 keeps the cold-wake, planned-wake and hold release inside the wake's restored-data and lease lifetime, where the hand-off cost is real. Group A contains, calls, waits on and tests no release machinery (gate A Step 6 greps for it). |
| @@ -1770,4 +1818,5 @@ None open. The one this plan raised, `carlos run` on fleet boxes (D4), Paul answ |
| - Task 2: `Upsert` keeps a rootfs row's hibernation unless re-tenanted, the replication arm keys on the effective runtime, `carlos add` refuses an existing rootfs host, `ErrRuntimeFixed` crosses the remote registry. Task 5: `BuildStateKept`, `socket_advice.go:121` and `restartscope.go:496` added, `movesphase1.go` dropped. Task 7: `RenameBetweenNoReplace`. Task 10: `Processes` checks the image's digest, root's refusals are refusals, launch env `rootfsLaunchEnv`, the sized tier. Task 12: the same, plus `runCopySuperseded` for RUN-C47. Task 13: the provision transitions are the control, a test enumerates the `seedMoveRefusal` sites, the Phase 1 citations dropped. Every agent-side egress slot struck (#328 checks on root's side). |
| - **Round 2 (Astra plan review R1 of b3a40781, 7 P1 and 4 P2; map in amend-report.md "Round 2"):** Task 5 widens only (`ActivatorLeased` keeps hibernating binary sidecars where today's no-kind sites have them); N1's staged arm launches without a health wait and every rootfs `Gen` carries its full identity (`stagedIdentityOf`), with the manifest read's (nil, nil) and `BoxArtifact` cases refused; every new interface goes through `SplitBackend` with a production-composition test; one `releaseRun` record owns a release from admission to proof (INV-7), outliving a failed wake with its lease, pin and latch, read by every consumer; a final worker exec gate (`workerGate`) and `LaunchRootfsWorker` (the pre-flight's `StartWorker` collides with the binary worker start); gates, `BuildIdentity` and pins off `a.mu` and published before exec; the rollback floor is a release floor (`RootfsLifecycleFloor`), not the unit set; INV tests cover the shared dispatch files, the agent-held obligations, a real health response between the bounds and resident accounting (`residentFailure`). |
| - **Round 3 (Astra plan review R2 of bbac6804: 8 of 11 fixed, N1 to N6 new; Paul's decision of 2026-10-26; map in amend-report.md "Round 3"):** `release` leaves Group A for its own Group R (R1 the operation, R2 before an overlap swap, R3 inside a wake, R gate), with INV-R1 to INV-R5. N1: retries keyed on the operation's state, not the entry's. N2: the reaper in `finishPendingStops` and the records in Shutdown's drain and exit report. N3: the instance awake ceiling and the plan-disabled stop in the consumer table. N4: the open-release check at every swap admission and wake, before the due decision. N6: one classification for every release result. N5 (Group W): `workerWakeGate` takes the wake's generation and replica. New Task D in Group A holds the declared-processes read both later groups share and logs what the box does not run yet; Task 12 holds the shared `startCmdUnit`, `stagedImageOf` and the control harness. Plan 4 depends on A and W, not R: its sample migrates with `db:prepare` before Puma. |
| + - **Round 4 (Astra plan review R3 of 39dfc0dc; map in amend-report.md "Round 4"):** Task 8's tick only reserves, and each resident's gate I/O and start run in a job off the sweeper, cancelled with the Service; Plan 2's gate hooks take a `ctx`. Task 5 makes retention require a box report for resident records. Task 7 keeps rootfs admission closed until a startup sweep proves no rootfs leftover runs, with a rootfs-only retry sweep (`server.go`'s `handleSweep` filter, now an allowed `instancectl` file), inherited by W's gates. Group R's hold outcomes never answer `SwapDown` except for a failed release, tested through the real scheduler, and release admission refuses beside an unfinished generation operation. The gates use pinned per-group copy sets and a declared-name inventory (`plan3_groups_test.go`) in place of the grep, and the later `instancectl` checks pass on an empty diff. |
| - Every file:line refreshed against main a912a342, spec rev 5; the RFS-3 file cells set to bare paths in the deck and here (texts unchanged); each task's header says whether it gets a cross-model review. `Service.rootfsRefusal` is now `rootfsStartRefusal`, because Plan 2's `rootfsRefusal` is a type in the same package. |