Document planned HA termination and witness results
Record T1/DR-4 ordering, release deadlines, single-writer fallback and baseline/fixed termination evidence in spec rev 6.4, section 9.9. Correct Task 1 to preserve control socket activation and nftables ordering.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/plans/2026-11-08-region-ha-graceful-terminate.md+17 −10docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md+67 −1
CI failed — run details
Intent
<task-notification> <task-id>bfrb46t2m</task-id> <tool-use-id>toolu_01F9zLYUHaEoDFPQRS75sQ1P</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/c23f0319-4761-45f6-bac7-f9471c7b9ab1/tasks/bfrb46t2m.output</output-file> <status>completed</status> <summary>Background command "W=/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-graceful/.superpowers/sdd/2026-11-08-region-ha-graceful-terminate; until [ -f $W/task-3-fix2.done ]; do sleep 20; done; echo done" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>bzydd5ugc</task-id> <tool-use-id>toolu_01WXRwR72436F3ucAt1vEU1k</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/c23f0319-4761-45f6-bac7-f9471c7b9ab1/tasks/bzydd5ugc.output</output-file> <status>completed</status> <summary>Background command "python3 -u /home/paulca/.cache/region-ha-graceful/witness.py --worktree $PWD --expect present > ~/.cache/region-ha-graceful/fix-driver-3.log 2>&1; echo exit $? >> ~/.cache/region-ha-graceful/fix-driver-3.log" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 27.7 g CO₂e (3,462,486 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/plans/2026-11-08-region-ha-graceful-terminate.md b/docs/superpowers/plans/2026-11-08-region-ha-graceful-terminate.md| index 0c67099f7..94d1e6fcc 100644 |
| --- a/docs/superpowers/plans/2026-11-08-region-ha-graceful-terminate.md |
| +++ b/docs/superpowers/plans/2026-11-08-region-ha-graceful-terminate.md |
| @@ -67,31 +67,38 @@ before the edge at shutdown). Reversing that deadlocks the agent's blocking |
| Files: `internal/host/units/carlos-edge.service` (embedded; find every test |
| that pins its content or parses it, e.g. grep for `carlos-edge.service` in |
| `internal/host/*_test.go` and the unit installer `ensureSystemUnits`), |
| +`internal/host/units/carlos-instance-control.service`, |
| `internal/activator/cmd.go` and `internal/activator/activator.go` comments |
| that say "systemd's 90 s TimeoutStopSec". |
| Change the edge unit's `[Unit]`: |
| ``` |
| -Wants=network-online.target carlos-instance-control.service |
| +Wants=network-online.target |
| 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 |
| ``` |
| and `[Service]` `TimeoutStopSec=120`, each with a comment stating why: |
| systemd stops units in reverse start order, so the edge (holding HA leases) |
| stops before the root control service, its socket and D-Bus, whose RPCs and |
| -reads are the stop proofs a release needs (region HA T1/DR-4); `Wants=` makes |
| -the control service run from boot, because a socket with a pending stop job |
| -refuses activation, so it cannot be socket-started during shutdown. Do not |
| -touch `BindsTo`/`After` on any instance template. |
| +reads are the stop proofs a release needs (region HA T1/DR-4). Do not add |
| +`Wants=` or `Requires=` on control; the agent socket-activates it after the |
| +edge starts. Do not touch `BindsTo`/`After` on any instance template. |
| + |
| +Shipped correction: run `20261108T034728-f08de2` stayed not ready for five minutes because control's start probe needs the edge's cgroup; drop `Wants=control` and keep `After=control`. |
| + |
| +Add `After=nftables.service` to control so startup hairpin recovery runs |
| +after nftables loads its rules, with no `Wants=` or `Requires=` on nftables. |
| Check the change does not create an ordering cycle with the control service: |
| -it is `After=` the three mounts only, and `Requires=` its socket; the group |
| -drop-in `carlos-edge-group.conf` adds nftables. Write a Go test that parses |
| -the embedded edge unit and asserts: `Wants` contains |
| -`carlos-instance-control.service`; `After` contains |
| +it is `After=` the three mounts and nftables, and `Requires=` its socket and |
| +the mounts; the group drop-in `carlos-edge-group.conf` also orders the edge |
| +after nftables. Write a Go test that parses the embedded units and asserts: |
| +edge `Wants` and `Requires` do not contain |
| +`carlos-instance-control.service`; edge `After` contains |
| `carlos-instance-control.service`, `carlos-instance-control.socket`, |
| -`dbus.service`; `TimeoutStopSec=120`; and that no embedded |
| +`dbus.service`; `TimeoutStopSec=120`; control has `After=nftables.service` |
| +without pulling nftables in; and that no embedded |
| `carlos-instance*` template or `carlos-instance-control.service` has |
| `Before=carlos-edge.service` or orders itself after anything that is ordered |
| after the edge (a direct cycle check over the embedded units is enough). |
diff --git a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md| index 1739d77a4..0919862d4 100644 |
| --- a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md |
| +++ b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md |
| @@ -1,6 +1,6 @@ |
| # Region HA without claims: N-box regions behind a load balancer |
| -Design, 2026-10-26, **rev 6.3** (§23 B10 addendum, 2026-11-05): rev 6 APPROVED by Paul on 2026-10-26, plus his ruling N-HA7 the same day (a scope ruling, not a redesign: §2.1, §8.4, §13, §19). Astra rounds 1 to 3 are complete, and the review budget is spent (AGENTS.md, stopping rules). Branch `design-region-ha-no-claims`, cut from `origin/main` at ddf3b929. Nothing here is built. |
| +Design, 2026-10-26, **rev 6.4** (§9.9 T1/DR-4, 2026-11-08): rev 6 APPROVED by Paul on 2026-10-26, plus his ruling N-HA7 the same day (a scope ruling, not a redesign: §2.1, §8.4, §13, §19). Astra rounds 1 to 3 are complete, and the review budget is spent (AGENTS.md, stopping rules). Branch `design-region-ha-no-claims`, cut from `origin/main` at ddf3b929. Nothing here is built. |
| This spec supersedes every claim-dependent part of "Region HA, spec 2: two-box regions" (`2026-10-15-region-ha-two-box-regions-design.md`, rev 21, cited **S2 §n**) and of spec 1 (`2026-10-04-region-ha-box-placement-design.md`, cited **S1 §n**). §16 lists what it reuses from S2, plan 2a (6834659c) and plan 2b (b1118925), and the removals this series owns. Line citations are to this worktree unless they name a module path. |
| @@ -11,6 +11,7 @@ This spec supersedes every claim-dependent part of "Region HA, spec 2: two-box r |
| - **Rev 5** applied round 3 (`docs/superpowers/notes/reviews/ASTRA-FINDINGS-region-ha-no-claims-r3.md`, 11ad7337, **astra-3.N**) directly, with Paul's approval of 2026-10-26. |
| - **Rev 6** is a scope cut Paul approved on 2026-10-26. Duty handoff drew a P1 in all three rounds, so the duty-file transfer protocol is deleted, not fixed again (stopping rule 2). Duties stay in local registries, as today. One scan-and-import moves them when a box leaves (§7.4). |
| - **Rev 6.2** adds the approved N-HA14 serialized operator ASG Standby maintenance exception to §12.1 (Paul, 2026-11-01). |
| +- **Rev 6.4** records T1/DR-4 planned termination: shutdown ordering, release budgets and the real-terminate witness (§9.9, 2026-11-08). |
| Under stopping rule 2, the families I2, I3 and I4 drew findings two rounds running. I2 and I4 are now stated as invariants, enforced in one place and checked by the simulation (§3.1). I3 drew a P1 in all three rounds, so rev 6 cuts its transfer protocol and restates I3 over the scan alone. |
| @@ -464,6 +465,71 @@ These are estimates; dev measures each one (§21). |
| - **A box that has lost S3** waits for the alarm and the runbook (§9.5). |
| - **A graceful termination** needs no takeover: the shutdown sleeps every instance and writes markers (`activator.go:5186-5194`). |
| +### 9.9 Planned termination |
| + |
| +T1/DR-4 makes a planned shutdown write a release marker when stop proofs, |
| +final durability and marker publication finish within the shutdown budget. |
| +The baseline could stop instance-control and D-Bus in parallel with the edge. |
| +With generations enabled, the required `StopGen` proof then failed and release |
| +was never reached. Separately, release's independent budgets could outlast |
| +the agent's 60 s wait, leaving release abandoned at process exit. |
| + |
| +`carlos-edge.service` now has `After=carlos-instance-control.socket |
| +carlos-instance-control.service dbus.service` and `TimeoutStopSec=120`. |
| +Reverse stop ordering keeps those active dependencies available until the |
| +edge stops. There is no `Wants=` on control: its start probe needs the edge's |
| +cgroup, so the agent socket-activates it after the edge starts. Starting |
| +control first in run `20261108T034728-f08de2` left the box not ready for five |
| +minutes. Control has `After=nftables.service` for startup hairpin recovery. |
| +Instance templates retain `BindsTo=` and `After=carlos-edge.service`, stopping |
| +before the edge; reversing that order would put blocking `systemctl stop` |
| +behind the edge's own stop job. |
| + |
| +The agent sets its deadline to receipt of SIGTERM + 90 s, before admission |
| +closure and HTTP drain. Existing shorter waits remain. For the effective |
| +shutdown deadline D, release uses these cutoffs: |
| + |
| +| Phase | Cutoff | Existing cap | |
| +|---|---|---| |
| +| Files `Final` | D - 40 s | 2 min | |
| +| Replica `Finish` | D - 10 s | 30 s | |
| +| Marker PUT | D | 10 s | |
| + |
| +Each phase gets the smaller of its cap and the time to its cutoff, floored |
| +at 1 s. Outside shutdown the existing caps apply. Contexts are cooperative; |
| +admission closure, publisher/sweeper joins and local release-record work can |
| +overrun D. The 120 s systemd timeout is the process-stop backstop, not a |
| +marker guarantee. |
| + |
| +The single-writer rule holds on timeout too: no marker until every host |
| +writer is proven stopped, the publisher is joined, and `Final` and `Finish` |
| +have returned. Bounded completion with a durability error can produce an |
| +unclean marker. A stuck finalizer produces no marker; takeover still needs |
| +lease expiry plus owner termination proof (§9.4 unchanged). A deadline is |
| +never proof that storage writes have stopped. |
| + |
| +`TestRootHATerminateRelease` (`internal/host/haterminate_rootrunner_linux_test.go`) |
| +uses the real agent, embedded units, systemd poweroff and EC2 |
| +`TerminateInstances`. Lease S3 is a loopback fixture whose writes are mirrored |
| +to real S3 off-box; this is not a real-S3 lease latency measurement. |
| +The ledger records these UTC timelines on 2026-11-08: |
| + |
| +- Baseline main, run `20261108T033846-e40376`: no marker; control stopped at |
| + +4.6 s, before the edge, and the stop RPC failed with broken pipe. |
| +- Fixed `a434b157`, run `20261108T040905-1fa711`, acceptance PASS: |
| + terminate at 04:11:02.207; generation stop at 04:11:04.770; edge SIGTERM at |
| + 04:11:05.292; clean release logged at 04:11:05.446; edge stopped at |
| + 04:11:05.456; control stopped at 04:11:05.471. The mirrored clean marker |
| + arrived +3.21 s after `TerminateInstances`. |
| +- Earlier fixed run `20261108T035758-9ef70e` had a clean marker at +3.13 s, |
| + but was INVALID because the observer lost the journal/unit-stop evidence. |
| + |
| +No ASG termination lifecycle hook is used (T1/DR-4 ruling). Revisit it only |
| +if EC2 cuts OS shutdown short; the witness did not show that. Cancellation |
| +and joining of Litestream work remains open as G2 F-A. Control still has no |
| +`Restart=`: if it dies and the agent never re-activates it, shutdown cannot |
| +prove termination and writes no marker. That failure remains safe. |
| + |
| ## 10. Load balancer health |
| Keep `internal/lbhealth`, with its six conditions (`internal/lbhealth/lbhealth.go:154-178`), and its endpoint (`internal/edge/lbhealth.go:21-39`). A **serving latch** replaces the claim's `SetHosting` caller (`internal/host/claimwiring.go:102-106`). |