Keep HA shutdown control dependencies alive until edge stops
Start instance-control with the edge and order edge after control, its socket and D-Bus. Set the explicit stop timeout to 120 seconds while preserving every instance template's stop ordering. Add embedded-unit ordering and timeout coverage, refresh the root-read census proposal, and correct the activator budget comments. Targeted host, activator and census tests and package vet pass. Independent census review remains required before merge.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+131
−6
docs/superpowers/notes/census-proposal-region-ha-graceful-terminate-t1.md+19 −0internal/activator/activator.go+1 −1internal/activator/cmd.go+3 −3internal/host/units/carlos-edge.service+10 −2internal/host/units_shutdown_test.go+91 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-region-ha-graceful-terminate-t1.tsv+6 −0
Intent
Attributed to this commit: 102 g CO₂e (10,086,552 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| new file mode 100644 |
| index 000000000..283d59516 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-region-ha-graceful-terminate-t1.md |
| @@ -0,0 +1,19 @@ |
| +# Census approval: region-ha-graceful-terminate-t1 |
| + |
| +Ruling `census-ruling-region-ha-graceful-terminate-t1`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `internal/host/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. | |
| + |
| +Envelopes re-pinned: `internal/activator`, `internal/host/units`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Recorded dispositions, which each change must still satisfy: |
| + |
| +- `internal/host/units/carlos-edge.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input |
| + |
| +Seal: `9cdff432a5de2ffeaa147fdafd6a486c61c27a0c38f77466bddc86b149332c7d` → `a2014042114a4dd671e52a07bbb686b9ef4b6aa97798cc95e1095680c66fd9b2`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-region-ha-graceful-terminate-t1.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/internal/activator/activator.go b/internal/activator/activator.go| index 38dbaaedb..04d963595 100644 |
| --- a/internal/activator/activator.go |
| +++ b/internal/activator/activator.go |
| @@ -6154,7 +6154,7 @@ func (a *Service) Shutdown(ctx context.Context) { |
| // already past that check rather than letting the stop below wait it out. |
| // The wait is right for a Bounce or an idle sleep — no deadline, and |
| // letting the exec finish is tidier — but a shutdown has a deadline it |
| - // does not control: systemd's TimeoutStopSec is 90s by default, and |
| + // does not control: the agent unit's TimeoutStopSec is 120s, and |
| // workerSpawnTimeout alone is 2 minutes. An agent that blocks on one |
| // host's bucket materialize gets SIGKILLed mid-shutdown, which strands |
| // leases and sockets for EVERY host on the box — far worse than |
diff --git a/internal/activator/cmd.go b/internal/activator/cmd.go| index 0ee66d2f8..da1a3dd75 100644 |
| --- a/internal/activator/cmd.go |
| +++ b/internal/activator/cmd.go |
| @@ -83,9 +83,9 @@ var cmdWakeBound = 60 * time.Second |
| // cmdStopBound bounds finishStop's wait for a run: the start in flight |
| // (cmdStartBound), the stop (DeadlineControl), the cgroup (actStopTimeout) |
| // and both streams (cmdAcceptGrace + cmdDrainBound each), with room. |
| -// Shutdown runs inside systemd's 90 s TimeoutStopSec for the agent: a |
| -// settle (about 62 s) fits; a start in flight on top may not, and an agent |
| -// killed mid-stop leaves the lease to its TTL. |
| +// Shutdown runs inside the agent unit's 120 s TimeoutStopSec. A settle |
| +// (about 62 s) fits, but other shutdown phases share that budget. An agent |
| +// killed mid-stop can leave the lease without a release marker. |
| const cmdStopBound = 2 * time.Minute |
| // cmdStartBound bounds RunCmd's StartCmd, well below cmdStopBound, so a |
diff --git a/internal/host/units/carlos-edge.service b/internal/host/units/carlos-edge.service| index 121ebdd4e..08ddc2787 100644 |
| --- a/internal/host/units/carlos-edge.service |
| +++ b/internal/host/units/carlos-edge.service |
| @@ -9,8 +9,13 @@ Description=carlos edge (TLS terminator, host router, activator, release adoptio |
| # requirements: an edge that starts without them would start unprotected, |
| # so it does not start at all. |
| Requires=data-instances.mount run-carlos-instances.mount run-carlos-logs.mount |
| -After=network-online.target data-instances.mount run-carlos-instances.mount run-carlos-logs.mount |
| -Wants=network-online.target |
| +# systemd stops units in reverse start order. Keep root control, its socket |
| +# and D-Bus available until the edge has stopped: their RPCs and reads prove |
| +# termination before HA leases can be released (region HA T1/DR-4). |
| +After=network-online.target data-instances.mount run-carlos-instances.mount run-carlos-logs.mount carlos-instance-control.socket carlos-instance-control.service dbus.service |
| +# Start control at boot: a socket with a pending stop job refuses activation, |
| +# so shutdown cannot rely on socket-starting the service (region HA T1/DR-4). |
| +Wants=network-online.target carlos-instance-control.service |
| [Service] |
| # Optional host-wide config (0600, root-owned): CARLOS_HIBERNATE_*, |
| @@ -22,6 +27,9 @@ ExecStart=/opt/carlos/carlos agent |
| ExecReload=/bin/kill -HUP $MAINPID |
| Restart=always |
| RestartSec=1 |
| +# Allow stop proofs and HA release to finish before systemd's forced kill; |
| +# this is the process-stop backstop, not a release guarantee (region HA T1/DR-4). |
| +TimeoutStopSec=120 |
| # --- hardening (ported from lchat-router.service; see Eleven's |
| # docs/instance-router.md § Hardening) --- |
diff --git a/internal/host/units_shutdown_test.go b/internal/host/units_shutdown_test.go| new file mode 100644 |
| index 000000000..13ac91bc5 |
| --- /dev/null |
| +++ b/internal/host/units_shutdown_test.go |
| @@ -0,0 +1,91 @@ |
| +package host |
| + |
| +import ( |
| + "slices" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func TestEdgeShutdownKeepsControlAvailable(t *testing.T) { |
| + names, err := unitNames() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + units := make(map[string]map[string][]string) |
| + for _, name := range names { |
| + props := make(map[string][]string) |
| + section := "" |
| + for _, line := range unitDirectives(t, name) { |
| + if strings.HasPrefix(line, "[") { |
| + section = line |
| + continue |
| + } |
| + key, value, ok := strings.Cut(line, "=") |
| + if !ok { |
| + continue |
| + } |
| + key = section + strings.TrimSpace(key) |
| + if strings.TrimSpace(value) == "" { |
| + delete(props, key) |
| + } else { |
| + props[key] = append(props[key], strings.Fields(value)...) |
| + } |
| + } |
| + units[name] = props |
| + } |
| + const edge = "carlos-edge.service" |
| + 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"}, |
| + } { |
| + for _, want := range wants { |
| + if !slices.Contains(units[edge][key], want) { |
| + t.Errorf("%s %s lacks %s", edge, key, want) |
| + } |
| + } |
| + } |
| + if got := units[edge]["[Service]TimeoutStopSec"]; len(got) != 1 || got[0] != "120" { |
| + t.Errorf("%s TimeoutStopSec = %v, want 120", edge, got) |
| + } |
| + |
| + after := make(map[string][]string) |
| + for _, name := range names { |
| + props := units[name] |
| + after[name] = append(after[name], props["[Unit]After"]...) |
| + for _, before := range props["[Unit]Before"] { |
| + after[before] = append(after[before], name) |
| + } |
| + template := strings.HasPrefix(name, "carlos-instance") && strings.Contains(name, "@") |
| + if template || name == "carlos-instance-control.service" { |
| + if slices.Contains(props["[Unit]Before"], edge) { |
| + t.Errorf("%s must not declare Before=%s", name, edge) |
| + } |
| + } |
| + if template { |
| + for _, key := range []string{"[Unit]BindsTo", "[Unit]After"} { |
| + if !slices.Contains(props[key], edge) { |
| + t.Errorf("%s lost %s=%s", name, key, edge) |
| + } |
| + } |
| + } |
| + } |
| + visited, visiting := make(map[string]bool), make(map[string]bool) |
| + var visit func(string, []string) |
| + visit = func(name string, path []string) { |
| + if visiting[name] { |
| + t.Errorf("embedded unit ordering cycle: %s", strings.Join(append(path, name), " -> ")) |
| + return |
| + } |
| + if visited[name] { |
| + return |
| + } |
| + visiting[name] = true |
| + for _, dependency := range after[name] { |
| + visit(dependency, append(path, name)) |
| + } |
| + visiting[name], visited[name] = false, true |
| + } |
| + for _, name := range names { |
| + visit(name, nil) |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index bca61cb2b..0184a6750 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -120,3 +120,4 @@ plan14-root-reads-claim-countdown.tsv 5b31785441c6a48ddae93e9f3c0f8962f7983b55d8 |
| plan14-root-reads-region-ha-dr2.tsv 7247af7f4de84593d83c6f60c0147d0a04836146197dd60c2ed2bf78919cad22 |
| plan14-root-reads-dr1-left-link.tsv 160744b3062d0ab9a0cb3c7be3a391ae38cf89ffe410ddd5d179e0c3cb509b66 |
| plan14-root-reads-claim-source.tsv 9cdff432a5de2ffeaa147fdafd6a486c61c27a0c38f77466bddc86b149332c7d |
| +plan14-root-reads-region-ha-graceful-terminate-t1.tsv a2014042114a4dd671e52a07bbb686b9ef4b6aa97798cc95e1095680c66fd9b2 |
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| new file mode 100644 |
| index 000000000..368c74f40 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-region-ha-graceful-terminate-t1.tsv |
| @@ -0,0 +1,6 @@ |
| +# 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. |
| +@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 |
| +@coverage internal/activator 98723d85739969db615d6b0f589fa04a31e62dc80d3b64d3b1094b5edf3eeade |
| +@coverage internal/host/units 08be088b567d574932918977d4a58f40d4830cb9d7d265a77994848ae04038b2 |