carlos run: rootfs rows run in their image; a one-shot is killed at lease loss; the run dir waits for the proof (rootfs plan 6 task 7a)
Brings back the run half of Plan 3 Task 12 (cut at bba9a52d), without --version, and fixes its two P1s. StartCmd takes a rootfs row, after the layout and run-directory checks, to startRootfsRun (backend_rootfs.go): the serving image is required (errNoCmdExe, errPartialStagedIdentity, both marked), then genEnv and the replica gate, then startRootfsCmd with the operator's argv exactly as given. startRootfsCmd takes a rootfsCmdLaunch (a process or an argv); StartRelease's request and launch file are byte-identical (goldens). C7 (Call A1): the lease watch covers every rootfs row, hibernating too. residentLeaseShort stops a run whatever the entry's state; at the loss root kills the one-shot unit (KillOneShot -> /stop kill=1, now taken for a rootfs cmd or tty stop), at once and again when a start in flight returns. The tick's no-signal fallback does the same. A rootfs run is refused when unwatched or with less than oneShotStartLead of lease left. INV-2: CmdSpec.AfterSettled is called once when no unit of the run can be running; the box removes the run directory there, not at cleanUp. The console admits an always-on rootfs record on a platform box (PF-2); a fleet record is still refused. docs/site/cli.md gains RFS-3-C27. Census overlay rootfs-apps-6 re-proposed (seal a4237374); the record-write census re-pins runsWorker.finish.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
approved_rootfs_copy_test.go+3 −0docs/site/cli.md+2 −0docs/superpowers/notes/census-proposal-rootfs-apps-6.md+29 −3docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md+1 −1internal/activator/activator.go+15 −10internal/activator/backend_rootfs.go+123 −14internal/activator/backend_unit.go+13 −0internal/activator/cmd.go+168 −12internal/activator/cmd_test.go+142 −0internal/activator/cmdunit.go+22 −1internal/activator/rootfs_cmd_lease_test.go+627 −0internal/activator/rootfs_cmd_test.go+485 −0internal/activator/rootfs_invariants_test.go+94 −1internal/activator/rootfs_service.go+83 −38internal/activator/rootfs_test.go+10 −6internal/activator/testdata/rootfs_golden/start_release.cmd+9 −0internal/activator/testdata/rootfs_golden/start_release.launch.cmd.json+12 −0internal/console/apiruns.go+6 −2internal/console/apiruns_rootfs_test.go+71 −0internal/host/runexec.go+36 −16internal/host/runexec_linux_test.go+182 −12internal/instancectl/client.go+5 −4internal/instancectl/rootfs.go+13 −8internal/instancectl/rootfs_test.go+123 −0internal/instancectl/server.go+5 −1internal/provision/rootfs_apps_6_census_test.go+5 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −1internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv+39 −3plan3_groups_test.go+5 −3
Intent
<task-notification> <task-id>a47f5ab8cb6500f55</task-id> <tool-use-id>toolu_01P57nfhq9skNhQVhcdMn121</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a47f5ab8cb6500f55.output</output-file> <status>completed</status> <summary>Agent "Plan 6 Task 7: trampoline tty role" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Status:** DONE_WITH_CONCERNS **Commit:** 3fd3c3a4 "instance-exec: the tty role takes its terminal over stdin (rootfs plan 6)", on top of 37a06e98. Not pushed. **Tests:** the 11 new instanceexec tests pass (5 from the brief, 6 added), and so do the existing trampoline, init, exit and claim tests. go vet is clean for linux/amd64, darwin/arm64, windows/amd64 and linux/arm64, and the root binary builds on all three cross targets. The census tests pass. I applied 19 mutations: 17 were killed and 2 survived (explained below). **What changed:** - `instance-exec tty` and `--rootfs tty` read `launch.tty.json` and launch through `ttyLaunch`, in the new `tty_linux.go`. `tty_other.go` is the non-linux stub. - `runInitChecked` now takes the tenant's stdio and whether to give it a controlling terminal. All three callers are migrated, one of them a test. - The `instance-exit` usage line now lists tty. **Concerns:** 1. **Census approval is owed on #280, not requested.** The rootfs-apps-6 overlay is re-proposed with seal `44581c37…`. It adds one new unit, `receivePTY`, and carries the 16 earlier claims over unchanged. The record-write census also needed a re-pin of `exit.go:parseExitArgs`, because its usage line changed; that is in `rootfs_apps_6_census_test.go`. 2. **The exit-role test was already green before I started.** Task 5 had made `ParseRole` accept tty, so both programs already parsed it. The real gap was the launch dispatch, which `TestExecDispatchesTheTTYRoleToTTYLaunch` now covers. 3. **Two mutants survive.** Ignoring the `MSG_CTRUNC` flag makes no difference on 64-bit. Skipping the TCGETS question can't be caught without root, though the verdict function itself is tested. 4. **I fixed a bug in my own test setup.** Calling `Fd()` on the pty master had switched off every read deadline, which let one mutant survive at first. With that fixed, the mutant is killed. 5. **A stop is ignored for up to 10 seconds while the trampoline waits for the pty.** If no pty arrives, the trampoline exits on its own when the wait ends, which is inside the 20-second stop timeout. 6. **The terminal test needs `sh`, `tty`, `ps` and `sleep` on the test host.** The full report (RED/GREEN, mutation table, callers, census card) is at `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/rootfs-apps-6/.superpowers/sdd/2026-10-24-rootfs-apps-6-interactive/task-7-report.md`. Scratch files are removed and no test processes are left running.</result> <usage><subagent_tokens>219612</subagent_tokens><tool_uses>72</tool_uses><duration_ms>1221519</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <tool-use-id>toolu_01USvxczJ4hNHdReJVzhSwcG</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting for the mutation runs to finish.</result> <usage><subagent_tokens>305809</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1391962</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Still waiting for the remaining mutation runs. I'll keep using the absolute path to the design-tunnel-websockets-471 worktree and won't touch rootfs-apps-6.</result> <usage><subagent_tokens>304996</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1393767</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting for the remaining mutations, M4 through M16.</result> <usage><subagent_tokens>305116</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1403266</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting for the next results.</result> <usage><subagent_tokens>305416</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1412617</duration_ms></usage> </task-notification>
<task-notification> <task-id>burabpppj</task-id> <tool-use-id>toolu_01LYRBtTWrpLE7Gi7iggPBAP</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/burabpppj.output</output-file> <status>completed</status> <summary>Background command "Run Astra review of Plan 6 Task 7" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting.</result> <usage><subagent_tokens>305700</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1422060</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting.</result> <usage><subagent_tokens>305999</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1433779</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting.</result> <usage><subagent_tokens>306296</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1452074</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting.</result> <usage><subagent_tokens>306587</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1463152</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting.</result> <usage><subagent_tokens>306874</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1474419</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting.</result> <usage><subagent_tokens>307163</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1483907</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting.</result> <usage><subagent_tokens>307453</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1493792</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting.</result> <usage><subagent_tokens>307737</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1503758</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting.</result> <usage><subagent_tokens>308021</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1516195</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting.</result> <usage><subagent_tokens>308311</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1526786</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting.</result> <usage><subagent_tokens>308601</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1536160</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" is waiting on its own background work</summary> <note>This agent stopped with background work of its own still running. It may resume on its own when that work completes or reports, and the same task-id notifies again if it does; the result below may be interim.</note> <result>Waiting for M16.</result> <usage><subagent_tokens>308899</subagent_tokens><tool_uses>84</tool_uses><duration_ms>1549849</duration_ms></usage> </task-notification>
<task-notification> <task-id>a58070cdd3a43a333</task-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a58070cdd3a43a333.output</output-file> <status>completed</status> <summary>Agent "#471 Task 6: production-wired witness" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Status:** DONE_WITH_CONCERNS **Commit:** `eef20b79` on `design-tunnel-websockets-471`, base `10151ad5`. Not pushed. Only test files changed, including the Task 5 carry-in: `TestStaleAdmissionIsRefused` now releases its paused handshake through a deferred `sync.Once`. **Tests:** `TestTunnelWebSocketEndToEnd` (cases 1-8, 10-12, 14-16), `TestTrustedChildIsNeeded` and `TestStaleAdmissionIsRefused` pass, and they pass again under `-race` with no data races. All 19 production mutations made their case fail on its own assertion, including the brief's two: cap 0 gives case 2 a 503, and a no-op `sweepUpgrades` makes case 15 time out. Vet passes for linux, darwin and windows, and `go build ./...` is clean. The census card is unchanged (seal `1379d066…5e7`). **Concerns:** 1. **Case 2b differs from the brief.** With the gate only on the box's `t.example.com` row, the login through the hub gets a 404, which I checked by running it. The hub 404s a login POST to an ungated row that is not a forward row. So the witness puts the gate on the hub's `-tunnel` row instead, and the app still never sees the cookie. This means a `-tunnel` row gated only on its box cannot be logged into through the hub. That predates this branch; the spec may want to say so. 2. **Owner change uses `baj`, not `k3x`**, following common.md and the Task 3 ruling. 3. **Case 12's "no Hijack" variant depends on the rate limit.** It is released by the body only because the rate limit wraps the hub's writer. With the rate limit off, the backstop would release it instead. It is released either way, so nothing leaks. 4. **A client that never closes holds a slot after the app closes.** The hub half-closes toward the client and keeps the slot until the client closes or writes. This is how Go's standard reverse proxy behaves, and the cap is unaffected. 5. **`X-Forwarded-Proto: https` depends on how the box dials.** It holds only because `Dial` hands back the TLS connection itself. If the start of the HTTP/2 traffic were ever read together with the 101, the app would see `http`. Over TLS that does not happen today. This is pre-existing and noted only. 6. **The hub restart (case 9) is Task 7's work, as the plan says**, not this task's. The dispatch mentioned it, but the brief does not list it. The scene already has the tracking listener Task 7 needs to model process death. The full report, with every case, the mutation table and the census card, is appended to `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-tunnel-websockets-471/.superpowers/sdd/2026-10-30-tunnel-websockets/task-6-report.md`. The new files are `internal/edge/tunnel_ws_e2e_test.go` and `internal/edge/trusted_child_test.go`. Scratch is removed, no processes are left running, and `/tmp/g` is untouched.</result> <usage><subagent_tokens>327456</subagent_tokens><tool_uses>93</tool_uses><duration_ms>1728414</duration_ms></usage> </task-notification>
Attributed to this commit: 10.6 g CO₂e (1,176,508 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on rootfs-apps-6-interactive, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/approved_rootfs_copy_test.go b/approved_rootfs_copy_test.go| index b059abbe7..88d4d7eed 100644 |
| --- a/approved_rootfs_copy_test.go |
| +++ b/approved_rootfs_copy_test.go |
| @@ -256,6 +256,9 @@ var rootfsCopyBuilt = []string{ |
| // Plan 6 Task 4: the interactive sessions setting |
| // (internal/console/apiinteractivesetting.go, apps_swap.go) |
| "RFS-6-C38", "RFS-6-C39", "RFS-6-C40", "RFS-6-C41", "RFS-6-C42", "RFS-6-C43", "RFS-6-C44", "RFS-6-C45", "RFS-6-C46", "RFS-6-C47", |
| + // Plan 6 Task 7a: carlos run on rootfs rows, the rootfs argv on the |
| + // image's PATH (docs/site/cli.md) |
| + "RFS-3-C27", |
| } |
| func mustParseRootfsRecord(t *testing.T) []copyRow { |
diff --git a/docs/site/cli.md b/docs/site/cli.md| index 7554e1071..0d3413384 100644 |
| --- a/docs/site/cli.md |
| +++ b/docs/site/cli.md |
| @@ -703,6 +703,8 @@ The command runs for at most 30 minutes unless you pass --timeout, up to 6 hours |
| A hibernating instance is woken first. A live one keeps serving, and the command opens the same database beside it. One run at a time per instance. carlos run needs the instance's box on the nested layout, and it is refused while the instance is moving. |
| +For a rootfs app the command after -- runs inside the instance's image and is found on the image's PATH. |
| + |
| carlos run exits with the command's own status, 128 plus the signal number when a signal ended it, 124 when it timed out, 125 when it was interrupted or the instance let go of it without a result, 130 when you cancelled it, 3 when the box refused it or did not pick it up within 60 seconds, and 2 when the console refused it. |
| carlos logs shows when each run started, who asked for it and how it ended. The command's output is not kept there. A service's run reads "started by service ci", with the person it named, if any, marked as the service's statement. |
diff --git a/docs/superpowers/notes/census-proposal-rootfs-apps-6.md b/docs/superpowers/notes/census-proposal-rootfs-apps-6.md| index 5a4ca08ba..0c91d8950 100644 |
| --- a/docs/superpowers/notes/census-proposal-rootfs-apps-6.md |
| +++ b/docs/superpowers/notes/census-proposal-rootfs-apps-6.md |
| @@ -1,9 +1,14 @@ |
| # Census approval: rootfs-apps-6 |
| -Ruling `census-ruling-rootfs-apps-6`. The independent reviewer approves or rejects every change below, 4 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| +Ruling `census-ruling-rootfs-apps-6`. The independent reviewer approves or rejects every change below, 12 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| | unit | change | read sites | what changed | |
| |---|---|---|---| |
| +| `internal/activator/activator.go` `Service.installProcLocked` | body | unchanged (1) | rootfs Plan 6 Task 7a (Call A1, Astra R1 P1-1): the lease watch is installed for every rootfs row (e.route.Rootfs()), not only a resident, so a hibernating rootfs row's run or session is reached at the lease's loss; the same one read of the entry's route; installs nothing else | |
| +| `internal/activator/backend_rootfs.go` `ExecBackend.StartRelease` | body | unchanged (2) | rootfs Plan 6 Task 7a: passes rootfsCmdLaunch{Process: release.ProcessRelease} to startRootfsCmd in place of the bare process name; its /cmd request and launch.cmd.json are byte-identical to before (TestStartReleaseIsUnchanged, goldens written from 3fd3c3a4); no read added | |
| +| `internal/activator/cmdunit.go` `type CmdSpec` | body | unchanged (1) | rootfs Plan 6 Task 7a: declaration only: gains AfterSettled, a callback field the caller sets (the box's run pass removes the run's directory in it), called once when no unit of the run can be running; reads nothing | |
| +| `internal/activator/rootfs_service.go` `Service.residentLeaseLost` | body | unchanged (2) | rootfs Plan 6 Task 7a (Call A1): residentLeaseLostLocked also returns one kill func per one-shot unit that may run; each runs off a.mu in the same WaitGroup as stopRootfsWorkersAtLoss and killResidentGens, which still run only for a resident (gens non-nil); the kills go to root's existing /stop through KillOneShot; no read added | |
| +| `internal/host/runexec.go` `runsWorker.execute` | body | unchanged (2) | rootfs Plan 6 Task 7a (INV-2): sets CmdSpec.AfterSettled to remove the run's directory (runs.RemoveRunDir under the instance's own directory, as cleanUp did) once the activator has proven no unit of the run runs; finish and cleanUp take removeDir, true only on the incarnation refusal before RunCmd; the directory goes later or at the same point, never earlier; no read added | |
| | `internal/host/units/carlos-instance-cmd@.service` `external` | body | unchanged (1) | rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else | |
| | `internal/host/units/carlos-instance-gen@.service` `external` | body | unchanged (1) | rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else | |
| | `internal/host/units/carlos-instance-probe.service` `external` | body | unchanged (1) | rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service, so the probe proves what the tenants get (its new pts-private line); fix round 1 (Astra P2, roll order): one line outside the namespace block, Environment=CARLOS_PROBE_PTS_PRIVATE=1, a constant the unit sets for its own process (the probe, as carlos, in the namespace); it names no path, adds no bind source or Exec line, and root reads nothing new | |
| @@ -16,8 +21,12 @@ Ruling `census-ruling-rootfs-apps-6`. The independent reviewer approves or rejec |
| | `internal/instanceexec/probe.go` `productionProbeEnv` | body | unchanged (1) | rootfs Plan 6 Task 5 (PF-8): the binary probe env sets devPts=/dev/pts and openPtmx (open /dev/ptmx O_RDWR|O_NOCTTY and close at once), the fields the rootfs probe env already set; read by the new pts-private line inside the probe unit (as carlos, in the namespace); fix round 1: also reads its own environment, CARLOS_PROBE_PTS_PRIVATE (exactly "1" enforces pts-private; otherwise the line is reported unverified), which the probe unit sets; the same direct site, no new root read | |
| | `internal/layout/plan.go` `NestedPlatformNames` | body | unchanged (1) | rootfs Plan 6 Task 5: the fixed role list gains RoleTTY, so launch.tty.json is one more fixed platform name; still reads nothing | |
| | `internal/provision/reconcile.go` `Reconcile` | body | unchanged (178) | rootfs Plan 6 Task 3: in the per-record loop, beside the RunSeen call, calls cfg.InteractiveSeen(rec) when the hook is set and the in-scope record carries an interactive-session marker (rec.Interactive != nil), once per record per pass, before the pass acts on it; the hook is the box worker's non-blocking note (Task 12). Same record keys and literal; no read added (registry read sites unchanged, 178); nothing written by the call | |
| +| `internal/activator/backend_rootfs.go` `ExecBackend.startRootfsCmd` | sites | +registry:Host | rootfs Plan 6 Task 7a: takes a rootfsCmdLaunch, a declared process or an operator's argv, exactly one or refused before anything is laid out; the launch file names the process or cmd, never an argv; CmdRootfs names the image with the process or with the argv in the request body, which root validates against the staged image itself (instancectl, unchanged); new site +registry:Host is that refusal's message | |
| +| `internal/activator/cmd.go` `Service.RunCmd` | sites | +registry:Host, +whole:Route ×2 | rootfs Plan 6 Task 7a: AfterSettled honoured on every path (called before return on each path that starts no unit, else by the settle that proves the unit gone); a rootfs run is refused as a lost lease (CmdStoppedError StopLeaseLost) when its entry is not under the lease watch (residentWatchedLocked), and, off a.mu, when the replica's in-memory SafeUntil leaves less than oneShotStartLead (oneShotHeadroom); new sites are e.route.Rootfs() and a log line; adds refusals only | |
| +| `internal/activator/cmdunit.go` `ExecBackend.StartCmd` | sites | +whole:Route | rootfs Plan 6 Task 7a: after the layout and run-directory checks, a rootfs row returns startRootfsRun (backend_rootfs.go) before nestedGate; the binary path is byte-identical (TestBinaryStartCmdLaunchGolden); new site +whole:Route is rt.Rootfs() | |
| +| `internal/activator/rootfs_service.go` `Service.rootfsTick` | sites | +whole:Route | rootfs Plan 6 Task 7a: the no-signal fallback also covers a hibernating rootfs entry with a one-shot unit that may run (oneShotHoldsLocked); it latches ownerKilled and runs each one-shot kill func (KillOneShot to root's existing /stop) with go off a.mu, beside a resident's killResidentGens and stopRootfsWorkersAtLoss as before; new site +whole:Route is e.route.Rootfs(); stops more, starts nothing | |
| -Envelopes re-pinned: `.`, `internal/appconfig`, `internal/host/units`, `internal/instancectl`, `internal/instanceexec`, `internal/layout`, `internal/provision`. |
| +Envelopes re-pinned: `.`, `internal/activator`, `internal/appconfig`, `internal/host`, `internal/host/units`, `internal/instancectl`, `internal/instanceexec`, `internal/layout`, `internal/provision`. |
| Removed units: the scan finds neither the declaration nor any of its sites. |
| @@ -31,6 +40,11 @@ A removed unit's recorded disposition and basis are in its table above. For a re |
| Recorded dispositions, which each change must still satisfy: |
| +- `internal/activator/activator.go` `Service.installProcLocked`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8: the one place a process, its generation and the lease replica are installed on an entry; a resident is put under its lease watch (watchResidentLeaseLocked) at that moment; reads only the entry's route |
| +- `internal/activator/backend_rootfs.go` `ExecBackend.StartRelease`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1: new; startRootfsCmd naming release.ProcessRelease, both streams through one capped line writer (releaseOutput, runs.MaxOutputBytes) into the caller's writer; no read of its own |
| +- `internal/activator/cmdunit.go` `type CmdSpec`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): declaration only; Prepare is a callback field, not a prepared statement |
| +- `internal/activator/rootfs_service.go` `Service.residentLeaseLost`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8 (C7): a resident's lost lease marks it and then kills its generations off a.mu (killResidentGens);rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.10: a resident's lost lease stops its workers (stopRootfsWorkersAtLoss, proven gone) in parallel with killResidentGens; rt is taken under the lock and passed to killResidentGens in place of e.route (the same route); site +whole:Route (that local rt); no file read |
| +- `internal/host/runexec.go` `runsWorker.execute`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): runs one picked run to its result in the bucket; every root action goes through instance control;rev3=PROPOSED-325;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=emits the run's start and end as member log events through the agent's EventSink; reads unchanged |
| - `internal/host/units/carlos-instance-cmd@.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=the cmd unit template (applied by PID 1 as root; its process runs as carlos): extends the J4 seed pattern to the run role. The template equals the seed template outside named lines, and the template-equality test pins that. Root lays out a staged executable validated by the same refuseStagedExe the seed and generation paths use, then starts this unit, which runs as carlos with the instance's own reach. No new trust of registry, /data or agent-asserted content beyond the seed path |
| - `internal/host/units/carlos-instance-gen@.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input |
| - `internal/host/units/carlos-instance-probe.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-2;basis=one more BindReadOnlyPaths= line, so PID 1 opens one more bind source: /run/carlos-control/exe/_probe/box-addrs, bound to /opt/carlos/box-addrs, root's list of the box's own addresses, which RunProbe writes before every run (#367) in the root-only directory the unit already binds from; no tenant, app or agent input names or writes it |
| @@ -43,14 +57,26 @@ Recorded dispositions, which each change must still satisfy: |
| - `internal/instanceexec/probe.go` `productionProbeEnv`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-2;basis=the binary probe's env gains boxAddrs (instancectl.BoxAddrsPath, /opt/carlos/box-addrs), which boxAddrClosed (a decision row) reads inside the probe unit, and mmapWX (realMmapWX, an anonymous mapping); the same one direct site |
| - `internal/layout/plan.go` `NestedPlatformNames`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-moves-offline;basis=root-input (J4, as main's moves units); the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): new, called only from the agent's offline sealer and source retire (IsNestedPlatformName): a fixed list of names, reads nothing |
| - `internal/provision/reconcile.go` `Reconcile`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), from its reconcile loops: each listed record is observed through the box's lifetime judge (ObserveWith: the record, then its host incarnation slot) before the shape, channel and scope checks, a stale record is left out and an unjudgeable one protected; the removal phase observes a row's own record key when the pass holds none for it under that key, and deletes a held row whose record is gone or stale through DeleteIfHold; a nil judge (claims on) is main's body; registry read sites unchanged, offsets moved; fix round 1: the removal phase observes a row's own key only under an account the listing trusts, so a retired or unmaterialised account's row keeps record gone, and the pass arms its own context with the judge; Task 7: under a judge an existing provisioned row of the record's own app and account follows the existing-row rules (heldByVanishedPredecessor and retireHeldPredecessor's DeleteIfHold first, the record then minted on the same pass; the hold; installRowLifetime), each a separate write under the host's hold lock; registry read sites unchanged, offsets moved;rev3=census-ruling-instance-egress-sizes-328-329;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=#328/#329 plan 1 Task 7: the pass reads its apps' policy objects (control/app-policy/<sqid>/<app>.json in the bucket) through the agent's PolicyCache, each verified with ReleasePub by apppolicy.VerifyKey (ed25519 over the policy's own domain line, bound to the account and app, unexpired, not future-dated; anything else is no policy), and carries the columns into its rows. New kinds registry:EgressAllow, registry:Size and registry:PolicyExpiresAt, one site each, all the assignment of a fresh row's columns (nr) from policies.cols; plus one whole:Route site, the existing row handed to policies.forRow. Other read sites unchanged, offsets moved; the agent's own pass, no root decision;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos, from its reconcile loops: after the scan, hands the in-scope records to cfg.Lifetimes (the box's lifetime index): Merge after a failed read or partial listing, Replace after a complete one, nothing on a dry run or with no index; the scan, judge and removal phases unchanged; the same 166 sites, no read added;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 2 and 5 (D5, spec §5.0): a seeded record over a row with a runtime is skipped and logged; a row with a runtime (or a new record with one) takes no seed; runtime and a rootfs row's hibernation are never converged from a record (a mismatch is logged; a record claiming a runtime its row lacks is not applied); reads Runtime of the record and the row; the box writes less; fix wave 1 (ceea6353, whole-branch P1-2): before minting a row for a record with no runtime and no row (both mint paths), the pass reads the app's kind marker once per app per pass (release.ReadAppKindMarker: one GET of the create-only kind.json from the release store s, through freshStore, validated by readAppKindMarker); a rootfs marker leaves the record unmaterialized and logged (an older console stripped its runtime), and a marker that cannot be read defers the mint this pass; a refusal before minting only, registry read sites unchanged, the box writes less; fix wave 2 (whole-branch r2 P1): the kind-marker read and its refusal apply only to a socket-backed instance record (DerivesPaths), so a static or upstream-backed record of a rootfs app, which carries no runtime by design, is minted as before with no read; fewer reads, registry read sites unchanged;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 10: the forward phase on the hub (FleetOwners set): the scan keeps the fleet-placed records it skips and counts records per host; a trash-only marker prefetch; disputed (failed-GET) hosts; armed, a host an in-scope and a fleet record both name is given neither, its journal waits and the removal phase keeps its row (+registry:Account, +registry:App, +registry:Host x2: the collision guard, its log line and report mark); the instance loop leaves a forward host; retirable excludes forward rows. Same record keys; writes only the registry (PutForward, DeleteForward); no bucket write. |
| +- `internal/activator/backend_rootfs.go` `ExecBackend.startRootfsCmd`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1 [pf R0.1, R1.4]: new; the agent's first caller of root's existing CmdRootfs (POST /cmd to root's control socket, unchanged). In order: rootfsGates; refuses a partial staged identity (version, path, digest); rootfsControl; prepare(rt, RoleCmd) (the instance's own directories); two stream listeners on the agent's own log sockets (logSocketNamed); the schema-2 launch file for RoleCmd with env alone (writeRootfsLaunchFor, the same writer and the same root reader as the web start's RoleRun file, rootfsLaunchEnv: never the agent's own environment); the caller's exec gate (runExecGate); then CmdRootfs(host, the row's tier memory.max, StagedImage{staged path, version, digest, process}), process being a declared process name root checks against the staged manifest. ErrStagedImage and ErrStartRefused are refusals with no unit; any other error returns a unit to stop and settle. Root validates the staged image and the process itself (instancectl, unchanged); registry:Host sites are log lines, socket and unit names |
| +- `internal/activator/cmd.go` `Service.RunCmd`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): admits one run against an awake entry under the agent's own lease, fence and swap checks; it starts nothing itself and root validates what it later names;rev3=census-ruling-edge-request-records;basis=passes nil for begin's new req parameter; no read added;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: a carlos run is refused with ErrCmdBusy while a release record of the host is open (a.releaseOps[rt.Host], in-memory), as a run already in flight refuses it; new site +registry:Host (that map lookup); adds a refusal only |
| +- `internal/activator/cmdunit.go` `ExecBackend.StartCmd`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): writes launch.cmd.json in the instance's own directory and asks instance control to start the cmd unit; root validates the staged executable it names (refuseStagedExe) and decides the start |
| +- `internal/activator/rootfs_service.go` `Service.rootfsTick`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: per activator tick, lists residents (Registry.ResidentInstances through the DueStore), and for each rootfs entry kills generations whose replica reports a lost lease with no watch installed, stops an exited rootfs process (StopExited), and supervises; then drops forgotten residents and reserves proactive starts (residentJob) for resident-shaped, unheld rows within the start ceiling after the locked admission;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.10: when the tick kills a lost-lease resident's generations it also starts stopRootfsWorkersAtLoss(e) beside them; superviseRootfsLocked (a no-op in Group A) is now the worker supervision; the same 15 read sites, no read added; stops more, starts nothing new on its own |
| New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff: |
| +- new `internal/activator/backend_rootfs.go:ExecBackend.KillOneShot`: reads +registry:Host ×9, +whole:Route; written legacy, accepted-legacy, frozen |
| +- new `internal/activator/backend_rootfs.go:ExecBackend.startRootfsRun`: reads +registry:Host ×3, +whole:Route ×4; written legacy, accepted-legacy, frozen |
| +- new `internal/activator/backend_unit.go:SplitBackend.KillOneShot`: reads +registry:Host, +whole:Route ×2; written legacy, accepted-legacy, frozen |
| +- new `internal/activator/cmd.go:Service.killOneShot`: reads +registry:Host ×3, +whole:Route; written legacy, accepted-legacy, frozen |
| +- new `internal/activator/cmd.go:Service.stopOneShotAtLease`: reads +registry:Host ×2, +whole:Route ×2; written legacy, accepted-legacy, frozen |
| +- new `internal/activator/cmd.go:Service.stopOneShotsAtLeaseLocked`: reads +whole:Route; written legacy, accepted-legacy, frozen |
| +- new `internal/activator/rootfs_service.go:Service.residentLeaseLostLocked`: reads +whole:Route ×2; written legacy, accepted-legacy, frozen |
| +- new `internal/activator/rootfs_service.go:Service.residentLeaseShort`: reads +whole:Route ×2; written legacy, accepted-legacy, frozen |
| - new `internal/host/units/carlos-instance-rootfs-tty@.service:external`: reads +file:external; written legacy, accepted-legacy, frozen |
| - new `internal/host/units/carlos-instance-tty@.service:external`: reads +file:external; written legacy, accepted-legacy, frozen |
| - new `internal/instancectl/cmd.go:Server.oneShotStatus`: reads +file:Query ×3; written legacy, accepted-legacy, frozen |
| - new `internal/instanceexec/tty_linux.go:receivePTY`: reads +file:Fstat; written legacy, accepted-legacy, frozen |
| -Seal: `1379d066c8dd2335d95d5f6e9c7bce65ff57f00b2b287a308d9b3f47911ae5e7` → `44581c3700aa3a72c593ef0493663ee42b2c9425231efbfbb6d67abd3a6fced8`. |
| +Seal: `1379d066c8dd2335d95d5f6e9c7bce65ff57f00b2b287a308d9b3f47911ae5e7` → `a423737430ea5ec92dd0f268aaa519463cd43c0f790cb730542121aca5b58d29`. |
| Overlay: `internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md b/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md| index 61c59e190..09072efa5 100644 |
| --- a/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md |
| +++ b/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md |
| @@ -196,7 +196,7 @@ From the plan: Every row goes to the deck in Task 1 and reaches code only once a |
| | RFS-3-C24 | internal/console/seedmove.go (rootfsMoveConflict, carlos apps place) | this app's instances are rootfs instances, which do not move. create new instances where you want them | approved | |
| | RFS-3-C25 | internal/host/systemapply.go (systemApplyRootfsRefusal; struck 2026-10-26 by Paul's Task 15 round 3 ruling: the floor refuses by the box's version, not its rows, and RFS-3-C30 replaces it) | %s cannot run rootfs instances, and this box still has: %s. delete those instances before installing it | struck | |
| | RFS-3-C26 | docs/site/cli.md (carlos run, a paragraph) | --version runs another build of the app against the instance, for example the build a deploy is about to bring in. The build must already be on the instance's box. The command still gets the environment the instance serves with. | approved | |
| -| RFS-3-C27 | docs/site/cli.md (carlos run, a paragraph) | For a rootfs app the command after -- runs inside the instance's image and is found on the image's PATH. | approved | |
| +| RFS-3-C27 | docs/site/cli.md (carlos run, a paragraph; built by Plan 6 Task 7a) | For a rootfs app the command after -- runs inside the instance's image and is found on the image's PATH. | approved | |
| | RFS-3-C28 | docs/site/cli.md (carlos run, the same paragraph) (live until Plan 6 Task 16 strikes it, replaced by RFS-6-C62) | carlos run does not reach instances on a customer fleet yet. | approved | |
| | RFS-3-C29 | internal/rolloutwords/words.go (EventReleaseLeaseLost) | the release command of build %s was stopped because this box no longer holds the instance. it runs again on the next attempt | approved | |
| | RFS-3-C30 | internal/console/rootfsfloor.go (consoleRootfsFloorRefusal, carlos system update and rollback refused at a channel on the rootfs floor: the channel, its release, the floor, the target) | %s runs %s, so it takes only %s or later, the releases that run rootfs instances. %s is not one. to move it there anyway, pass --allow-below-rootfs-floor | approved | |
diff --git a/internal/activator/activator.go b/internal/activator/activator.go| index 994d6a85d..101919460 100644 |
| --- a/internal/activator/activator.go |
| +++ b/internal/activator/activator.go |
| @@ -492,12 +492,14 @@ type actEntry struct { |
| // wake goroutine starts; never written again. A request's wake of a |
| // resident row leaves it false. |
| resident bool |
| - // ownerDone ends a resident's lease watch (watchResidentLeaseLocked, |
| - // Astra Task 8 R1 1): made at the awake transition, closed by |
| - // finishStop as the entry is forgotten. Under a.mu. |
| + // ownerDone ends a rootfs entry's lease watch (watchResidentLeaseLocked, |
| + // Astra Task 8 R1 1; every rootfs row since Plan 6 Task 7a): made at the |
| + // awake transition, closed by finishStop as the entry is forgotten. |
| + // Under a.mu. |
| ownerDone chan struct{} |
| // ownerKilled: the tick's second-line lease check (rootfsTick) has |
| - // already killed this unwatched resident's generations. Under a.mu. |
| + // already killed this unwatched rootfs entry's one-shot units and, a |
| + // resident, its generations. Under a.mu. |
| ownerKilled bool |
| // probe is set for an entry ProbeWake made (moves Plan 3 Task 5): the |
| // claim path runs with the probe's policy, and the entry is held for |
| @@ -3101,20 +3103,23 @@ func (a *Service) beginStopLocked(e *actEntry, why string) { |
| // respawn run under the lease the wake took). Every install path comes |
| // through here: a wake (wake), a hold's pinned wake and a resident's |
| // restart (both wakes), a swap's successor (swapOverlap) and a worker's |
| -// respawn and a recovery probe's install. For a resident row the lease |
| +// respawn and a recovery probe's install. For a rootfs row the lease |
| // watch is installed here too, before the function returns, so no fence, |
| // shutdown or queued-restart transition the caller runs after it can leave |
| -// a resident process unwatched (Plan 3 Task 8, C7: one invariant in one |
| -// place). The watch is held until finishStop, after the stop's termination |
| -// proof, closes it. TestResidentProcessInstallsGoThroughOnePlace refuses |
| -// any other write of these fields. The caller holds a.mu. |
| +// a rootfs process unwatched (Plan 3 Task 8, C7: one invariant in one |
| +// place). Every rootfs row, resident or hibernating, is watched (Plan 6 |
| +// Task 7a, Call A1), so a run or session on either is reached at the |
| +// lease's loss; the watch's resident actions stay a resident's. The watch |
| +// is held until finishStop, after the stop's termination proof, closes it. |
| +// TestResidentProcessInstallsGoThroughOnePlace refuses any other write of |
| +// these fields. The caller holds a.mu. |
| func (a *Service) installProcLocked(e *actEntry, rep Rep, proc Proc, g Gen) { |
| if rep != nil { |
| e.rep = rep |
| } |
| e.proc = proc |
| e.gen = g |
| - if e.route.Resident() { |
| + if e.route.Rootfs() { |
| a.watchResidentLeaseLocked(e) |
| } |
| } |
diff --git a/internal/activator/backend_rootfs.go b/internal/activator/backend_rootfs.go| index db95c24d6..224669f16 100644 |
| --- a/internal/activator/backend_rootfs.go |
| +++ b/internal/activator/backend_rootfs.go |
| @@ -175,25 +175,52 @@ func (b *ExecBackend) ReleaseEnv(ctx context.Context, rt registry.Route) (map[st |
| // writer (releaseOutput) [pf R1.5]. |
| func (b *ExecBackend) StartRelease(ctx context.Context, rt registry.Route, id release.StagedIdentity, env map[string]string, out io.Writer) (CmdUnit, error) { |
| o := newReleaseOutput(rt.Host, out, runs.MaxOutputBytes) |
| - return b.startRootfsCmd(ctx, rt, id, release.ProcessRelease, env, o.stream(), o.stream()) |
| + return b.startRootfsCmd(ctx, rt, id, rootfsCmdLaunch{Process: release.ProcessRelease}, env, o.stream(), o.stream()) |
| } |
| -// startRootfsCmd starts process, a declared process of id, in rt's rootfs |
| -// cmd unit [pf R0.1, R1.4], in this order: every rootfs gate; a whole |
| -// identity and a control channel with a rootfs half; the instance's |
| -// directories; the two stream listeners the unit writes stdout and stderr |
| -// to; a schema-2 launch file with env alone (rootfsLaunchEnv, never the |
| -// agent's own environment); the caller's exec gate, the last thing before |
| -// root is asked; then CmdRootfs at the row's tier. Root's answers given |
| -// before systemctl start are refusals (marked, no unit): nothing of the |
| -// build ran. Any other error after the POST hands back a unit with the |
| +// rootfsCmdLaunch is what a rootfs cmd unit runs from its image: a |
| +// declared process (release.ProcessRelease for Group R, release. |
| +// ProcessConsole for a console session), or an operator's command (carlos |
| +// run, run -it). Exactly one of the two is set. |
| +type rootfsCmdLaunch struct { |
| + // Process is a declared process of the image, "" for an argv. |
| + Process string |
| + // Argv is the operator's command, found on the image's PATH; nil for a |
| + // process. |
| + Argv []string |
| +} |
| + |
| +// processName is the launch file's name for what l runs: its process, or |
| +// "cmd" for an operator's command. |
| +func (l rootfsCmdLaunch) processName() string { |
| + if l.Process != "" { |
| + return l.Process |
| + } |
| + return string(instancectl.RoleCmd) |
| +} |
| + |
| +// startRootfsCmd starts l, a declared process of id or an operator's |
| +// command, in rt's rootfs cmd unit [pf R0.1, R1.4], in this order: every |
| +// rootfs gate; a whole identity, exactly one of l's two fields, and a |
| +// control channel with a rootfs half; the instance's directories; the two |
| +// stream listeners the unit writes stdout and stderr to; a schema-2 launch |
| +// file with env alone (rootfsLaunchEnv, never the agent's own |
| +// environment), naming l's process or "cmd", never an argv; the caller's |
| +// exec gate, the last thing before root is asked; then CmdRootfs at the |
| +// row's tier naming the image with l's process or argv. Root's answers |
| +// given before systemctl start are refusals (marked, no unit): nothing of |
| +// the build ran. Any other error after the POST hands back a unit with the |
| // error, since the unit may be running and must still be stopped and |
| -// settled. StartCmd, the binary path, is a separate function and stays as |
| -// it is (INV-6). |
| -func (b *ExecBackend) startRootfsCmd(ctx context.Context, rt registry.Route, id release.StagedIdentity, process string, env map[string]string, stdout, stderr io.Writer) (CmdUnit, error) { |
| +// settled. The binary path (StartCmd's binary arm) is a separate function |
| +// and stays as it is (INV-6). |
| +func (b *ExecBackend) startRootfsCmd(ctx context.Context, rt registry.Route, id release.StagedIdentity, l rootfsCmdLaunch, env map[string]string, stdout, stderr io.Writer) (CmdUnit, error) { |
| if !rt.Rootfs() { |
| return nil, refuseRootfs(fmt.Errorf("%s: a rootfs command runs only on a rootfs instance", rt.Host)) |
| } |
| + if (l.Process == "") == (len(l.Argv) == 0) { |
| + return nil, refuseRootfs(fmt.Errorf("%s: a rootfs command names a declared process or an argv, exactly one", rt.Host)) |
| + } |
| + process := l.processName() |
| if err := b.rootfsGates(ctx, rt); err != nil { |
| return nil, err |
| } |
| @@ -233,7 +260,7 @@ func (b *ExecBackend) startRootfsCmd(ctx context.Context, rt registry.Route, id |
| return fail(err) |
| } |
| unit := instancectl.RootfsUnitName(instancectl.RoleCmd, rt.Host) |
| - inv, err := rc.CmdRootfs(ctx, rt.Host, b.tier(rt).MemoryMax, stagedImageOf(id, process, nil)) |
| + inv, err := rc.CmdRootfs(ctx, rt.Host, b.tier(rt).MemoryMax, stagedImageOf(id, l.Process, l.Argv)) |
| if errors.Is(err, instancectl.ErrStagedImage) || errors.Is(err, instancectl.ErrStartRefused) { |
| // Answered before systemctl start: a refusal, never the build's |
| // failure (INV-4). |
| @@ -250,6 +277,88 @@ func (b *ExecBackend) startRootfsCmd(ctx context.Context, rt registry.Route, id |
| return &cmdUnit{b: b, rt: rt, inv: inv, out: out, errs: errs}, nil |
| } |
| +// startRootfsRun is StartCmd's rootfs arm (carlos run on a rootfs row, |
| +// rootfs apps Plan 6 Task 7a), after StartCmd's layout and run-directory |
| +// checks: the serving generation's image is required (spec.serving, which |
| +// RunCmd sets from the generation it admitted the run against), whole, or |
| +// the run is refused with nothing laid out (errNoCmdExe, or |
| +// errPartialStagedIdentity, both marked); the environment that generation |
| +// launched with is required (errNoGenEnv), and the replica gate is asked as |
| +// for a binary run; then startRootfsCmd runs spec.Args exactly as given, |
| +// with no live-link prefix (the image's PATH finds its first word), with |
| +// rootfsCmdVars over that environment. No egress step: #328 checks in |
| +// root's rootfs start. |
| +func (b *ExecBackend) startRootfsRun(ctx context.Context, rt registry.Route, spec CmdSpec) (CmdUnit, error) { |
| + x := spec.serving |
| + if x == nil { |
| + return nil, refuseRootfs(fmt.Errorf("%s: %w", rt.Host, errNoCmdExe)) |
| + } |
| + id := release.StagedIdentity{Version: x.Version, StagedPath: x.Path, Digest: x.Digest} |
| + if id.Version == "" || id.StagedPath == "" || id.Digest == "" { |
| + return nil, refuseRootfs(fmt.Errorf("%s: %w (build %q, path %q, digest %q)", rt.Host, errPartialStagedIdentity, id.Version, id.StagedPath, id.Digest)) |
| + } |
| + if spec.genEnv == nil { |
| + return nil, fmt.Errorf("%s: %w", rt.Host, errNoGenEnv) |
| + } |
| + // As a binary run's (StartCmd): on a replica the command starts only |
| + // with its home's key, checked before anything is laid out. |
| + if err := b.replicaKeyGate(rt, spec.genEnv, spec.genKeyLayer, false); err != nil { |
| + return nil, err |
| + } |
| + env := b.rootfsCmdVars(rt, spec.genEnv, b.pathsFor(rt).dbPath, spec.RunID, spec.RunDir) |
| + return b.startRootfsCmd(ctx, rt, id, rootfsCmdLaunch{Argv: spec.Args}, env, spec.Stdout, spec.Stderr) |
| +} |
| + |
| +// oneShotKiller is the lease's kill of a rootfs one-shot unit (rootfs apps |
| +// Plan 6 Task 7a, Call A1; C7): the unit of role (cmd, or tty) killed |
| +// outright by root and proven gone, the moment the instance's lease is |
| +// lost. ExecBackend has it; SplitBackend forwards it. |
| +type oneShotKiller interface { |
| + KillOneShot(ctx context.Context, rt registry.Route, role instancectl.Role) error |
| +} |
| + |
| +var ( |
| + _ oneShotKiller = (*ExecBackend)(nil) |
| + _ oneShotKiller = (*SplitBackend)(nil) |
| +) |
| + |
| +// errOneShotKillBinary: a binary row holds no resident lease and its |
| +// commands are not killed at a loss (its stop's own settle decides). |
| +var errOneShotKillBinary = errors.New("activator: a binary row's command has no lease kill") |
| + |
| +// KillOneShot implements oneShotKiller, for a rootfs row only: root kills |
| +// the rootfs unit of role outright (StopRootfs with kill: SIGKILL, stop, |
| +// its cgroup proven empty, then its files), on DeadlineControl, then the |
| +// agent reads that unit's cgroup until it is empty or roleEmptyBound |
| +// passes. Neither bound is the caller's to cut short. nil is the proof. |
| +func (b *ExecBackend) KillOneShot(ctx context.Context, rt registry.Route, role instancectl.Role) error { |
| + if !rt.Rootfs() { |
| + return fmt.Errorf("%s: %w", rt.Host, errOneShotKillBinary) |
| + } |
| + if !instancectl.OneShot(role) { |
| + return fmt.Errorf("%s: role %s is not a one-shot unit", rt.Host, role) |
| + } |
| + rc, err := b.rootfsControl() |
| + if err != nil { |
| + return fmt.Errorf("%s: %w", rt.Host, err) |
| + } |
| + unit := instancectl.RootfsUnitName(role, rt.Host) |
| + sctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), instancectl.DeadlineControl) |
| + err = rc.StopRootfs(sctx, rt.Host, role, 0, "", true) |
| + cancel() |
| + if err != nil { |
| + log.Printf("activator: %s: kill %s: %v", rt.Host, unit, err) |
| + return fmt.Errorf("%s: kill %s: %w", rt.Host, unit, err) |
| + } |
| + wctx, wcancel := context.WithTimeout(context.WithoutCancel(ctx), roleEmptyBound) |
| + defer wcancel() |
| + if err := b.waitRoleCgroupEmpty(wctx, rt, role); err != nil { |
| + log.Printf("activator: %s: %s after its kill: %v", rt.Host, unit, err) |
| + return fmt.Errorf("%s: %s after its kill: %w", rt.Host, unit, err) |
| + } |
| + return nil |
| +} |
| + |
| // releaseOutput is where both streams of a release command go [pf R1.5]: |
| // one sink for both, guarded by a mutex (each stream's copy runs in its own |
| // goroutine), fed whole lines by a line splitter per stream so the two |
diff --git a/internal/activator/backend_unit.go b/internal/activator/backend_unit.go| index ec26c6b18..10e13bec3 100644 |
| --- a/internal/activator/backend_unit.go |
| +++ b/internal/activator/backend_unit.go |
| @@ -60,6 +60,7 @@ import ( |
| "github.com/carlosframework/platform/internal/cgroup" |
| "github.com/carlosframework/platform/internal/hafresh" |
| "github.com/carlosframework/platform/internal/hostfiles" |
| + "github.com/carlosframework/platform/internal/instancectl" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| @@ -516,6 +517,18 @@ func (b *SplitBackend) KillGen(ctx context.Context, rt registry.Route, n uint64) |
| return k.KillGen(ctx, rt, n) |
| } |
| +// KillOneShot dispatches like KillGen (rootfs apps Plan 6 Task 7a): the |
| +// half that runs rt kills its one-shot unit. A half without the kill (the |
| +// unit backend, a test double) refuses, wrapping errOneShotKillBinary, so |
| +// a caller never believes a kill it could not make. |
| +func (b *SplitBackend) KillOneShot(ctx context.Context, rt registry.Route, role instancectl.Role) error { |
| + k, ok := b.pick(rt).(oneShotKiller) |
| + if !ok { |
| + return fmt.Errorf("%s: this backend cannot kill a %s unit: %w", rt.Host, role, errOneShotKillBinary) |
| + } |
| + return k.KillOneShot(ctx, rt, role) |
| +} |
| + |
| // LegacyRunGone is legacyRunProver for the composed backend (#292): an |
| // exec row's nested run unit is the exec side's to stop and prove. A |
| // unit-backed row never starts a carlos-instance@ unit, so it refuses |
diff --git a/internal/activator/cmd.go b/internal/activator/cmd.go| index 001940007..9e9038663 100644 |
| --- a/internal/activator/cmd.go |
| +++ b/internal/activator/cmd.go |
| @@ -3,6 +3,7 @@ package activator |
| import ( |
| "context" |
| "errors" |
| + "fmt" |
| "log" |
| "sync" |
| "time" |
| @@ -128,6 +129,21 @@ type cmdHold struct { |
| // whose pin for gen may have been this run's alone. Set before the |
| // unit starts and never written again. |
| onProven func() |
| + // afterSettled is the run's CmdSpec.AfterSettled, called once |
| + // (settledOnce), off a.mu, when no unit of the run can be running: by |
| + // RunCmd on a path that starts none, else by the settle that first |
| + // proves the unit gone (after onProven). Set before the hold is |
| + // attached and never written again. |
| + afterSettled func() |
| + settledOnce sync.Once |
| +} |
| + |
| +// settled calls afterSettled, at most once whoever calls it. Never call |
| +// it with a.mu held, nor while a unit of the run may still be running. |
| +func (h *cmdHold) settled() { |
| + if h.afterSettled != nil { |
| + h.settledOnce.Do(h.afterSettled) |
| + } |
| } |
| // cmdSettle is one settle attempt: done closes when it has ended, and err |
| @@ -190,8 +206,11 @@ func (h *cmdHold) settle(at *cmdSettle) { |
| h.settling, h.lastTry = nil, h.now() |
| h.mu.Unlock() |
| close(at.done) |
| - if err == nil && h.onProven != nil { |
| - h.onProven() |
| + if err == nil { |
| + if h.onProven != nil { |
| + h.onProven() |
| + } |
| + h.settled() |
| } |
| } |
| @@ -389,6 +408,113 @@ func (a *Service) interruptCmdsLocked(e *actEntry, n uint64, why string) { |
| } |
| } |
| +// oneShotHoldsLocked reports whether a one-shot unit of e may be running: |
| +// a run's (cmdHoldsLocked). Task 9 adds a session's. The caller holds a.mu. |
| +func oneShotHoldsLocked(e *actEntry) bool { |
| + return len(cmdHoldsLocked(e)) > 0 |
| +} |
| + |
| +// stopOneShotsAtLeaseLocked is a rootfs instance's lease reaching its |
| +// one-shot units (rootfs apps Plan 6 Task 7a, Call A1; C7): one func per |
| +// hold of e that may be running, for the caller to run off a.mu. With kill |
| +// false (residentLeaseShort, while a drain still fits) each stops its run |
| +// (StopLeaseLost), bounded by cmdStopBound. With kill true (the loss |
| +// itself: residentLeaseLostLocked, and the tick's fallback) root kills the |
| +// role's unit at once (KillOneShot), again once a start that was in flight |
| +// returns a unit, and then the run's stop settles its streams and records |
| +// the reason. A kill or settle that fails is logged: the entry's stop path |
| +// still keeps the lease until the hold is proven (settleCmds). Nothing for |
| +// a binary row, which holds no resident lease. The caller holds a.mu. |
| +func (a *Service) stopOneShotsAtLeaseLocked(e *actEntry, rt registry.Route, kill bool) []func() { |
| + if !rt.Rootfs() { |
| + return nil |
| + } |
| + var out []func() |
| + for _, h := range cmdHoldsLocked(e) { |
| + out = append(out, func() { a.stopOneShotAtLease(rt, h, instancectl.RoleCmd, kill) }) |
| + } |
| + return out |
| +} |
| + |
| +// stopOneShotAtLease is one of stopOneShotsAtLeaseLocked's funcs. Never |
| +// call it with a.mu held. |
| +func (a *Service) stopOneShotAtLease(rt registry.Route, h *cmdHold, role instancectl.Role, kill bool) { |
| + ctx, cancel := context.WithTimeout(context.Background(), cmdStopBound) |
| + defer cancel() |
| + if kill { |
| + inFlight := true |
| + select { |
| + case <-h.started: |
| + inFlight = false |
| + default: |
| + } |
| + a.killOneShot(ctx, rt, role, h.runID) |
| + if inFlight { |
| + // The start may reach systemd after the kill: once it returns a |
| + // unit, that unit is killed too. |
| + select { |
| + case <-h.started: |
| + if h.unit != nil { |
| + a.killOneShot(ctx, rt, role, h.runID) |
| + } |
| + case <-ctx.Done(): |
| + log.Printf("activator: %s: run %s's start did not return within %s of its lease's loss; the stop keeps the lease until it is proven", rt.Host, h.runID, cmdStopBound) |
| + return |
| + } |
| + } |
| + } |
| + if err := h.stop(ctx, StopLeaseLost); err != nil { |
| + log.Printf("activator: %s: run %s is not proven stopped after its lease ran short or was lost: %v; the stop keeps the lease until it is", rt.Host, h.runID, err) |
| + } |
| +} |
| + |
| +// killOneShot is the backend's KillOneShot of rt's role unit, for run id, |
| +// logged either way. Never call it with a.mu held. |
| +func (a *Service) killOneShot(ctx context.Context, rt registry.Route, role instancectl.Role, id string) { |
| + k, ok := a.backend.(oneShotKiller) |
| + if !ok { |
| + log.Printf("activator: %s: this backend has no one-shot kill; run %s's stop decides", rt.Host, id) |
| + return |
| + } |
| + kctx, cancel := context.WithTimeout(ctx, instancectl.DeadlineControl+roleEmptyBound) |
| + defer cancel() |
| + if err := k.KillOneShot(kctx, rt, role); err != nil { |
| + log.Printf("activator: %s: kill run %s's %s unit after its lease was lost: %v; its stop keeps the lease until it is proven", rt.Host, id, role, err) |
| + return |
| + } |
| + log.Printf("activator: %s: run %s's %s unit killed and proven gone after its lease was lost", rt.Host, id, role) |
| +} |
| + |
| +// oneShotStartLead is the safe time a rootfs one-shot start needs left on |
| +// the lease when RunCmd asks (C7, the worker rule, workerStartLead): its |
| +// start on DeadlineControl, then its kill and proof inside the lease's |
| +// safety deadline. |
| +func oneShotStartLead() time.Duration { return instancectl.DeadlineControl + workerProofBound } |
| + |
| +// errOneShotNoHeadroom refuses a rootfs one-shot start that could not be |
| +// started, killed and proven before the lease's safety deadline. |
| +var errOneShotNoHeadroom = errors.New("activator: the instance's lease is too close to its safety deadline to start a command") |
| + |
| +// oneShotHeadroom is workerHeadroom with oneShotStartLead: nil when rep's |
| +// safety deadline is more than oneShotStartLead away, or when rep has no |
| +// lease signal (the tick's rep.Err check is then its line). Never call it |
| +// with a.mu held. |
| +func (a *Service) oneShotHeadroom(rep Rep) error { |
| + held := watchOf(rep) |
| + if held == nil { |
| + return nil |
| + } |
| + until, err := held.SafeUntil() |
| + now := time.Now |
| + if a.leaseNow != nil { |
| + now = a.leaseNow |
| + } |
| + if err != nil || until.Sub(now()) <= oneShotStartLead() { |
| + return fmt.Errorf("%w: %w", errSwapLeaseLost, errOneShotNoHeadroom) |
| + } |
| + return nil |
| +} |
| + |
| // retryCmdSettlesLocked is the sweep's retry of every run of e whose stop |
| // was asked for and is not proven (re-review 6): a run interrupted when a |
| // swap retired its generation, a run whose own Stop failed, and a released |
| @@ -447,20 +573,28 @@ func (a *Service) settleCmds(e *actEntry) bool { |
| // checks (re-review 5). A run whose ctx ends before the start returns |
| // ctx's error and starts nothing. |
| func (a *Service) RunCmd(ctx context.Context, rt registry.Route, spec CmdSpec) (CmdHandle, error) { |
| + // refuse ends a run that never had a hold: nothing of it started, so |
| + // its files are the caller's again (AfterSettled) before it returns. |
| + refuse := func(err error) (CmdHandle, error) { |
| + if spec.AfterSettled != nil { |
| + spec.AfterSettled() |
| + } |
| + return nil, err |
| + } |
| if a.cfg.HostWrites.Enabled { |
| - return nil, ErrCmdClaim |
| + return refuse(ErrCmdClaim) |
| } |
| if rt.Kind != "instance" { |
| - return nil, ErrCmdNotInstance |
| + return refuse(ErrCmdNotInstance) |
| } |
| cb, ok := a.backend.(CmdBackend) |
| if !ok { |
| - return nil, ErrCmdNotNested |
| + return refuse(ErrCmdNotNested) |
| } |
| if c, ok := a.backend.(Classifier); !ok { |
| - return nil, ErrCmdNotNested |
| + return refuse(ErrCmdNotNested) |
| } else if l, _ := c.Layout(rt); l != LayoutNested { |
| - return nil, ErrCmdNotNested |
| + return refuse(ErrCmdNotNested) |
| } |
| wctx, cancel := context.WithTimeout(ctx, cmdWakeBound) |
| defer cancel() |
| @@ -477,11 +611,12 @@ func (a *Service) RunCmd(ctx context.Context, rt registry.Route, spec CmdSpec) ( |
| if wctx.Err() != nil && ctx.Err() == nil { |
| err = errWakeTimeout |
| } |
| - return nil, &CmdWakeError{Reason: memberSafeWakeReason(err), Err: err} |
| + return refuse(&CmdWakeError{Reason: memberSafeWakeReason(err), Err: err}) |
| } |
| pctx, pcancel := context.WithCancel(ctx) |
| defer pcancel() |
| h := newCmdHold(spec.RunID, pcancel, a.now) |
| + h.afterSettled = spec.AfterSettled |
| a.mu.Lock() |
| e := a.entries[rt.Host] |
| switch { |
| @@ -492,18 +627,18 @@ func (a *Service) RunCmd(ctx context.Context, rt registry.Route, spec CmdSpec) ( |
| } |
| a.mu.Unlock() |
| release() |
| - return nil, &CmdStoppedError{Reason: why} |
| + return refuse(&CmdStoppedError{Reason: why}) |
| case e.worker: |
| a.mu.Unlock() |
| release() |
| - return nil, ErrCmdNotInstance |
| + return refuse(ErrCmdNotInstance) |
| case cmdBusyLocked(e), a.releaseOps[rt.Host] != nil: |
| // A release command of the host, running or not proven stopped, |
| // holds its cmd unit as a run does (Group R, INV-R1): the record is |
| // asked, never an entry field. |
| a.mu.Unlock() |
| release() |
| - return nil, ErrCmdBusy |
| + return refuse(ErrCmdBusy) |
| } |
| e.cmd = h |
| a.mu.Unlock() |
| @@ -512,6 +647,7 @@ func (a *Service) RunCmd(ctx context.Context, rt registry.Route, spec CmdSpec) ( |
| abandon := func(err error) (CmdHandle, error) { |
| close(h.started) |
| run.Release() |
| + h.settled() // no unit started |
| return nil, err |
| } |
| var prepErr error |
| @@ -650,12 +786,28 @@ func (a *Service) RunCmd(ctx context.Context, rt registry.Route, spec CmdSpec) ( |
| // Not reached while the starting hold keeps swaps out; a |
| // generation that changed anyway is never started against. |
| refused = errSwapBusy |
| + case e.route.Rootfs() && !residentWatchedLocked(e): |
| + // A rootfs command starts only where a lease path reaches it (the |
| + // worker rule, installRootfsWorkerLocked): the lease watch, or the |
| + // tick's rep.Err check for a replica with no lease signal (rootfs |
| + // apps Plan 6 Task 7a, C7). |
| + refused = &CmdStoppedError{Reason: StopLeaseLost} |
| default: |
| if why := cmdOwnershipLocked(a, e); why != "" { |
| refused = &CmdStoppedError{Reason: why} |
| } |
| } |
| + rootfs, rep := e.route.Rootfs(), e.rep |
| a.mu.Unlock() |
| + if refused == nil && rootfs { |
| + // A rootfs command is killed at the lease's loss (Call A1), so it |
| + // starts only with time left for its start, kill and proof before |
| + // the safety deadline (C7, the worker rule). Off a.mu. |
| + if err := a.oneShotHeadroom(rep); err != nil { |
| + log.Printf("activator: %s: run %s not started: %v", rt.Host, spec.RunID, err) |
| + refused = &CmdStoppedError{Reason: StopLeaseLost} |
| + } |
| + } |
| if refused != nil { |
| return abandon(refused) |
| } |
| @@ -666,12 +818,16 @@ func (a *Service) RunCmd(ctx context.Context, rt registry.Route, spec CmdSpec) ( |
| if u != nil { |
| // The start reached the control service, so the unit may be |
| // running: settle it now. Release keeps it for the next stop |
| - // if it does not settle. |
| + // if it does not settle, and the settle that proves it gone |
| + // calls AfterSettled. |
| sctx, scancel := context.WithTimeout(context.WithoutCancel(ctx), cmdStopBound) |
| _ = h.stop(sctx, "") |
| scancel() |
| } |
| run.Release() |
| + if u == nil { |
| + h.settled() // nothing of the start can be running |
| + } |
| return nil, err |
| } |
| a.mu.Lock() |
diff --git a/internal/activator/cmd_test.go b/internal/activator/cmd_test.go| index 82b7f1a02..cba3dd191 100644 |
| --- a/internal/activator/cmd_test.go |
| +++ b/internal/activator/cmd_test.go |
| @@ -707,3 +707,145 @@ func TestStartCmdNamesTheServingBuild(t *testing.T) { |
| t.Fatalf("cmd starts %v, want one naming %v", ctl.cmdExes, x) |
| } |
| } |
| + |
| +// CmdSpec.AfterSettled (rootfs apps Plan 6 Task 7a, INV-2) is called |
| +// exactly once on every path, and only when no unit of the run can be |
| +// running: before RunCmd returns on each path that starts none, and |
| +// otherwise from the settle that first proves the unit gone, however late. |
| +func TestRunCmdAfterSettledRunsOnceOnEveryPath(t *testing.T) { |
| + t.Parallel() |
| + type rig struct { |
| + a *Service |
| + cb *cmdFakeBackend |
| + clk *fakeClock |
| + rt registry.Route |
| + n *atomic.Int32 |
| + } |
| + spec := func(r rig, id string) CmdSpec { |
| + return CmdSpec{RunID: id, AfterSettled: func() { r.n.Add(1) }} |
| + } |
| + settledOnce := func(t *testing.T, r rig, what string) { |
| + t.Helper() |
| + waitFor(t, what, func() bool { return r.n.Load() >= 1 }) |
| + time.Sleep(20 * time.Millisecond) |
| + if n := r.n.Load(); n != 1 { |
| + t.Fatalf("%s: AfterSettled ran %d times, want once", what, n) |
| + } |
| + } |
| + for _, c := range []struct { |
| + name string |
| + cfg Config |
| + run func(t *testing.T, r rig) |
| + }{ |
| + {"claim control armed (ErrCmdClaim)", Config{HostWrites: hostwrite.Config{Enabled: true}}, func(t *testing.T, r rig) { |
| + if _, err := r.a.RunCmd(context.Background(), r.rt, spec(r, "run_a")); !errors.Is(err, ErrCmdClaim) { |
| + t.Fatalf("err = %v", err) |
| + } |
| + if r.n.Load() != 1 { |
| + t.Fatalf("AfterSettled ran %d times before RunCmd returned, want once", r.n.Load()) |
| + } |
| + }}, |
| + {"a run already attached (ErrCmdBusy)", Config{}, func(t *testing.T, r rig) { |
| + first, err := r.a.RunCmd(context.Background(), r.rt, CmdSpec{RunID: "run_a"}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer first.Release() |
| + if _, err := r.a.RunCmd(context.Background(), r.rt, spec(r, "run_b")); !errors.Is(err, ErrCmdBusy) { |
| + t.Fatalf("err = %v", err) |
| + } |
| + if r.n.Load() != 1 { |
| + t.Fatalf("AfterSettled ran %d times before RunCmd returned, want once", r.n.Load()) |
| + } |
| + }}, |
| + {"a Prepare error", Config{}, func(t *testing.T, r rig) { |
| + s := spec(r, "run_a") |
| + s.Prepare = func(context.Context) error { return errors.New("download failed") } |
| + if _, err := r.a.RunCmd(context.Background(), r.rt, s); err == nil { |
| + t.Fatal("RunCmd started past a Prepare error") |
| + } |
| + if r.n.Load() != 1 || r.cb.cmdStarts != 0 { |
| + t.Fatalf("AfterSettled %d, starts %d; want once and none", r.n.Load(), r.cb.cmdStarts) |
| + } |
| + }}, |
| + {"ctx cancelled before the start", Config{}, func(t *testing.T, r rig) { |
| + ctx, cancel := context.WithCancel(context.Background()) |
| + s := spec(r, "run_a") |
| + s.Prepare = func(context.Context) error { cancel(); return nil } |
| + if _, err := r.a.RunCmd(ctx, r.rt, s); !errors.Is(err, context.Canceled) { |
| + t.Fatalf("err = %v", err) |
| + } |
| + if r.n.Load() != 1 || r.cb.cmdStarts != 0 { |
| + t.Fatalf("AfterSettled %d, starts %d; want once and none", r.n.Load(), r.cb.cmdStarts) |
| + } |
| + }}, |
| + {"StartCmd returned no unit", Config{}, func(t *testing.T, r rig) { |
| + r.cb.startErr = errors.New("refused before anything ran") |
| + if _, err := r.a.RunCmd(context.Background(), r.rt, spec(r, "run_a")); err == nil { |
| + t.Fatal("RunCmd did not fail") |
| + } |
| + if r.n.Load() != 1 { |
| + t.Fatalf("AfterSettled ran %d times before RunCmd returned, want once", r.n.Load()) |
| + } |
| + }}, |
| + {"StartCmd returned a unit whose first settle failed", Config{}, func(t *testing.T, r rig) { |
| + r.cb.startErr, r.cb.errWithUnit = errors.New("502 mid-roll"), true |
| + r.cb.unit.setSettleErr(errors.New("processes remained")) |
| + if _, err := r.a.RunCmd(context.Background(), r.rt, spec(r, "run_a")); err == nil { |
| + t.Fatal("RunCmd did not fail") |
| + } |
| + if r.n.Load() != 0 { |
| + t.Fatal("AfterSettled ran while the unit that may have started is unproven") |
| + } |
| + r.cb.unit.setSettleErr(nil) |
| + r.clk.advance(actStopTimeout) |
| + r.a.mu.Lock() |
| + r.a.retryCmdSettlesLocked(r.a.entries[r.rt.Host]) |
| + r.a.mu.Unlock() |
| + settledOnce(t, r, "the sweep's retry proving the unit gone") |
| + }}, |
| + {"a started run whose Stop fails", Config{}, func(t *testing.T, r rig) { |
| + r.cb.unit.setSettleErr(errors.New("processes remained")) |
| + h, err := r.a.RunCmd(context.Background(), r.rt, spec(r, "run_a")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := h.Stop(context.Background()); err == nil { |
| + t.Fatal("Stop succeeded") |
| + } |
| + h.Release() |
| + if r.n.Load() != 0 { |
| + t.Fatal("AfterSettled ran after a failed Stop") |
| + } |
| + r.cb.unit.setSettleErr(nil) |
| + r.a.Bounce(r.rt.Host) |
| + waitFor(t, "the instance's stop", func() bool { r.a.sweepOnce(); return r.a.entryCount() == 0 }) |
| + settledOnce(t, r, "the instance's stop proving the run gone") |
| + }}, |
| + {"a started run whose Stop succeeds", Config{}, func(t *testing.T, r rig) { |
| + h, err := r.a.RunCmd(context.Background(), r.rt, spec(r, "run_a")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if r.n.Load() != 0 { |
| + t.Fatal("AfterSettled ran while the run's unit runs") |
| + } |
| + if err := h.Stop(context.Background()); err != nil { |
| + t.Fatal(err) |
| + } |
| + if r.n.Load() != 1 { |
| + t.Fatalf("AfterSettled ran %d times after a proven Stop, want once", r.n.Load()) |
| + } |
| + if err := h.Stop(context.Background()); err != nil { |
| + t.Fatal(err) |
| + } |
| + h.Release() |
| + settledOnce(t, r, "a second Stop") |
| + }}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + a, cb, clk := testCmdActivator(t, c.cfg) |
| + c.run(t, rig{a: a, cb: cb, clk: clk, rt: testRoute("c.example.com"), n: &atomic.Int32{}}) |
| + }) |
| + } |
| +} |
diff --git a/internal/activator/cmdunit.go b/internal/activator/cmdunit.go| index ac604ee75..6487043c7 100644 |
| --- a/internal/activator/cmdunit.go |
| +++ b/internal/activator/cmdunit.go |
| @@ -52,12 +52,24 @@ type CmdSpec struct { |
| // last check is that old by then. An error ends the run before launch, |
| // as Prepare's does. |
| Recheck func(ctx context.Context) error |
| + // AfterSettled, when set, is called exactly once, never with a.mu |
| + // held, when no unit of this run can be running (rootfs apps Plan 6 |
| + // Task 7a, INV-2): the caller's files (CARLOS_RUN_DIR) go then, never |
| + // before. RunCmd calls it before it returns on every path that starts |
| + // no unit (each refusal, an abandon, a start that returned no unit); |
| + // otherwise the settle that first proves the unit gone calls it (the |
| + // run's own Stop, the instance's stop, a swap's interruption, the |
| + // sweep's retry, the lease-loss stop). It is never called while the |
| + // proof is missing: an agent that exits first leaves the files to the |
| + // next agent's boot pass, which runs after the startup sweep. |
| + AfterSettled func() |
| // serving is the serving generation's staged build, set by RunCmd at its |
| // last awake check when that generation names one, generations on or |
| // off (zero-downtime spec §7.5 and settings ruling R-EXEC-SIDECAR: what |
| // runs beside an instance is its serving artifact). Nil runs the live |
| - // link. Callers cannot set it. |
| + // link; a rootfs row's run refuses without one (startRootfsRun). |
| + // Callers cannot set it. |
| serving *instancectl.StagedExe |
| // genEnv is the file environment the run's generation launched with, |
| // from its handle (unitProc.LaunchEnv), set by RunCmd with serving |
| @@ -89,6 +101,8 @@ var _ cmdExeStarter = (*instancectl.Client)(nil) |
| // errNoCmdExe: a run names its serving generation's build and the control |
| // channel cannot carry it. The run is refused rather than run on the live |
| // link, which after a fallback names a build the instance is not serving. |
| +// A rootfs row's command always names its image, so a rootfs run with no |
| +// serving build to name is refused with it too (startRootfsRun). |
| var errNoCmdExe = errors.New("activator: the instance-control client cannot name a run's build") |
| // CmdUnit is a started cmd unit. |
| @@ -169,6 +183,10 @@ func (b *ExecBackend) cmdLayout(rt registry.Route) (Layout, string) { |
| // has root mount that build instead of the live link, and needs no live |
| // link of its own. The argv is the same /opt/carlos/live/<host> inside the |
| // namespace either way. |
| +// |
| +// A rootfs row leaves the binary path after the layout and run-directory |
| +// checks, before the nested gate, for startRootfsRun (backend_rootfs.go): |
| +// its command runs in the serving generation's image. |
| func (b *ExecBackend) StartCmd(ctx context.Context, rt registry.Route, spec CmdSpec) (CmdUnit, error) { |
| if l, why := b.cmdLayout(rt); l != LayoutNested { |
| return nil, fmt.Errorf("%w: %s is %s (%s)", ErrCmdNotNested, rt.Host, l, why) |
| @@ -176,6 +194,9 @@ func (b *ExecBackend) StartCmd(ctx context.Context, rt registry.Route, spec CmdS |
| if err := checkCmdRunDir(b.pathsFor(rt).dataDir, spec); err != nil { |
| return nil, fmt.Errorf("%s: %w", rt.Host, err) |
| } |
| + if rt.Rootfs() { |
| + return b.startRootfsRun(ctx, rt, spec) |
| + } |
| if err := b.nestedGate(rt); err != nil { |
| return nil, err |
| } |
diff --git a/internal/activator/rootfs_cmd_lease_test.go b/internal/activator/rootfs_cmd_lease_test.go| new file mode 100644 |
| index 000000000..4267af036 |
| --- /dev/null |
| +++ b/internal/activator/rootfs_cmd_lease_test.go |
| @@ -0,0 +1,627 @@ |
| +package activator |
| + |
| +// Rootfs apps Plan 6 Task 7a (Call A1; C7): a carlos run on a rootfs row is |
| +// under the instance's lease watch, hibernating or resident. When the watch |
| +// begins the lease's drain (residentLeaseShort) the run is stopped, whatever |
| +// the entry's state; at the loss itself its unit is killed outright by root |
| +// (KillOneShot), at once and again when a start in flight returns, beside a |
| +// resident's generation kills; and the lease is released only after the |
| +// run's hold is proven. Not parallel: residentPoll and residentDrainBudget |
| +// are package vars. |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "fmt" |
| + "path/filepath" |
| + "sync" |
| + "sync/atomic" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/instancectl" |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// leaseCmdUnit is a run's unit whose settles are recorded among the |
| +// backend's events ("settle"), failing while settleErr is set. |
| +type leaseCmdUnit struct { |
| + b *fakeBackend |
| + mu sync.Mutex |
| + settles int |
| + settleErr error |
| + settledAt time.Time // when a settle last succeeded |
| +} |
| + |
| +func (u *leaseCmdUnit) Invocation() string { return "inv1" } |
| +func (u *leaseCmdUnit) Poll(ctx context.Context) (instancectl.CmdStatus, error) { |
| + <-ctx.Done() |
| + return instancectl.CmdStatus{}, ctx.Err() |
| +} |
| +func (u *leaseCmdUnit) StopAndSettle(context.Context) error { |
| + u.b.record("settle") |
| + u.mu.Lock() |
| + defer u.mu.Unlock() |
| + u.settles++ |
| + if u.settleErr == nil { |
| + u.settledAt = time.Now() |
| + } |
| + return u.settleErr |
| +} |
| +func (u *leaseCmdUnit) setSettleErr(err error) { |
| + u.mu.Lock() |
| + defer u.mu.Unlock() |
| + u.settleErr = err |
| +} |
| +func (u *leaseCmdUnit) settleCount() int { |
| + u.mu.Lock() |
| + defer u.mu.Unlock() |
| + return u.settles |
| +} |
| + |
| +// runLeaseBackend is killBackend (KillGen recorded "kill:<n>") with the run |
| +// capability on the nested layout and the one-shot kill (oneShotKiller), |
| +// recorded "killoneshot:<role>" with its time. StartCmd blocks on |
| +// startGate when it is set, after closing startEntered. |
| +type runLeaseBackend struct { |
| + *killBackend |
| + unit *leaseCmdUnit |
| + |
| + omu sync.Mutex |
| + oneShots []time.Time |
| + onOneShot func() |
| + startGate chan struct{} |
| + startEntered chan struct{} |
| + cmdStarts int |
| +} |
| + |
| +func (b *runLeaseBackend) StartCmd(context.Context, registry.Route, CmdSpec) (CmdUnit, error) { |
| + b.omu.Lock() |
| + gate, entered := b.startGate, b.startEntered |
| + b.cmdStarts++ |
| + b.omu.Unlock() |
| + if entered != nil { |
| + close(entered) |
| + } |
| + if gate != nil { |
| + <-gate |
| + } |
| + return b.unit, nil |
| +} |
| + |
| +func (b *runLeaseBackend) KillOneShot(_ context.Context, rt registry.Route, role instancectl.Role) error { |
| + b.omu.Lock() |
| + b.oneShots = append(b.oneShots, time.Now()) |
| + hook := b.onOneShot |
| + b.omu.Unlock() |
| + b.record(fmt.Sprintf("killoneshot:%s", role)) |
| + if hook != nil { |
| + hook() |
| + } |
| + return nil |
| +} |
| + |
| +func (b *runLeaseBackend) oneShotKills() []time.Time { |
| + b.omu.Lock() |
| + defer b.omu.Unlock() |
| + return append([]time.Time(nil), b.oneShots...) |
| +} |
| + |
| +func (b *runLeaseBackend) starts() int { |
| + b.omu.Lock() |
| + defer b.omu.Unlock() |
| + return b.cmdStarts |
| +} |
| + |
| +// runLeaseService is residentKillService over a runLeaseBackend. Its |
| +// leaseNow puts every rootfs run's headroom check an hour before the |
| +// lease's safety deadline, so a short test lease still admits a run; the |
| +// test that checks the headroom sets its own. |
| +func runLeaseService(t *testing.T, routes ...registry.Route) (*Service, *runLeaseBackend, *fakeClock) { |
| + t.Helper() |
| + fb := &fakeBackend{layoutFn: func(registry.Route) (Layout, string) { return LayoutNested, "" }} |
| + b := &runLeaseBackend{killBackend: &killBackend{fakeBackend: fb}} |
| + b.unit = &leaseCmdUnit{b: fb} |
| + clk := &fakeClock{t: time.Unix(1_700_000_000, 0)} |
| + reg, err := registry.Open(filepath.Join(t.TempDir(), "registry.db")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, b, reg) |
| + a.now = clk.now |
| + a.gens = true |
| + armRootfsForTest(a) |
| + startsFromStagedIdentity(fb) |
| + a.residentJitter = func() float64 { return 0 } |
| + a.residentLister = &fakeResidents{routes: routes} |
| + a.leaseNow = func() time.Time { return time.Now().Add(-time.Hour) } |
| + t.Cleanup(func() { |
| + // A test that failed with a run unproven leaves a stop pending: |
| + // prove it, and let the sweep finish it, before the Shutdown. |
| + b.unit.setSettleErr(nil) |
| + for deadline := time.Now().Add(5 * time.Second); time.Now().Before(deadline) && a.stopsPending(); { |
| + clk.advance(time.Minute) |
| + a.sweepOnce() |
| + time.Sleep(10 * time.Millisecond) |
| + } |
| + a.Shutdown(context.Background()) |
| + }) |
| + return a, b, clk |
| +} |
| + |
| +// stopsPending reports whether any entry is stopping. |
| +func (a *Service) stopsPending() bool { |
| + a.mu.Lock() |
| + defer a.mu.Unlock() |
| + for _, e := range a.entries { |
| + if e.state == actStopping { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// ownedRepUntil has b's next replica carry the lease's own signal with |
| +// until as its safety deadline, recording "close" when it is given back, |
| +// and returns where the replica will be. |
| +func ownedRepUntil(b *runLeaseBackend, until func() time.Time) *atomic.Pointer[ownedRep] { |
| + var p atomic.Pointer[ownedRep] |
| + b.mu.Lock() |
| + b.repWrap = func(r *fakeRep) Rep { |
| + r.setOnClose(func() { b.record("close") }) |
| + o := newOwnedRep(r, until()) |
| + p.Store(o) |
| + return o |
| + } |
| + b.mu.Unlock() |
| + return &p |
| +} |
| + |
| +func lastIndexOf(events []string, ev string) int { |
| + for i := len(events) - 1; i >= 0; i-- { |
| + if events[i] == ev { |
| + return i |
| + } |
| + } |
| + return -1 |
| +} |
| + |
| +// stallDrain holds proc's SIGTERM drain until the returned end is called; |
| +// a generation kill (KillGen) ends it too. end is safe to call twice and |
| +// runs at cleanup. |
| +func stallDrain(t *testing.T, b *runLeaseBackend, proc *fakeProc) (end func()) { |
| + t.Helper() |
| + drain := make(chan struct{}) |
| + proc.setStopGate(drain) |
| + var once sync.Once |
| + end = func() { once.Do(func() { proc.exit(); close(drain) }) } |
| + t.Cleanup(end) |
| + b.kmu.Lock() |
| + b.onKill = func(uint64) { end() } |
| + b.kmu.Unlock() |
| + return end |
| +} |
| + |
| +// finishStop advances the clock and sweeps until host's stop is finished. |
| +func finishStopOf(t *testing.T, a *Service, clk *fakeClock, host string) { |
| + t.Helper() |
| + waitFor(t, "the stop to finish", func() bool { |
| + clk.advance(time.Minute) |
| + a.sweepOnce() |
| + return !a.hasEntry(host) |
| + }) |
| +} |
| + |
| +// An awake resident with a run attached and its web drain stalled: the |
| +// loss asks root to kill the run's unit at once (KillOneShot cmd), beside |
| +// the generation kill, before anything of the entry's stop has settled the |
| +// run; the run reads as interrupted by the lost lease at the loss; the |
| +// lease is given back only after the run's hold is proven. |
| +func TestResidentLeaseLossKillsAnAttachedRun(t *testing.T) { |
| + host := "shop.example.com" |
| + a, b, clk := runLeaseService(t, residentRoute(host)) |
| + rep := ownedRepUntil(b, func() time.Time { return time.Now().Add(time.Hour) }) |
| + startResident(t, a, host) |
| + var settled atomic.Int32 |
| + run, err := a.RunCmd(context.Background(), residentRoute(host), CmdSpec{RunID: "run_a", AfterSettled: func() { settled.Add(1) }}) |
| + if err != nil { |
| + t.Fatalf("RunCmd: %v", err) |
| + } |
| + end := stallDrain(t, b, b.lastProc()) |
| + b.kmu.Lock() |
| + b.onKill = nil // the drain stays stalled until the test ends it |
| + b.kmu.Unlock() |
| + b.unit.setSettleErr(errors.New("processes remained")) |
| + lostAt := time.Now() |
| + rep.Load().lose(errors.New("renew: the lock was taken")) |
| + waitFor(t, "the run's kill at the loss", func() bool { return len(b.oneShotKills()) > 0 }) |
| + if d := b.oneShotKills()[0].Sub(lostAt); d > time.Second { |
| + t.Fatalf("the run was killed %s after the loss", d) |
| + } |
| + waitFor(t, "the generation's kill", func() bool { return len(b.killTimes()) > 0 }) |
| + ev := b.events() |
| + if k, s := indexWithPrefix(ev, "killoneshot:cmd"), indexWithPrefix(ev, "settle"); k < 0 || s >= 0 && s < k { |
| + t.Fatalf("events %v: the run was not killed before anything settled it", ev) |
| + } |
| + if why, at := run.Interrupted(); why != StopLeaseLost || !at.Equal(clk.now()) { |
| + t.Fatalf("Interrupted() = %q at %v, want %q at the loss (%v)", why, at, StopLeaseLost, clk.now()) |
| + } |
| + // The drain ends; the run's settle still fails, so the stop keeps the |
| + // lease. |
| + end() |
| + waitFor(t, "the entry's stop to keep its unproven run", func() bool { |
| + a.mu.Lock() |
| + defer a.mu.Unlock() |
| + e := a.entries[host] |
| + return e != nil && e.pendingStop |
| + }) |
| + if rep.Load().isClosed() || settled.Load() != 0 { |
| + t.Fatalf("while the run was unproven: lease closed %v, AfterSettled %d", rep.Load().isClosed(), settled.Load()) |
| + } |
| + b.unit.setSettleErr(nil) |
| + finishStopOf(t, a, clk, host) |
| + ev = b.events() |
| + if s, c := lastIndexOf(ev, "settle"), indexWithPrefix(ev, "close"); c < 0 || c < s { |
| + t.Fatalf("events %v: the lease was given back before the run's hold was proven", ev) |
| + } |
| + run.Release() |
| + if n := settled.Load(); n != 1 { |
| + t.Fatalf("AfterSettled ran %d times, want once", n) |
| + } |
| +} |
| + |
| +// P1 #1's scenario: the entry is already stopping (a restart, its drain |
| +// stalled) when the lease runs short and then is lost. residentLeaseShort |
| +// stops the run anyway, before the safety deadline, and the loss kills it. |
| +func TestResidentLeaseLossKillsTheRunOfAnAlreadyStoppingEntry(t *testing.T) { |
| + shrinkDrainBudget(t, 400*time.Millisecond) |
| + host := "shop.example.com" |
| + a, b, clk := runLeaseService(t, residentRoute(host)) |
| + deadline := time.Now().Add(1200 * time.Millisecond) |
| + ownedRepUntil(b, func() time.Time { return deadline }) |
| + startResident(t, a, host) |
| + run, err := a.RunCmd(context.Background(), residentRoute(host), CmdSpec{RunID: "run_a"}) |
| + if err != nil { |
| + t.Fatalf("RunCmd: %v", err) |
| + } |
| + stallDrain(t, b, b.lastProc()) |
| + b.unit.setSettleErr(errors.New("processes remained")) |
| + if !a.Bounce(host) { |
| + t.Fatal("Bounce found no awake entry") |
| + } |
| + waitFor(t, "the run's stop at the short lease", func() bool { return b.unit.settleCount() > 0 }) |
| + if !time.Now().Before(deadline) { |
| + t.Fatalf("the run's stop began %s after the safety deadline", time.Since(deadline)) |
| + } |
| + waitFor(t, "the run's kill at the loss", func() bool { return len(b.oneShotKills()) > 0 }) |
| + if k := b.oneShotKills()[0]; k.Before(deadline.Add(-50 * time.Millisecond)) { |
| + t.Fatalf("the kill came %s before the loss", deadline.Sub(k)) |
| + } |
| + if why, _ := run.Interrupted(); why != StopLeaseLost { |
| + t.Fatalf("Interrupted() = %q, want %q", why, StopLeaseLost) |
| + } |
| + b.unit.setSettleErr(nil) |
| + finishStopOf(t, a, clk, host) |
| + run.Release() |
| +} |
| + |
| +// A start in flight at the loss: the kill is asked at once, and again once |
| +// the start returns a unit; the hold then settles and AfterSettled runs |
| +// once. |
| +func TestResidentLeaseLossKillsARunWhoseStartIsInFlight(t *testing.T) { |
| + host := "shop.example.com" |
| + a, b, clk := runLeaseService(t, residentRoute(host)) |
| + rep := ownedRepUntil(b, func() time.Time { return time.Now().Add(time.Hour) }) |
| + startResident(t, a, host) |
| + b.kmu.Lock() |
| + b.onKill = func(uint64) { b.lastProc().exit() } |
| + b.kmu.Unlock() |
| + gate, entered := make(chan struct{}), make(chan struct{}) |
| + b.omu.Lock() |
| + b.startGate, b.startEntered = gate, entered |
| + b.omu.Unlock() |
| + var opened sync.Once |
| + open := func() { opened.Do(func() { close(gate) }) } |
| + t.Cleanup(open) |
| + var settled atomic.Int32 |
| + type result struct { |
| + run CmdHandle |
| + err error |
| + } |
| + ran := make(chan result, 1) |
| + go func() { |
| + run, err := a.RunCmd(context.Background(), residentRoute(host), CmdSpec{RunID: "run_a", AfterSettled: func() { settled.Add(1) }}) |
| + ran <- result{run, err} |
| + }() |
| + <-entered |
| + rep.Load().lose(errors.New("renew: the lock was taken")) |
| + waitFor(t, "the kill at the loss", func() bool { return len(b.oneShotKills()) == 1 }) |
| + time.Sleep(50 * time.Millisecond) |
| + if n := len(b.oneShotKills()); n != 1 { |
| + t.Fatalf("%d kills while the start is blocked, want one", n) |
| + } |
| + open() |
| + waitFor(t, "the kill again once the start returned its unit", func() bool { return len(b.oneShotKills()) == 2 }) |
| + r := <-ran |
| + if r.err != nil { |
| + t.Fatalf("RunCmd: %v", r.err) |
| + } |
| + waitFor(t, "the hold to settle", func() bool { return settled.Load() == 1 }) |
| + if why, _ := r.run.Interrupted(); why != StopLeaseLost { |
| + t.Fatalf("Interrupted() = %q, want %q", why, StopLeaseLost) |
| + } |
| + r.run.Release() |
| + finishStopOf(t, a, clk, host) |
| + if n := settled.Load(); n != 1 { |
| + t.Fatalf("AfterSettled ran %d times, want once", n) |
| + } |
| +} |
| + |
| +// A renewal that hangs: the run's stop begins at residentLeaseShort, not |
| +// after the stalled web drain, and is proven before the safety deadline. |
| +func TestResidentLeaseShortStopsTheRunBeforeTheDrain(t *testing.T) { |
| + shrinkDrainBudget(t, 800*time.Millisecond) |
| + host := "shop.example.com" |
| + a, b, clk := runLeaseService(t, residentRoute(host)) |
| + deadline := time.Now().Add(1500 * time.Millisecond) |
| + ownedRepUntil(b, func() time.Time { return deadline }) |
| + startResident(t, a, host) |
| + var settled atomic.Int32 |
| + run, err := a.RunCmd(context.Background(), residentRoute(host), CmdSpec{RunID: "run_a", AfterSettled: func() { settled.Add(1) }}) |
| + if err != nil { |
| + t.Fatalf("RunCmd: %v", err) |
| + } |
| + proc := b.lastProc() |
| + stallDrain(t, b, proc) |
| + waitFor(t, "the run proven stopped at the short lease", func() bool { return settled.Load() == 1 }) |
| + if !time.Now().Before(deadline) { |
| + t.Fatalf("the run was proven stopped %s after the safety deadline", time.Since(deadline)) |
| + } |
| + if proc.stopCalls() != 0 { |
| + t.Fatal("the generation's drain finished first: the run waited for it") |
| + } |
| + if why, _ := run.Interrupted(); why != StopLeaseLost { |
| + t.Fatalf("Interrupted() = %q, want %q", why, StopLeaseLost) |
| + } |
| + finishStopOf(t, a, clk, host) |
| + run.Release() |
| +} |
| + |
| +// The run's headroom: with less than oneShotStartLead left before the |
| +// lease's safety deadline at the last check, a rootfs run is refused as a |
| +// lost lease, StartCmd is never called, and AfterSettled runs once. |
| +func TestRootfsRunRefusedWithoutLeaseHeadroom(t *testing.T) { |
| + host := "shop.example.com" |
| + a, b, _ := runLeaseService(t, residentRoute(host)) |
| + until := time.Now().Add(time.Hour) |
| + ownedRepUntil(b, func() time.Time { return until }) |
| + startResident(t, a, host) |
| + a.leaseNow = func() time.Time { return until.Add(-oneShotStartLead()).Add(time.Millisecond) } |
| + var settled atomic.Int32 |
| + _, err := a.RunCmd(context.Background(), residentRoute(host), CmdSpec{RunID: "run_a", AfterSettled: func() { settled.Add(1) }}) |
| + var se *CmdStoppedError |
| + if !errors.As(err, &se) || se.Reason != StopLeaseLost { |
| + t.Fatalf("RunCmd = %v, want CmdStoppedError{StopLeaseLost}", err) |
| + } |
| + if b.starts() != 0 || settled.Load() != 1 { |
| + t.Fatalf("starts %d, AfterSettled %d; want none and once", b.starts(), settled.Load()) |
| + } |
| + // With the lead and a second more, the run starts. |
| + a.leaseNow = func() time.Time { return until.Add(-oneShotStartLead()).Add(-time.Second) } |
| + run, err := a.RunCmd(context.Background(), residentRoute(host), CmdSpec{RunID: "run_b"}) |
| + if err != nil { |
| + t.Fatalf("RunCmd with headroom: %v", err) |
| + } |
| + if err := run.Stop(context.Background()); err != nil { |
| + t.Fatal(err) |
| + } |
| + run.Release() |
| +} |
| + |
| +// A binary always-on row's run is never killed through the lease: no |
| +// KillOneShot is asked when its lease is lost, at the tick, or at its stop. |
| +func TestBinaryRunsNeverAskTheLeaseKill(t *testing.T) { |
| + host := "blog.example.com" |
| + a, b, clk := runLeaseService(t) |
| + rep := ownedRepUntil(b, func() time.Time { return time.Now().Add(time.Hour) }) |
| + rt := testRoute(host) |
| + rt.Hibernate = false |
| + run, err := a.RunCmd(context.Background(), rt, CmdSpec{RunID: "run_a"}) |
| + if err != nil { |
| + t.Fatalf("RunCmd: %v", err) |
| + } |
| + a.mu.Lock() |
| + e := a.entries[host] |
| + fs := a.stopOneShotsAtLeaseLocked(e, e.route, true) |
| + a.mu.Unlock() |
| + if len(fs) != 0 { |
| + t.Fatalf("a binary row's lease stop has %d one-shot funcs", len(fs)) |
| + } |
| + rep.Load().lose(errors.New("renew: the lock was taken")) |
| + a.rootfsTick() |
| + a.Bounce(host) |
| + finishStopOf(t, a, clk, host) |
| + run.Release() |
| + if n := len(b.oneShotKills()); n != 0 { |
| + t.Fatalf("a binary row's run was killed through the lease %d times", n) |
| + } |
| +} |
| + |
| +// Astra R1 P1-1: a hibernating rootfs row woken by RunCmd is under the |
| +// lease watch from its wake's install. At short its run's stop starts; at |
| +// the loss root kills the run's unit at once; no generation kill and no |
| +// worker stop are asked (its web stays the sweep's). An entry already |
| +// stopping (an idle stop, its drain stalled) gets the same kill. |
| +func TestHibernatingRootfsLeaseLossKillsItsRun(t *testing.T) { |
| + for _, stopping := range []bool{false, true} { |
| + t.Run(map[bool]string{false: "awake", true: "already stopping"}[stopping], func(t *testing.T) { |
| + shrinkDrainBudget(t, 400*time.Millisecond) |
| + host := "shop.example.com" |
| + a, b, clk := runLeaseService(t) |
| + deadline := time.Now().Add(1500 * time.Millisecond) |
| + ownedRepUntil(b, func() time.Time { return deadline }) |
| + rt := rootfsGateRoute(host) |
| + run, err := a.RunCmd(context.Background(), rt, CmdSpec{RunID: "run_a"}) |
| + if err != nil { |
| + t.Fatalf("RunCmd: %v", err) |
| + } |
| + a.mu.Lock() |
| + watched := a.entries[host] != nil && a.entries[host].ownerDone != nil |
| + a.mu.Unlock() |
| + if !watched { |
| + t.Fatal("the wake's install left the hibernating rootfs entry unwatched") |
| + } |
| + proc := b.lastProc() |
| + end := stallDrain(t, b, proc) |
| + b.unit.setSettleErr(errors.New("processes remained")) |
| + if stopping { |
| + if err := run.Stop(context.Background()); err == nil { |
| + t.Fatal("the run's Stop succeeded with its settle failing") |
| + } |
| + run.Release() |
| + clk.advance(2 * time.Hour) |
| + a.sweepOnce() |
| + if why := a.stopWhyOf(host); why != StopIdle { |
| + t.Fatalf("the idle sweep did not stop the entry: %q", why) |
| + } |
| + } |
| + before := b.unit.settleCount() |
| + waitFor(t, "the run's stop at the short lease", func() bool { return b.unit.settleCount() > before }) |
| + if !time.Now().Before(deadline) { |
| + t.Fatalf("the run's stop began %s after the safety deadline", time.Since(deadline)) |
| + } |
| + waitFor(t, "the run's kill at the loss", func() bool { return len(b.oneShotKills()) > 0 }) |
| + time.Sleep(50 * time.Millisecond) |
| + if n := len(b.killTimes()); n != 0 { |
| + t.Fatalf("a hibernating row's generation was killed %d times at the loss", n) |
| + } |
| + if !stopping { |
| + if why := a.stopWhyOf(host); why != "" { |
| + t.Fatalf("the watch began a hibernating entry's stop (%q): its web is the sweep's", why) |
| + } |
| + if why, _ := run.Interrupted(); why != StopLeaseLost { |
| + t.Fatalf("Interrupted() = %q, want %q", why, StopLeaseLost) |
| + } |
| + run.Release() |
| + } |
| + end() |
| + b.unit.setSettleErr(nil) |
| + finishStopOf(t, a, clk, host) |
| + }) |
| + } |
| +} |
| + |
| +// A hibernating rootfs row whose replica has no lease signal: one tick, |
| +// with its replica's Err set, asks KillOneShot once (latched), off a.mu; |
| +// a later tick asks nothing more, and no generation is killed. |
| +func TestHibernatingRootfsTickFallbackKillsItsRun(t *testing.T) { |
| + host := "shop.example.com" |
| + a, b, clk := runLeaseService(t) |
| + rt := rootfsGateRoute(host) |
| + run, err := a.RunCmd(context.Background(), rt, CmdSpec{RunID: "run_a"}) |
| + if err != nil { |
| + t.Fatalf("RunCmd: %v", err) |
| + } |
| + asked := make(chan struct{}, 4) |
| + hold := make(chan struct{}) |
| + var released sync.Once |
| + letGo := func() { released.Do(func() { close(hold) }) } |
| + t.Cleanup(letGo) |
| + b.omu.Lock() |
| + b.onOneShot = func() { asked <- struct{}{}; <-hold } |
| + b.omu.Unlock() |
| + b.lastRep().setErr(errors.New("lease renewal failed")) |
| + a.rootfsTick() // returns with the kill held: it runs off the tick |
| + select { |
| + case <-asked: |
| + case <-time.After(5 * time.Second): |
| + t.Fatal("the tick asked no kill") |
| + } |
| + a.mu.Lock() // the kill runs off a.mu |
| + a.mu.Unlock() |
| + letGo() |
| + a.rootfsTick() |
| + time.Sleep(50 * time.Millisecond) |
| + if n := len(b.oneShotKills()); n != 1 { |
| + t.Fatalf("%d kills over two ticks, want one (latched)", n) |
| + } |
| + if n := len(b.killTimes()); n != 0 { |
| + t.Fatalf("a hibernating row's generation was killed %d times", n) |
| + } |
| + waitFor(t, "the run's stop after the kill", func() bool { return b.unit.settleCount() > 0 }) |
| + run.Release() |
| + a.Bounce(host) |
| + finishStopOf(t, a, clk, host) |
| +} |
| + |
| +// The worker rule for a run: an awake rootfs entry whose replica has the |
| +// lease's signal but no watch running refuses a run as a lost lease; |
| +// StartCmd is never called and AfterSettled runs once. |
| +func TestRootfsRunRefusedWhenUnwatched(t *testing.T) { |
| + host := "shop.example.com" |
| + a, b, _ := runLeaseService(t, residentRoute(host)) |
| + ownedRepUntil(b, func() time.Time { return time.Now().Add(time.Hour) }) |
| + e := startResident(t, a, host) |
| + a.mu.Lock() |
| + close(e.ownerDone) |
| + e.ownerDone = nil |
| + a.mu.Unlock() |
| + var settled atomic.Int32 |
| + _, err := a.RunCmd(context.Background(), residentRoute(host), CmdSpec{RunID: "run_a", AfterSettled: func() { settled.Add(1) }}) |
| + var se *CmdStoppedError |
| + if !errors.As(err, &se) || se.Reason != StopLeaseLost { |
| + t.Fatalf("RunCmd = %v, want CmdStoppedError{StopLeaseLost}", err) |
| + } |
| + if b.starts() != 0 || settled.Load() != 1 { |
| + t.Fatalf("starts %d, AfterSettled %d; want none and once", b.starts(), settled.Load()) |
| + } |
| +} |
| + |
| +// With no run attached, a resident's watch is what it was: a hanging |
| +// renewal begins the stop before the deadline and the loss kills the |
| +// generation; an outright loss kills it at once. No one-shot kill is asked. |
| +func TestResidentLeaseWatchUnchangedForResidents(t *testing.T) { |
| + t.Run("hang", func(t *testing.T) { |
| + shrinkDrainBudget(t, 300*time.Millisecond) |
| + host := "shop.example.com" |
| + a, b, clk := runLeaseService(t, residentRoute(host)) |
| + deadline := time.Now().Add(900 * time.Millisecond) |
| + ownedRepUntil(b, func() time.Time { return deadline }) |
| + startResident(t, a, host) |
| + proc := b.lastProc() |
| + stallDrain(t, b, proc) |
| + waitFor(t, "the stop at the short lease", func() bool { return a.stopWhyOf(host) == StopLeaseLost }) |
| + if !time.Now().Before(deadline) { |
| + t.Fatalf("the stop began %s after the deadline", time.Since(deadline)) |
| + } |
| + waitFor(t, "the kill at the loss", func() bool { return len(b.killTimes()) > 0 }) |
| + finishStopOf(t, a, clk, host) |
| + if n := len(b.oneShotKills()); n != 0 { |
| + t.Fatalf("%d one-shot kills with no run attached", n) |
| + } |
| + }) |
| + t.Run("loss", func(t *testing.T) { |
| + host := "shop.example.com" |
| + a, b, clk := runLeaseService(t, residentRoute(host)) |
| + rep := ownedRepUntil(b, func() time.Time { return time.Now().Add(time.Hour) }) |
| + e := startResident(t, a, host) |
| + proc := b.lastProc() |
| + stallDrain(t, b, proc) |
| + lostAt := time.Now() |
| + rep.Load().lose(errors.New("renew: the lock was taken")) |
| + waitFor(t, "the kill", func() bool { return len(b.killTimes()) > 0 }) |
| + if d := b.killTimes()[0].Sub(lostAt); d > time.Second { |
| + t.Fatalf("killed %s after the loss", d) |
| + } |
| + a.mu.Lock() |
| + why := e.stopWhy |
| + a.mu.Unlock() |
| + if why != StopLeaseLost { |
| + t.Fatalf("stopped for %q, want %q", why, StopLeaseLost) |
| + } |
| + finishStopOf(t, a, clk, host) |
| + if n := len(b.oneShotKills()); n != 0 { |
| + t.Fatalf("%d one-shot kills with no run attached", n) |
| + } |
| + }) |
| +} |
diff --git a/internal/activator/rootfs_cmd_test.go b/internal/activator/rootfs_cmd_test.go| new file mode 100644 |
| index 000000000..e80ef42ee |
| --- /dev/null |
| +++ b/internal/activator/rootfs_cmd_test.go |
| @@ -0,0 +1,485 @@ |
| +//go:build linux |
| + |
| +package activator |
| + |
| +// Plan 6 Task 7a (Plan 3 Task 12's run half, without --version): carlos |
| +// run on a rootfs row, through the real control handler |
| +// (rootfsCtlHarness). The run's argv reaches root as the image's argv, its |
| +// launch file carries only the composed environment, and its unit is |
| +// polled, stopped and proven gone as the rootfs cmd unit. Not parallel: |
| +// the tests set the agent's PATH or shrink package bounds. |
| +// |
| +// The harness starts a real rootfs image only where the box platform is |
| +// linux-arm64 (release's manifest rule names rootfs-linux-arm64 alone, and |
| +// root resolves the image for its own platform). On another platform the |
| +// request is still sent and checked, and root's refusal of the image is |
| +// checked as a refusal; the tests that need a running unit say so and |
| +// skip. |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "fmt" |
| + "io" |
| + "net" |
| + "net/http" |
| + "os" |
| + "path/filepath" |
| + "slices" |
| + "sort" |
| + "strings" |
| + "sync" |
| + "sync/atomic" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/instancectl" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +const rootfsGoldenDir = "testdata/rootfs_golden" |
| + |
| +// writeRootfsGolden writes the goldens instead of reading them: once, on |
| +// the code before Task 7a's refactor of startRootfsCmd. |
| +var writeRootfsGolden = os.Getenv("CARLOS_WRITE_ROOTFS_GOLDEN") == "1" |
| + |
| +func checkRootfsGolden(t *testing.T, name string, got []byte) { |
| + t.Helper() |
| + path := filepath.Join(rootfsGoldenDir, name) |
| + if writeRootfsGolden { |
| + if err := os.MkdirAll(rootfsGoldenDir, 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.WriteFile(path, got, 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + return |
| + } |
| + want, err := os.ReadFile(path) |
| + if err != nil { |
| + t.Fatalf("golden %s: %v", path, err) |
| + } |
| + if string(got) != string(want) { |
| + t.Errorf("the release's start changed: %s differs\n--- got\n%s\n--- want\n%s", path, got, want) |
| + } |
| +} |
| + |
| +// TestStartReleaseIsUnchanged: StartRelease's /cmd (its query, and no |
| +// body) and the launch.cmd.json it writes (Process "release") are byte for |
| +// byte what they were before startRootfsCmd took a rootfsCmdLaunch. The |
| +// goldens were written from 3fd3c3a4. |
| +func TestStartReleaseIsUnchanged(t *testing.T) { |
| + h := newRootfsCtlHarness(t) |
| + h.runProbes() |
| + id := stageRootfsWithProcesses(t, h.eb, "v2", map[string]release.Process{ |
| + release.ProcessWeb: {Command: []string{"/app/serve"}, WorkingDir: "/app"}, |
| + release.ProcessRelease: {Command: []string{"/app/migrate"}, WorkingDir: "/app"}, |
| + }) |
| + env := map[string]string{"CARLOS_SOCKET": h.rt.Socket, "CARLOS_DB": h.eb.pathsFor(h.rt).dbPath, "SHOP_MODE": "live"} |
| + u, _ := h.eb.StartRelease(context.Background(), h.rt, id, env, io.Discard) |
| + if cu, ok := u.(*cmdUnit); ok && cu != nil { |
| + cu.out.Close() |
| + cu.errs.Close() |
| + } |
| + roots := nestedRoots(h.eb) |
| + cmds := h.cmdRequests() |
| + if len(cmds) != 1 { |
| + t.Fatalf("%d /cmd requests, want one", len(cmds)) |
| + } |
| + var lines []string |
| + for k, vs := range cmds[0].query { |
| + for _, v := range vs { |
| + lines = append(lines, k+"="+v) |
| + } |
| + } |
| + sort.Strings(lines) |
| + got := fmt.Sprintf("query\n%s\nbody %q\n", strings.Join(lines, "\n"), cmds[0].body) |
| + checkRootfsGolden(t, "start_release.cmd", goldenPaths([]byte(got), roots)) |
| + raw, err := os.ReadFile(filepath.Join(provision.InstanceDir(h.eb.DataDir, h.rt.Host), instancectl.LaunchFileName(instancectl.RoleCmd))) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var l instancectl.Launch |
| + if err := json.Unmarshal(raw, &l); err != nil || l.Process != release.ProcessRelease { |
| + t.Fatalf("launch.cmd.json %s (%v), want process release", raw, err) |
| + } |
| + checkRootfsGolden(t, "start_release.launch.cmd.json", goldenPaths(raw, roots)) |
| +} |
| + |
| +// harnessStartsImages reports whether the harness's root can start a |
| +// rootfs image on this box. |
| +func harnessStartsImages() bool { return release.BoxPlatform() == "linux-arm64" } |
| + |
| +// runSpecIn is a run's spec on the harness's row: its run directory where |
| +// checkCmdRunDir wants it, and buffers for its streams. |
| +func (h *rootfsCtlHarness) runSpecIn(id string, args ...string) CmdSpec { |
| + dir := filepath.Join(h.eb.pathsFor(h.rt).dataDir, CmdRunDirName, id) |
| + return CmdSpec{RunID: id, RunDir: dir, Args: args, Stdout: &syncBuffer{}, Stderr: &syncBuffer{}} |
| +} |
| + |
| +// noBinaryCmdUnit fails t if root was asked anything about the binary cmd |
| +// unit of the harness's row. |
| +func (h *rootfsCtlHarness) noBinaryCmdUnit(t *testing.T) { |
| + t.Helper() |
| + binary := instancectl.UnitName(instancectl.RoleCmd, h.rt.Host) |
| + for _, c := range h.callsLike("") { |
| + if strings.Contains(c, binary) { |
| + t.Errorf("root was asked about the binary cmd unit: %q", c) |
| + } |
| + } |
| +} |
| + |
| +// listenersClosed fails t if either of the run's stream listeners still |
| +// accepts a connection. |
| +func (h *rootfsCtlHarness) listenersClosed(t *testing.T) { |
| + t.Helper() |
| + for _, name := range []string{string(instancectl.RoleCmd), cmdErrSocket} { |
| + path := h.eb.logSocketNamed(h.rt.Host, name) |
| + if c, err := net.DialTimeout("unix", path, time.Second); err == nil { |
| + c.Close() |
| + t.Errorf("the %s listener %s still accepts", name, path) |
| + } |
| + } |
| +} |
| + |
| +// TestRootfsRunRunsArgsInTheImage: StartCmd on a rootfs row sends root the |
| +// serving image and the member's arguments exactly as given (no live-link |
| +// prefix) as /cmd's argv, at the row's tier; writes a schema-2 |
| +// launch.cmd.json naming process "cmd" with no argv and the composed |
| +// environment only; and never names the binary cmd unit. |
| +func TestRootfsRunRunsArgsInTheImage(t *testing.T) { |
| + t.Setenv("PATH", "/agent/bin") |
| + h := newRootfsCtlHarness(t) |
| + h.runProbes() |
| + id, err := h.eb.BuildIdentity(h.rt, "v1") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + spec := h.runSpecIn("run_a", "bin/rails", "db:seed", "--trace") |
| + spec.serving = stagedExeOf(id) |
| + spec.genEnv = map[string]string{"SHOP_MODE": "live", "CARLOS_SOCKET": "/tenant/elsewhere.sock", "CARLOS_CONTROL_SOCKET": "/x", "CARLOS_PURGE": "header"} |
| + u, err := h.eb.StartCmd(context.Background(), h.rt, spec) |
| + |
| + cmds := h.cmdRequests() |
| + if len(cmds) != 1 { |
| + t.Fatalf("%d /cmd requests, want one (StartCmd: %v)", len(cmds), err) |
| + } |
| + q := cmds[0].query |
| + if q.Get("runtime") != "rootfs" || q.Get("image") != id.StagedPath || q.Get("version") != "v1" || q.Get("digest") != id.Digest || q.Has("process") { |
| + t.Fatalf("/cmd query %v, want the serving image %+v and no process", q, id) |
| + } |
| + if want := fmt.Sprint(h.eb.tier(h.rt).MemoryMax); q.Get("memory_max") != want { |
| + t.Errorf("/cmd memory_max %q, want the row's tier %s", q.Get("memory_max"), want) |
| + } |
| + want, _ := json.Marshal(map[string][]string{"argv": spec.Args}) |
| + if !bytes.Equal(cmds[0].body, want) { |
| + t.Fatalf("/cmd body %s, want %s: the member's arguments exactly", cmds[0].body, want) |
| + } |
| + for _, a := range spec.Args { |
| + if strings.HasPrefix(a, "/opt/carlos/live/") { |
| + t.Errorf("the argv carries a live-link prefix: %q", a) |
| + } |
| + } |
| + |
| + l := readLaunchNamed(t, h.eb, h.rt, instancectl.LaunchFileName(instancectl.RoleCmd)) |
| + if l.Schema != instancectl.LaunchSchemaRootfs || l.Runtime != registry.RuntimeRootfsV1 || l.Process != "cmd" || len(l.Argv) != 0 { |
| + t.Fatalf("launch.cmd.json schema %d runtime %q process %q argv %q; want schema %d, rootfs, cmd, no argv", |
| + l.Schema, l.Runtime, l.Process, l.Argv, instancectl.LaunchSchemaRootfs) |
| + } |
| + for _, want := range []string{"CARLOS_SOCKET=" + h.rt.Socket, "CARLOS_DB=" + h.eb.pathsFor(h.rt).dbPath, "CARLOS_RUN_ID=run_a", "CARLOS_RUN_DIR=" + spec.RunDir, "SHOP_MODE=live"} { |
| + if !slices.Contains(l.Env, want) { |
| + t.Errorf("launch env lacks %s:\n%s", want, strings.Join(l.Env, "\n")) |
| + } |
| + } |
| + for _, kv := range l.Env { |
| + k, _, _ := strings.Cut(kv, "=") |
| + if k == "PATH" || k == "CARLOS_CONTROL_SOCKET" || k == "CARLOS_PURGE" || kv == "CARLOS_SOCKET=/tenant/elsewhere.sock" { |
| + t.Errorf("launch env carries %s", kv) |
| + } |
| + } |
| + h.noBinaryCmdUnit(t) |
| + |
| + unit := instancectl.RootfsUnitName(instancectl.RoleCmd, h.rt.Host) |
| + if !harnessStartsImages() { |
| + // Root refuses the image itself here (see the file comment): a |
| + // refusal, nothing started, no unit handed back. |
| + if !errors.Is(err, instancectl.ErrStagedImage) || !errors.Is(err, errRootfsRefused) || u != nil { |
| + t.Fatalf("on %s: StartCmd = %v, %v; want root's staged-image refusal, marked, and no unit", release.BoxPlatform(), u, err) |
| + } |
| + if starts := h.callsLike("start --no-block " + unit); len(starts) != 0 { |
| + t.Fatalf("a refused /cmd started %v", starts) |
| + } |
| + return |
| + } |
| + if err != nil { |
| + t.Fatalf("StartCmd: %v", err) |
| + } |
| + if starts := h.callsLike("start --no-block " + unit); len(starts) != 1 { |
| + t.Fatalf("root's starts %v, want %s once", h.callsLike("start "), unit) |
| + } |
| + raw, err := os.ReadFile(filepath.Join(instancectl.RootfsExeDir(h.srv.ExeRoot, provision.InstanceID(h.rt.Host), instancectl.RoleCmd), "launch.json")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var rl instancectl.RootfsLaunch |
| + if err := json.Unmarshal(raw, &rl); err != nil { |
| + t.Fatal(err) |
| + } |
| + if rl.Process != "cmd" || !slices.Equal(rl.Argv, spec.Args) || rl.Version != "v1" || !strings.EqualFold(rl.Digest, id.Digest) { |
| + t.Fatalf("root's launch %+v, want process cmd, argv %q, build v1 at %s", rl, spec.Args, id.Digest) |
| + } |
| + h.release(unit) |
| + if err := u.StopAndSettle(context.Background()); err != nil { |
| + t.Fatalf("StopAndSettle once the unit ended: %v", err) |
| + } |
| + h.noBinaryCmdUnit(t) |
| +} |
| + |
| +// TestRootfsRunNeedsTheServingImage: a rootfs run names its image or does |
| +// not start. With none it is refused (errNoCmdExe), and with a partial one |
| +// (errPartialStagedIdentity), both marked; in both nothing is asked of |
| +// root, no launch file is written and no listener is left. |
| +func TestRootfsRunNeedsTheServingImage(t *testing.T) { |
| + h := newRootfsCtlHarness(t) |
| + h.runProbes() |
| + id, err := h.eb.BuildIdentity(h.rt, "v1") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + partial := stagedExeOf(id) |
| + partial.Digest = "" |
| + for _, c := range []struct { |
| + name string |
| + serving *instancectl.StagedExe |
| + want error |
| + }{{"no image", nil, errNoCmdExe}, {"a partial identity", partial, errPartialStagedIdentity}} { |
| + t.Run(c.name, func(t *testing.T) { |
| + spec := h.runSpecIn("run_a", "true") |
| + spec.serving, spec.genEnv = c.serving, map[string]string{} |
| + u, err := h.eb.StartCmd(context.Background(), h.rt, spec) |
| + if !errors.Is(err, c.want) || !errors.Is(err, errRootfsRefused) || u != nil { |
| + t.Fatalf("StartCmd = %v, %v; want %v, marked, and no unit", u, err, c.want) |
| + } |
| + if n := len(h.cmdRequests()); n != 0 { |
| + t.Fatalf("%d /cmd requests, want none", n) |
| + } |
| + if _, err := os.Stat(filepath.Join(provision.InstanceDir(h.eb.DataDir, h.rt.Host), instancectl.LaunchFileName(instancectl.RoleCmd))); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("launch.cmd.json: %v, want none written", err) |
| + } |
| + for _, name := range []string{string(instancectl.RoleCmd), cmdErrSocket} { |
| + if _, err := os.Stat(h.eb.logSocketNamed(h.rt.Host, name)); !errors.Is(err, os.ErrNotExist) { |
| + t.Errorf("the %s listener's socket: %v, want none", name, err) |
| + } |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// TestRootfsRunRefusedByRootIsARefusal: root answers /cmd 503 (its |
| +// readiness, a probe flipping), then 403 (its image check): each is a |
| +// refusal, marked errRootfsRefused, with no unit handed back, both stream |
| +// listeners closed, and nothing started (INV-4). |
| +func TestRootfsRunRefusedByRootIsARefusal(t *testing.T) { |
| + h := newRootfsCtlHarness(t) |
| + h.runProbes() |
| + id, err := h.eb.BuildIdentity(h.rt, "v1") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, c := range []struct { |
| + status int |
| + want error |
| + }{{http.StatusServiceUnavailable, instancectl.ErrStartRefused}, {http.StatusForbidden, instancectl.ErrStagedImage}} { |
| + t.Run(fmt.Sprint(c.status), func(t *testing.T) { |
| + h.mu.Lock() |
| + h.cmdStatus = c.status |
| + h.mu.Unlock() |
| + spec := h.runSpecIn("run_a", "true") |
| + spec.serving, spec.genEnv = stagedExeOf(id), map[string]string{} |
| + u, err := h.eb.StartCmd(context.Background(), h.rt, spec) |
| + if !errors.Is(err, errRootfsRefused) || !errors.Is(err, c.want) || u != nil { |
| + t.Fatalf("StartCmd = %v, %v; want a marked %v and no unit", u, err, c.want) |
| + } |
| + if v := verdictOf(err); v != gateNoOwnership { |
| + t.Fatalf("verdictOf = %d, want gateNoOwnership", v) |
| + } |
| + h.listenersClosed(t) |
| + if starts := h.callsLike("start --no-block"); len(starts) != 0 { |
| + t.Fatalf("a refused /cmd started %v", starts) |
| + } |
| + }) |
| + } |
| + if n := len(h.cmdRequests()); n != 2 { |
| + t.Fatalf("%d /cmd requests, want the two refused", n) |
| + } |
| +} |
| + |
| +// heldRep is a replica that records its close. |
| +type heldRep struct { |
| + mu sync.Mutex |
| + closed bool |
| +} |
| + |
| +func (r *heldRep) Err() error { return nil } |
| +func (r *heldRep) Close(context.Context) error { |
| + r.mu.Lock() |
| + defer r.mu.Unlock() |
| + r.closed = true |
| + return nil |
| +} |
| +func (r *heldRep) isClosed() bool { |
| + r.mu.Lock() |
| + defer r.mu.Unlock() |
| + return r.closed |
| +} |
| + |
| +type heldLease struct{ rep *heldRep } |
| + |
| +func (l heldLease) Replicate(context.Context, string, time.Duration) (Rep, error) { return l.rep, nil } |
| +func (heldLease) Release(context.Context) error { return nil } |
| + |
| +// runHarnessBackend is harnessBackend whose lease's replica records its |
| +// close, so a test sees the replica held while a run is unproven. |
| +type runHarnessBackend struct { |
| + *harnessBackend |
| + rep *heldRep |
| +} |
| + |
| +func (b *runHarnessBackend) Acquire(ctx context.Context, rt registry.Route) (Lease, error) { |
| + _, _ = b.harnessBackend.Acquire(ctx, rt) |
| + return heldLease{rep: b.rep}, nil |
| +} |
| + |
| +// awakeHarnessRow is a Service over the harness (harnessService's, with a |
| +// replica that records its close), its startup sweep clean, and the row |
| +// awake through its rootfs generation unit. |
| +func awakeHarnessRow(t *testing.T, h *rootfsCtlHarness) (*Service, *runHarnessBackend, *fakeClock) { |
| + t.Helper() |
| + reg, err := registry.Open(filepath.Join(t.TempDir(), "registry.db")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { reg.Close() }) |
| + hb := &runHarnessBackend{harnessBackend: &harnessBackend{SplitBackend: productionBackend(t, h.eb)}, rep: &heldRep{}} |
| + a := New(Config{Bucket: "test-bucket", Idle: time.Hour}, hb, reg) |
| + clk := &fakeClock{t: time.Unix(1_700_000_000, 0)} |
| + a.now = clk.now |
| + a.gens = true |
| + a.ArmRootfs() |
| + t.Cleanup(func() { a.Shutdown(context.Background()) }) |
| + if err := reg.Upsert(h.rt); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := startupSweepFor(a, h); err != nil { |
| + t.Fatalf("startup sweep: %v", err) |
| + } |
| + h.serveGenerations() |
| + done, err := a.beginRequest(context.Background(), h.rt) |
| + if err != nil { |
| + t.Fatalf("wake: %v", err) |
| + } |
| + done() |
| + return a, hb, clk |
| +} |
| + |
| +// TestRootfsRunPollsAndStopsTheRootfsUnit: a run started through |
| +// Service.RunCmd on an awake rootfs entry, through the real control |
| +// handler with no binary cmd unit anywhere. Its Poll reads the rootfs cmd |
| +// unit (running, then done with its invocation once it ends). Its Stop |
| +// sends "stop carlos-instance-rootfs-cmd@…" and is unproven while that |
| +// unit's cgroup is populated. A Bounce keeps the stop pending, with the |
| +// lease and replica held, until it empties. |
| +func TestRootfsRunPollsAndStopsTheRootfsUnit(t *testing.T) { |
| + if !harnessStartsImages() { |
| + t.Skipf("the harness's root starts a rootfs image only on linux-arm64, and this box is %s", release.BoxPlatform()) |
| + } |
| + old := roleEmptyBound |
| + roleEmptyBound = 300 * time.Millisecond |
| + t.Cleanup(func() { roleEmptyBound = old }) |
| + h := newRootfsCtlHarness(t) |
| + h.runProbes() |
| + h.eb.ObservePoll = 20 * time.Millisecond |
| + a, hb, clk := awakeHarnessRow(t, h) |
| + host := h.rt.Host |
| + |
| + var settled atomic.Int32 |
| + spec := h.runSpecIn("run_a", "bin/rails", "runner", "Shop.sync") |
| + spec.AfterSettled = func() { settled.Add(1) } |
| + run, err := a.RunCmd(context.Background(), h.rt, spec) |
| + if err != nil { |
| + t.Fatalf("RunCmd: %v", err) |
| + } |
| + unit := instancectl.RootfsUnitName(instancectl.RoleCmd, host) |
| + if len(h.callsLike("start --no-block "+unit)) != 1 { |
| + t.Fatalf("root's starts %v, want %s once", h.callsLike("start"), unit) |
| + } |
| + h.noBinaryCmdUnit(t) |
| + l := readLaunchNamed(t, h.eb, h.rt, instancectl.LaunchFileName(instancectl.RoleCmd)) |
| + if !slices.Contains(l.Env, "CARLOS_SOCKET="+h.rt.Socket) { |
| + t.Fatalf("the run's CARLOS_SOCKET is not the canonical %s:\n%s", h.rt.Socket, strings.Join(l.Env, "\n")) |
| + } |
| + |
| + type polled struct { |
| + st instancectl.CmdStatus |
| + err error |
| + } |
| + pollDone := make(chan polled, 1) |
| + go func() { |
| + st, err := run.Poll(context.Background()) |
| + pollDone <- polled{st, err} |
| + }() |
| + select { |
| + case p := <-pollDone: |
| + t.Fatalf("Poll answered %+v (%v) while the rootfs cmd unit runs; the binary unit would read as gone", p.st, p.err) |
| + case <-time.After(400 * time.Millisecond): |
| + } |
| + |
| + h.setStuck(unit, true) |
| + sctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| + if err := run.Stop(sctx); err == nil { |
| + t.Fatal("the run's Stop proved the rootfs cmd unit gone while its cgroup is populated") |
| + } |
| + cancel() |
| + if len(h.callsLike("stop "+unit)) == 0 { |
| + t.Fatalf("the run's Stop never reached %s", unit) |
| + } |
| + if !a.Bounce(host) { |
| + t.Fatal("Bounce found no awake entry") |
| + } |
| + waitFor(t, "the instance's stop to keep its unproven run", func() bool { |
| + a.mu.Lock() |
| + defer a.mu.Unlock() |
| + e := a.entries[host] |
| + return e != nil && e.pendingStop |
| + }) |
| + if hb.rep.isClosed() || !a.hasEntry(host) || settled.Load() != 0 { |
| + t.Fatalf("while the run's unit was unproven: replica closed %v, entry %v, AfterSettled %d", hb.rep.isClosed(), a.hasEntry(host), settled.Load()) |
| + } |
| + h.noBinaryCmdUnit(t) |
| + |
| + h.release(unit) |
| + select { |
| + case p := <-pollDone: |
| + if p.err != nil || p.st.State != instancectl.CmdDone || p.st.InvocationID != run.Invocation() { |
| + t.Fatalf("Poll after the unit ended = %+v, %v; want done for invocation %s", p.st, p.err, run.Invocation()) |
| + } |
| + case <-time.After(10 * time.Second): |
| + t.Fatal("Poll did not answer once the rootfs cmd unit ended") |
| + } |
| + waitFor(t, "the sweep to prove the run gone and finish the stop", func() bool { |
| + clk.advance(time.Minute) |
| + a.sweepOnce() |
| + return !a.hasEntry(host) |
| + }) |
| + if !hb.rep.isClosed() { |
| + t.Fatal("the stop finished without closing the replica") |
| + } |
| + run.Release() |
| + if n := settled.Load(); n != 1 { |
| + t.Fatalf("AfterSettled ran %d times, want once after the proof", n) |
| + } |
| +} |
diff --git a/internal/activator/rootfs_invariants_test.go b/internal/activator/rootfs_invariants_test.go| index 13f0b5c7a..092b27169 100644 |
| --- a/internal/activator/rootfs_invariants_test.go |
| +++ b/internal/activator/rootfs_invariants_test.go |
| @@ -95,7 +95,10 @@ var ( |
| // the seam exists, whatever the forwarder is called. |
| var ( |
| rootfsNamePattern = regexp.MustCompile(`(?i)rootfs`) |
| - rootfsSeamInterfaces = []string{"RootfsControl", "rootfsStartable", "rootfsDBPlacer", "ProcessReader", "ReleaseBackend", "RootfsWorkerBackend", "rootfsFirstBootMarker"} |
| + rootfsSeamInterfaces = []string{"RootfsControl", "rootfsStartable", "rootfsDBPlacer", "ProcessReader", "ReleaseBackend", "RootfsWorkerBackend", "rootfsFirstBootMarker", |
| + // Plan 6 Task 7a: the lease's one-shot kill, so SplitBackend's |
| + // KillOneShot is read too. |
| + "oneShotKiller"} |
| ) |
| // isRootfsFile is the files the structural guard reads whole. |
| @@ -760,6 +763,60 @@ var rootfsProofHandles = map[string]func(t *testing.T, r *rootfsProofRig){ |
| } |
| r.noBinaryVerb(t) |
| }, |
| + // Plan 6 Task 7a: a rootfs run's unit (StartCmd), and the lease's kill |
| + // of it (KillOneShot). |
| + "rootfs run cmdUnit (StartCmd)": rootfsRunProofRow, |
| +} |
| + |
| +// rootfsRunProofRow is INV-1's run row (Plan 6 Task 7a): the unit a |
| +// rootfs run's StartCmd hands back, through the production composition |
| +// (SplitBackend to StartCmd's rootfs arm), is started, polled, stopped and |
| +// proven as the rootfs cmd unit, with no binary unit present; and the |
| +// lease's kill of it (KillOneShot through SplitBackend) names it too and |
| +// stays unproven while its group is populated. |
| +func rootfsRunProofRow(t *testing.T, r *rootfsProofRig) { |
| + old := roleEmptyBound |
| + roleEmptyBound = 100 * time.Millisecond |
| + t.Cleanup(func() { roleEmptyBound = old }) |
| + r.ctl.cmdInv = "inv-r" |
| + r.ctl.cmdStatusRootfs = instancectl.CmdStatus{InvocationID: "inv-r", State: instancectl.CmdRunning} |
| + r.ctl.cmdStatus = instancectl.CmdStatus{InvocationID: "inv-r", State: instancectl.CmdGone} // the binary unit's answer |
| + id := stagedRootfsIdentity(t, r.b, "v2") |
| + dir := filepath.Join(r.b.pathsFor(r.rt).dataDir, CmdRunDirName, "run_a") |
| + spec := CmdSpec{RunID: "run_a", RunDir: dir, Args: []string{"true"}, Stdout: &syncBuffer{}, Stderr: &syncBuffer{}, |
| + serving: stagedExeOf(id), genEnv: map[string]string{}} |
| + pb := productionBackend(t, r.b) |
| + u, err := pb.StartCmd(context.Background(), r.rt, spec) |
| + if err != nil { |
| + t.Fatalf("StartCmd: %v", err) |
| + } |
| + r.ctl.mustHaveCallPrefix(t, "cmd-rootfs "+r.rt.Host+" ") |
| + if img := r.ctl.lastRootfsImage(); img.Process != "" || len(img.Argv) != 1 || img.Argv[0] != "true" || img.Path != id.StagedPath { |
| + t.Fatalf("the run named image %+v, want the serving image with the run's argv", img) |
| + } |
| + st, err := u.Poll(context.Background()) |
| + if err != nil || st.State != instancectl.CmdRunning { |
| + t.Fatalf("Poll = %+v, %v; want running, from the rootfs cmd unit", st, err) |
| + } |
| + r.ctl.mustHaveCallPrefix(t, "cmdstatus-rootfs "+r.rt.Host+" inv-r") |
| + unit := instancectl.RootfsUnitName(instancectl.RoleCmd, r.rt.Host) |
| + if err := u.StopAndSettle(context.Background()); err == nil { |
| + t.Fatalf("StopAndSettle proved the cmd unit gone while %s's group is populated", unit) |
| + } |
| + r.ctl.mustHaveCallPrefix(t, "stop-rootfs "+r.rt.Host+" role=cmd gen=0") |
| + if err := pb.KillOneShot(context.Background(), r.rt, instancectl.RoleCmd); err == nil { |
| + t.Fatalf("KillOneShot proved the cmd unit gone while %s's group is populated", unit) |
| + } |
| + r.ctl.mustHaveCallPrefix(t, "stop-rootfs "+r.rt.Host+" role=cmd gen=0 worker= kill=true") |
| + r.noBinaryVerb(t) |
| + r.setPopulated(t, unit, false) |
| + if err := u.StopAndSettle(context.Background()); err != nil { |
| + t.Fatalf("StopAndSettle once %s's group is empty: %v", unit, err) |
| + } |
| + if err := pb.KillOneShot(context.Background(), r.rt, instancectl.RoleCmd); err != nil { |
| + t.Fatalf("KillOneShot once %s's group is empty: %v", unit, err) |
| + } |
| + r.noBinaryVerb(t) |
| } |
| // stagedRootfsIdentity stages acme/shop at ver as root's staging leaves it |
| @@ -1006,6 +1063,13 @@ var rootfsRefusals = []struct { |
| {"an open release record at a successor's exec (launchRefused)", launchRefused{errReleaseOpen}}, |
| {"an overlap without its release pass (errReleaseNotPassed)", errReleaseNotPassed}, |
| {"a release for a plan-disabled route (errReleaseTurnedOff)", errReleaseTurnedOff}, |
| + // Plan 6 Task 7a: a rootfs run with no image to name, and with a |
| + // partial one, as startRootfsRun marks them; root's pre-start /cmd |
| + // answers come through as N1's rows above |
| + // (TestRootfsRunRefusedByRootIsARefusal sends both through the real |
| + // client). |
| + {"a rootfs run with no image (errNoCmdExe, marked)", refuseRootfs(fmt.Errorf("x: %w", errNoCmdExe))}, |
| + {"a rootfs run with a partial image (errPartialStagedIdentity, marked)", refuseRootfs(fmt.Errorf("x: %w", errPartialStagedIdentity))}, |
| } |
| // rootfsReleaseResults are the release's results that are not the build's |
| @@ -1131,6 +1195,35 @@ var rootfsLaunchRows = map[string]func(t *testing.T) (instancectl.Launch, map[st |
| } |
| return readLaunchNamed(t, eb, rt, instancectl.WorkerLaunchFileName("jobs")), vars |
| }, |
| + // Plan 6 Task 7a: a carlos run's launch file, written by the |
| + // production composition's StartCmd over the environment its |
| + // generation launched with, under the agent's PATH (the test sets it). |
| + "run": func(t *testing.T) (instancectl.Launch, map[string]string) { |
| + b, ctl := newRootfsBackend(t) |
| + ctl.cmdInv = "inv-r" |
| + rt := rootfsRoute(b) |
| + up, _ := startRootfsGen7(t, b, ctl, rt, "SHOP_MODE=live\n") |
| + id := stagedRootfsIdentity(t, b, "v2") |
| + p := b.pathsFor(rt) |
| + dir := filepath.Join(p.dataDir, CmdRunDirName, "r1") |
| + spec := CmdSpec{RunID: "r1", RunDir: dir, Args: []string{"true"}, Stdout: &syncBuffer{}, Stderr: &syncBuffer{}, |
| + serving: stagedExeOf(id), genEnv: up.LaunchEnv()} |
| + u, err := productionBackend(t, b).StartCmd(context.Background(), rt, spec) |
| + if err != nil { |
| + t.Fatalf("StartCmd: %v", err) |
| + } |
| + u.(*cmdUnit).out.Close() |
| + u.(*cmdUnit).errs.Close() |
| + l := readLaunchNamed(t, b, rt, instancectl.LaunchFileName(instancectl.RoleCmd)) |
| + if l.Process != "cmd" { |
| + t.Fatalf("the run's launch names process %q, want cmd", l.Process) |
| + } |
| + vars := b.rootfsCmdVars(rt, up.LaunchEnv(), p.dbPath, "r1", dir) |
| + if vars["SHOP_MODE"] != "live" { |
| + t.Fatalf("the instance's file did not reach the composed variables: %v", vars) |
| + } |
| + return l, vars |
| + }, |
| } |
| // rootfsComposerRows: process -> its composer's variables, production-wired: |
diff --git a/internal/activator/rootfs_service.go b/internal/activator/rootfs_service.go| index 1975c1042..5e289c67a 100644 |
| --- a/internal/activator/rootfs_service.go |
| +++ b/internal/activator/rootfs_service.go |
| @@ -656,9 +656,11 @@ func (a *Service) residentOrderLocked(routes []registry.Route) []registry.Route |
| // residents", so nothing is stopped and nothing forgotten. |
| // 2. Every awake rootfs entry whose process exited is stopped as the |
| // sweep's crash arm stops one (StopExited), so a crash is seen within |
| -// residentPoll rather than the sweep's 30 s. A resident with no lease |
| -// watch (its replica has no lease signal), awake or stopping, whose |
| -// replica reports its lease lost has its generations killed once, its |
| +// residentPoll rather than the sweep's 30 s. A resident, or a |
| +// hibernating rootfs entry with a one-shot unit that may run, with no |
| +// lease watch (its replica has no lease signal), awake or stopping, |
| +// whose replica reports its lease lost has its one-shot units killed |
| +// once (Plan 6 Task 7a) and, a resident, its generations killed, its |
| // workers stopped (stopRootfsWorkersAtLoss) and its stop begun |
| // (residentLeaseLostLocked): the second line under the watch |
| // installProcLocked installs. Then superviseRootfsLocked (the |
| @@ -686,15 +688,21 @@ func (a *Service) rootfsTick() { |
| if !e.route.Rootfs() { |
| continue |
| } |
| - // The second line under the lease watch, for a resident whose |
| + // The second line under the lease watch, for a resident, or a |
| + // hibernating rootfs entry with a one-shot unit that may run, whose |
| // replica has no lease signal (no watch was installed): awake or |
| - // already stopping, fenced or not, a lost lease kills its |
| - // generations once (residentLeaseLostLocked). |
| - if e.route.Resident() && e.ownerDone == nil && !e.ownerKilled && e.rep != nil && |
| + // already stopping, fenced or not, a lost lease kills its one-shot |
| + // units and a resident's generations once |
| + // (residentLeaseLostLocked), each off a.mu. |
| + if e.route.Rootfs() && (e.route.Resident() || oneShotHoldsLocked(e)) && e.ownerDone == nil && !e.ownerKilled && e.rep != nil && |
| (e.state == actAwake || e.state == actStopping) { |
| if err := e.rep.Err(); err != nil { |
| e.ownerKilled = true |
| - if gens := a.residentLeaseLostLocked(e, err); gens != nil { |
| + gens, oneShots := a.residentLeaseLostLocked(e, err) |
| + for _, f := range oneShots { |
| + go f() |
| + } |
| + if gens != nil { |
| go a.killResidentGens(e.route, gens) |
| go a.stopRootfsWorkersAtLoss(e) // [pf W1.10] |
| } |
| @@ -837,7 +845,9 @@ var _ residentOwnership = (*lease.Replicator)(nil) |
| var residentDrainBudget = 30 * time.Second |
| // watchResidentLeaseLocked starts e's lease watch. Only installProcLocked |
| -// calls it, as a resident process is installed, so the watch exists before |
| +// calls it, as a rootfs process is installed (a resident's, and since Plan |
| +// 6 Task 7a a hibernating rootfs row's too, whose one-shot units the |
| +// watch reaches), so the watch exists before |
| // any transition after the install can stop the entry. Idempotent: a swap's |
| // successor keeps the entry's one watch. A replica without the lease's |
| // signal is left to the tick's rep.Err check. The watch is held through |
| @@ -853,12 +863,14 @@ func (a *Service) watchResidentLeaseLocked(e *actEntry) { |
| go a.watchResidentLease(e, sig, done) |
| } |
| -// watchResidentLease is one resident's lease watch: the safe deadline is read |
| -// again whenever it was due to fall inside the drain budget (a renewal may |
| -// have moved it); once it does, a graceful stop begins (StopLeaseLost) if |
| -// the entry is still awake; at loss, whatever the entry's state (awake, |
| -// stopping, a drain stalled), its generations are killed at once, and the |
| -// stop path's proof still decides when the lease goes. |
| +// watchResidentLease is one rootfs entry's lease watch: the safe deadline |
| +// is read again whenever it was due to fall inside the drain budget (a |
| +// renewal may have moved it); once it does, its one-shot units are stopped |
| +// and a resident's graceful stop begins (StopLeaseLost) if the entry is |
| +// still awake (residentLeaseShort); at loss, whatever the entry's state |
| +// (awake, stopping, a drain stalled), its one-shot units and a resident's |
| +// generations are killed at once (residentLeaseLost), and the stop path's |
| +// proof still decides when the lease goes. |
| func (a *Service) watchResidentLease(e *actEntry, sig residentOwnership, done <-chan struct{}) { |
| draining := false |
| for { |
| @@ -908,56 +920,89 @@ func stopTimer(t *time.Timer) { |
| } |
| } |
| -// residentLeaseShort begins e's graceful stop when the lease's safe time |
| -// left (left) can no longer wait: renewals are not landing, and a drain |
| -// begun later would outlast the deadline. |
| +// residentLeaseShort is the watch's answer when the lease's safe time left |
| +// (left) can no longer wait: renewals are not landing, and a drain begun |
| +// later would outlast the deadline. Every one-shot unit of e that may run |
| +// is stopped now, off a.mu, whatever e's state (awake or already stopping, |
| +// resident or hibernating: Plan 6 Task 7a, C7), and a resident that is |
| +// still awake begins its graceful stop. |
| func (a *Service) residentLeaseShort(e *actEntry, left time.Duration) { |
| a.mu.Lock() |
| - defer a.mu.Unlock() |
| - if a.entries[e.host] != e || e.state != actAwake { |
| + if a.entries[e.host] != e { |
| + a.mu.Unlock() |
| return |
| } |
| - log.Printf("activator: %s: its lease is not renewing and is safe for %s more; stopping it while a drain still fits", e.host, left.Round(time.Millisecond)) |
| - a.beginStopLocked(e, StopLeaseLost) |
| + oneShots := a.stopOneShotsAtLeaseLocked(e, e.route, false) |
| + if len(oneShots) > 0 { |
| + log.Printf("activator: %s: its lease is not renewing and is safe for %s more; stopping its commands", e.host, left.Round(time.Millisecond)) |
| + } |
| + if e.route.Resident() && e.state == actAwake { |
| + log.Printf("activator: %s: its lease is not renewing and is safe for %s more; stopping it while a drain still fits", e.host, left.Round(time.Millisecond)) |
| + a.beginStopLocked(e, StopLeaseLost) |
| + } |
| + a.mu.Unlock() |
| + for _, f := range oneShots { |
| + go f() |
| + } |
| } |
| -// residentLeaseLost is the loss itself: e is stopped if it is still awake, |
| -// and every generation it has is killed and proven gone, off a.mu. |
| +// residentLeaseLost is the loss itself, off a.mu: every one-shot unit of |
| +// e that may run is killed (Plan 6 Task 7a, Call A1), and a resident is |
| +// stopped if it is still awake and every generation it has is killed and |
| +// proven gone. |
| // |
| -// Its workers are stopped at the same moment, beside the kills and |
| -// without waiting for the entry's stop [pf W1.10]: root kills only a |
| +// A resident's workers are stopped at the same moment, beside the kills |
| +// and without waiting for the entry's stop [pf W1.10]: root kills only a |
| // generation, so each is stopped and proven gone (stopRootfsWorkersAtLoss). |
| func (a *Service) residentLeaseLost(e *actEntry, err error) { |
| a.mu.Lock() |
| - gens := a.residentLeaseLostLocked(e, err) |
| + gens, oneShots := a.residentLeaseLostLocked(e, err) |
| rt := e.route |
| a.mu.Unlock() |
| + var wg sync.WaitGroup |
| + for _, f := range oneShots { |
| + wg.Add(1) |
| + go func() { |
| + defer wg.Done() |
| + f() |
| + }() |
| + } |
| if gens != nil { |
| - var wg sync.WaitGroup |
| wg.Add(1) |
| go func() { |
| defer wg.Done() |
| a.stopRootfsWorkersAtLoss(e) |
| }() |
| a.killResidentGens(rt, gens) |
| - wg.Wait() |
| } |
| + wg.Wait() |
| } |
| -// residentLeaseLostLocked begins e's stop for a lost lease (if it is still |
| -// awake), cancels its generation attempts, and returns every generation |
| -// number the entry has (the current one and each operation member's) for |
| -// killResidentGens; nil when e is no longer the host's entry. The caller |
| -// holds a.mu. |
| -func (a *Service) residentLeaseLostLocked(e *actEntry, err error) []uint64 { |
| +// residentLeaseLostLocked is the loss for e under a.mu. oneShots is one |
| +// kill func per one-shot unit of e that may run, whatever e's state |
| +// (stopOneShotsAtLeaseLocked, kill true), for the caller to run off a.mu. |
| +// For a resident it also begins e's stop (if it is still awake), cancels |
| +// its generation attempts, and returns in gens every generation number the |
| +// entry has (the current one and each operation member's) for |
| +// killResidentGens. gens is nil for a hibernating entry (its generations |
| +// stay the sweep's: its rep.Err stop) and, with oneShots, for an entry |
| +// that is no longer the host's. The caller holds a.mu. |
| +func (a *Service) residentLeaseLostLocked(e *actEntry, err error) (gens []uint64, oneShots []func()) { |
| if a.entries[e.host] != e { |
| - return nil |
| + return nil, nil |
| + } |
| + oneShots = a.stopOneShotsAtLeaseLocked(e, e.route, true) |
| + if !e.route.Resident() { |
| + if len(oneShots) > 0 { |
| + log.Printf("activator: LEASE LOST for %s (%v); killing its commands", e.host, err) |
| + } |
| + return nil, oneShots |
| } |
| log.Printf("activator: LEASE LOST for always-on %s (%v); killing it", e.host, err) |
| if e.state == actAwake { |
| a.beginStopLocked(e, StopLeaseLost) |
| } |
| - gens := []uint64{} |
| + gens = []uint64{} |
| if e.gen.N != 0 { |
| gens = append(gens, e.gen.N) |
| } |
| @@ -969,7 +1014,7 @@ func (a *Service) residentLeaseLostLocked(e *actEntry, err error) []uint64 { |
| gens = append(gens, n) |
| } |
| } |
| - return gens |
| + return gens, oneShots |
| } |
| // killResidentGens kills each generation outright through the backend's |
diff --git a/internal/activator/rootfs_test.go b/internal/activator/rootfs_test.go| index 98b077de2..bfce1e284 100644 |
| --- a/internal/activator/rootfs_test.go |
| +++ b/internal/activator/rootfs_test.go |
| @@ -1032,8 +1032,9 @@ func TestRootfsStartRefusesABinaryStagedUnderARootfsRow(t *testing.T) { |
| } |
| // A rootfs row never reaches a binary launch: the binary unit starts |
| -// (seed, sidecar, a swap's spawn, cmd) refuse it at nestedGate, and the |
| -// flat seam refuses it with RFS-2-C01. Nothing is asked of root. |
| +// (seed, sidecar, a swap's spawn) refuse it at nestedGate, and the flat |
| +// seam refuses it with RFS-2-C01. A run (StartCmd) takes its rootfs arm. |
| +// Nothing is asked of root. |
| func TestRootfsRowsNeverTakeABinaryLaunch(t *testing.T) { |
| t.Parallel() |
| b, ctl := newRootfsBackend(t) |
| @@ -1046,15 +1047,18 @@ func TestRootfsRowsNeverTakeABinaryLaunch(t *testing.T) { |
| _, _, err := b.spawnUnitFrom(context.Background(), rt, rt.Socket, 0, nil, cgroup.Limit{}) |
| return err |
| }, |
| - "cmd": func() error { |
| - _, err := b.StartCmd(context.Background(), rt, CmdSpec{RunID: "r1", RunDir: filepath.Join(provision.InstanceDir(b.DataDir, rt.Host), CmdRunDirName, "r1")}) |
| - return err |
| - }, |
| } { |
| if err := start(); !errors.Is(err, errRootfsBinaryLaunch) { |
| t.Errorf("%s: %v", name, err) |
| } |
| } |
| + // A run (StartCmd) takes its rootfs arm since Plan 6 Task 7a, never |
| + // the binary one: with no image to name it is refused (errNoCmdExe, |
| + // marked) before anything is asked of root. |
| + _, err := b.StartCmd(context.Background(), rt, CmdSpec{RunID: "r1", RunDir: filepath.Join(provision.InstanceDir(b.DataDir, rt.Host), CmdRunDirName, "r1")}) |
| + if !errors.Is(err, errNoCmdExe) || !errors.Is(err, errRootfsRefused) || errors.Is(err, errRootfsBinaryLaunch) { |
| + t.Errorf("cmd: %v, want the rootfs arm's errNoCmdExe, marked", err) |
| + } |
| if len(ctl.callList()) != 0 { |
| t.Errorf("root was asked: %v", ctl.callList()) |
| } |
diff --git a/internal/activator/testdata/rootfs_golden/start_release.cmd b/internal/activator/testdata/rootfs_golden/start_release.cmd| new file mode 100644 |
| index 000000000..0443f5375 |
| --- /dev/null |
| +++ b/internal/activator/testdata/rootfs_golden/start_release.cmd |
| @@ -0,0 +1,9 @@ |
| +query |
| +digest=d5e89ddfab1dd66998c2d61ec281b755cde84945a6fa483aebed049f9c60ed41 |
| +host=shop.example.com |
| +image=$OPT/versions/v2/acme/shop |
| +memory_max=1073741824 |
| +process=release |
| +runtime=rootfs |
| +version=v2 |
| +body "" |
diff --git a/internal/activator/testdata/rootfs_golden/start_release.launch.cmd.json b/internal/activator/testdata/rootfs_golden/start_release.launch.cmd.json| new file mode 100644 |
| index 000000000..a49d11094 |
| --- /dev/null |
| +++ b/internal/activator/testdata/rootfs_golden/start_release.launch.cmd.json |
| @@ -0,0 +1,12 @@ |
| +{ |
| + "schema": 2, |
| + "host": "shop.example.com", |
| + "argv": null, |
| + "env": [ |
| + "CARLOS_DB=$ROOT/data/instances/shop.example.com/shop.example.com.db", |
| + "CARLOS_SOCKET=$ROOT/run/instances/shop.example.com/app.sock", |
| + "SHOP_MODE=live" |
| + ], |
| + "runtime": "rootfs-v1", |
| + "process": "release" |
| +} |
diff --git a/internal/console/apiruns.go b/internal/console/apiruns.go| index b9d61437c..2b797609c 100644 |
| --- a/internal/console/apiruns.go |
| +++ b/internal/console/apiruns.go |
| @@ -264,14 +264,18 @@ func runMetaRefusalCode(msg string) string { |
| } |
| // runClassRefusal is spec §5.1 refusal 5 as a sentence, "" for a |
| -// platform-run, hibernating exec instance on a platform box. |
| +// platform-run, hibernating exec instance on a platform box, or a rootfs |
| +// instance on a platform box (rootfs apps Plan 6 Task 7a, PF-2: it never |
| +// hibernates, and the platform runs its process always). A rootfs record |
| +// on a customer fleet is still refused, as every fleet record is, until |
| +// runs reach fleet boxes through the console's door (Task 16). |
| func runClassRefusal(rec provision.Record) string { |
| switch { |
| case rec.Kind != "" && rec.Kind != "instance": |
| return fmt.Sprintf("%s is a %s route. carlos run works on instances", rec.Host, rec.Kind) |
| case rec.Addr != "" || len(rec.Addrs) > 0: |
| return fmt.Sprintf("%s is served from its own address, so the platform does not run its process", rec.Host) |
| - case !rec.HibernateOrDefault(): |
| + case !rec.HibernateOrDefault() && rec.Runtime != provision.RuntimeRootfsV1: |
| return fmt.Sprintf("%s does not sleep, so the platform does not run its process", rec.Host) |
| case rec.Pool != "": |
| return fmt.Sprintf("%s is a pooled instance. carlos run works on instances with a process of their own", rec.Host) |
diff --git a/internal/console/apiruns_rootfs_test.go b/internal/console/apiruns_rootfs_test.go| new file mode 100644 |
| index 000000000..0a409743b |
| --- /dev/null |
| +++ b/internal/console/apiruns_rootfs_test.go |
| @@ -0,0 +1,71 @@ |
| +package console |
| + |
| +// Rootfs apps Plan 6 Task 7a (PF-2): the run door admits a rootfs |
| +// instance, which never hibernates (the platform runs its process always), |
| +// on a platform box, and keeps the fleet refusal for a rootfs record until |
| +// runs reach fleet boxes through the console's door (Task 16). |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "net/http" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| +) |
| + |
| +// putAcctShopRecord writes an instance record of fx's shop app in its |
| +// account, with the fields a hibernating exec instance has, overridden by |
| +// whatever rec sets. |
| +func putAcctShopRecord(t *testing.T, fx *interactiveFx, rec provision.Record) { |
| + t.Helper() |
| + rec.App, rec.Account = "shop", fx.acct |
| + if rec.CreatedAt.IsZero() { |
| + rec.CreatedAt = time.Now().UTC() |
| + } |
| + if rec.Hibernate == nil { |
| + yes := true |
| + rec.Hibernate = &yes |
| + } |
| + body, err := json.Marshal(rec) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := fx.rel.Put(context.Background(), provision.RecordKey(rec.Account, rec.App, rec.Host), body, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +func (fx *interactiveFx) runsURL(host string) string { |
| + return fx.ts.URL + "/api/cli/apps/" + fx.acct + "/shop/instances/" + host + "/runs" |
| +} |
| + |
| +func TestRunDoorAdmitsRootfsResident(t *testing.T) { |
| + fx := newInteractiveFx(t, 7, "run-rootfs") |
| + no := false |
| + putAcctShopRecord(t, fx, provision.Record{Host: "rootfs.example.com", Runtime: provision.RuntimeRootfsV1, Hibernate: &no, Region: "uk"}) |
| + if status, body := postRun(t, fx.runsURL("rootfs.example.com"), fx.alice, okMeta(), nil); status != http.StatusAccepted { |
| + t.Fatalf("a rootfs instance on a platform box: %d %s, want 202", status, body) |
| + } |
| + // An always-on binary instance is still refused, with today's sentence. |
| + putAcctShopRecord(t, fx, provision.Record{Host: "awake.example.com", Hibernate: &no, Region: "uk"}) |
| + status, body := postRun(t, fx.runsURL("awake.example.com"), fx.alice, okMeta(), nil) |
| + if status != http.StatusConflict || errorOf(t, body) != "awake.example.com does not sleep, so the platform does not run its process" { |
| + t.Errorf("an always-on binary instance: %d %s, want today's refusal", status, body) |
| + } |
| +} |
| + |
| +func TestRunDoorStillRefusesARootfsFleetInstance(t *testing.T) { |
| + fx := newInteractiveFx(t, 7, "run-rootfs-fleet") |
| + no := false |
| + putAcctShopRecord(t, fx, provision.Record{Host: "fleet.example.com", Runtime: provision.RuntimeRootfsV1, Hibernate: &no, Region: "fleet/home"}) |
| + status, body := postRun(t, fx.runsURL("fleet.example.com"), fx.alice, okMeta(), nil) |
| + if status != http.StatusConflict || errorOf(t, body) != "fleet.example.com runs on your fleet home. carlos run works on platform boxes only" { |
| + t.Fatalf("a rootfs instance on a fleet: %d %s, want today's fleet refusal", status, body) |
| + } |
| + if strings.Contains(body, "does not sleep") { |
| + t.Fatalf("a rootfs fleet instance got the always-on sentence: %s", body) |
| + } |
| +} |
diff --git a/internal/host/runexec.go b/internal/host/runexec.go| index 8168142a6..2c6d7ad49 100644 |
| --- a/internal/host/runexec.go |
| +++ b/internal/host/runexec.go |
| @@ -121,13 +121,17 @@ func runFinishOurs(id, box, boot string) func(*provision.Record) error { |
| // execute is one picked run's life (run spec §5.2 to §5.7): the |
| // incarnation, the launch (Prepare checks the record again and stages the |
| // files), the poll, a cancel or a timeout, then the unit stopped, every |
| -// chunk written, result.json, the done CAS, the run directory deleted and |
| -// the hold released, in that order. |
| +// chunk written, result.json, the done CAS and the hold released, in that |
| +// order. The run directory goes when the activator has proven no unit of |
| +// the run can be running (CmdSpec.AfterSettled, rootfs apps Plan 6 Task |
| +// 7a, INV-2), which may be after execute returns; a run refused before |
| +// RunCmd removes it itself. |
| func (w *runsWorker) execute(ctx context.Context, rec provision.Record, req runs.Request, rt registry.Route, h *runHandle) { |
| defer w.forget(req.ID) |
| instDir := provision.InstanceDir(w.dataDir, rec.Host) |
| if req.Account != rec.Account || req.App != rec.App || req.Host != rec.Host || req.Incarnation == "" || req.Incarnation != recordIncarnation(rec) { |
| - w.finish(ctx, rec, req, runs.Result{Refused: runs.RefusedIncarnation}, nil) |
| + // Refused before RunCmd: nothing of the run ever started. |
| + w.finish(ctx, rec, req, runs.Result{Refused: runs.RefusedIncarnation}, nil, true) |
| return |
| } |
| // The chunker's context is not the run's: a cancel or a timeout must |
| @@ -171,6 +175,11 @@ func (w *runsWorker) execute(ctx context.Context, rec provision.Record, req runs |
| notOurs, recheckErr = errors.Is(err, errRunNotOurs), err |
| return err |
| }, |
| + // The directory, the run's uploaded files included, goes once no |
| + // unit of the run can be running, never before (INV-2): RunCmd |
| + // calls this on a path that starts nothing, and otherwise the |
| + // settle that proves the unit gone does, however late. |
| + AfterSettled: func() { w.removeRunDir(rec, req) }, |
| } |
| // The launch runs under the run's deadline and its cancel, the whole |
| // admission through (re-review 5): the wake, Prepare, a wait for a |
| @@ -187,7 +196,7 @@ func (w *runsWorker) execute(ctx context.Context, rec provision.Record, req runs |
| // The record gives the run to no one, or to another boot: |
| // whoever holds it writes its result. |
| chunks.Close() |
| - w.cleanUp(rec, req, nil) |
| + w.cleanUp(rec, req, nil, false) |
| log.Printf("agent: runs: %s %s: not launched: %v", rec.Host, req.ID, err) |
| return |
| } |
| @@ -203,7 +212,7 @@ func (w *runsWorker) execute(ctx context.Context, rec provision.Record, req runs |
| log.Printf("agent: runs: %s %s: start: %v", rec.Host, req.ID, err) |
| } |
| closeOutput(&res) |
| - w.finish(ctx, rec, req, res, nil) |
| + w.finish(ctx, rec, req, res, nil, false) |
| return |
| } |
| log.Printf("agent: runs: %s: run %s started (%s)", rec.Host, req.ID, handle.Invocation()) |
| @@ -242,7 +251,7 @@ func (w *runsWorker) execute(ctx context.Context, rec provision.Record, req runs |
| res.Interrupted = runs.InterruptedGone |
| } |
| closeOutput(&res) |
| - w.finish(ctx, rec, req, res, handle) |
| + w.finish(ctx, rec, req, res, handle, false) |
| } |
| // endedByContext reports whether err is a context's end: a read cut short |
| @@ -428,10 +437,10 @@ func (w *runsWorker) follow(ctx context.Context, rec provision.Record, req runs. |
| // finish writes the run's result, then CASes the run to done only if the |
| // result landed and the record names the run as this box's under this |
| -// boot, then cleans up. A result that cannot be written leaves the run |
| -// picked: the sweep ends it as lost with a result of its own, so a run is |
| -// never done without one. |
| -func (w *runsWorker) finish(ctx context.Context, rec provision.Record, req runs.Request, res runs.Result, handle activator.CmdHandle) { |
| +// boot, then cleans up (cleanUp, removeDir as it says). A result that |
| +// cannot be written leaves the run picked: the sweep ends it as lost with |
| +// a result of its own, so a run is never done without one. |
| +func (w *runsWorker) finish(ctx context.Context, rec provision.Record, req runs.Request, res runs.Result, handle activator.CmdHandle, removeDir bool) { |
| res.Box, res.Ended = w.box, w.now().UTC() |
| fctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), runFinishBound) |
| defer cancel() |
| @@ -455,20 +464,31 @@ func (w *runsWorker) finish(ctx context.Context, rec provision.Record, req runs. |
| log.Printf("agent: runs: %s %s: done: %v", rec.Host, req.ID, err) |
| } |
| } |
| - w.cleanUp(rec, req, handle) |
| + w.cleanUp(rec, req, handle, removeDir) |
| } |
| -// cleanUp deletes the run's directory (an error is logged, never acted |
| -// on) and releases the activator's hold. |
| -func (w *runsWorker) cleanUp(rec provision.Record, req runs.Request, handle activator.CmdHandle) { |
| - if err := runs.RemoveRunDir(provision.InstanceDir(w.dataDir, rec.Host), req.ID); err != nil && !errors.Is(err, os.ErrNotExist) { |
| - log.Printf("agent: runs: %s %s: remove run dir: %v", rec.Host, req.ID, err) |
| +// cleanUp releases the activator's hold, and with removeDir deletes the |
| +// run's directory. removeDir is true only on a path that never called |
| +// RunCmd (the incarnation refusal before launch): every path after RunCmd |
| +// leaves the directory to CmdSpec.AfterSettled, which the activator calls |
| +// once no unit of the run can be running (INV-2). |
| +func (w *runsWorker) cleanUp(rec provision.Record, req runs.Request, handle activator.CmdHandle, removeDir bool) { |
| + if removeDir { |
| + w.removeRunDir(rec, req) |
| } |
| if handle != nil { |
| handle.Release() |
| } |
| } |
| +// removeRunDir deletes the run's directory; an error is logged, never |
| +// acted on. |
| +func (w *runsWorker) removeRunDir(rec provision.Record, req runs.Request) { |
| + if err := runs.RemoveRunDir(provision.InstanceDir(w.dataDir, rec.Host), req.ID); err != nil && !errors.Is(err, os.ErrNotExist) { |
| + log.Printf("agent: runs: %s %s: remove run dir: %v", rec.Host, req.ID, err) |
| + } |
| +} |
| + |
| // untilLanded retries f until it succeeds, answers a conflict or a missing |
| // object (neither changes on a retry), or ctx ends. |
| func untilLanded(ctx context.Context, f func(context.Context) error) error { |
diff --git a/internal/host/runexec_linux_test.go b/internal/host/runexec_linux_test.go| index 76b55e4cc..a81268daf 100644 |
| --- a/internal/host/runexec_linux_test.go |
| +++ b/internal/host/runexec_linux_test.go |
| @@ -31,6 +31,10 @@ type fakeHandle struct { |
| askedAt time.Time // when the interrupting stop was asked for; zero is "long ago" |
| afterStop *instancectl.CmdStatus |
| stopErr error |
| + // afterSettled is the run's CmdSpec.AfterSettled, which a Stop that |
| + // succeeds calls once, as the activator's proving settle does. |
| + afterSettled func() |
| + settledOnce sync.Once |
| } |
| func (h *fakeHandle) interrupt(why string) { |
| @@ -66,23 +70,48 @@ func (h *fakeHandle) Interrupted() (string, time.Time) { |
| func (h *fakeHandle) Stop(context.Context) error { |
| h.mu.Lock() |
| h.stops++ |
| - err := h.stopErr |
| + err, after := h.stopErr, h.afterSettled |
| h.mu.Unlock() |
| + if err == nil && after != nil { |
| + h.settledOnce.Do(after) |
| + } |
| return err |
| } |
| + |
| +// settledByStop is the AfterSettled the handle was given, for a test whose |
| +// Stop failed to call as a later settle would. |
| +func (h *fakeHandle) settledByStop() func() { |
| + h.mu.Lock() |
| + defer h.mu.Unlock() |
| + return h.afterSettled |
| +} |
| func (h *fakeHandle) Release() { h.mu.Lock(); h.released = true; h.mu.Unlock() } |
| // fakeLauncher counts the units it starts. With noUnit set it starts none: |
| // a test that must start no unit fails at once instead of following one. |
| +// It honours CmdSpec.AfterSettled as the activator does: called before it |
| +// returns on a path that starts no unit, and handed to the handle, whose |
| +// successful Stop calls it. maybeStarted, with err, is a start that may |
| +// have begun (Prepare ran, then err): AfterSettled is held, not called. |
| type fakeLauncher struct { |
| - mu sync.Mutex |
| - calls int |
| - units int |
| - noUnit bool |
| - err error |
| - handle *fakeHandle |
| - out string |
| - errOut string |
| + mu sync.Mutex |
| + calls int |
| + units int |
| + noUnit bool |
| + err error |
| + maybeStarted bool |
| + held func() // AfterSettled, held by a start that may have begun |
| + handle *fakeHandle |
| + out string |
| + errOut string |
| +} |
| + |
| +// settled calls spec's AfterSettled, as the activator does on a path that |
| +// started no unit. |
| +func settled(spec activator.CmdSpec) { |
| + if spec.AfterSettled != nil { |
| + spec.AfterSettled() |
| + } |
| } |
| func (l *fakeLauncher) started() int { l.mu.Lock(); defer l.mu.Unlock(); return l.units } |
| @@ -91,22 +120,34 @@ func (l *fakeLauncher) RunCmd(ctx context.Context, rt registry.Route, spec activ |
| l.mu.Lock() |
| l.calls++ |
| l.mu.Unlock() |
| - if l.err != nil { |
| + if l.err != nil && !l.maybeStarted { |
| + settled(spec) |
| return nil, l.err |
| } |
| if spec.Prepare != nil { |
| if err := spec.Prepare(ctx); err != nil { |
| + settled(spec) |
| return nil, err |
| } |
| } |
| + if l.err != nil { |
| + l.mu.Lock() |
| + l.held = spec.AfterSettled |
| + l.mu.Unlock() |
| + return nil, l.err |
| + } |
| l.mu.Lock() |
| l.units++ |
| l.mu.Unlock() |
| if l.noUnit { |
| + settled(spec) |
| return nil, errors.New("fake: a unit was started") |
| } |
| io.WriteString(spec.Stdout, l.out) |
| io.WriteString(spec.Stderr, l.errOut) |
| + l.handle.mu.Lock() |
| + l.handle.afterSettled = spec.AfterSettled |
| + l.handle.mu.Unlock() |
| return l.handle, nil |
| } |
| @@ -370,6 +411,7 @@ func TestRunStagesItsFiles(t *testing.T) { |
| type stagedReader struct{ read func(activator.CmdSpec) } |
| func (l *stagedReader) RunCmd(ctx context.Context, rt registry.Route, spec activator.CmdSpec) (activator.CmdHandle, error) { |
| + defer settled(spec) // nothing started |
| if err := spec.Prepare(ctx); err != nil { |
| return nil, err |
| } |
| @@ -460,7 +502,8 @@ func TestRunFinishedBeforeAnInstanceStopKeepsItsExit(t *testing.T) { |
| // A run interrupted by a retired generation while its unit is still |
| // running, and whose stop keeps failing, ends interrupted (exit 125) as |
| // soon as the interruption is seen: the worker does not follow the command |
| -// to its own end or its timeout (re-review 6). |
| +// to its own end or its timeout (re-review 6). Its directory stays until |
| +// the unit is proven gone (Plan 6 Task 7a, INV-2). |
| func TestRunInterruptedWhileItsStopIsRetriedEndsAt125(t *testing.T) { |
| s := release.NewDirStore(t.TempDir()) |
| rec, req := pickedRun(t, s, 3600) |
| @@ -470,7 +513,11 @@ func TestRunInterruptedWhileItsStopIsRetriedEndsAt125(t *testing.T) { |
| h.interrupt(activator.StopRelease) |
| }() |
| start := time.Now() |
| - res := runWith(t, s, &fakeLauncher{handle: h}, rec, req, newRunHandle()) |
| + w := execWorker(t, s, &fakeLauncher{handle: h}, "boot-1") |
| + res := executeOnly(t, w, s, rec, req) |
| + if _, err := os.Stat(runDirOf(w, req)); err != nil { |
| + t.Fatalf("the run directory went while the unit's stop is unproven: %v", err) |
| + } |
| if res.Interrupted != activator.StopRelease || res.TimedOut || res.Cancelled { |
| t.Fatalf("result %+v, want interrupted by the retirement", res) |
| } |
| @@ -649,6 +696,7 @@ type stoppedDuringPrepare struct{} |
| func (stoppedDuringPrepare) RunCmd(ctx context.Context, rt registry.Route, spec activator.CmdSpec) (activator.CmdHandle, error) { |
| _ = spec.Prepare(ctx) |
| + settled(spec) |
| return nil, &activator.CmdStoppedError{Reason: activator.StopRestart} |
| } |
| @@ -677,6 +725,7 @@ type waitsForSwitch struct { |
| } |
| func (l *waitsForSwitch) RunCmd(ctx context.Context, rt registry.Route, spec activator.CmdSpec) (activator.CmdHandle, error) { |
| + defer settled(spec) // nothing started |
| if err := spec.Prepare(ctx); err != nil { |
| return nil, err |
| } |
| @@ -744,6 +793,7 @@ func (b *blockOneRead) Get(ctx context.Context, key string) ([]byte, string, err |
| type rechecksAfterSwitch struct{ store *blockOneRead } |
| func (l *rechecksAfterSwitch) RunCmd(ctx context.Context, rt registry.Route, spec activator.CmdSpec) (activator.CmdHandle, error) { |
| + defer settled(spec) // nothing started |
| if err := spec.Prepare(ctx); err != nil { |
| return nil, err |
| } |
| @@ -798,3 +848,123 @@ func TestExitOfReadsNumbersAndWords(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// stagedRun is a picked run with one input file, in.csv, in the store. |
| +func stagedRun(t *testing.T, s release.Store) (provision.Record, runs.Request) { |
| + t.Helper() |
| + rec, req := pickedRun(t, s, 60) |
| + body := []byte("a,b\n") |
| + sum := sha256.Sum256(body) |
| + req.Files = []runs.File{{Name: "in.csv", Size: int64(len(body)), SHA256: hex.EncodeToString(sum[:])}} |
| + if _, err := s.Put(context.Background(), runs.InputKey(rec.Account, rec.App, req.ID, "in.csv"), body, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + return rec, req |
| +} |
| + |
| +// executeOnly runs execute with no assertion on the run directory, and |
| +// returns the result it wrote. |
| +func executeOnly(t *testing.T, w *runsWorker, s release.Store, rec provision.Record, req runs.Request) *runs.Result { |
| + t.Helper() |
| + rt, _ := runOwnedRoute(runHost)(runHost) |
| + h := newRunHandle() |
| + w.active[req.ID] = h |
| + w.execute(context.Background(), rec, req, *rt, h) |
| + res, err := runs.ReadResult(context.Background(), s, rec.Account, rec.App, req.ID) |
| + if err != nil || res == nil { |
| + t.Fatalf("no result: %v", err) |
| + } |
| + return res |
| +} |
| + |
| +// Rootfs apps Plan 6 Task 7a (P1 #4, INV-2): the run's directory, with its |
| +// uploaded input, outlives a Stop that did not prove the unit gone. The |
| +// result is written, and the directory goes only when AfterSettled is |
| +// called, as the activator calls it once the unit is proven gone. |
| +func TestRunDirKeptUntilTheUnitIsProvenGone(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + rec, req := stagedRun(t, s) |
| + h := &fakeHandle{polls: make(chan instancectl.CmdStatus, 1), stopErr: errors.New("processes remained")} |
| + h.polls <- instancectl.CmdStatus{State: instancectl.CmdDone, InvocationID: "inv1", Result: "exit-code", Status: "0", Code: "1"} |
| + w := execWorker(t, s, &fakeLauncher{handle: h}, "boot-1") |
| + res := executeOnly(t, w, s, rec, req) |
| + if res.Started.IsZero() { |
| + t.Fatalf("result %+v, want a started run", res) |
| + } |
| + if _, err := os.Stat(runDirOf(w, req) + "/in.csv"); err != nil { |
| + t.Fatalf("the run's input went before its unit was proven gone: %v", err) |
| + } |
| + after := h.settledByStop() |
| + if after == nil { |
| + t.Fatal("the run handed RunCmd no AfterSettled") |
| + } |
| + after() |
| + if _, err := os.Stat(runDirOf(w, req)); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("AfterSettled left the run directory: %v", err) |
| + } |
| +} |
| + |
| +// A start that may have begun (RunCmd's error after the POST, no unit, no |
| +// AfterSettled): the result is start failed and the directory stays until |
| +// AfterSettled. |
| +func TestRunDirKeptAfterAStartThatMayHaveBegun(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + rec, req := stagedRun(t, s) |
| + l := &fakeLauncher{err: errors.New("start cmd unit: timeout"), maybeStarted: true} |
| + w := execWorker(t, s, l, "boot-1") |
| + res := executeOnly(t, w, s, rec, req) |
| + if res.Interrupted != runs.InterruptedStartFailed { |
| + t.Fatalf("result %+v, want start failed", res) |
| + } |
| + if _, err := os.Stat(runDirOf(w, req) + "/in.csv"); err != nil { |
| + t.Fatalf("the run's input went while its start may have begun: %v", err) |
| + } |
| + if l.held == nil { |
| + t.Fatal("the run handed RunCmd no AfterSettled") |
| + } |
| + l.held() |
| + if _, err := os.Stat(runDirOf(w, req)); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("AfterSettled left the run directory: %v", err) |
| + } |
| +} |
| + |
| +// Nothing started: RunCmd's refusal calls AfterSettled before it returns, |
| +// and the directory is gone when execute returns; an incarnation refusal, |
| +// before RunCmd, removes it itself. |
| +func TestRunDirRemovedWhenNothingStarted(t *testing.T) { |
| + plant := func(t *testing.T, w *runsWorker, req runs.Request) { |
| + t.Helper() |
| + if err := os.MkdirAll(runDirOf(w, req), 0o700); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.WriteFile(runDirOf(w, req)+"/in.csv", []byte("a,b\n"), 0o600); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + t.Run("refused by RunCmd", func(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + rec, req := pickedRun(t, s, 60) |
| + w := execWorker(t, s, &fakeLauncher{err: activator.ErrCmdClaim}, "boot-1") |
| + plant(t, w, req) |
| + if res := executeOnly(t, w, s, rec, req); res.Refused != runs.RefusedClaim { |
| + t.Fatalf("result %+v", res) |
| + } |
| + if _, err := os.Stat(runDirOf(w, req)); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("the run directory after a refusal: %v, want gone", err) |
| + } |
| + }) |
| + t.Run("incarnation refused before RunCmd", func(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + rec, req := pickedRun(t, s, 60) |
| + req.Incarnation = strings.Repeat("0", 64) |
| + l := &fakeLauncher{handle: &fakeHandle{}} |
| + w := execWorker(t, s, l, "boot-1") |
| + plant(t, w, req) |
| + if res := executeOnly(t, w, s, rec, req); res.Refused != runs.RefusedIncarnation || l.calls != 0 { |
| + t.Fatalf("result %+v, launches %d", res, l.calls) |
| + } |
| + if _, err := os.Stat(runDirOf(w, req)); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("the run directory after an incarnation refusal: %v, want gone", err) |
| + } |
| + }) |
| +} |
diff --git a/internal/instancectl/client.go b/internal/instancectl/client.go| index 2e2f1a70c..190a3d7f9 100644 |
| --- a/internal/instancectl/client.go |
| +++ b/internal/instancectl/client.go |
| @@ -458,7 +458,7 @@ func setStagedImage(q url.Values, img StagedImage) { |
| // rootfsStopValues is the query of a rootfs termination verb: the role, the |
| // generation of a run role, the name of a worker, kill=1 for a generation |
| -// killed outright, and runtime=rootfs. |
| +// or a one-shot unit killed outright, and runtime=rootfs. |
| func rootfsStopValues(host string, role Role, gen uint64, worker string, kill bool) url.Values { |
| q := hostRole(host, role) |
| q.Set("runtime", runtimeRootfs) |
| @@ -537,13 +537,14 @@ func (c *Client) startRootfsQuery(ctx context.Context, q url.Values, memoryMax i |
| } |
| // StopRootfs stops one rootfs unit of host: the run unit (gen 0), a |
| -// generation, the named worker, or the cmd or tty unit. kill (a generation only) |
| -// kills the generation outright, as StopGen's does. A generation or worker |
| +// generation, the named worker, or the cmd or tty unit. kill (a generation, |
| +// or a one-shot role: the cmd or tty unit, Plan 6 Task 7a) kills the unit |
| +// outright, as StopGen's does. A generation, a worker or a killed unit |
| // whose stop root could not prove (its cgroup still populated) keeps its |
| // files and answers ErrGenUnproven. |
| func (c *Client) StopRootfs(ctx context.Context, host string, role Role, gen uint64, worker string, kill bool) error { |
| status, _, err := c.do(ctx, DeadlineControl, http.MethodPost, "/stop", rootfsStopValues(host, role, gen, worker, kill), nil) |
| - if err != nil && status == statusGenUnproven && (gen != 0 || worker != "") { |
| + if err != nil && status == statusGenUnproven && (gen != 0 || worker != "" || kill) { |
| return fmt.Errorf("%w: %w", ErrGenUnproven, err) |
| } |
| return err |
diff --git a/internal/instancectl/rootfs.go b/internal/instancectl/rootfs.go| index 20a6800c7..efb836217 100644 |
| --- a/internal/instancectl/rootfs.go |
| +++ b/internal/instancectl/rootfs.go |
| @@ -1131,12 +1131,14 @@ func (s *Server) startRootfsCmd(w http.ResponseWriter, r *http.Request, req requ |
| // stopRootfs is /stop with runtime=rootfs: the run unit (with the legacy |
| // start fence, as the binary run unit), a generation (kill=1 kills it |
| -// outright), a worker, or the cmd or tty unit. A stopped unit's files go |
| -// with it: a generation's or worker's drop-in directory and exe layout, a |
| -// cmd's or session's layout, and in every case the unit's jit drop-in. Every role's go only |
| -// once it is proven gone (removeRootfsUnitFiles); unproven, they stay for |
| -// the sweep and the answer is statusGenUnproven for a generation or |
| -// worker, 502 for the run, cmd or tty unit. |
| +// outright), a worker, or the cmd or tty unit (kill=1 kills it outright |
| +// too: the agent's kill at a lease's loss, Plan 6 Task 7a). A stopped |
| +// unit's files go with it: a generation's or worker's drop-in directory |
| +// and exe layout, a cmd's or session's layout, and in every case the |
| +// unit's jit drop-in. Every role's go only once it is proven gone |
| +// (removeRootfsUnitFiles); unproven, they stay for the sweep and the |
| +// answer is statusGenUnproven for a generation, a worker or a kill, 502 |
| +// for the run, cmd or tty unit's plain stop. |
| func (s *Server) stopRootfs(w http.ResponseWriter, r *http.Request, req request) { |
| ctx := r.Context() |
| unit := rootfsUnitOf(req) |
| @@ -1153,7 +1155,9 @@ func (s *Server) stopRootfs(w http.ResponseWriter, r *http.Request, req request) |
| return |
| } |
| } |
| - perStart := req.gen != 0 || req.role == RoleWorker |
| + // A kill's unproven answer is statusGenUnproven whatever the role, so |
| + // the agent types it (ErrGenUnproven) as it types a generation's. |
| + perStart := req.gen != 0 || req.role == RoleWorker || req.kill |
| if req.kill { |
| if err := s.killGen(ctx, req.host, unit); err != nil { |
| s.logf("instance-control: %s: kill %s: termination unproven, files kept: %v", req.host, unit, err) |
| @@ -1168,7 +1172,8 @@ func (s *Server) stopRootfs(w http.ResponseWriter, r *http.Request, req request) |
| // (removeRootfsUnitFiles) and only under the unit's lock, which a start |
| // in flight holds (task 11 fix E6); unproven, they stay for the sweep (a |
| // generation's or worker's are what it finds them by), and the answer |
| - // says so: statusGenUnproven for a generation or worker, 502 otherwise. |
| + // says so: statusGenUnproven for a generation, a worker or a kill, 502 |
| + // otherwise. |
| var err error |
| if OneShot(req.role) { |
| err = s.cleanCmdExe(ctx, req.role, req.host, true) |
diff --git a/internal/instancectl/rootfs_test.go b/internal/instancectl/rootfs_test.go| index 1612cb7c9..ccc8adb24 100644 |
| --- a/internal/instancectl/rootfs_test.go |
| +++ b/internal/instancectl/rootfs_test.go |
| @@ -3367,3 +3367,126 @@ func TestSweepCoversTTYUnits(t *testing.T) { |
| t.Error("no list-units call") |
| } |
| } |
| + |
| +// Plan 6 Task 7a (Call A1): the lease's kill of a one-shot unit. /stop with |
| +// runtime=rootfs, a one-shot role and kill=1 kills the role's rootfs unit |
| +// outright (SIGKILL, then stop), waits for its cgroup to empty, and only |
| +// then removes its layout: 204. A cgroup that stays populated answers |
| +// statusGenUnproven with the layout kept. |
| +func TestRootfsOneShotStopKills(t *testing.T) { |
| + for _, role := range []string{"cmd", "tty"} { |
| + t.Run(role, func(t *testing.T) { |
| + f := rootfsFixture(t) |
| + f.srv.cgroupWaitBudget = 100 * time.Millisecond |
| + unit := RootfsUnitName(roleOf(role), f.host) |
| + if status, body := f.startRole(t, role); status != 200 { |
| + t.Fatalf("start %s: %d %s", role, status, body) |
| + } |
| + dir := RootfsExeDir(f.srv.ExeRoot, provision.InstanceID(f.host), roleOf(role)) |
| + if !exists(dir) { |
| + t.Fatalf("no layout for the %s unit", role) |
| + } |
| + q := url.Values{"host": {f.host}, "role": {role}, "runtime": {"rootfs"}, "kill": {"1"}} |
| + |
| + // Populated: the kill is unproven and the layout stays. |
| + ev := filepath.Join(f.srv.CgroupRoot, parentSlices, SliceName(f.host), unit, "cgroup.events") |
| + if err := os.MkdirAll(filepath.Dir(ev), 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.WriteFile(ev, []byte("populated 1\n"), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + from := len(f.ctl.snapshot()) |
| + if status, body := f.post(t, "/stop", q); status != statusGenUnproven || !strings.Contains(body, "termination unproven") { |
| + t.Fatalf("an unproven kill: %d %s, want %d", status, body, statusGenUnproven) |
| + } |
| + f.ctl.mustHaveCallsInOrderFrom(t, from, "kill --signal=SIGKILL "+unit, "stop "+unit) |
| + if !exists(dir) { |
| + t.Fatal("an unproven kill removed the layout") |
| + } |
| + |
| + // The cgroup empty, but systemd still reports the unit active: |
| + // the layout's proof refuses, and a kill's answer says so as |
| + // statusGenUnproven, the layout kept. |
| + if err := os.WriteFile(ev, []byte("populated 0\n"), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + f.ctl.set("show -p ActiveState --value "+unit, "active\n") |
| + if status, body := f.post(t, "/stop", q); status != statusGenUnproven || !strings.Contains(body, "termination unproven") { |
| + t.Fatalf("a kill whose unit still reads active: %d %s, want %d", status, body, statusGenUnproven) |
| + } |
| + if !exists(dir) { |
| + t.Fatal("a kill whose unit still reads active removed the layout") |
| + } |
| + f.ctl.set("show -p ActiveState --value "+unit, "inactive\n") |
| + |
| + // Proven: the same kill removes it. |
| + from = len(f.ctl.snapshot()) |
| + if status, body := f.post(t, "/stop", q); status != http.StatusNoContent { |
| + t.Fatalf("a proven kill: %d %s, want 204", status, body) |
| + } |
| + f.ctl.mustHaveCallsInOrderFrom(t, from, "kill --signal=SIGKILL "+unit, "stop "+unit) |
| + if exists(dir) { |
| + t.Fatal("the layout survived a proven kill") |
| + } |
| + for _, other := range []string{UnitName(roleOf(role), f.host), RootfsGenUnitName(f.host, 2)} { |
| + f.ctl.mustNotHaveCall(t, "kill --signal=SIGKILL "+other) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// kill=1 stays off every other stop: a rootfs worker's, a binary one-shot |
| +// role's, and the run unit's with no generation are 400; a generation's |
| +// stop takes it as before. |
| +func TestKillStaysOffTheOtherStops(t *testing.T) { |
| + f := rootfsFixture(t) |
| + for _, q := range []url.Values{ |
| + {"host": {f.host}, "role": {"worker"}, "worker": {"jobs"}, "runtime": {"rootfs"}, "kill": {"1"}}, |
| + {"host": {f.host}, "role": {"cmd"}, "kill": {"1"}}, |
| + {"host": {f.host}, "role": {"tty"}, "kill": {"1"}}, |
| + {"host": {f.host}, "role": {"run"}, "kill": {"1"}}, |
| + {"host": {f.host}, "role": {"run"}, "runtime": {"rootfs"}, "kill": {"1"}}, |
| + {"host": {f.host}, "role": {"cmd"}, "runtime": {"rootfs"}, "kill": {"true"}}, |
| + } { |
| + before := len(f.ctl.snapshot()) |
| + if status, body := f.post(t, "/stop", q); status != http.StatusBadRequest || !strings.Contains(body, "kill=1 belongs to a generation stop only") { |
| + t.Errorf("%v: %d %s, want 400", q, status, body) |
| + } |
| + if calls := f.ctl.snapshot()[before:]; len(calls) != 0 { |
| + t.Errorf("%v: a refused stop asked systemd %v", q, calls) |
| + } |
| + } |
| + if status, body := f.post(t, "/stop", url.Values{"host": {f.host}, "role": {"run"}, "gen": {"3"}, "kill": {"1"}}); status == http.StatusBadRequest { |
| + t.Errorf("a generation's kill: %d %s, want it taken", status, body) |
| + } |
| + f.ctl.mustHaveCall(t, "kill --signal=SIGKILL "+GenUnitName(f.host, 3)) |
| +} |
| + |
| +// The client types an unproven one-shot kill as ErrGenUnproven, as it does |
| +// a generation's or a worker's; an unproven plain stop of the cmd unit |
| +// stays a plain error. |
| +func TestStopRootfsTypesAnUnprovenOneShotKill(t *testing.T) { |
| + f := rootfsFixture(t) |
| + f.srv.cgroupWaitBudget = 100 * time.Millisecond |
| + c := f.client(t) |
| + ctx := context.Background() |
| + if status, body := f.startRole(t, "cmd"); status != 200 { |
| + t.Fatalf("cmd: %d %s", status, body) |
| + } |
| + unit := RootfsUnitName(RoleCmd, f.host) |
| + ev := filepath.Join(f.srv.CgroupRoot, parentSlices, SliceName(f.host), unit, "cgroup.events") |
| + if err := os.MkdirAll(filepath.Dir(ev), 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.WriteFile(ev, []byte("populated 1\n"), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := c.StopRootfs(ctx, f.host, RoleCmd, 0, "", true); !errors.Is(err, ErrGenUnproven) { |
| + t.Fatalf("an unproven one-shot kill: %v, want ErrGenUnproven", err) |
| + } |
| + f.ctl.set("show -p ActiveState --value "+unit, "active\n") |
| + if err := c.StopRootfs(ctx, f.host, RoleCmd, 0, "", false); err == nil || errors.Is(err, ErrGenUnproven) { |
| + t.Fatalf("an unproven plain cmd stop: %v, want a plain error", err) |
| + } |
| +} |
diff --git a/internal/instancectl/server.go b/internal/instancectl/server.go| index 1d4a8e0db..fffc3337f 100644 |
| --- a/internal/instancectl/server.go |
| +++ b/internal/instancectl/server.go |
| @@ -642,7 +642,11 @@ func parseQuery(host string, q url.Values, v verbShape) (request, error) { |
| req.gen = n |
| } |
| if q.Has("kill") { |
| - if !v.kill || req.gen == 0 || q.Get("kill") != "1" { |
| + // A generation's stop, or (rootfs apps Plan 6 Task 7a, Call A1) a |
| + // rootfs one-shot unit's: the agent's kill of a run or a session at |
| + // its lease's loss. No other stop takes it. |
| + oneShot := req.rootfs() && v.rootfsStop && OneShot(req.role) |
| + if !v.kill || (req.gen == 0 && !oneShot) || q.Get("kill") != "1" { |
| return request{}, errors.New("kill=1 belongs to a generation stop only") |
| } |
| req.kill = true |
diff --git a/internal/provision/rootfs_apps_6_census_test.go b/internal/provision/rootfs_apps_6_census_test.go| index 275aba425..8ea25cdb8 100644 |
| --- a/internal/provision/rootfs_apps_6_census_test.go |
| +++ b/internal/provision/rootfs_apps_6_census_test.go |
| @@ -22,12 +22,17 @@ package provision |
| // ExecStopPost= runs it (PF-9); the role parsing, its refusals and the |
| // -run-dir usage text naming instances/<id> are unchanged, nothing |
| // written. |
| +// - Task 7a: runsWorker.finish passes a removeDir argument through to |
| +// cleanUp (true only for the incarnation refusal before RunCmd: the run |
| +// directory otherwise waits for CmdSpec.AfterSettled, INV-2); the |
| +// result write and the one SetRecordRun (runFinishOurs) are unchanged. |
| func rootfsApps6WriteCensusInventory() []censusEntry { |
| entries := append([]censusEntry(nil), fleetPublicRoutesWriteCensusInventory()...) |
| replacements := []censusEntry{ |
| {"internal/provision/reconcile.go", "Reconcile", "key-site", "key:ParseRecordKey,key:RecordKey,lit:instances", "be1b699f14a2f8d6935d959dee168bdf6fb556cd78da458f5ba8a1c0e8512a17"}, |
| {"internal/console/authcli.go", "Server.registerCLIRoutes", "key-site", "lit:instances,lit:sidecars", "93f090dcda4e5364f3cff993cebfc1385550039316a59aacaba72ba933ba14b3"}, |
| {"internal/instanceexec/exit.go", "parseExitArgs", "key-site", "lit:instances", "be3a7828e292b4977c42f21d8283fc9d185505ced9ffdf2543267a88bc8033a9"}, |
| + {"internal/host/runexec.go", "runsWorker.finish", "record-writer", "key:SetRecordRun", "f586bc77d175652d19bed1e7cceb7ecad523f7a1125bc798c19109e0a4f55ee2"}, |
| } |
| for _, r := range replacements { |
| found := false |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index b6feb521d..c618ba15b 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -43,4 +43,4 @@ plan14-root-reads-region-ha-dead-holder-backoff.tsv 8f6a1865b0abcea9d4fb68232cc2 |
| plan14-root-reads-managed-fleets-1c-451.tsv af326671321edda76c7e6217a47892605a9e3b886fa880ad6d049c2f28f63873 |
| plan14-root-reads-fleet-public-routes.tsv bca6ef741a96b72767b1747789cd01b3111d61b68548cbe368258c31f3d53a2e |
| plan14-root-reads-fleet-routes-followups.tsv 1379d066c8dd2335d95d5f6e9c7bce65ff57f00b2b287a308d9b3f47911ae5e7 |
| -plan14-root-reads-rootfs-apps-6.tsv 44581c3700aa3a72c593ef0493663ee42b2c9425231efbfbb6d67abd3a6fced8 |
| +plan14-root-reads-rootfs-apps-6.tsv a423737430ea5ec92dd0f268aaa519463cd43c0f790cb730542121aca5b58d29 |
diff --git a/internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv b/internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv| index 4d6e83973..736b96d6b 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-rootfs-apps-6.tsv |
| @@ -1,7 +1,12 @@ |
| # Census overlay rootfs-apps-6, written by census-propose (#369). census-ruling-rootfs-apps-6, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-rootfs-apps-6.md. |
| -# 12 body, 0 sites, 7 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +# 17 body, 4 sites, 9 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| # 1 removed: each unit's declaration, or each envelope's directory, is absent from the scanned tree, so its row goes, a frozen declaration is retired as absent, and an envelope is retired. |
| -# 4 new dispositions: 0 reads re-frozen at their disposition with the claim, 4 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other. |
| +# 12 new dispositions: 0 reads re-frozen at their disposition with the claim, 12 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other. |
| +@legacy 1f6bcc9cf0f66285a303c9d14a8ac511b721f7941c0fe45c18eeaf5ec7c42662 internal/activator/activator.go Service.installProcLocked legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8: the one place a process, its generation and the lease replica are installed on an entry; a resident is put under its lease watch (watchResidentLeaseLocked) at that moment; reads only the entry's route;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (Call A1, Astra R1 P1-1): the lease watch is installed for every rootfs row (e.route.Rootfs()), not only a resident, so a hibernating rootfs row's run or session is reached at the lease's loss; the same one read of the entry's route; installs nothing else whole:Route@144 cacc399eb6e09be70d3a2ad1774800fb6a252590cebd62dd0e9f369e97275f81 |
| +@legacy a3fb62ce1d8e3c0003ac3404e257da6a6069b7761f4327cb559844ae0ac4fcbc internal/activator/backend_rootfs.go ExecBackend.StartRelease legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1: new; startRootfsCmd naming release.ProcessRelease, both streams through one capped line writer (releaseOutput, runs.MaxOutputBytes) into the caller's writer; no read of its own;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: passes rootfsCmdLaunch{Process: release.ProcessRelease} to startRootfsCmd in place of the bare process name; its /cmd request and launch.cmd.json are byte-identical to before (TestStartReleaseIsUnchanged, goldens written from 3fd3c3a4); no read added registry:Host@182,whole:Route@247 9dd1cb5cf2b170f59e5e46a121a665bd0ca4d6c9698aab63804880848b5ee9ee |
| +@legacy a743ccbd44c9d21980323e3e2ccdaf87d2b602a5408bca7d5a882c1d5d453fe3 internal/activator/cmdunit.go type CmdSpec legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): declaration only; Prepare is a callback field, not a prepared statement;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: declaration only: gains AfterSettled, a callback field the caller sets (the box's run pass removes the run's directory in it), called once when no unit of the run can be running; reads nothing file:Prepare@487 f3c596b537f466e707f4974aa06065fb08bebb4a89749c8d6138810c9aa0a5b2 |
| +@legacy 2d9c727dee13d2655dcd898f0f5aecaa20902fa217ea6cf20a3ecce21e657388 internal/activator/rootfs_service.go Service.residentLeaseLost legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8 (C7): a resident's lost lease marks it and then kills its generations off a.mu (killResidentGens);rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.10: a resident's lost lease stops its workers (stopRootfsWorkersAtLoss, proven gone) in parallel with killResidentGens; rt is taken under the lock and passed to killResidentGens in place of e.route (the same route); site +whole:Route (that local rt); no file read;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (Call A1): residentLeaseLostLocked also returns one kill func per one-shot unit that may run; each runs off a.mu in the same WaitGroup as stopRootfsWorkersAtLoss and killResidentGens, which still run only for a resident (gens non-nil); the kills go to root's existing /stop through KillOneShot; no read added whole:Route@137,whole:Route@394 64ce2f74e65941ea2a731518c773cb9b27456f2db298c69ed4e02de375b1777f |
| +@legacy 6d257f47ef6aac75f3139d8e0ea689774fb9bd3bfca50c0f321573a483ded5e9 internal/host/runexec.go runsWorker.execute legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): runs one picked run to its result in the bucket; every root action goes through instance control;rev3=PROPOSED-325;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=emits the run's start and end as member log events through the agent's EventSink; reads unchanged;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (INV-2): sets CmdSpec.AfterSettled to remove the run's directory (runs.RemoveRunDir under the instance's own directory, as cleanUp did) once the activator has proven no unit of the run runs; finish and cleanUp take removeDir, true only on the incarnation refusal before RunCmd; the directory goes later or at the same point, never earlier; no read added file:Prepare@1905,whole:Route@2916 43bd160066b4d3e7aef00e3891001bc5ffa9a40f597cb6e5cc7215eae2814df9 |
| @legacy ee96c9cf9e4e6b0dea8325a3eaf0053773b3a20d3940afe881a0db8aa71b2d23 internal/host/units/carlos-instance-cmd@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the cmd unit template (applied by PID 1 as root; its process runs as carlos): extends the J4 seed pattern to the run role. The template equals the seed template outside named lines, and the template-equality test pins that. Root lays out a staged executable validated by the same refuseStagedExe the seed and generation paths use, then starts this unit, which runs as carlos with the instance's own reach. No new trust of registry, /data or agent-asserted content beyond the seed path;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else file:external@0 925113f4c51c091f0da65c2c67c5902aa35ab37abbe6491ca935820517e8149d |
| @legacy c986824bab7acb9d785c21f3a48d18f8e678d9252eaea80839ec869f52787a5e internal/host/units/carlos-instance-gen@.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else file:external@0 0bd25fefd9306449d55e235e9bd8986466bc4cd68ad56b5614d32596ce39c262 |
| @legacy 4cb19ff14f607602d752f0e329036d5c52eb64f4b1547b2116918b77cb5f4af1 internal/host/units/carlos-instance-probe.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-2;basis=one more BindReadOnlyPaths= line, so PID 1 opens one more bind source: /run/carlos-control/exe/_probe/box-addrs, bound to /opt/carlos/box-addrs, root's list of the box's own addresses, which RunProbe writes before every run (#367) in the root-only directory the unit already binds from; no tenant, app or agent input names or writes it;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service, so the probe proves what the tenants get (its new pts-private line); fix round 1 (Astra P2, roll order): one line outside the namespace block, Environment=CARLOS_PROBE_PTS_PRIVATE=1, a constant the unit sets for its own process (the probe, as carlos, in the namespace); it names no path, adds no bind source or Exec line, and root reads nothing new file:external@0 a803c8e83ffd95ceca691e0c47e623acfa50e88dcddd3166e6660473aa86695b |
| @@ -14,10 +19,27 @@ |
| @legacy eaf433e09f4fce09c3df3357d5811657d4db19eb29eccd96df40666f382fb49d internal/instanceexec/probe.go productionProbeEnv legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-2;basis=the binary probe's env gains boxAddrs (instancectl.BoxAddrsPath, /opt/carlos/box-addrs), which boxAddrClosed (a decision row) reads inside the probe unit, and mmapWX (realMmapWX, an anonymous mapping); the same one direct site;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5 (PF-8): the binary probe env sets devPts=/dev/pts and openPtmx (open /dev/ptmx O_RDWR|O_NOCTTY and close at once), the fields the rootfs probe env already set; read by the new pts-private line inside the probe unit (as carlos, in the namespace); fix round 1: also reads its own environment, CARLOS_PROBE_PTS_PRIVATE (exactly "1" enforces pts-private; otherwise the line is reported unverified), which the probe unit sets; the same direct site, no new root read data-literal@67 9de3096aec14bb54d72ee47eceb866cc2b6b80fcda8206cf9a4d5476f0f0d177 |
| @legacy 7282b3718ce918bbd9d7e4dce31a4737bca6eddb45048749c502c8261c740cf8 internal/layout/plan.go NestedPlatformNames legacy accepted-legacy accepted-legacy;rev3=census-ruling-moves-offline;basis=root-input (J4, as main's moves units); the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): new, called only from the agent's offline sealer and source retire (IsNestedPlatformName): a fixed list of names, reads nothing;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the fixed role list gains RoleTTY, so launch.tty.json is one more fixed platform name; still reads nothing data-literal@84 faf3813dcb08f2e153a45b53f4461899327775c298419fc7fe817e80110119d0 |
| @legacy 438a9858d01281800b89923ab2c4bf47bba5c3eab23e07fe43af9a5e3a9ae755 internal/provision/reconcile.go Reconcile legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), from its reconcile loops: each listed record is observed through the box's lifetime judge (ObserveWith: the record, then its host incarnation slot) before the shape, channel and scope checks, a stale record is left out and an unjudgeable one protected; the removal phase observes a row's own record key when the pass holds none for it under that key, and deletes a held row whose record is gone or stale through DeleteIfHold; a nil judge (claims on) is main's body; registry read sites unchanged, offsets moved; fix round 1: the removal phase observes a row's own key only under an account the listing trusts, so a retired or unmaterialised account's row keeps record gone, and the pass arms its own context with the judge; Task 7: under a judge an existing provisioned row of the record's own app and account follows the existing-row rules (heldByVanishedPredecessor and retireHeldPredecessor's DeleteIfHold first, the record then minted on the same pass; the hold; installRowLifetime), each a separate write under the host's hold lock; registry read sites unchanged, offsets moved;rev3=census-ruling-instance-egress-sizes-328-329;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=#328/#329 plan 1 Task 7: the pass reads its apps' policy objects (control/app-policy/<sqid>/<app>.json in the bucket) through the agent's PolicyCache, each verified with ReleasePub by apppolicy.VerifyKey (ed25519 over the policy's own domain line, bound to the account and app, unexpired, not future-dated; anything else is no policy), and carries the columns into its rows. New kinds registry:EgressAllow, registry:Size and registry:PolicyExpiresAt, one site each, all the assignment of a fresh row's columns (nr) from policies.cols; plus one whole:Route site, the existing row handed to policies.forRow. Other read sites unchanged, offsets moved; the agent's own pass, no root decision;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos, from its reconcile loops: after the scan, hands the in-scope records to cfg.Lifetimes (the box's lifetime index): Merge after a failed read or partial listing, Replace after a complete one, nothing on a dry run or with no index; the scan, judge and removal phases unchanged; the same 166 sites, no read added;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 2 and 5 (D5, spec §5.0): a seeded record over a row with a runtime is skipped and logged; a row with a runtime (or a new record with one) takes no seed; runtime and a rootfs row's hibernation are never converged from a record (a mismatch is logged; a record claiming a runtime its row lacks is not applied); reads Runtime of the record and the row; the box writes less; fix wave 1 (ceea6353, whole-branch P1-2): before minting a row for a record with no runtime and no row (both mint paths), the pass reads the app's kind marker once per app per pass (release.ReadAppKindMarker: one GET of the create-only kind.json from the release store s, through freshStore, validated by readAppKindMarker); a rootfs marker leaves the record unmaterialized and logged (an older console stripped its runtime), and a marker that cannot be read defers the mint this pass; a refusal before minting only, registry read sites unchanged, the box writes less; fix wave 2 (whole-branch r2 P1): the kind-marker read and its refusal apply only to a socket-backed instance record (DerivesPaths), so a static or upstream-backed record of a rootfs app, which carries no runtime by design, is minted as before with no read; fewer reads, registry read sites unchanged;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 10: the forward phase on the hub (FleetOwners set): the scan keeps the fleet-placed records it skips and counts records per host; a trash-only marker prefetch; disputed (failed-GET) hosts; armed, a host an in-scope and a fleet record both name is given neither, its journal waits and the removal phase keeps its row (+registry:Account, +registry:App, +registry:Host x2: the collision guard, its log line and report mark); the instance loop leaves a forward host; retirable excludes forward rows. Same record keys; writes only the registry (PutForward, DeleteForward); no bucket write.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 3: in the per-record loop, beside the RunSeen call, calls cfg.InteractiveSeen(rec) when the hook is set and the in-scope record carries an interactive-session marker (rec.Interactive != nil), once per record per pass, before the pass acts on it; the hook is the box worker's non-blocking note (Task 12). Same record keys and literal; no read added (registry read sites unchanged, 178); nothing written by the call registry:Account@36233,registry:Account@37498,registry:Account@55577,registry:Account@55623,registry:Account@56467,registry:Account@56844,registry:Account@57070,registry:Account@57137,registry:Account@57183,registry:Account@57276,registry:Account@57318,registry:Account@57966,registry:Account@58224,registry:Account@58764,registry:Account@58812,registry:Account@59185,registry:Account@59231,registry:Account@59476,registry:Account@59901,registry:Account@60389,registry:Account@61125,registry:Account@61318,registry:Account@61664,registry:Account@62229,registry:App@36206,registry:App@37471,registry:App@55597,registry:App@55635,registry:App@56479,registry:App@56856,registry:App@57082,registry:App@57157,registry:App@57195,registry:App@57296,registry:App@57978,registry:App@58236,registry:App@58776,registry:App@58824,registry:App@59205,registry:App@59243,registry:App@59488,registry:App@59913,registry:App@60401,registry:App@61137,registry:App@61330,registry:App@61676,registry:App@62241,registry:ClaimOwnership@36820,registry:DBPath@45677,registry:DBPath@45692,registry:DBPath@45938,registry:DBPath@46541,registry:DBPath@46554,registry:EgressAllow@35319,registry:Gate@42022,registry:Gate@42162,registry:Gate@42449,registry:Hibernate@40694,registry:Hibernate@40892,registry:Hibernate@40957,registry:Hibernate@41296,registry:Hibernate@41647,registry:Hibernate@41957,registry:HoldOp@60870,registry:HoldOp@60961,registry:HoldOp@61096,registry:HoldOp@61472,registry:Host@26327,registry:Host@55556,registry:Host@56443,registry:Host@56820,registry:Host@56984,registry:Host@57090,registry:Host@57986,registry:Host@58192,registry:Host@59068,registry:Host@59340,registry:Host@59455,registry:Host@59778,registry:Host@59875,registry:Host@60266,registry:Host@60363,registry:Host@60577,registry:Host@60952,registry:Host@61087,registry:Host@61291,registry:Host@61364,registry:Host@61463,registry:Host@61638,registry:Host@61713,registry:Host@61799,registry:Host@62206,registry:Kind@36962,registry:Kind@37225,registry:Kind@45595,registry:Kind@45608,registry:Kind@45718,registry:Kind@45731,registry:Kind@46452,registry:Kind@46463,registry:Kind@54680,registry:Kind@60568,registry:Kind@61078,registry:Kind@61454,registry:Kind@61629,registry:Kind@61790,registry:PolicyExpiresAt@35344,registry:Pool@54766,registry:Provisioned@36182,registry:Provisioned@37447,registry:Provisioned@54725,registry:RateLimit@42535,registry:RateLimit@42686,registry:RateLimit@42973,registry:Region@54755,registry:Replication@41381,registry:Replication@41508,registry:Runtime@28984,registry:Runtime@29162,registry:Runtime@31367,registry:Runtime@40061,registry:Runtime@40115,registry:Runtime@40319,registry:Seed@44075,registry:SeedSource@43558,registry:Size@35335,registry:Socket@45643,registry:Socket@45658,registry:Socket@45955,registry:Socket@46511,registry:Socket@46524,registry:Unit@45561,registry:Unit@45574,registry:Unit@46478,registry:Unit@46489,whole:ClaimOwnership@36823,whole:ClaimOwnership@36840,whole:Route@26309,whole:Route@26320,whole:Route@26338,whole:Route@27619,whole:Route@29479,whole:Route@29486,whole:Route@29526,whole:Route@29887,whole:Route@30225,whole:Route@30672,whole:Route@30723,whole:Route@30760,whole:Route@32432,whole:Route@32641,whole:Route@32980,whole:Route@32989,whole:Route@33035,whole:Route@35268,whole:Route@35827,whole:Route@36298,whole:Route@36308,whole:Route@36665,whole:Route@36672,whole:Route@36740,whole:Route@37063,whole:Route@38096,whole:Route@41047,whole:Route@45787,whole:Route@47373,whole:Route@47418,whole:Route@47428,whole:Route@48298,whole:Route@49325,whole:Route@54791,whole:Route@54939,whole:Route@56036,whole:Route@56395,whole:Route@56777,whole:Route@61551,whole:Route@62136,whole:Route@62186 be1b699f14a2f8d6935d959dee168bdf6fb556cd78da458f5ba8a1c0e8512a17 |
| +@legacy 9445b2cd43f346e302fb258e6dbaab84278b049edd9ac5d90cd452e2a7df3176 internal/activator/backend_rootfs.go ExecBackend.KillOneShot legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (Call A1), new: a rootfs row only (else errOneShotKillBinary) and a one-shot role only (cmd or tty): StopRootfs(host, role, 0, no worker, kill) to root's existing /stop on DeadlineControl, then waitRoleCgroupEmpty (unitEvents on the role's rootfs unit) on roleEmptyBound; nil is the proof; the registry:Host sites are log and error text and the host passed to root, which names the unit from its own validated host registry:Host@1027,registry:Host@154,registry:Host@279,registry:Host@374,registry:Host@433,registry:Host@563,registry:Host@661,registry:Host@720,registry:Host@958,whole:Route@881 46947416ed240d9e94383816308df5fcd6181a8fe7b0df166bc0cba4768b6836 |
| +@legacy f3315ebf8463f7ed07168e6eb6b6395ca72b89d38a2398681e4470882cac93d5 internal/activator/backend_rootfs.go ExecBackend.startRootfsRun legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: StartCmd's rootfs arm: refuses a run with no serving image (errNoCmdExe) or a partial one (errPartialStagedIdentity), both marked, and one with no launch environment (errNoGenEnv); asks replicaKeyGate; composes rootfsCmdVars over the generation's launch environment and the row's dbPath; then startRootfsCmd with the operator's argv exactly as given; root validates the image by digest and runs the argv inside the instance's namespace; the registry:Host sites are error text registry:Host@192,registry:Host@450,registry:Host@587,whole:Route@773,whole:Route@874,whole:Route@902,whole:Route@969 28ac40abb07e2561c7b8bf0e75d79645d2b20dfb8f5a05cfe33cb0b0ba350da5 |
| +@legacy c6d7609e34806d3c51e249713109f3bb9bae3c0645d4b6bf9f8190e48f9ce88b internal/activator/backend_unit.go SplitBackend.KillOneShot legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: forwards KillOneShot by pick(rt), as KillGen does; a half without it refuses (errOneShotKillBinary); reads only the route registry:Host@219,whole:Route@123,whole:Route@286 59823fbe5e35c5b54e0843a681ad59f684bd28e3a8315c1571198b3e5c43d3ee |
| +@legacy d6543d9dad5ac1da40d0cbaaa7cfefb37f8c0b473c902957dc27420a61371899 internal/activator/cmd.go Service.killOneShot legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: the backend's KillOneShot (oneShotKiller) for one run, bounded by DeadlineControl plus roleEmptyBound, logged either way; the registry:Host sites are log lines registry:Host@240,registry:Host@549,registry:Host@680,whole:Route@398 3eb9bb7269c2a5fc8d4c798d884d92f7fa32eddbde588a3c9ad2d741211b869b |
| +@legacy acd4a733f1d39bf9444302ee997852e46f6cdd946f2d68b1baa7c9b02400ea6b internal/activator/cmd.go Service.stopOneShotAtLease legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: one run hold's lease stop, off a.mu: with kill, killOneShot at once and again once a start that was in flight returns a unit; then the hold's own stop (StopLeaseLost) bounded by cmdStopBound; the registry:Host sites are log lines registry:Host@714,registry:Host@961,whole:Route@309,whole:Route@529 46c39957f77353866dc7d8adbababfde54bd8634f5669fd61c3011a54f5e7c9a |
| +@legacy 58054c1bdae99b3fcd68352771c4e1f1d34650d1d17a9e87379ddb2284425a06 internal/activator/cmd.go Service.stopOneShotsAtLeaseLocked legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: one stopOneShotAtLease func per run hold that may be running (cmdHoldsLocked), none for a binary row (rt.Rootfs()); in memory only whole:Route@240 985fd564c12bf8f0339915e776d38d3139eb28b7c44c047bd91bbfd9fad3792d |
| +@legacy 6d3fbdea661079d19e104dae75e1fe1943ee5fbaf40435e501b5afd8d4bd2c98 internal/activator/rootfs_service.go Service.residentLeaseLostLocked legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: a census unit now (two whole:Route sites, e.route to stopOneShotsAtLeaseLocked and e.route.Resident()): also returns the one-shot kill funcs of any rootfs entry that is the host's, whatever its state; a hibernating entry gets no stop and no generation kills; in memory only whole:Route@198,whole:Route@218 6266ff6af94cc58e1226f3921da636cc6fa7d365340ecce216f0493d2d7e97a7 |
| +@legacy 44b446f87f5f55a32ba63c481687b01c59c7a8c20d2b41ff82b9a37709081399 internal/activator/rootfs_service.go Service.residentLeaseShort legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: a census unit now (two whole:Route sites, e.route to stopOneShotsAtLeaseLocked and e.route.Resident()): stops every one-shot unit that may run, whatever the entry's state, off a.mu; begins a resident's graceful stop only while it is awake, as before; in memory only whole:Route@188,whole:Route@377 c39a0d4aeb53d0608e3c3e95ea3742ef6dab8ea3419a061a3415ffe5c491ecfe |
| @legacy 14cec7be2873b15f373f40e319f5c6c61d441f521121499f2a04b331bd3453f3 internal/host/units/carlos-instance-rootfs-tty@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5, new: the rootfs tty template, carlos-instance-rootfs-cmd@.service outside named lines held by TestRootfsTTYTemplateEqualsRootfsCmdOutsideTheNamedLines: Description (tty), ExecStart/ExecStopPost instance-exec/instance-exit --rootfs tty %I, StandardInput=file:/run/carlos/logs/%I.tty.sock with StandardOutput/StandardError=journal, and RootImage plus the two BindReadOnlyPaths sources under /run/carlos-control/exe/%I/rootfs/tty/ (root-only exe layout) instead of rootfs/cmd/. The rootfs namespace block byte for byte (TestRootfsTemplatesShareOneNamespace), runs as carlos, binds only the instance own and root paths (TestRootfsTemplatesBindOnlyTheInstancesOwnAndRoots). Task 6: POST /tty runtime=rootfs (startRootfsCmd with RoleTTY) starts it through Plan 2's rootfs one-shot path (preflight, validateStagedImage, ensureRootfsExe under rootfs/tty/, jit drop-in and owed reload, post-start MemoryDenyWriteExecute check); its files go only through removeRootfsUnitFiles (stopRootfs and cleanCmdExe with RoleTTY, the sweep) file:external@0 d57f6d6fbe553e5ba5a5762ab2bd72586835ce1db748b67044edd1bf90af6953 |
| @legacy b18625dfcfcaa6d4e0ae128e2b77ad7fb53d0a4206458b43ef4125d248e6ef58 internal/host/units/carlos-instance-tty@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5, new: the binary tty template, carlos-instance-cmd@.service outside six named lines held by TestTTYTemplateEqualsCmdOutsideTheNamedLines: Description (tty), ExecStart/ExecStopPost instance-exec/instance-exit tty %I (the same root binary as every template), StandardInput=file:/run/carlos/logs/%I.tty.sock replacing the cmd StandardOutput socket (PID 1 opens it as root on the nosymfollow logs mount, as the cmd streams), StandardOutput=journal, StandardError=journal, and BindReadOnlyPaths sources tty-app/tty-live under /run/carlos-control/exe/%I (root-only exe layout, as cmd-app/cmd-live). Same namespace block byte for byte, runs as carlos. Task 6: POST /tty (handleOneShot(RoleTTY), claimAwareLegacy) starts it, after the role lock, the loaded-state refusal and refuseStagedExe; the tty-app/tty-live sources are laid out by ensureCmdExeAt(RoleTTY) and removed by removeCmdExe(RoleTTY) at /stop role=tty and /sweep file:external@0 060295d0956afad52db77dba1988c508cf4289f9b5a18242a206a315145b8e0d |
| @legacy 9491fe16a762f2bfb2e6b288428f67b157b813d01c226917ec4c3366ebffb305 internal/instancectl/cmd.go Server.oneShotStatus legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 6: handleCmdStatus's body moved whole and made role-aware (it serves GET /cmd/{host} and GET /tty/{host} through handleOneShotStatus(role), both claimAwareLegacy): the same three file:Query sites (the URL query read for the invocation, for parseQuery and for the role check); the role check now refuses any role field but the route's own (role=tty on /cmd and role=cmd on /tty are 400, before any show); the unit shown is UnitName(role, host) or RootfsUnitName(role, host) for runtime=rootfs, a name root builds from a validated host and a route constant; read-only systemctl show, starts and stops nothing; no file read added file:Query@1090,file:Query@384,file:Query@759 9ea847d9a1e6b0e0929f27b27a9ade5c783c0de1ba0d997523c939be8293e701 |
| @legacy 8e00efef4ecab3057d44b14e01fba5aa93e5359ba841c4fea91b57487481202f internal/instanceexec/tty_linux.go receivePTY legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7 (PF-9), new: the trampoline's tty role, run by instance-exec [--rootfs] tty %I as carlos inside the instance's namespace (never root): one recvmsg on its own stdin (the tty unit's StandardInput= socket to the agent), exactly the hello carlos-tty/1 and exactly one SCM_RIGHTS fd (received close-on-exec), else refused with every received fd closed; the one Fstat is of that received fd, which must be a character device of a Unix98 pty slave major (136-143) that answers TCGETS, else refused and closed; it opens, runs and follows no path; the fd becomes only the tenant's stdio and controlling terminal (runTTYInit through runInitChecked, which closes the init's copy after the fork); no root process reads anything new file:Fstat@1454 1099af8a1dc0732b74afbe42bc45ccce6df3db9662ff7dc41f278e2bd4a274ce |
| +@legacy 97a58a2321cfbf2ad11c05eb4b6d1f681d249c0b40391cb4ebe293d4cc66da4e internal/activator/backend_rootfs.go ExecBackend.startRootfsCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1 [pf R0.1, R1.4]: new; the agent's first caller of root's existing CmdRootfs (POST /cmd to root's control socket, unchanged). In order: rootfsGates; refuses a partial staged identity (version, path, digest); rootfsControl; prepare(rt, RoleCmd) (the instance's own directories); two stream listeners on the agent's own log sockets (logSocketNamed); the schema-2 launch file for RoleCmd with env alone (writeRootfsLaunchFor, the same writer and the same root reader as the web start's RoleRun file, rootfsLaunchEnv: never the agent's own environment); the caller's exec gate (runExecGate); then CmdRootfs(host, the row's tier memory.max, StagedImage{staged path, version, digest, process}), process being a declared process name root checks against the staged manifest. ErrStagedImage and ErrStartRefused are refusals with no unit; any other error returns a unit to stop and settle. Root validates the staged image and the process itself (instancectl, unchanged); registry:Host sites are log lines, socket and unit names;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: takes a rootfsCmdLaunch, a declared process or an operator's argv, exactly one or refused before anything is laid out; the launch file names the process or cmd, never an argv; CmdRootfs names the image with the process or with the argv in the request body, which root validates against the staged image itself (instancectl, unchanged); new site +registry:Host is that refusal's message registry:Host@1056,registry:Host@1175,registry:Host@1239,registry:Host@1357,registry:Host@1529,registry:Host@1953,registry:Host@1993,registry:Host@2305,registry:Host@2629,registry:Host@2756,registry:Host@2854,registry:Host@303,registry:Host@473,registry:Host@727,registry:Host@899,whole:Route@2009,whole:Route@2694,whole:Route@2698,whole:Route@2897,whole:Route@2935,whole:Route@2939,whole:Route@544,whole:Route@947 92d9513d414706d8e94e320826b512272210f73130e1e700d94c540afec0b346 |
| +@legacy 24677dea5779d57c560884eebbeea0abdcb9389b985089aefd1bf4f44bcc7b7f internal/activator/cmd.go Service.RunCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): admits one run against an awake entry under the agent's own lease, fence and swap checks; it starts nothing itself and root validates what it later names;rev3=census-ruling-edge-request-records;basis=passes nil for begin's new req parameter; no read added;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: a carlos run is refused with ErrCmdBusy while a release record of the host is open (a.releaseOps[rt.Host], in-memory), as a run already in flight refuses it; new site +registry:Host (that map lookup); adds a refusal only;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: AfterSettled honoured on every path (called before return on each path that starts no unit, else by the settle that proves the unit gone); a rootfs run is refused as a lost lease (CmdStoppedError StopLeaseLost) when its entry is not under the lease watch (residentWatchedLocked), and, off a.mu, when the replica's in-memory SafeUntil leaves less than oneShotStartLead (oneShotHeadroom); new sites are e.route.Rootfs() and a log line; adds refusals only file:Prepare@2243,file:Prepare@2277,registry:Host@1371,registry:Host@1696,registry:Host@7249,registry:Host@8485,registry:Kind@437,whole:Route@683,whole:Route@7653,whole:Route@8117,whole:Route@8650,whole:Route@869 36a03283c6c294123e02bb1779bcc6ad0ae273f69297ab35ff37e95cf2e52d8d |
| +@legacy 170b90032d9379a8456afec905fc67a0ef82176b56fa2a8d841f39a9a010b7f8 internal/activator/cmdunit.go ExecBackend.StartCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): writes launch.cmd.json in the instance's own directory and asks instance control to start the cmd unit; root validates the staged executable it names (refuseStagedExe) and decides the start;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: after the layout and run-directory checks, a rootfs row returns startRootfsRun (backend_rootfs.go) before nestedGate; the binary path is byte-identical (TestBinaryStartCmdLaunchGolden); new site +whole:Route is rt.Rootfs() registry:Host@1576,registry:Host@1700,registry:Host@1764,registry:Host@1887,registry:Host@2034,registry:Host@218,registry:Host@2188,registry:Host@2316,registry:Host@2404,registry:Host@2808,registry:Host@2877,registry:Host@2928,registry:Host@343,registry:Host@624,registry:Host@706,registry:Host@810,whole:Route@130,whole:Route@1360,whole:Route@1467,whole:Route@2086,whole:Route@2332,whole:Route@2420,whole:Route@2740,whole:Route@2744,whole:Route@275,whole:Route@2973,whole:Route@2977,whole:Route@409,whole:Route@446 d509ae582cfb0b76ee8fced8fcb50f3c4c43f04124c67711bae473866d9cdef7 |
| +@legacy 9cf38b9e2187459c195b34026f96a71b7bf7883f4d7219e66562c9f446fbbdc3 internal/activator/rootfs_service.go Service.rootfsTick legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: per activator tick, lists residents (Registry.ResidentInstances through the DueStore), and for each rootfs entry kills generations whose replica reports a lost lease with no watch installed, stops an exited rootfs process (StopExited), and supervises; then drops forgotten residents and reserves proactive starts (residentJob) for resident-shaped, unheld rows within the start ceiling after the locked admission;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.10: when the tick kills a lost-lease resident's generations it also starts stopRootfsWorkersAtLoss(e) beside them; superviseRootfsLocked (a no-op in Group A) is now the worker supervision; the same 15 read sites, no read added; stops more, starts nothing new on its own;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: the no-signal fallback also covers a hibernating rootfs entry with a one-shot unit that may run (oneShotHoldsLocked); it latches ownerKilled and runs each one-shot kill func (KillOneShot to root's existing /stop) with go off a.mu, beside a resident's killResidentGens and stopRootfsWorkersAtLoss as before; new site +whole:Route is e.route.Rootfs(); stops more, starts nothing registry:Host@1842,registry:Host@2071,registry:Host@2427,whole:Route@113,whole:Route@1200,whole:Route@1795,whole:Route@1824,whole:Route@1993,whole:Route@2024,whole:Route@2106,whole:Route@2271,whole:Route@2320,whole:Route@2465,whole:Route@397,whole:Route@803,whole:Route@824 de44f5578a049a224f06a302863752c3a4ff53767478a54d08e373db018efe82 |
| +internal/activator/activator.go Service.installProcLocked legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8: the one place a process, its generation and the lease replica are installed on an entry; a resident is put under its lease watch (watchResidentLeaseLocked) at that moment; reads only the entry's route;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (Call A1, Astra R1 P1-1): the lease watch is installed for every rootfs row (e.route.Rootfs()), not only a resident, so a hibernating rootfs row's run or session is reached at the lease's loss; the same one read of the entry's route; installs nothing else whole:Route@144 cacc399eb6e09be70d3a2ad1774800fb6a252590cebd62dd0e9f369e97275f81 |
| +internal/activator/backend_rootfs.go ExecBackend.StartRelease legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1: new; startRootfsCmd naming release.ProcessRelease, both streams through one capped line writer (releaseOutput, runs.MaxOutputBytes) into the caller's writer; no read of its own;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: passes rootfsCmdLaunch{Process: release.ProcessRelease} to startRootfsCmd in place of the bare process name; its /cmd request and launch.cmd.json are byte-identical to before (TestStartReleaseIsUnchanged, goldens written from 3fd3c3a4); no read added registry:Host@182,whole:Route@247 9dd1cb5cf2b170f59e5e46a121a665bd0ca4d6c9698aab63804880848b5ee9ee |
| +internal/activator/cmdunit.go type CmdSpec legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): declaration only; Prepare is a callback field, not a prepared statement;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: declaration only: gains AfterSettled, a callback field the caller sets (the box's run pass removes the run's directory in it), called once when no unit of the run can be running; reads nothing file:Prepare@487 f3c596b537f466e707f4974aa06065fb08bebb4a89749c8d6138810c9aa0a5b2 |
| +internal/activator/rootfs_service.go Service.residentLeaseLost legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 8 (C7): a resident's lost lease marks it and then kills its generations off a.mu (killResidentGens);rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.10: a resident's lost lease stops its workers (stopRootfsWorkersAtLoss, proven gone) in parallel with killResidentGens; rt is taken under the lock and passed to killResidentGens in place of e.route (the same route); site +whole:Route (that local rt); no file read;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (Call A1): residentLeaseLostLocked also returns one kill func per one-shot unit that may run; each runs off a.mu in the same WaitGroup as stopRootfsWorkersAtLoss and killResidentGens, which still run only for a resident (gens non-nil); the kills go to root's existing /stop through KillOneShot; no read added whole:Route@137,whole:Route@394 64ce2f74e65941ea2a731518c773cb9b27456f2db298c69ed4e02de375b1777f |
| +internal/host/runexec.go runsWorker.execute legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): runs one picked run to its result in the bucket; every root action goes through instance control;rev3=PROPOSED-325;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=emits the run's start and end as member log events through the agent's EventSink; reads unchanged;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (INV-2): sets CmdSpec.AfterSettled to remove the run's directory (runs.RemoveRunDir under the instance's own directory, as cleanUp did) once the activator has proven no unit of the run runs; finish and cleanUp take removeDir, true only on the incarnation refusal before RunCmd; the directory goes later or at the same point, never earlier; no read added file:Prepare@1905,whole:Route@2916 43bd160066b4d3e7aef00e3891001bc5ffa9a40f597cb6e5cc7215eae2814df9 |
| internal/host/units/carlos-instance-cmd@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the cmd unit template (applied by PID 1 as root; its process runs as carlos): extends the J4 seed pattern to the run role. The template equals the seed template outside named lines, and the template-equality test pins that. Root lays out a staged executable validated by the same refuseStagedExe the seed and generation paths use, then starts this unit, which runs as carlos with the instance's own reach. No new trust of registry, /data or agent-asserted content beyond the seed path;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else file:external@0 925113f4c51c091f0da65c2c67c5902aa35ab37abbe6491ca935820517e8149d |
| internal/host/units/carlos-instance-gen@.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else file:external@0 0bd25fefd9306449d55e235e9bd8986466bc4cd68ad56b5614d32596ce39c262 |
| internal/host/units/carlos-instance-probe.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-2;basis=one more BindReadOnlyPaths= line, so PID 1 opens one more bind source: /run/carlos-control/exe/_probe/box-addrs, bound to /opt/carlos/box-addrs, root's list of the box's own addresses, which RunProbe writes before every run (#367) in the root-only directory the unit already binds from; no tenant, app or agent input names or writes it;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service, so the probe proves what the tenants get (its new pts-private line); fix round 1 (Astra P2, roll order): one line outside the namespace block, Environment=CARLOS_PROBE_PTS_PRIVATE=1, a constant the unit sets for its own process (the probe, as carlos, in the namespace); it names no path, adds no bind source or Exec line, and root reads nothing new file:external@0 a803c8e83ffd95ceca691e0c47e623acfa50e88dcddd3166e6660473aa86695b |
| @@ -30,16 +52,30 @@ internal/instancectl/server.go type Server legacy accepted-legacy accepted-legac |
| internal/instanceexec/probe.go productionProbeEnv legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-2;basis=the binary probe's env gains boxAddrs (instancectl.BoxAddrsPath, /opt/carlos/box-addrs), which boxAddrClosed (a decision row) reads inside the probe unit, and mmapWX (realMmapWX, an anonymous mapping); the same one direct site;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5 (PF-8): the binary probe env sets devPts=/dev/pts and openPtmx (open /dev/ptmx O_RDWR|O_NOCTTY and close at once), the fields the rootfs probe env already set; read by the new pts-private line inside the probe unit (as carlos, in the namespace); fix round 1: also reads its own environment, CARLOS_PROBE_PTS_PRIVATE (exactly "1" enforces pts-private; otherwise the line is reported unverified), which the probe unit sets; the same direct site, no new root read data-literal@67 9de3096aec14bb54d72ee47eceb866cc2b6b80fcda8206cf9a4d5476f0f0d177 |
| internal/layout/plan.go NestedPlatformNames legacy accepted-legacy accepted-legacy;rev3=census-ruling-moves-offline;basis=root-input (J4, as main's moves units); the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): new, called only from the agent's offline sealer and source retire (IsNestedPlatformName): a fixed list of names, reads nothing;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the fixed role list gains RoleTTY, so launch.tty.json is one more fixed platform name; still reads nothing data-literal@84 faf3813dcb08f2e153a45b53f4461899327775c298419fc7fe817e80110119d0 |
| internal/provision/reconcile.go Reconcile legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos), from its reconcile loops: each listed record is observed through the box's lifetime judge (ObserveWith: the record, then its host incarnation slot) before the shape, channel and scope checks, a stale record is left out and an unjudgeable one protected; the removal phase observes a row's own record key when the pass holds none for it under that key, and deletes a held row whose record is gone or stale through DeleteIfHold; a nil judge (claims on) is main's body; registry read sites unchanged, offsets moved; fix round 1: the removal phase observes a row's own key only under an account the listing trusts, so a retired or unmaterialised account's row keeps record gone, and the pass arms its own context with the judge; Task 7: under a judge an existing provisioned row of the record's own app and account follows the existing-row rules (heldByVanishedPredecessor and retireHeldPredecessor's DeleteIfHold first, the record then minted on the same pass; the hold; installRowLifetime), each a separate write under the host's hold lock; registry read sites unchanged, offsets moved;rev3=census-ruling-instance-egress-sizes-328-329;identity=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos);basis=#328/#329 plan 1 Task 7: the pass reads its apps' policy objects (control/app-policy/<sqid>/<app>.json in the bucket) through the agent's PolicyCache, each verified with ReleasePub by apppolicy.VerifyKey (ed25519 over the policy's own domain line, bound to the account and app, unexpired, not future-dated; anything else is no policy), and carries the columns into its rows. New kinds registry:EgressAllow, registry:Size and registry:PolicyExpiresAt, one site each, all the assignment of a fresh row's columns (nr) from policies.cols; plus one whole:Route site, the existing row handed to policies.forRow. Other read sites unchanged, offsets moved; the agent's own pass, no root decision;rev3=census-ruling-region-ha-p1a;basis=the agent as carlos, from its reconcile loops: after the scan, hands the in-scope records to cfg.Lifetimes (the box's lifetime index): Merge after a failed read or partial listing, Replace after a complete one, nothing on a dry run or with no index; the scan, judge and removal phases unchanged; the same 166 sites, no read added;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 2 and 5 (D5, spec §5.0): a seeded record over a row with a runtime is skipped and logged; a row with a runtime (or a new record with one) takes no seed; runtime and a rootfs row's hibernation are never converged from a record (a mismatch is logged; a record claiming a runtime its row lacks is not applied); reads Runtime of the record and the row; the box writes less; fix wave 1 (ceea6353, whole-branch P1-2): before minting a row for a record with no runtime and no row (both mint paths), the pass reads the app's kind marker once per app per pass (release.ReadAppKindMarker: one GET of the create-only kind.json from the release store s, through freshStore, validated by readAppKindMarker); a rootfs marker leaves the record unmaterialized and logged (an older console stripped its runtime), and a marker that cannot be read defers the mint this pass; a refusal before minting only, registry read sites unchanged, the box writes less; fix wave 2 (whole-branch r2 P1): the kind-marker read and its refusal apply only to a socket-backed instance record (DerivesPaths), so a static or upstream-backed record of a rootfs app, which carries no runtime by design, is minted as before with no read; fewer reads, registry read sites unchanged;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): Task 10: the forward phase on the hub (FleetOwners set): the scan keeps the fleet-placed records it skips and counts records per host; a trash-only marker prefetch; disputed (failed-GET) hosts; armed, a host an in-scope and a fleet record both name is given neither, its journal waits and the removal phase keeps its row (+registry:Account, +registry:App, +registry:Host x2: the collision guard, its log line and report mark); the instance loop leaves a forward host; retirable excludes forward rows. Same record keys; writes only the registry (PutForward, DeleteForward); no bucket write.;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 3: in the per-record loop, beside the RunSeen call, calls cfg.InteractiveSeen(rec) when the hook is set and the in-scope record carries an interactive-session marker (rec.Interactive != nil), once per record per pass, before the pass acts on it; the hook is the box worker's non-blocking note (Task 12). Same record keys and literal; no read added (registry read sites unchanged, 178); nothing written by the call registry:Account@36233,registry:Account@37498,registry:Account@55577,registry:Account@55623,registry:Account@56467,registry:Account@56844,registry:Account@57070,registry:Account@57137,registry:Account@57183,registry:Account@57276,registry:Account@57318,registry:Account@57966,registry:Account@58224,registry:Account@58764,registry:Account@58812,registry:Account@59185,registry:Account@59231,registry:Account@59476,registry:Account@59901,registry:Account@60389,registry:Account@61125,registry:Account@61318,registry:Account@61664,registry:Account@62229,registry:App@36206,registry:App@37471,registry:App@55597,registry:App@55635,registry:App@56479,registry:App@56856,registry:App@57082,registry:App@57157,registry:App@57195,registry:App@57296,registry:App@57978,registry:App@58236,registry:App@58776,registry:App@58824,registry:App@59205,registry:App@59243,registry:App@59488,registry:App@59913,registry:App@60401,registry:App@61137,registry:App@61330,registry:App@61676,registry:App@62241,registry:ClaimOwnership@36820,registry:DBPath@45677,registry:DBPath@45692,registry:DBPath@45938,registry:DBPath@46541,registry:DBPath@46554,registry:EgressAllow@35319,registry:Gate@42022,registry:Gate@42162,registry:Gate@42449,registry:Hibernate@40694,registry:Hibernate@40892,registry:Hibernate@40957,registry:Hibernate@41296,registry:Hibernate@41647,registry:Hibernate@41957,registry:HoldOp@60870,registry:HoldOp@60961,registry:HoldOp@61096,registry:HoldOp@61472,registry:Host@26327,registry:Host@55556,registry:Host@56443,registry:Host@56820,registry:Host@56984,registry:Host@57090,registry:Host@57986,registry:Host@58192,registry:Host@59068,registry:Host@59340,registry:Host@59455,registry:Host@59778,registry:Host@59875,registry:Host@60266,registry:Host@60363,registry:Host@60577,registry:Host@60952,registry:Host@61087,registry:Host@61291,registry:Host@61364,registry:Host@61463,registry:Host@61638,registry:Host@61713,registry:Host@61799,registry:Host@62206,registry:Kind@36962,registry:Kind@37225,registry:Kind@45595,registry:Kind@45608,registry:Kind@45718,registry:Kind@45731,registry:Kind@46452,registry:Kind@46463,registry:Kind@54680,registry:Kind@60568,registry:Kind@61078,registry:Kind@61454,registry:Kind@61629,registry:Kind@61790,registry:PolicyExpiresAt@35344,registry:Pool@54766,registry:Provisioned@36182,registry:Provisioned@37447,registry:Provisioned@54725,registry:RateLimit@42535,registry:RateLimit@42686,registry:RateLimit@42973,registry:Region@54755,registry:Replication@41381,registry:Replication@41508,registry:Runtime@28984,registry:Runtime@29162,registry:Runtime@31367,registry:Runtime@40061,registry:Runtime@40115,registry:Runtime@40319,registry:Seed@44075,registry:SeedSource@43558,registry:Size@35335,registry:Socket@45643,registry:Socket@45658,registry:Socket@45955,registry:Socket@46511,registry:Socket@46524,registry:Unit@45561,registry:Unit@45574,registry:Unit@46478,registry:Unit@46489,whole:ClaimOwnership@36823,whole:ClaimOwnership@36840,whole:Route@26309,whole:Route@26320,whole:Route@26338,whole:Route@27619,whole:Route@29479,whole:Route@29486,whole:Route@29526,whole:Route@29887,whole:Route@30225,whole:Route@30672,whole:Route@30723,whole:Route@30760,whole:Route@32432,whole:Route@32641,whole:Route@32980,whole:Route@32989,whole:Route@33035,whole:Route@35268,whole:Route@35827,whole:Route@36298,whole:Route@36308,whole:Route@36665,whole:Route@36672,whole:Route@36740,whole:Route@37063,whole:Route@38096,whole:Route@41047,whole:Route@45787,whole:Route@47373,whole:Route@47418,whole:Route@47428,whole:Route@48298,whole:Route@49325,whole:Route@54791,whole:Route@54939,whole:Route@56036,whole:Route@56395,whole:Route@56777,whole:Route@61551,whole:Route@62136,whole:Route@62186 be1b699f14a2f8d6935d959dee168bdf6fb556cd78da458f5ba8a1c0e8512a17 |
| +internal/activator/backend_rootfs.go ExecBackend.KillOneShot legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a (Call A1), new: a rootfs row only (else errOneShotKillBinary) and a one-shot role only (cmd or tty): StopRootfs(host, role, 0, no worker, kill) to root's existing /stop on DeadlineControl, then waitRoleCgroupEmpty (unitEvents on the role's rootfs unit) on roleEmptyBound; nil is the proof; the registry:Host sites are log and error text and the host passed to root, which names the unit from its own validated host registry:Host@1027,registry:Host@154,registry:Host@279,registry:Host@374,registry:Host@433,registry:Host@563,registry:Host@661,registry:Host@720,registry:Host@958,whole:Route@881 46947416ed240d9e94383816308df5fcd6181a8fe7b0df166bc0cba4768b6836 |
| +internal/activator/backend_rootfs.go ExecBackend.startRootfsRun legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: StartCmd's rootfs arm: refuses a run with no serving image (errNoCmdExe) or a partial one (errPartialStagedIdentity), both marked, and one with no launch environment (errNoGenEnv); asks replicaKeyGate; composes rootfsCmdVars over the generation's launch environment and the row's dbPath; then startRootfsCmd with the operator's argv exactly as given; root validates the image by digest and runs the argv inside the instance's namespace; the registry:Host sites are error text registry:Host@192,registry:Host@450,registry:Host@587,whole:Route@773,whole:Route@874,whole:Route@902,whole:Route@969 28ac40abb07e2561c7b8bf0e75d79645d2b20dfb8f5a05cfe33cb0b0ba350da5 |
| +internal/activator/backend_unit.go SplitBackend.KillOneShot legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: forwards KillOneShot by pick(rt), as KillGen does; a half without it refuses (errOneShotKillBinary); reads only the route registry:Host@219,whole:Route@123,whole:Route@286 59823fbe5e35c5b54e0843a681ad59f684bd28e3a8315c1571198b3e5c43d3ee |
| +internal/activator/cmd.go Service.killOneShot legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: the backend's KillOneShot (oneShotKiller) for one run, bounded by DeadlineControl plus roleEmptyBound, logged either way; the registry:Host sites are log lines registry:Host@240,registry:Host@549,registry:Host@680,whole:Route@398 3eb9bb7269c2a5fc8d4c798d884d92f7fa32eddbde588a3c9ad2d741211b869b |
| +internal/activator/cmd.go Service.stopOneShotAtLease legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: one run hold's lease stop, off a.mu: with kill, killOneShot at once and again once a start that was in flight returns a unit; then the hold's own stop (StopLeaseLost) bounded by cmdStopBound; the registry:Host sites are log lines registry:Host@714,registry:Host@961,whole:Route@309,whole:Route@529 46c39957f77353866dc7d8adbababfde54bd8634f5669fd61c3011a54f5e7c9a |
| +internal/activator/cmd.go Service.stopOneShotsAtLeaseLocked legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a, new: one stopOneShotAtLease func per run hold that may be running (cmdHoldsLocked), none for a binary row (rt.Rootfs()); in memory only whole:Route@240 985fd564c12bf8f0339915e776d38d3139eb28b7c44c047bd91bbfd9fad3792d |
| +internal/activator/rootfs_service.go Service.residentLeaseLostLocked legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: a census unit now (two whole:Route sites, e.route to stopOneShotsAtLeaseLocked and e.route.Resident()): also returns the one-shot kill funcs of any rootfs entry that is the host's, whatever its state; a hibernating entry gets no stop and no generation kills; in memory only whole:Route@198,whole:Route@218 6266ff6af94cc58e1226f3921da636cc6fa7d365340ecce216f0493d2d7e97a7 |
| +internal/activator/rootfs_service.go Service.residentLeaseShort legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: a census unit now (two whole:Route sites, e.route to stopOneShotsAtLeaseLocked and e.route.Resident()): stops every one-shot unit that may run, whatever the entry's state, off a.mu; begins a resident's graceful stop only while it is awake, as before; in memory only whole:Route@188,whole:Route@377 c39a0d4aeb53d0608e3c3e95ea3742ef6dab8ea3419a061a3415ffe5c491ecfe |
| internal/host/units/carlos-instance-rootfs-tty@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5, new: the rootfs tty template, carlos-instance-rootfs-cmd@.service outside named lines held by TestRootfsTTYTemplateEqualsRootfsCmdOutsideTheNamedLines: Description (tty), ExecStart/ExecStopPost instance-exec/instance-exit --rootfs tty %I, StandardInput=file:/run/carlos/logs/%I.tty.sock with StandardOutput/StandardError=journal, and RootImage plus the two BindReadOnlyPaths sources under /run/carlos-control/exe/%I/rootfs/tty/ (root-only exe layout) instead of rootfs/cmd/. The rootfs namespace block byte for byte (TestRootfsTemplatesShareOneNamespace), runs as carlos, binds only the instance own and root paths (TestRootfsTemplatesBindOnlyTheInstancesOwnAndRoots). Task 6: POST /tty runtime=rootfs (startRootfsCmd with RoleTTY) starts it through Plan 2's rootfs one-shot path (preflight, validateStagedImage, ensureRootfsExe under rootfs/tty/, jit drop-in and owed reload, post-start MemoryDenyWriteExecute check); its files go only through removeRootfsUnitFiles (stopRootfs and cleanCmdExe with RoleTTY, the sweep) file:external@0 d57f6d6fbe553e5ba5a5762ab2bd72586835ce1db748b67044edd1bf90af6953 |
| internal/host/units/carlos-instance-tty@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5, new: the binary tty template, carlos-instance-cmd@.service outside six named lines held by TestTTYTemplateEqualsCmdOutsideTheNamedLines: Description (tty), ExecStart/ExecStopPost instance-exec/instance-exit tty %I (the same root binary as every template), StandardInput=file:/run/carlos/logs/%I.tty.sock replacing the cmd StandardOutput socket (PID 1 opens it as root on the nosymfollow logs mount, as the cmd streams), StandardOutput=journal, StandardError=journal, and BindReadOnlyPaths sources tty-app/tty-live under /run/carlos-control/exe/%I (root-only exe layout, as cmd-app/cmd-live). Same namespace block byte for byte, runs as carlos. Task 6: POST /tty (handleOneShot(RoleTTY), claimAwareLegacy) starts it, after the role lock, the loaded-state refusal and refuseStagedExe; the tty-app/tty-live sources are laid out by ensureCmdExeAt(RoleTTY) and removed by removeCmdExe(RoleTTY) at /stop role=tty and /sweep file:external@0 060295d0956afad52db77dba1988c508cf4289f9b5a18242a206a315145b8e0d |
| internal/instancectl/cmd.go Server.oneShotStatus legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 6: handleCmdStatus's body moved whole and made role-aware (it serves GET /cmd/{host} and GET /tty/{host} through handleOneShotStatus(role), both claimAwareLegacy): the same three file:Query sites (the URL query read for the invocation, for parseQuery and for the role check); the role check now refuses any role field but the route's own (role=tty on /cmd and role=cmd on /tty are 400, before any show); the unit shown is UnitName(role, host) or RootfsUnitName(role, host) for runtime=rootfs, a name root builds from a validated host and a route constant; read-only systemctl show, starts and stops nothing; no file read added file:Query@1090,file:Query@384,file:Query@759 9ea847d9a1e6b0e0929f27b27a9ade5c783c0de1ba0d997523c939be8293e701 |
| internal/instanceexec/tty_linux.go receivePTY legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7 (PF-9), new: the trampoline's tty role, run by instance-exec [--rootfs] tty %I as carlos inside the instance's namespace (never root): one recvmsg on its own stdin (the tty unit's StandardInput= socket to the agent), exactly the hello carlos-tty/1 and exactly one SCM_RIGHTS fd (received close-on-exec), else refused with every received fd closed; the one Fstat is of that received fd, which must be a character device of a Unix98 pty slave major (136-143) that answers TCGETS, else refused and closed; it opens, runs and follows no path; the fd becomes only the tenant's stdio and controlling terminal (runTTYInit through runInitChecked, which closes the init's copy after the fork); no root process reads anything new file:Fstat@1454 1099af8a1dc0732b74afbe42bc45ccce6df3db9662ff7dc41f278e2bd4a274ce |
| +internal/activator/backend_rootfs.go ExecBackend.startRootfsCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R, R1 [pf R0.1, R1.4]: new; the agent's first caller of root's existing CmdRootfs (POST /cmd to root's control socket, unchanged). In order: rootfsGates; refuses a partial staged identity (version, path, digest); rootfsControl; prepare(rt, RoleCmd) (the instance's own directories); two stream listeners on the agent's own log sockets (logSocketNamed); the schema-2 launch file for RoleCmd with env alone (writeRootfsLaunchFor, the same writer and the same root reader as the web start's RoleRun file, rootfsLaunchEnv: never the agent's own environment); the caller's exec gate (runExecGate); then CmdRootfs(host, the row's tier memory.max, StagedImage{staged path, version, digest, process}), process being a declared process name root checks against the staged manifest. ErrStagedImage and ErrStartRefused are refusals with no unit; any other error returns a unit to stop and settle. Root validates the staged image and the process itself (instancectl, unchanged); registry:Host sites are log lines, socket and unit names;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: takes a rootfsCmdLaunch, a declared process or an operator's argv, exactly one or refused before anything is laid out; the launch file names the process or cmd, never an argv; CmdRootfs names the image with the process or with the argv in the request body, which root validates against the staged image itself (instancectl, unchanged); new site +registry:Host is that refusal's message registry:Host@1056,registry:Host@1175,registry:Host@1239,registry:Host@1357,registry:Host@1529,registry:Host@1953,registry:Host@1993,registry:Host@2305,registry:Host@2629,registry:Host@2756,registry:Host@2854,registry:Host@303,registry:Host@473,registry:Host@727,registry:Host@899,whole:Route@2009,whole:Route@2694,whole:Route@2698,whole:Route@2897,whole:Route@2935,whole:Route@2939,whole:Route@544,whole:Route@947 92d9513d414706d8e94e320826b512272210f73130e1e700d94c540afec0b346 |
| +internal/activator/cmd.go Service.RunCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): admits one run against an awake entry under the agent's own lease, fence and swap checks; it starts nothing itself and root validates what it later names;rev3=census-ruling-edge-request-records;basis=passes nil for begin's new req parameter; no read added;rev3=census-ruling-rootfs-apps-3-release;basis=rootfs Plan 3 Group R: a carlos run is refused with ErrCmdBusy while a release record of the host is open (a.releaseOps[rt.Host], in-memory), as a run already in flight refuses it; new site +registry:Host (that map lookup); adds a refusal only;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: AfterSettled honoured on every path (called before return on each path that starts no unit, else by the settle that proves the unit gone); a rootfs run is refused as a lost lease (CmdStoppedError StopLeaseLost) when its entry is not under the lease watch (residentWatchedLocked), and, off a.mu, when the replica's in-memory SafeUntil leaves less than oneShotStartLead (oneShotHeadroom); new sites are e.route.Rootfs() and a log line; adds refusals only file:Prepare@2243,file:Prepare@2277,registry:Host@1371,registry:Host@1696,registry:Host@7249,registry:Host@8485,registry:Kind@437,whole:Route@683,whole:Route@7653,whole:Route@8117,whole:Route@8650,whole:Route@869 36a03283c6c294123e02bb1779bcc6ad0ae273f69297ab35ff37e95cf2e52d8d |
| +internal/activator/cmdunit.go ExecBackend.StartCmd legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): writes launch.cmd.json in the instance's own directory and asks instance control to start the cmd unit; root validates the staged executable it names (refuseStagedExe) and decides the start;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: after the layout and run-directory checks, a rootfs row returns startRootfsRun (backend_rootfs.go) before nestedGate; the binary path is byte-identical (TestBinaryStartCmdLaunchGolden); new site +whole:Route is rt.Rootfs() registry:Host@1576,registry:Host@1700,registry:Host@1764,registry:Host@1887,registry:Host@2034,registry:Host@218,registry:Host@2188,registry:Host@2316,registry:Host@2404,registry:Host@2808,registry:Host@2877,registry:Host@2928,registry:Host@343,registry:Host@624,registry:Host@706,registry:Host@810,whole:Route@130,whole:Route@1360,whole:Route@1467,whole:Route@2086,whole:Route@2332,whole:Route@2420,whole:Route@2740,whole:Route@2744,whole:Route@275,whole:Route@2973,whole:Route@2977,whole:Route@409,whole:Route@446 d509ae582cfb0b76ee8fced8fcb50f3c4c43f04124c67711bae473866d9cdef7 |
| +internal/activator/rootfs_service.go Service.rootfsTick legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Tasks 7 and 8: per activator tick, lists residents (Registry.ResidentInstances through the DueStore), and for each rootfs entry kills generations whose replica reports a lost lease with no watch installed, stops an exited rootfs process (StopExited), and supervises; then drops forgotten residents and reserves proactive starts (residentJob) for resident-shaped, unheld rows within the start ceiling after the locked admission;rev3=census-ruling-rootfs-apps-3-workers;basis=rootfs Plan 3 Group W, W1.10: when the tick kills a lost-lease resident's generations it also starts stopRootfsWorkersAtLoss(e) beside them; superviseRootfsLocked (a no-op in Group A) is now the worker supervision; the same 15 read sites, no read added; stops more, starts nothing new on its own;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 7a: the no-signal fallback also covers a hibernating rootfs entry with a one-shot unit that may run (oneShotHoldsLocked); it latches ownerKilled and runs each one-shot kill func (KillOneShot to root's existing /stop) with go off a.mu, beside a resident's killResidentGens and stopRootfsWorkersAtLoss as before; new site +whole:Route is e.route.Rootfs(); stops more, starts nothing registry:Host@1842,registry:Host@2071,registry:Host@2427,whole:Route@113,whole:Route@1200,whole:Route@1795,whole:Route@1824,whole:Route@1993,whole:Route@2024,whole:Route@2106,whole:Route@2271,whole:Route@2320,whole:Route@2465,whole:Route@397,whole:Route@803,whole:Route@824 de44f5578a049a224f06a302863752c3a4ff53767478a54d08e373db018efe82 |
| @remove internal/instancectl/cmd.go Server.handleCmdStatus |
| @removed internal/instancectl/cmd.go Server.handleCmdStatus H3 census-ruling-rootfs-apps-6;absent;basis=rootfs Plan 6 Task 6: moved whole to Server.oneShotStatus (role-aware; see its claim), not deleted: no check, refusal or validation is lost |
| @coverage . fbc28f10f89cd03cac31bae0d798ae7f707eb7671284a6115abd8c1c214369b6 |
| +@coverage internal/activator 8413e57c046e67da3e953ab1207c8a75da33a88dddab6b41b30684f16c808f14 |
| @coverage internal/appconfig cac8d8ef7538a456d034801c95ce6508a4983e5516b3bbbd302bec0fbafdd479 |
| +@coverage internal/host 69c09eff5b3b87756182f001086b391c02b867e82e8d21ea40722c992fec43a7 |
| @coverage internal/host/units c3cc4f3b917fdb938f20d406b1704ec54e24553851c298e312056d397d10b0e1 |
| -@coverage internal/instancectl ee755f7827ba8ab62cfe3d67c29a6ce9cc88c276ab995fb58a5fb5a36f18b51a |
| +@coverage internal/instancectl 096e845eb71478e8b68726160cff450f8ba850869dae65582dabd25f445527e9 |
| @coverage internal/instanceexec 65f6db1c6bf469f1d19615ec989f54c20de3b73c3c03ae2d677cffbcc60470fd |
| @coverage internal/layout 1527c3b31d87743798002b1ebefcd2cb0dc422a8642f72a3ff8dbefbd2c84d9b |
| @coverage internal/provision e1ecfdc3d169773ac6dd9dc09a6d0feea768ceb1b80195199c5ef74b2f0e6f5c |
diff --git a/plan3_groups_test.go b/plan3_groups_test.go| index d61b9ad87..6bc6cf034 100644 |
| --- a/plan3_groups_test.go |
| +++ b/plan3_groups_test.go |
| @@ -40,12 +40,14 @@ import ( |
| // plan3CopyRuns is Task 12's carlos run rows (--version and rootfs runs), |
| // cut by Paul 2026-10-26, for a later rootfs-runs task (#431). It is a |
| // group like R and W that has not started, so its rows stay pinned and |
| -// unbuilt until that task starts it. |
| +// unbuilt until that task starts it. RFS-3-C27 (a rootfs run's argv on |
| +// the image's PATH) moved to Group A when Plan 6 Task 7a built carlos run |
| +// on rootfs rows without --version. |
| var ( |
| - plan3CopyA = plan3IDs(11, 12, 14, 15, 16, 23, 24, 30, 31, 32, 33, 34) |
| + plan3CopyA = plan3IDs(11, 12, 14, 15, 16, 23, 24, 27, 30, 31, 32, 33, 34) |
| plan3CopyR = plan3IDs(1, 2, 3, 4, 5, 6, 7, 29) |
| plan3CopyW = plan3IDs(8, 9, 10, 35) |
| - plan3CopyRuns = plan3IDs(17, 18, 19, 20, 21, 22, 26, 27, 28) |
| + plan3CopyRuns = plan3IDs(17, 18, 19, 20, 21, 22, 26, 28) |
| ) |
| // plan3GroupsStarted and plan3GroupsLanded: "R" and "W" (and "A" in |