Order instance control after nftables for boot recovery
Wait for the nftables ruleset before startup hairpin recovery without pulling nftables into non-group boot transactions. Correct the control service lifetime comment and fold the group drop-in into the edge node in the shutdown ordering test. Refresh the Task 1 census proposal. Validated covering host tests, census checks, and host/provision vet.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/notes/census-proposal-region-ha-graceful-terminate-t1.md+2 −0internal/host/units/carlos-instance-control.service+7 −2internal/host/units_shutdown_test.go+32 −5internal/provision/testdata/plan14-root-reads-region-ha-graceful-terminate-t1.tsv+3 −2
Intent
<task-notification> <task-id>a28f3cd3e47f7e3e8</task-id> <tool-use-id>toolu_01NdtxkTqbDGfkFsm8YggXNu</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/c23f0319-4761-45f6-bac7-f9471c7b9ab1/tasks/a28f3cd3e47f7e3e8.output</output-file> <status>completed</status> <summary>Agent "Review Task 1 (spec + quality)" 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>### Spec Compliance - ✅ Spec compliant. Every item in the brief has a matching hunk. - `internal/host/units/carlos-edge.service:15` sets `After=` to the exact string the brief asks for, adding the control socket, the control service and `dbus.service`. `:18` sets `Wants=network-online.target carlos-instance-control.service`. Each has a comment explaining reverse stop order, stop proofs and the pending-stop-job refusal, citing T1/DR-4. - `carlos-edge.service:30` adds `TimeoutStopSec=120` under `[Service]`, with a comment calling it a backstop, not a release guarantee. - The diff touches no instance template. The new test also checks that `BindsTo`/`After` to the edge are still in place (`units_shutdown_test.go:62-68`). - `internal/host/units_shutdown_test.go:36-50` asserts the required `Wants`, `After` and `TimeoutStopSec=120` (exactly one value). `:52-61` rejects `Before=carlos-edge.service` on every `carlos-instance*@` template and on the control service. `:72-90` runs a cycle search (DFS) over the combined `After`/`Before` graph of all embedded units. That covers the brief's "orders itself after anything ordered after the edge" check. - Both "90 s" comments are updated (`internal/activator/activator.go:6157`, `internal/activator/cmd.go:86-88`). Check I ran: a grep of non-test Go under `internal/` for `TimeoutStopSec` and systemd 90 s mentions found no other stale 90 s comment. `instanceexec/init_linux.go` and `claimunit_template.go` refer to other units. - The report includes `systemd-analyze verify` output for base and group variants. It shows only the expected "/opt/carlos/carlos not executable" errors and no ordering-cycle diagnostic. - Extra, but needed by repo process: the census overlay, the chain entry and the card (`internal/provision/testdata/plan14-root-reads-region-ha-graceful-terminate-t1.tsv`, `plan14-root-reads-chain.tsv:123`, `docs/superpowers/notes/census-proposal-region-ha-graceful-terminate-t1.md`). The unit's bytes and the comments in two packages changed, so the pins had to be re-taken. The card's claim ("static unit names only; no new input… instance template ordering unchanged") matches the diff. - ⚠️ Cannot verify from the diff: boot ordering of control against nftables on group boxes. Because of `Wants=`, `carlos-instance-control.service` now starts at boot, before the edge. Its unit has no `After=nftables.service` (checked `internal/host/units/carlos-instance-control.service`, `[Unit]` section). At startup it runs `resumeGroupHairpin` (`internal/instancectl/server.go:338`). With no edge main PID, or a stale one, that path goes to `op.Rollback`/`op.Revoke` (`internal/instancectl/hairpin.go:374-379`), and any error is `log.Fatal`. The control unit also has no `Restart=`. If revoke or rollback needs nftables before `nftables.service` is up, control fails at boot and stays down until the agent's first socket request starts it again. That recovers in normal operation. The controller should get a group-box reboot test before any roll. The implementer flagged the same thing. The brief mandates the `Wants=` design. - ⚠️ Cannot verify from the diff: whether shutdown actually writes a clean marker. That depends on later tasks (the 90 s agent budget and the reserves). This task only provides ordering and the timeout backstop, as the report says. ### Strengths - The unit change matches the brief's directive text character for character, and the comments state the actual reason (reverse stop order; a socket with a pending stop job refuses activation) instead of restating the directive. - The test is a real structural check of the embedded unit files, not a mock. It parses sections, handles empty-value resets (`units_shutdown_test.go:28-29`), converts `Before=` into reverse edges correctly (`:56-58`), and its cycle error prints the whole path. The report shows it failing before the unit change and passing after. - The cmd.go comment now correctly says a kill mid-stop can leave the lease without a marker, rather than implying TTL expiry is enough. ### Issues #### Critical (Must Fix) None. #### Important (Should Fix) None. #### Minor (Nice to Have) - **Drop-in left out of the graph** (`internal/host/units_shutdown_test.go:14-34, 72-90`). `unitNames()` returns `carlos-edge-group.conf` (checked `internal/host/bootstrap.go:702` and the `units/` listing). The test treats that file as its own node, so the drop-in's `After=nftables.service` is never merged into `carlos-edge.service`. No cycle results today because nftables is not an embedded unit, but the brief names this drop-in as part of the cycle check, and a future drop-in ordering could slip past. Fix: fold `carlos-edge-group.conf` directives into the `carlos-edge.service` node before the DFS. - **Stale header comment on the control service** (`internal/host/units/carlos-instance-control.service:1-2`). It still says "Socket-activated, so it runs only while there is work." With the edge's new `Wants=` it runs from boot. The diff doesn't touch this file, but the comment now describes the opposite of how the service behaves. Update it to say control is started with the edge and kept up through edge shutdown (T1/DR-4). - **Recovery gap if control dies** (no file in the diff; `carlos-instance-control.service` `[Service]` has no `Restart=`). If control crashes during the edge's life and the edge doesn't connect again before shutdown, control is not running when stop proofs need it, and socket activation is refused once the socket's stop job is pending. This is outside Task 1's brief. Worth raising at the whole-branch review: either `Restart=on-failure` on control, or a shutdown path that treats "control unreachable" as no proof, meaning no marker. ### Assessment **Task quality:** Approved **Reasoning:** The unit change, the comments and the test match the brief exactly. The test checks real embedded content, and there is evidence it failed before the change and passed after. The remaining risk is boot ordering of the now-eagerly-started control service against nftables on group boxes, which needs a reboot test before deployment, not a code fix in this task.</result> <usage><subagent_tokens>62549</subagent_tokens><tool_uses>7</tool_uses><duration_ms>76986</duration_ms></usage> </task-notification>
Attributed to this commit: 14.8 g CO₂e (1,841,627 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on region-ha-graceful-terminate, 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/docs/superpowers/notes/census-proposal-region-ha-graceful-terminate-t1.md b/docs/superpowers/notes/census-proposal-region-ha-graceful-terminate-t1.md| index 283d59516..c9b735721 100644 |
| --- a/docs/superpowers/notes/census-proposal-region-ha-graceful-terminate-t1.md |
| +++ b/docs/superpowers/notes/census-proposal-region-ha-graceful-terminate-t1.md |
| @@ -5,6 +5,7 @@ Ruling `census-ruling-region-ha-graceful-terminate-t1`. The independent reviewer |
| | unit | change | read sites | what changed | |
| |---|---|---|---| |
| | `internal/host/units/carlos-edge.service` `external` | body | unchanged (1) | Region HA T1/DR-4: start instance-control with the edge and order edge after its service, socket and D-Bus so stop proofs remain available during edge shutdown; set TimeoutStopSec=120. Static unit names only; no new input, command, path, capability or root read. Instance template ordering is unchanged. | |
| +| `internal/host/units/carlos-instance-control.service` `external` | body | unchanged (1) | Region HA T1/DR-4 fix round 1: order control after nftables.service so startup hairpin recovery waits for the loaded ruleset; no Wants or Requires added. Update the startup and shutdown lifetime comment. Static unit ordering only; no new root read, input, path, command or capability. | |
| Envelopes re-pinned: `internal/activator`, `internal/host/units`. |
| @@ -13,6 +14,7 @@ Review: a model from the other family than the author reads the branch's diff ag |
| Recorded dispositions, which each change must still satisfy: |
| - `internal/host/units/carlos-edge.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input |
| +- `internal/host/units/carlos-instance-control.service` `external`: authority, task B3,C,D,E1,J4. Basis: root-input;kept=B3,C,D,E1;scope=protected-decision-only;rev3=census-ruling-agent-start-demo-3;basis=Correct the runtime-write comment to include escaped demo snapshot .mount units alongside per-generation drop-ins; service directives are unchanged. |
| Seal: `9cdff432a5de2ffeaa147fdafd6a486c61c27a0c38f77466bddc86b149332c7d` → `a2014042114a4dd671e52a07bbb686b9ef4b6aa97798cc95e1095680c66fd9b2`. |
diff --git a/internal/host/units/carlos-instance-control.service b/internal/host/units/carlos-instance-control.service| index f0786113a..4c781661e 100644 |
| --- a/internal/host/units/carlos-instance-control.service |
| +++ b/internal/host/units/carlos-instance-control.service |
| @@ -1,5 +1,7 @@ |
| -# The root instance-control service (isolated-exec design §5). Socket- |
| -# activated, so it runs only while there is work. Its whole job is |
| +# The root instance-control service (isolated-exec design §5). The edge's |
| +# Wants= starts it at boot, and it stays up through the edge's stop |
| +# (region HA T1/DR-4). The socket still activates it if it is not running. |
| +# Its whole job is |
| # systemctl start/stop/set-property on the three instance templates' units |
| # and their host slices, on the agent's request, plus running the readiness |
| # probe. Every unit name it passes to systemctl is built from a validated |
| @@ -26,6 +28,9 @@ |
| Description=carlos instance control (root: start/stop carlos-instance*@ units for the agent) |
| Requires=carlos-instance-control.socket data-instances.mount run-carlos-instances.mount run-carlos-logs.mount |
| After=data-instances.mount run-carlos-instances.mount run-carlos-logs.mount |
| +# Startup hairpin recovery may revoke or roll back saved rules, so wait for |
| +# nftables to load them. Ordering alone leaves non-group boxes unaffected. |
| +After=nftables.service |
| [Service] |
| ExecStart=/opt/carlos/carlos instance-control |
diff --git a/internal/host/units_shutdown_test.go b/internal/host/units_shutdown_test.go| index 13ac91bc5..b40c63b19 100644 |
| --- a/internal/host/units_shutdown_test.go |
| +++ b/internal/host/units_shutdown_test.go |
| @@ -1,21 +1,34 @@ |
| package host |
| import ( |
| + _ "embed" |
| "slices" |
| "strings" |
| "testing" |
| ) |
| +//go:embed units/carlos-edge-group.conf |
| +var edgeGroupShutdownDropIn string |
| + |
| func TestEdgeShutdownKeepsControlAvailable(t *testing.T) { |
| names, err := unitNames() |
| if err != nil { |
| t.Fatal(err) |
| } |
| + names = append(names, "carlos-edge-group.conf") |
| units := make(map[string]map[string][]string) |
| for _, name := range names { |
| props := make(map[string][]string) |
| section := "" |
| - for _, line := range unitDirectives(t, name) { |
| + body := edgeGroupShutdownDropIn |
| + if name != "carlos-edge-group.conf" { |
| + body = readUnit(t, name) |
| + } |
| + for _, line := range strings.Split(body, "\n") { |
| + line = strings.TrimSpace(line) |
| + if line == "" || strings.HasPrefix(line, "#") { |
| + continue |
| + } |
| if strings.HasPrefix(line, "[") { |
| section = line |
| continue |
| @@ -34,9 +47,13 @@ func TestEdgeShutdownKeepsControlAvailable(t *testing.T) { |
| units[name] = props |
| } |
| const edge = "carlos-edge.service" |
| + for key, values := range units["carlos-edge-group.conf"] { |
| + units[edge][key] = append(units[edge][key], values...) |
| + } |
| + delete(units, "carlos-edge-group.conf") |
| for key, wants := range map[string][]string{ |
| "[Unit]Wants": {"carlos-instance-control.service"}, |
| - "[Unit]After": {"carlos-instance-control.service", "carlos-instance-control.socket", "dbus.service"}, |
| + "[Unit]After": {"carlos-instance-control.service", "carlos-instance-control.socket", "dbus.service", "nftables.service"}, |
| } { |
| for _, want := range wants { |
| if !slices.Contains(units[edge][key], want) { |
| @@ -47,10 +64,20 @@ func TestEdgeShutdownKeepsControlAvailable(t *testing.T) { |
| if got := units[edge]["[Service]TimeoutStopSec"]; len(got) != 1 || got[0] != "120" { |
| t.Errorf("%s TimeoutStopSec = %v, want 120", edge, got) |
| } |
| + const control = "carlos-instance-control.service" |
| + if !slices.Contains(units[control]["[Unit]After"], "nftables.service") { |
| + t.Errorf("%s must order startup after nftables.service for hairpin recovery", control) |
| + } |
| + for _, key := range []string{"[Unit]Wants", "[Unit]Requires"} { |
| + if slices.Contains(units[control][key], "nftables.service") { |
| + t.Errorf("%s must not add %s=nftables.service on non-group boxes", control, key) |
| + } |
| + } |
| after := make(map[string][]string) |
| - for _, name := range names { |
| - props := units[name] |
| + // nftables is supplied by the host and orders itself before network-pre. |
| + after["network-pre.target"] = append(after["network-pre.target"], "nftables.service") |
| + for name, props := range units { |
| after[name] = append(after[name], props["[Unit]After"]...) |
| for _, before := range props["[Unit]Before"] { |
| after[before] = append(after[before], name) |
| @@ -85,7 +112,7 @@ func TestEdgeShutdownKeepsControlAvailable(t *testing.T) { |
| } |
| visiting[name], visited[name] = false, true |
| } |
| - for _, name := range names { |
| + for name := range after { |
| visit(name, nil) |
| } |
| } |
diff --git a/internal/provision/testdata/plan14-root-reads-region-ha-graceful-terminate-t1.tsv b/internal/provision/testdata/plan14-root-reads-region-ha-graceful-terminate-t1.tsv| index 368c74f40..22d2e36a3 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-region-ha-graceful-terminate-t1.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-region-ha-graceful-terminate-t1.tsv |
| @@ -1,6 +1,7 @@ |
| # Census overlay region-ha-graceful-terminate-t1, written by census-propose (#369). census-ruling-region-ha-graceful-terminate-t1, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-region-ha-graceful-terminate-t1.md. |
| -# 1 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +# 2 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| @legacy f88f2eb6e612286bcea895a993c42bde3c90a1b3d6048dbb0bb63dc88f4445eb internal/host/units/carlos-edge.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-region-ha-graceful-terminate-t1;basis=Region HA T1/DR-4: start instance-control with the edge and order edge after its service, socket and D-Bus so stop proofs remain available during edge shutdown; set TimeoutStopSec=120. Static unit names only; no new input, command, path, capability or root read. Instance template ordering is unchanged. file:external@0 282d2bf1ab94c34139fea7d355a57368bd8f4d5ed0e4c31910808023e97b0d5a |
| internal/host/units/carlos-edge.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-region-ha-graceful-terminate-t1;basis=Region HA T1/DR-4: start instance-control with the edge and order edge after its service, socket and D-Bus so stop proofs remain available during edge shutdown; set TimeoutStopSec=120. Static unit names only; no new input, command, path, capability or root read. Instance template ordering is unchanged. file:external@0 282d2bf1ab94c34139fea7d355a57368bd8f4d5ed0e4c31910808023e97b0d5a |
| +internal/host/units/carlos-instance-control.service external authority B3,C,D,E1,J4 root-input;kept=B3,C,D,E1;scope=protected-decision-only;rev3=census-ruling-agent-start-demo-3;basis=Correct the runtime-write comment to include escaped demo snapshot .mount units alongside per-generation drop-ins; service directives are unchanged.;rev3=census-ruling-region-ha-graceful-terminate-t1;basis=Region HA T1/DR-4 fix round 1: order control after nftables.service so startup hairpin recovery waits for the loaded ruleset; no Wants or Requires added. Update the startup and shutdown lifetime comment. Static unit ordering only; no new root read, input, path, command or capability. file:external@0 4d3e0383f099cfb3e09bbf8676c50b3ebeaa4360389218fa932e118fbc550b97 |
| @coverage internal/activator 98723d85739969db615d6b0f589fa04a31e62dc80d3b64d3b1094b5edf3eeade |
| -@coverage internal/host/units 08be088b567d574932918977d4a58f40d4830cb9d7d265a77994848ae04038b2 |
| +@coverage internal/host/units bb64c804f6d030a72c420040e350ac29a36b74178528616bc6653c3ddf083876 |