carlos / platform Public

Region HA P1b-1 plan: takeover on confirmed termination and same-box re-take before expiry (rev 1), with the Astra round 1 brief

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev c5e8bde0a2601a9fe01dffa8edf2ae79ef2dde23 parent 81db487
2 files changed, +284 −0
  • docs/superpowers/plans/2026-10-27-region-ha-p1b1-takeover.md +226 −0
  • docs/superpowers/plans/CODEX-PLAN-REGION-HA-P1B1-BRIEF-1.md +58 −0

CI failed — run details

diff --git a/docs/superpowers/plans/2026-10-27-region-ha-p1b1-takeover.md b/docs/superpowers/plans/2026-10-27-region-ha-p1b1-takeover.md
new file mode 100644
index 000000000..e86d26ecf
--- /dev/null
+++ b/docs/superpowers/plans/2026-10-27-region-ha-p1b1-takeover.md
@@ -0,0 +1,226 @@
+# Region HA P1b-1: takeover and fast re-take Implementation Plan
+
+> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
+
+**Goal:** A born-HA host whose box is terminated comes back on a surviving box of its pool within minutes, and a host whose agent crashed comes back on the same box within seconds of the agent's restart, instead of after the 15-minute lease.
+
+**Architecture:**
+- **The pure decision.** `hafresh.DecideAcquire` gains one proof, `Proofs.OwnerTerminated`, and two rows: a lock owned by another box whose instance EC2 confirms `terminated` is taken, expired or not; and this box's own lock is taken before expiry with the existing same-box proof.
+- **The oracle.** `termfence` gains a confirmer: one `DescribeInstances` for the owner's instance id, checked against this box's own account and region, with spec §9.2's cache (positive 24 h, negative 10 s).
+- **The wiring.** The box learns its account and region from the identity document it already reads. The activator hands both proofs to `lease.AcquireHA`. Every takeover is request-driven: the first request for the host at a survivor runs the acquire.
+
+**Tech Stack:** Go 1.26, aws-sdk-go-v2 (S3 conditional writes, EC2 `DescribeInstances`), `internal/lease/leasetest`, the seeded simulation in `internal/sim/regionha`.
+
+**Spec:** `docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md` (rev 6.1) §9.2, §9.4's "owner confirmed terminated" row, §9.6, and Paul's ruling N-HA8 below. P1a's plan, `docs/superpowers/plans/2026-10-26-region-ha-p1a-first-slice.md`, is the base this slice changes.
+
+**Status: rev 1, for review. Round limit: three Astra rounds (stopping rule); a P1 in round three goes to Paul as a cut.**
+
+## Ruling N-HA8 (Paul, 2026-10-27)
+
+P1b is cut into slices. This slice, P1b-1, is two things only:
+1. **Takeover on confirmed termination** (§9.2, §9.4), request-driven. No SQS consumer, no scan, no duties.
+2. **Same-box re-take before expiry.** §9.6's "later improvement" moves forward. Evidence: in the 2026-10-27 kill drill on dev, the nested unit stopped 4 ms after the agent died (`BindsTo=carlos-edge.service`), and the restarted agent's sweep proved it gone at once, yet the host stayed down 13m54s waiting for its own lease to expire.
+
+Why now: under P1a, a born-HA host on a dead box never comes back, which is worse than a legacy host.
+
+Deferred to later slices: forwarding (§6), duties and the scan (§7), the termination queue consumer (§9.1), deleting the dead box's edges file (§9.3 step 2), the serving latch and lifecycle hook (§10), hairpin (§12.4), roles.
+
+Task 1 writes this ruling into the spec (§2's rulings, §9.6's last bullet, §19's plan table).
+
+## Global Constraints
+
+- **Termination is evidence only when** a `DescribeInstances` reply names the owner's instance id in this box's own account and region, in state exactly `terminated` (§9.2). `shutting-down`, `stopped`, `stopping`, a missing instance and an error are not evidence. Absence is never evidence.
+- **Cache:** a confirmed termination is kept 24 h; a "not terminated" answer, or an error, 10 s, per instance id. At most one describe per instance id per 10 s per box.
+- **Who may take over:** only a box that already serves the host's route (its pool), because the request has to reach that box's activator. No new placement rule.
+- **No proof without identity.** An HA acquire refuses when this box's instance id, account or region is unknown (`lease.ErrNoSelf`). A lock without `iid=` can never be confirmed terminated or re-taken.
+- **Same-box before expiry** needs exactly P1a's proof (`sameBoxProven`): nested containment, this agent's startup sweep, the host never acquired by this process, the host slice and flat cgroup empty. Nothing weaker.
+- **Restore after a takeover** is P1a's no-marker restore: the local copy is never kept (`hafresh.KeepNoMarker`).
+- **Owner format unchanged:** `box/v1;ref=<ref>;iid=<iid>;pid=<pid>;ha=1`. Account and region are not added to it.
+- **Budget:** a takeover wake is P1a's 1 GET + 1 conditional PUT, plus 1 EC2 `DescribeInstances` (no S3 cost). A refused or held wake against a live other box adds at most one describe per 10 s per owner instance id. Non-HA hosts: unchanged.
+- **IAM:** none new. The box role's inventory statement already allows `ec2:DescribeInstances` (`infra/modules/region-host/main.tf:211-235`).
+- **Cross-compile:** darwin and windows build. Nothing here is linux-only.
+- **Copy:** none. Log lines are diagnostics.
+- **Tests:** locally, touched packages only: `nice -n 19 go test <pkg> -run '<names>' -count=1`. Leave `GOCACHE` at its default.
+- **Simulation:** one 3000-seed sweep per revision, serial, `nice -n 19`, `PAR=2`.
+
+## Review Focus
+
+1. **A stopped box, not terminated** (EC2 stop, a hibernating spot instance). Its HA hosts stay down until it starts or is terminated; no survivor takes them. Task 1: `TestDecideAcquireStoppedOwnerIsNotTaken`; Task 2: `TestConfirmStatesOtherThanTerminated`.
+2. **A describe that fails** (throttling, a network error, a missing IAM grant). The host stays held or refused, the failure is cached 10 s, and the next request tries again. Task 2: `TestConfirmErrorIsCachedBriefly`; Task 4: `TestTakeoverDescribeFailureKeepsHostDown`.
+3. **An owner instance id from another account or region** (a copied bucket, a cross-region lock). Never evidence. Task 2: `TestConfirmRefusesOtherAccountOrRegion`.
+4. **This process's own live lock** (a second wake for a host this process already holds). The proof's "acquired here" check keeps it held, never re-taken. Task 4: `TestOwnLiveLockIsNeverRetaken`.
+5. **A box that has not learned its instance id yet** (IMDS slow at boot). Its HA wakes refuse until `haSelfRetry` sets it; legacy hosts are unaffected. Task 3: `TestAcquireHARefusesWithoutInstanceID`.
+
+---
+
+Tasks 1, 2 and 4 are **[own review]** (stopping rule 3): they decide when a second box may write. Task 5 is the simulation **[own review]**. Task 6 is the dev drill and needs Paul's go before anything touches dev.
+
+### Task 1: The acquire table takes a terminated owner's lock, and this box's own lock before expiry [own review]
+
+**Files:**
+- Modify: `internal/hafresh/acquire.go` (`Proofs`, the reason constants, `DecideAcquire`)
+- Modify: `internal/hafresh/owner.go:13` (`Self`)
+- Test: `internal/hafresh/acquire_test.go`
+- Modify: `docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md` (§2, §9.4, §9.6, §19: N-HA8)
+
+**Interfaces:**
+- Produces:
+ - `type Self struct{ Ref, IID, Account, Region string }`. `OwnerFor` still writes only `Ref` and `IID`. Positional literals `Self{"b", "i-b"}` in tests become keyed.
+ - `type Proofs struct { SameBoxEmpty func() (bool, error); OwnerTerminated func(iid string) (bool, error) }`
+ - `const ReasonTerminated = "holder terminated"`, `const ReasonSameBoxEarly = "same box, proven empty, before expiry"`. The existing `"same box, proven empty"` reason becomes `const ReasonSameBox`.
+
+The new table, in this order:
+
+| Lock | Proof | Decision |
+|---|---|---|
+| absent | | create (unchanged) |
+| not HA-format | | refuse, leftover lock (unchanged) |
+| release marker | | take (unchanged) |
+| HA owner, unparseable | | refuse, malformed marker (unchanged) |
+| owner IID is self.IID (non-empty), expired | SameBoxEmpty true | take, `ReasonSameBox` |
+| owner IID is self.IID, expired | missing, false or error | refuse, `ReasonSameBoxUnsure` (unchanged) |
+| owner IID is self.IID, unexpired | SameBoxEmpty true | take, `ReasonSameBoxEarly` |
+| owner IID is self.IID, unexpired | missing, false or error | held by the owner |
+| owner IID is another non-empty IID, expired or not | OwnerTerminated(o.IID) true | take, `ReasonTerminated` |
+| owner IID another, unexpired | missing, false or error | held by the owner |
+| owner IID another or empty, expired | missing, false or error | refuse, `ReasonOtherExpired` (plus `": " + err` on an error) |
+
+`OwnerTerminated` is never called for this box's own IID or for an empty one. `SameBoxEmpty` is never called for another box's lock.
+
+- [ ] **Step 1: Write the failing tests** in `acquire_test.go`:
+ - `TestDecideAcquireTable`: the row `{unexpired, mine, yes}` changes from `ActHeld` to `ActTake`. Add rows: `{unexpired, other, terminated}` → `ActTake`; `{expired, other, terminated}` → `ActTake`; `{unexpired, other, notTerminated}` → `ActHeld`; `{expired, other, terminatedErr}` → `ActRefuse`; `{unexpired, mine, no}` → `ActHeld`; `{unexpired, mine, broken}` → `ActHeld`.
+ - `TestDecideAcquireReasons`: the three take reasons are `ReasonSameBox`, `ReasonSameBoxEarly`, `ReasonTerminated`; an error from `OwnerTerminated` on an expired lock gives a reason starting `ReasonOtherExpired + ": "`.
+ - `TestDecideAcquireProofScope`: with proofs that record their calls, `OwnerTerminated` is called once with `"i-b"` for another box's lock and never for this box's or an `iid`-less owner's; `SameBoxEmpty` is never called for another box's lock.
+ - `TestDecideAcquireStoppedOwnerIsNotTaken`: `OwnerTerminated` answering false, on an unexpired and on an expired lock of `i-b`: `ActHeld`, then `ActRefuse`.
+- [ ] **Step 2: Run** `nice -n 19 go test ./internal/hafresh -run 'TestDecideAcquire' -count=1`. Expected: FAIL (the new fields and constants are undefined).
+- [ ] **Step 3: Implement** the table above in `DecideAcquire(v View, self Self, now time.Time, p Proofs) Decision`, and the `Self` fields. Update the doc comment's bullet list to the new table.
+- [ ] **Step 4: Run** the Step 2 command, then `nice -n 19 go build ./... && GOOS=darwin go build ./... && GOOS=windows go build ./...`. Expected: PASS and clean builds (fix positional `Self{...}` literals the build reports).
+- [ ] **Step 5: Write N-HA8 into the spec:** add it under §2's rulings; in §9.4's table, the row "Expired, owner is this box's instance id" becomes "Expired or unexpired, owner is this box's instance id"; §9.6's last bullet becomes "Same-box takeover before expiry: P1b-1 (N-HA8)"; §19's table gains a P1b-1 row above P1b. Two sentences each, no more.
+- [ ] **Step 6: Commit** `region-ha p1b-1: the acquire table takes a terminated owner's lock and this box's own before expiry`.
+
+### Task 2: `termfence.Confirmer`: is this instance terminated, in this box's account and region [own review]
+
+**Files:**
+- Create: `internal/termfence/confirm.go`
+- Test: `internal/termfence/confirm_test.go`
+
+**Interfaces:**
+- Consumes: `termfence.EC2`, `DescribeInstance`, `FromDescribe` (existing).
+- Produces:
+ - `func SameAccountTerminated(self boxid.Cloud, iid string, o Observation) error`: nil only when `self.Complete()`, `iid != ""`, `iid != self.InstanceID`, and `o` is `Via == ViaDescribe`, `Found`, `o.InstanceID == iid`, `o.Account == self.Account`, `o.Region == self.Region`, `o.State == "terminated"`. Every refusal wraps `ErrNotEvidence`.
+ - `type Confirmer struct { API func(ctx context.Context, region string) (EC2, error); Self func() boxid.Cloud; Now func() time.Time; /* unexported cache, mutex */ }`
+ - `func (c *Confirmer) Terminated(ctx context.Context, iid string) (bool, error)`: one describe per miss through `DescribeInstance(ctx, api, boxid.Cloud{Provider: "aws", Account: self.Account, Region: self.Region, InstanceID: iid})`; true only when `SameAccountTerminated` is nil. `ErrNotEvidence` answers `(false, nil)`; any other error `(false, err)`. A true answer is cached `24 * time.Hour`; false and errors `10 * time.Second`. `API` is called lazily, once, and its client kept.
+ - `const ConfirmPositiveTTL = 24 * time.Hour`, `ConfirmNegativeTTL = 10 * time.Second`.
+
+- [ ] **Step 1: Write the failing tests** with the package's existing fake `EC2` (see `fence_test.go`'s describe fake):
+ - `TestConfirmTerminatedOwner`: a reply naming `i-b`, account and region equal to self's, state `terminated` → `(true, nil)`; the request asked for `i-b` alone in self's region.
+ - `TestConfirmStatesOtherThanTerminated`: `running`, `stopped`, `stopping`, `shutting-down`, `pending` → `(false, nil)`; an empty reply (NotFound) → `(false, nil)`.
+ - `TestConfirmRefusesOtherAccountOrRegion`: the reply's `OwnerId` differs → false; self's region is `eu-west-1` and the describe is issued only there.
+ - `TestConfirmRefusesSelfAndIncompleteIdentity`: `iid == self.InstanceID` → false with no describe; `Self()` missing the account → `(false, err)` with no describe.
+ - `TestConfirmCachesPositiveForADay`: two calls 23 h apart make one describe; a call at 24 h + 1 s makes a second.
+ - `TestConfirmErrorIsCachedBriefly`: a describe error → `(false, err)`; a call 5 s later makes no describe and answers `(false, err)` again; a call at 11 s describes again.
+ - `TestConfirmNegativeCachedTenSeconds`: `running`, then a call at 9 s makes no describe; at 11 s with `terminated` → true.
+- [ ] **Step 2: Run** `nice -n 19 go test ./internal/termfence -run 'TestConfirm' -count=1`. Expected: FAIL (undefined).
+- [ ] **Step 3: Implement** `confirm.go` with the signatures above. The cache stores the answer and the error per iid.
+- [ ] **Step 4: Run** the Step 2 command and the whole package: `nice -n 19 go test ./internal/termfence -count=1`. Expected: PASS.
+- [ ] **Step 5: Commit** `region-ha p1b-1: termfence.Confirmer, one cached describe per owner`.
+
+### Task 3: The box knows its account and region; an HA acquire refuses without the full identity
+
+**Files:**
+- Modify: `internal/host/haself.go` (`haSelfNow`, `haSelfRetry`, `readInstanceID` → `readIdentity`)
+- Modify: `internal/lease/ha.go:66-70` (the self check in `acquireHATTL`)
+- Test: `internal/host/haself_test.go`, `internal/lease/ha_test.go`
+
+**Interfaces:**
+- Consumes: `hafresh.Self` with `Account`, `Region` (Task 1).
+- Produces:
+ - `func readIdentity(client *http.Client, base string) (iid, account, region string, err error)`: the same IMDSv2 token and document read, within `haIdentityRead`, decoding `instanceId`, `accountId` and `region`.
+ - `haSelfNow` fills all four fields; `haSelfRetry` sets the identity only once all three of `IID`, `Account`, `Region` are non-empty.
+ - `lease.AcquireHA` returns `ErrNoSelf` when `Ref`, `IID`, `Account` or `Region` is empty. Its message becomes `"lease: this box's identity (reference, instance id, account, region) is not known yet; HA acquire refused"`.
+
+- [ ] **Step 1: Write the failing tests:**
+ - `TestHASelfNowNamesTheBox` (extend): the fake IMDS document carries `accountId` `111122223333` and `region` `eu-west-1`; `haSelfNow` returns both.
+ - `TestHASelfRetryWaitsForTheWholeIdentity`: a document with `instanceId` but no `region` does not call `set`; the next tick with all three does, once.
+ - `TestAcquireHARefusesWithoutInstanceID`: `lease.SetSelf(hafresh.Self{Ref: "a"})`, then `AcquireHA` → `errors.Is(err, ErrNoSelf)` with zero requests on the fake store; the same with `IID` set and `Region` empty.
+- [ ] **Step 2: Run** `nice -n 19 go test ./internal/host -run 'TestHASelf' -count=1` and `nice -n 19 go test ./internal/lease -run 'TestAcquireHARefusesWithout' -count=1`. Expected: FAIL.
+- [ ] **Step 3: Implement** the three changes. Update every `lease` and `activator` test fixture that sets an HA self with only `Ref` or `Ref` and `IID` so it carries all four (the build and `go test ./internal/lease ./internal/activator -run 'HA|SameBox' -count=1` find them).
+- [ ] **Step 4: Run** the Step 2 commands and `nice -n 19 go test ./internal/lease ./internal/activator -run 'HA|SameBox|Lease' -count=1`. Expected: PASS.
+- [ ] **Step 5: Commit** `region-ha p1b-1: the box's lease identity carries its account and region`.
+
+### Task 4: The activator hands both proofs to the HA acquire; the agent wires the confirmer [own review]
+
+**Files:**
+- Modify: `internal/activator/hawake.go:317` (the `Proofs` built in `acquireClassified`)
+- Modify: `internal/activator/hasamebox.go` (`sameBoxEmpty`'s log and the alarm wording)
+- Modify: `internal/activator/activator.go` (a new `ExecBackend` field next to `StartupSwept`)
+- Modify: `internal/lease/ha.go` (the acquire's log word)
+- Modify: `internal/host/agent.go:476` (the wiring)
+- Test: `internal/activator/hasamebox_test.go`, `internal/activator/hatakeover_test.go` (create), `internal/lease/ha_test.go`, `internal/host/agent_layout_test.go` or the nearest existing agent-wiring test
+
+**Interfaces:**
+- Consumes: `hafresh.Proofs.OwnerTerminated` (Task 1), `termfence.Confirmer.Terminated` (Task 2), the full `hafresh.Self` (Task 3).
+- Produces:
+ - `ExecBackend.OwnerTerminated func(ctx context.Context, iid string) (bool, error)`. Nil: no takeover (another box's lock stays held or refused, as in P1a).
+ - `func (b *ExecBackend) ownerTerminated(ctx context.Context, rt registry.Route) func(iid string) (bool, error)`: nil when the field is nil. On true it logs `activator: %s: the holder %s is terminated (EC2); taking the host over`. On an error it logs at most once a minute per host, through the existing `sameBoxState.alarm` throttle or a twin of it.
+ - `lease`: the acquire's log word comes from the decision's reason: `first wake`, `clean marker`, `unclean marker`, `same-box takeover`, `same-box takeover before expiry`, `holder terminated`. `classifyAndTake`'s callback keeps the last `hafresh.Decision` it saw so the log names the round that won.
+ - The agent builds one `termfence.Confirmer` with `Self` from `lease.CurrentSelf()` (as `boxid.Cloud{Provider: "aws", ...}`) and `API` building an `ec2.Client` through `rootaws.LoadDefaultConfig(ctx, awsconfig.WithRegion(region))`, and sets `eb.OwnerTerminated = confirmer.Terminated`.
+
+- [ ] **Step 1: Write the failing tests:**
+ - `hatakeover_test.go`, `TestTakeoverOfATerminatedHolder`: a fake HA lock owned by `box/v1;ref=b;iid=i-b;pid=7;ha=1`, unexpired; `OwnerTerminated` answers true for `i-b`. The wake acquires, the lock's new owner names this box with generation + 1, and the wake restores (`haWake.view` has no marker, the keep reason is `no-marker`).
+ - `TestTakeoverDescribeFailureKeepsHostDown`: `OwnerTerminated` answers an error. The wake fails with `errLeaseHeld` (unexpired) or `errLeaseRefused` (expired); the lock is unchanged.
+ - `TestNoTakeoverWithoutTheOracle`: `OwnerTerminated` nil; an unexpired lock of `i-b` is held, an expired one refused, nothing written.
+ - `hasamebox_test.go`, `TestSameBoxRetakeBeforeExpiry`: `sameBoxReady(b)`; the lock is this box's (`iid` equal to self's), another pid, unexpired. The wake acquires, logging `same-box takeover before expiry`.
+ - `TestOwnLiveLockIsNeverRetaken`: as above, but `markAcquiredHere(b, host)` first. The wake fails with `errLeaseHeld`; nothing written.
+ - `TestSameBoxAlarmWordingIsNotAboutExpiry`: the alarm text no longer claims the lock expired (it says "this box's HA lock").
+ - An agent-wiring test: `eb.OwnerTerminated` is set when the agent builds the backend.
+- [ ] **Step 2: Run** `nice -n 19 go test ./internal/activator -run 'TestTakeover|TestNoTakeover|TestSameBox|TestOwnLiveLock' -count=1`. Expected: FAIL.
+- [ ] **Step 3: Implement** the field, `ownerTerminated`, the `Proofs` at `hawake.go:317` (`hafresh.Proofs{SameBoxEmpty: b.sameBoxEmpty(ctx, rt), OwnerTerminated: b.ownerTerminated(ctx, rt)}`), the log words, the alarm wording and the agent wiring.
+- [ ] **Step 4: Run** the Step 2 command, then `nice -n 19 go test ./internal/activator ./internal/lease ./internal/host -run 'HA|SameBox|Takeover|Lease|AgentEntry' -count=1`, then the three `go build` targets from Task 1 Step 4. Expected: PASS and clean builds.
+- [ ] **Step 5: Commit** `region-ha p1b-1: the HA wake takes a terminated holder's host, and its own before expiry`.
+
+### Task 5: The simulation terminates boxes and re-takes early [own review]
+
+**Files:**
+- Modify: `internal/sim/regionha/world_test.go` (a `terminated` box state, the confirmer's view), `actions_test.go` (`terminate`, `decideAcquire`'s proofs), `invariants_test.go` (`checkLiveness`), `rules_test.go` (new rules), `witness_test.go` (one witness per new rule), `sim_test.go` (the action mix)
+- Modify: `internal/sim/regionha/expected-outcomes.txt` only if a rule is a documented miss
+
+**Interfaces:**
+- Consumes: `hafresh.DecideAcquire` with both proofs (Task 1). The model drives the real decision; mutations change only what the model hands it.
+- Produces:
+ - `func (w *world) terminate(b *box)`: everything `crash` does, plus every unit's processes gone (stragglers included, since the machine is gone), the box's disk and local copies gone, and the box never restarts. `w.terminated[b.IID] = true` becomes visible to the confirmer only after a delay of 1 to 12 ticks (EC2's lag).
+ - `decideAcquire` passes `OwnerTerminated: func(iid string) (bool, error) { return w.confirmedTerminated(iid), nil }` and, sometimes, an error (a seeded 10 % of calls).
+ - `checkLiveness` (I5): a host whose lock names a terminated, confirmed box, with no live box holding it, is stranded once the model has given every surviving box of its pool a wake attempt after the confirmation.
+- New rules (each caught alone, each with a witness):
+ - `"takeover-unconfirmed"`: the model answers `OwnerTerminated` true for a box that is hung or alive. Expected: I1 (two holders, or a write by a box that no longer holds).
+ - `"early-retake-own-process"`: the model drops the "acquired here" check from `sameBoxEmpty`. Expected: I1 (two awake entries on one box).
+ - `"no-takeover"`: the model never confirms. Expected: I5 (stranded host).
+
+- [ ] **Step 1: Write the four witnesses** in `witness_test.go` (each a short scripted run that fails only under its rule) and add the rules to `allRules`.
+- [ ] **Step 2: Run** `nice -n 19 go test ./internal/sim/regionha -run 'TestWitness' -count=1`. Expected: FAIL (the actions and rules are not modelled).
+- [ ] **Step 3: Implement** `terminate`, the confirmer's lag, the proofs, the I5 extension and the action mix (terminate at about the rate of `crash`).
+- [ ] **Step 4: Run** the witnesses, then one sweep as `mutate.sh`'s header says: `D=$(mktemp -d -p "$TMPDIR" rhasim.XXXXXX); go test -c -o "$D/regionha.test" ./internal/sim/regionha/ && RHASIM_PAR=2 nice -n 19 internal/sim/regionha/mutate.sh "$D/regionha.test" 3000; rm -r "$D"`. Expected: every rule caught alone, no EXPECTED-MISS change, the unmutated sweep clean.
+- [ ] **Step 5: Commit** `region-ha p1b-1: the simulation terminates boxes and re-takes before expiry`.
+
+### Task 6: Dev drill. Needs Paul's go before anything touches dev.
+
+Release and roll by the platform release recipe in the README and the roll-order rule (dev boxes, dev console, check; flagship only after this drill passes, with `CONSOLE_HA_REGIONS` unset there). Log every step with UTC times in the session's own roll log.
+
+- [ ] **Step 1: Pre-checks on dev.** On leo and sophie, from the agent's environment: `aws ec2 describe-instances --instance-ids <the other box's id> --region eu-west-1` answers (the role allows it). Both boxes run the new release; `agent: lease locks name this box` shows the iid; no `LEASE HELD` for hosts other than the drill's.
+- [ ] **Step 2: Agent-crash drill.** With `hapair-a1` awake on leo and probes through both boxes every 5 s: `kill -9` leo's agent. Expected: after the agent's restart, `HA lease acquired ... (same-box takeover before expiry)` on leo, `restored (no-marker)`, rows intact; sophie answers held, never takes. **Pass: kill to first 200 under 30 s.**
+- [ ] **Step 3: The third box.** In `platform-infrastructure/dev`, add `region-ie-c.tf`, a copy of `region-ie-b.tf` with `host_ie_c`, `carlos-dev-ie-c`, `carlos-dev-host-c`. Apply only that module (`tofu apply -target=module.host_ie_c`; a whole-root apply restarts every box). Bootstrap it as ie-b was, with `CARLOS_POOLS=hapair`, and check `hapair-a1`'s route is nested on it and its certificate is mirrored.
+- [ ] **Step 4: Stop drill.** Wake `hapair-a1` on box C (requests through C only) and write a row. `aws ec2 stop-instances` C. Probes through leo and sophie every 5 s for 5 minutes. Expected: held, then refused; never taken; one describe per 10 s per box at most (agent logs).
+- [ ] **Step 5: Takeover drill.** `aws ec2 start-instances` C and wait for its agent. Wake `hapair-a1` on C again (requests through C only), write rows w1 to w3, then `aws ec2 terminate-instances` C, probing through leo and sophie every 5 s. Expected: held until EC2 reports `terminated`, then `the holder ... is terminated (EC2); taking the host over`, `HA lease acquired ... (holder terminated)`, `restored (no-marker)`, rows w1 to w3 present except at most the last second's (stream class). **Pass: terminate to first 200 under 3 minutes (§9.8).**
+- [ ] **Step 6: Clean up.** `tofu destroy -target=module.host_ie_c` and delete `region-ie-c.tf` (one commit adding, one removing, or neither pushed: say which in the log). `hapair-a1` asleep behind a clean marker. Pools on leo and sophie stay.
+- [ ] **Step 7: Report** on the branch's amadan discussion: the three timelines, describe counts, and any deviation.
+
+## Census
+
+Agent-run changes only (`internal/hafresh`, `internal/termfence`, `internal/lease`, `internal/activator`, `internal/host`'s agent wiring and identity read). Expected classes: `body` and `sites`. Run `make census-card`, CLAIMS, `make census-propose`; a cross-model reviewer approves.
+
+## Spec gaps and follow-ups
+
+- **A lock without `iid=`** written by P1a on a box that had not learned its instance id can never be taken over. Task 3 stops new ones; the drill's pre-check reads every HA lock on dev for one.
+- **Cross-region requests** for a taken-over host may still dial the dead box until its edges entry ages out (§9.3 step 2 is deferred). Step 5 notes whether dev sees it.
+- **Always-on workers and due wakes** of a dead box's host wait for a request (no scan in this slice).
+- **#440** items (publisher mutex, files outside the files dir, BindsTo premise) stay on #440.
diff --git a/docs/superpowers/plans/CODEX-PLAN-REGION-HA-P1B1-BRIEF-1.md b/docs/superpowers/plans/CODEX-PLAN-REGION-HA-P1B1-BRIEF-1.md
new file mode 100644
index 000000000..b5e86c9e8
--- /dev/null
+++ b/docs/superpowers/plans/CODEX-PLAN-REGION-HA-P1B1-BRIEF-1.md
@@ -0,0 +1,58 @@
+# Review brief: Region HA P1b-1 plan (takeover and fast re-take), round 1 of 3
+
+Repo carlos/platform, branch `region-ha-p1b1-takeover`, the commit that adds this brief.
+Under review: `docs/superpowers/plans/2026-10-27-region-ha-p1b1-takeover.md`.
+Authorities: `docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md` (rev 6.1, MERGED) and
+`docs/superpowers/plans/2026-10-26-region-ha-p1a-first-slice.md` (P1a, MERGED as fd93024, #433 fix 80343a5),
+plus the code on this branch (main at 81db4870). Do not review against unmerged branches; if this work needs one, say so as a P1 and stop.
+
+You are an independent reviewer. Read the plan, then the code it names, and check every claim against that code.
+
+## Fixed: do not re-argue
+
+- Paul's ruling N-HA8 (in the plan): this slice is only (1) takeover on EC2-confirmed termination, request-driven,
+ and (2) same-box re-take before expiry with P1a's existing same-box proof. Forwarding, duties, scan, the SQS
+ consumer, edges-file deletion, the serving latch, hairpin and roles are deferred. Report only mechanisms in this
+ slice that fail to honour the spec's safety rules, not the absence of deferred pieces.
+- The spec's rulings §2 (N-HA1..N-HA7) and "expiry alone never lets another box acquire".
+- The drill uses a throwaway third dev box (Paul).
+
+## What to check
+
+1. **Single writer.** Can either new table row (`OwnerTerminated`, `ReasonSameBoxEarly`) let two processes write
+ one host's database, replica or files at once? In particular: an in-flight renewal or replication PUT from the
+ old process; a hung (SIGSTOP) agent while a new agent process runs; pid reuse; the activator calling acquire
+ for a host it already holds (`internal/activator/hasamebox.go`, `hawake.go:270-330`, `internal/lease/ha.go`).
+2. **Termination evidence.** Is `SameAccountTerminated` plus the cache as strict as §9.2 and
+ `internal/termfence/fence.go`'s `Verify`? Is caching an error or a negative for 10 s, and a positive for 24 h,
+ safe? Can a positive be wrong (instance id reuse is impossible on EC2; check for anything else)?
+3. **Identity.** Task 3 makes `AcquireHA` refuse without iid/account/region. Does anything on main construct
+ `hafresh.Self` or call `lease.SetSelf` in a way this breaks (console, CLI, tests, `haSelfRetry` timing)? Does
+ refusing at early boot strand a host?
+4. **The restore after takeover.** Does P1a's no-marker restore path actually run for a taken-over lock (the view
+ has a held, non-marker owner of another box), including files and the H6 trio? Cite the code.
+5. **Tests and the simulation.** Do the named tests exercise what the plan claims? Are Task 5's rules catchable by
+ the model as it is (`internal/sim/regionha`), and is the I5 extension well-defined?
+6. **The drill.** Is Task 6 runnable as written on dev (`platform-infrastructure/dev/region-ie-b.tf` uses
+ `infra/modules/region-host` from the GitHub mirror's main), and do its pass bounds follow §9.8?
+
+## Severity
+
+- **P1**: unsafe, would not compile, a test fails, or it would not work. Blocks merge.
+- **P2**: wrong or missing. Fixed without reopening this review. (The census, and review of any newly changed
+ security, root, termination or production-storage behaviour, still check the fix; see AGENTS.md, "Stopping rules".)
+- **P3**: clarity or polish. Goes on a follow-up list; never a reason for another round.
+
+A P1 states its failure scenario and the evidence (file:line). Do not raise a P2 to P1 to keep the review open.
+
+## Output
+
+Findings ranked P1, P2, P3. Each gives the section or task, the problem, the evidence (file:line, verified), the
+failure scenario, a concrete fix and the invariant or trust boundary it breaks (that is its fault family). End with
+exactly one verdict:
+
+- **READY**: no P1 and no P2.
+- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another round.
+- **NOT READY**: one or more P1s, listed.
+
+Do not edit files. Do not spawn Anthropic-model reviewers or subagents of your own. Do not run the full test suites.