carlos / platform Public

Region HA P1b-1 plan rev 2: round 1 fixes (settle rule, identity predicate, sim oracles, drill without graceful shutdown), round 2 brief

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev c98b239bc601d4e999e0bf1be14f098d1719bf02 parent c5e8bde
3 files changed, +176 −16
  • docs/superpowers/plans/2026-10-27-region-ha-p1b1-takeover.md +41 −16
  • docs/superpowers/plans/CODEX-PLAN-REGION-HA-P1B1-BRIEF-2.md +71 −0
  • docs/superpowers/plans/CODEX-PLAN-REGION-HA-P1B1-R1.md +64 −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
index e86d26ecf..b38ae0b1e 100644
--- a/docs/superpowers/plans/2026-10-27-region-ha-p1b1-takeover.md
+++ b/docs/superpowers/plans/2026-10-27-region-ha-p1b1-takeover.md
@@ -13,7 +13,17 @@
**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.**
+**Status: rev 2, for Astra round 2 of 3. Round limit: three Astra rounds (stopping rule); a P1 in round three goes to Paul as a cut.**
+
+## Round 1 dispositions (`CODEX-PLAN-REGION-HA-P1B1-R1.md`)
+
+| Finding | Disposition |
+|---|---|
+| r1.1 P1: a dead process's already-sent upload can land after the takeover's restore | **Accepted, by a settle rule, not storage fencing.** Every take of a lock that a dead process held (the terminated owner's, and this box's own) waits `hafresh.SettleAfterDeath`, 60 s, after the death is first known: for a termination, after this box first saw `terminated`; for the same box, after this agent process started (the old process died before it). A request a dead sender already put on the wire either completes or is abandoned by S3 well inside that (the kernel flushes or resets within seconds, S3 drops an idle request after about 20 s, and a fully received PUT commits in seconds). This is a time margin of the same kind P1a's expiry gives; generation-isolated replica and manifest fencing is a later design (follow-ups). Task 5 models the late upload and a `no-settle` mutation. |
+| r1.2 P1: a partial initial identity never retries | Accepted. `hafresh.Self.Complete()` is the one predicate; `agent.go:232` starts the retry on `!Complete()`, the retry ends on `Complete()`. Task 3 adds a production-entry test and updates the existing fixture. |
+| r1.3 P1: `early-retake-own-process` cannot be caught | Accepted. Replaced by `early-retake-live-process` with a racing duplicate-wake action and an acquire-time oracle (Task 5). |
+| r1.4 P2: I5 fairness | Accepted. Termination visibility is world truth, independent of the confirmer; I5 needs an eligible survivor and is checked after a fault-free, post-settle wake attempt by each one. |
+| r1.5 P2: graceful stop/terminate writes a marker | Accepted. The drill uses `--skip-os-shutdown`, checks C's lock is a non-marker lock before and after, observes the stop through expiry, and records confirmation and restore separately. |
## Ruling N-HA8 (Paul, 2026-10-27)
@@ -33,6 +43,7 @@ Task 1 writes this ruling into the spec (§2's rulings, §9.6's last bullet, §1
- **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.
+- **Settle:** `hafresh.SettleAfterDeath = 60 * time.Second`. A terminated owner's lock is taken only once this box first saw `terminated` at least that long ago; this box's own lock (expired or not) only once this agent process has run at least that long. Until then the wake answers held (unexpired) or refused (expired), as without proof.
- **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.
@@ -49,7 +60,8 @@ Task 1 writes this ruling into the spec (§2's rulings, §9.6's last bullet, §1
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`.
+5. **A box that has not learned its full identity yet** (IMDS slow or partial at boot). Its HA wakes refuse until the retry sets it; legacy hosts are unaffected. Task 3: `TestAcquireHARefusesWithoutInstanceID`, `TestAgentRetriesAPartialIdentity`.
+6. **An upload the dead process already sent** lands after the take. The settle rule keeps the take behind it. Task 5: the `late-upload` action and the `no-settle` witness; Task 2: `TestConfirmWaitsTheSettle`; Task 4: `TestSameBoxWaitsTheSettle`.
---
@@ -67,6 +79,7 @@ Tasks 1, 2 and 4 are **[own review]** (stopping rule 3): they decide when a seco
- 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 SettleAfterDeath = 60 * time.Second` (the settle rule; the proofs apply it, `DecideAcquire` does not).
- `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:
@@ -95,7 +108,7 @@ The new table, in this order:
- [ ] **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 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; §9.4 also gains the settle rule (r1.1) as one sentence.
- [ ] **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]
@@ -108,8 +121,8 @@ The new table, in this order:
- 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.
+ - `type Confirmer struct { API func(ctx context.Context, region string) (EC2, error); Self func() boxid.Cloud; Now func() time.Time; Settle time.Duration; /* unexported cache, mutex */ }`. The agent sets `Settle` to `hafresh.SettleAfterDeath`; zero means no wait (tests only).
+ - `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})`; evidence when `SameAccountTerminated` is nil. The first evidence for an iid records `firstSeen`; `Terminated` answers true only once `now - firstSeen >= Settle`, and until then `(false, nil)` with no further describe. `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):
@@ -119,6 +132,7 @@ The new table, in this order:
- `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.
+ - `TestConfirmWaitsTheSettle`: `Settle` 60 s; `terminated` at t0 → `(false, nil)`; at t0 + 59 s → false with no second describe; at t0 + 60 s → true, still one describe in all.
- `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.
@@ -129,6 +143,8 @@ The new table, in this order:
**Files:**
- Modify: `internal/host/haself.go` (`haSelfNow`, `haSelfRetry`, `readInstanceID` → `readIdentity`)
+- Modify: `internal/host/agent.go:232` (the retry starts on `!self.Complete()`)
+- Modify: `internal/hafresh/owner.go` (`func (s Self) Complete() bool`: `Ref`, `IID`, `Account`, `Region` all non-empty)
- Modify: `internal/lease/ha.go:66-70` (the self check in `acquireHATTL`)
- Test: `internal/host/haself_test.go`, `internal/lease/ha_test.go`
@@ -136,12 +152,14 @@ The new table, in this order:
- 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"`.
+ - `haSelfNow` fills all four fields; `haSelfRetry` sets the identity only once it is `Complete()`, and `agent.go:232` starts it whenever the startup identity is not `Complete()`. One predicate, both places (r1.2).
+ - `lease.AcquireHA` returns `ErrNoSelf` when the self is not `Complete()`. 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.
+ - `TestHASelfRetrySetsALateInstanceID` (update): its fake document gains `accountId` and `region`.
+ - `TestAgentRetriesAPartialIdentity`: through the production entry (the code at `agent.go:232`, extracted to a function if needed): a startup identity with `IID` but no `Region` starts the retry, and a later complete document reaches `lease.CurrentSelf()`.
- `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).
@@ -164,13 +182,15 @@ The new table, in this order:
- `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`.
+ - `ExecBackend.ProcessStarted time.Time`, set by the agent when it builds the backend. `sameBoxProven` gains a last check: `time.Since(b.ProcessStarted) >= hafresh.SettleAfterDeath` (through the backend's clock seam), else `"this agent process has run %s; a same-box take waits %s after the old process's death"`. A zero `ProcessStarted` refuses. This applies to both same-box rows. The settle refusal is not an alarm: it logs once per host, not through `sameBoxState.alarm`.
+ - The agent builds one `termfence.Confirmer` (with `Settle: hafresh.SettleAfterDeath`) 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`.
+ - `TestSameBoxWaitsTheSettle`: as above with `ProcessStarted` 30 s ago → `errLeaseHeld`, nothing written; at 61 s → acquired. The same for an expired own lock (`errLeaseRefused`, then acquired).
- `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.
@@ -189,16 +209,20 @@ The new table, in this order:
- 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.
+ - **Termination truth** (`w.terminated[iid]`, the tick it happened) is the world's, read by the oracles; the confirmer is a separate model function that the mutations change. The confirmer answers true only `Settle` ticks (6) after its first evidence, and a seeded 10 % of its calls answer an error while faults are on.
+ - `decideAcquire` passes `OwnerTerminated: w.confirmer(b)` and a `SameBoxEmpty` that also checks the process has run `Settle` ticks.
+ - **`lateUpload`** (r1.1): when a process dies (crash or terminate) with an upload in flight (a replica write or a manifest write it had begun), the upload lands at a seeded tick 0 to 4 after the death (always under `Settle`). Its write goes through the existing `replicaWrite` / `manifestWrite` with the dead pid. The existing writer oracle fails I1 if it lands after another process took the lock.
+ - **`duplicateWake`** (r1.3): a second wake attempt for a host that has an entry on this box, between `stopMain` and the release (the window where the slice reads empty and the lease is still this process's). It calls `acquireHA`; the acquire-time oracle fails I1 when a take's classified lock names this box's current live pid.
+ - **I5 after a termination** (r1.4): at the end of a run, if a host's lock names a box that is terminated in truth and some live box of the host's pool exists, the model turns faults off, advances past `Settle`, gives each such box one wake attempt, and only then fails I5 if no box holds the host. With no eligible survivor, I5 does not apply.
- 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).
+ - `"early-retake-live-process"`: the model drops the "acquired here" check from `sameBoxEmpty`. Witness: `duplicateWake` in the stop window. Expected: I1 (the acquire-time oracle).
+ - `"no-settle"`: the confirmer and the same-box proof ignore `Settle`. Witness: a terminate with an upload in flight landing at tick 3, a survivor's wake at tick 2. Expected: I1 (the late write after the take).
- `"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 1: Write the four witnesses** (`takeover-unconfirmed`, `early-retake-live-process`, `no-settle`, `no-takeover`) 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 3: Implement** `terminate`, the confirmer's lag and settle, `lateUpload`, `duplicateWake`, the acquire-time oracle, the I5 phase 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`.
@@ -207,10 +231,10 @@ The new table, in this order:
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 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 90 s** (the 60 s settle plus the restart).
- [ ] **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 4: Stop drill.** Wake `hapair-a1` on box C (requests through C only) and write a row. Read `lock.json`: C's owner, no marker. `aws ec2 stop-instances --skip-os-shutdown` C (no graceful shutdown, so no marker), and read `lock.json` again: unchanged. Probe through leo and sophie every 5 s until 5 minutes past the lock's `expires_at` (about 20 minutes). Expected: held until expiry, refused after; never taken; at most one describe per 10 s per box (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, check `lock.json` is C's non-marker lock, then `aws ec2 terminate-instances --skip-os-shutdown` C, probing through leo and sophie every 5 s, and check `lock.json` is still C's. Expected: held until EC2 reports `terminated` and the settle has passed, 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). Record separately: terminate call, first `terminated` evidence on each survivor, the take, `restored`, first 200. **Pass: no write lost before the last second, no take before the settle; target terminate to first 200 under 3 minutes (§9.8's estimate). Over 3 minutes is a reported deviation with the components, not a failure.**
- [ ] **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.
@@ -221,6 +245,7 @@ Agent-run changes only (`internal/hafresh`, `internal/termfence`, `internal/leas
## 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.
+- **Storage fencing** (r1.1): replica and manifest writes carry no ownership generation. The settle rule is a time margin; a generation-isolated layout (or conditional publication bound to the lock's generation) is a later design, needed before any rule shortens the settle.
- **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-2.md b/docs/superpowers/plans/CODEX-PLAN-REGION-HA-P1B1-BRIEF-2.md
new file mode 100644
index 000000000..72d6a8036
--- /dev/null
+++ b/docs/superpowers/plans/CODEX-PLAN-REGION-HA-P1B1-BRIEF-2.md
@@ -0,0 +1,71 @@
+# Review brief: Region HA P1b-1 plan (takeover and fast re-take), round 2 of 3
+
+Repo carlos/platform, branch `region-ha-p1b1-takeover`, the commit that adds this brief (rev 2).
+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?
+
+## Round 2
+
+Earlier rounds: `docs/superpowers/plans/CODEX-PLAN-REGION-HA-P1B1-R1.md` (round 1, NOT READY: 3 P1, 2 P2). The plan's
+"Round 1 dispositions" table says how each was handled.
+
+First give one line per P1 and P2 from round 1: resolved, partly, or not. Carry every unresolved or partly resolved
+finding forward at its current severity, then add new findings. The verdict covers everything outstanding.
+
+On r1.1 specifically: the plan answers with a 60 s settle (a time margin), not generation fencing, and lists fencing as
+a follow-up. Judge whether the settle's argument (kernel flush or reset, S3's idle-request timeout, PUT commit time)
+holds for both the terminated-box and the restarted-agent cases. If you still rate it P1, say exactly which in-flight
+request survives 60 s past its sender's death, and how.
+
+## 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.
diff --git a/docs/superpowers/plans/CODEX-PLAN-REGION-HA-P1B1-R1.md b/docs/superpowers/plans/CODEX-PLAN-REGION-HA-P1B1-R1.md
new file mode 100644
index 000000000..ac2aeac69
--- /dev/null
+++ b/docs/superpowers/plans/CODEX-PLAN-REGION-HA-P1B1-R1.md
@@ -0,0 +1,64 @@
+Reviewed `region-ha-p1b1-takeover` at `c5e8bde0a2601a9fe01dffa8edf2ae79ef2dde23`. No files changed, subagents spawned, or tests run.
+
+1. **P1 — Tasks 1 and 4: takeover does not fence outstanding data uploads.**
+
+ The new rows permit immediate acquisition after termination or the same-box proof ([plan:80](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/docs/superpowers/plans/2026-10-27-region-ha-p1b1-takeover.md:80)). The conditional write protects `lock.json`, but replication uses the ordinary replica client without a lease-generation fence ([lease.go:429](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/lease/lease.go:429)). Its LTX keys contain transaction ranges, and uploads carry no write precondition ([replica_client.go:702](/home/paulca/go/pkg/mod/github.com/benbjohnson/litestream@v0.5.14/s3/replica_client.go:702)). Files publication checks the manifest’s ETag, independently of the lease ([publisher.go:291](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/hostfiles/publisher.go:291)).
+
+ **Failure scenario:** an old process sends an upload, then dies before receiving its result. The replacement acquires and restores before that upload commits. The old upload subsequently changes the replica or manifest after restoration; an LTX upload can collide with the replacement’s transaction range. Process death and empty cgroups do not establish that a remote request has settled. S3 provides no atomic relationship between updates to these separate keys. [https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)
+
+ **Fix:** specify storage fencing for both replica and manifest publication before enabling these rows—for example, generation-isolated data with authoritative conditional publication. Add a witness that delays an already-sent upload until after takeover and restore. Old lease renewals themselves are protected by the lock ETag; that protection must extend to data.
+
+ **Fault family:** I1, storage writes crossing ownership generations.
+
+2. **P1 — Task 3: an incomplete initial identity can permanently disable HA acquisition.**
+
+ Task 3 requires all identity fields and changes the retry loop’s completion condition ([plan:138](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/docs/superpowers/plans/2026-10-27-region-ha-p1b1-takeover.md:138)), but the production caller starts that loop only when `self.IID == ""` ([agent.go:232](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/host/agent.go:232)).
+
+ **Failure scenario:** the initial document supplies an instance ID but omits account or region—the partial-document case Task 3 explicitly tests. Every HA acquire refuses, yet no retry starts, even when IMDS subsequently returns a complete document. Testing `haSelfRetry` directly misses this.
+
+ The existing retry test also supplies only `instanceId`; under the proposed completion condition it times out unless updated ([haself_test.go:73](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/host/haself_test.go:73)).
+
+ **Fix:** use the same completeness predicate when starting and completing retries. Add a production-entry test covering partial initial identity followed by complete identity, and update the existing retry fixture.
+
+ **Fault family:** identity admission and recovery liveness.
+
+3. **P1 — Task 5: `early-retake-own-process` cannot produce its promised I1 failure in the existing model.**
+
+ The plan requires dropping only `AcquiredHere` to produce “two awake entries on one box” ([plan:196](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/docs/superpowers/plans/2026-10-27-region-ha-p1b1-takeover.md:196)). However:
+
+ - The remaining proof still requires the slice to be empty ([actions_test.go:17](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/sim/regionha/actions_test.go:17)).
+ - Requests do not acquire while an entry exists ([actions_test.go:822](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/sim/regionha/actions_test.go:822)).
+ - `startWake` overwrites the single entry for that host ([actions_test.go:289](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/sim/regionha/actions_test.go:289)).
+ - The write oracle compares box identity and PID, not acquisition generation ([invariants_test.go:80](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/sim/regionha/invariants_test.go:80)).
+
+ **Failure scenario:** the required mutation remains undetected, so Task 5’s “every rule caught alone” gate cannot pass through the stated mechanism.
+
+ **Fix:** explicitly model a retained old lease/publisher while tenant processes are absent, permit the second acquire attempt, and distinguish acquisition generations in the write oracle. Alternatively, test the forbidden acquisition directly with an I3 oracle. Specify a witness reachable under the single mutation.
+
+ **Fault family:** simulation fidelity at the acquisition-generation boundary.
+
+4. **P2 — Task 5: I5 counts unsuccessful opportunities as proof of stranding.**
+
+ The plan injects describe errors on 10% of calls, then declares a host stranded after every survivor has attempted a wake ([plan:192](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/docs/superpowers/plans/2026-10-27-region-ha-p1b1-takeover.md:192)).
+
+ **Failure scenario:** every survivor’s attempt receives an injected error; correct refusal is reported as an I5 violation. With no survivors, “every surviving box” is vacuously satisfied. Also, if I5 reads the mutated confirmation function, `no-takeover` can suppress its own oracle precondition. Existing finalization neither supplies takeover attempts nor defines these distinctions ([world_test.go:537](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/sim/regionha/world_test.go:537)).
+
+ **Fix:** define termination visibility independently of the mutated confirmer, require an eligible survivor, clear transient faults, and supply completed fault-free wake attempts before checking I5.
+
+ **Fault family:** liveness-oracle fairness and independence.
+
+5. **P2 — Task 6: graceful shutdown can bypass both intended drill cases.**
+
+ Steps 4–5 use ordinary EC2 stop and terminate operations while expecting a held, non-marker lock ([plan:212](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/docs/superpowers/plans/2026-10-27-region-ha-p1b1-takeover.md:212)). These operations attempt graceful OS shutdown. [https://aws.amazon.com/about-aws/whats-new/2025/07/amazon-ec2-skip-os-shutdown-option-during-stop-terminate/](https://aws.amazon.com/about-aws/whats-new/2025/07/amazon-ec2-skip-os-shutdown-option-during-stop-terminate/)
+
+ The agent calls `svc.Shutdown` ([agent.go:1107](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/host/agent.go:1107)); a successful HA stop publishes a release marker ([activator.go:4498](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/activator/activator.go:4498)). A survivor may therefore acquire legitimately before termination confirmation. The stop drill’s “never taken” assertion can fail on correct behavior, and the takeover drill can exercise marker acquisition instead.
+
+ The five-minute stop observation also cannot guarantee “held, then refused”: the lease TTL is fifteen minutes ([lease.go:40](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/lease/lease.go:40)).
+
+ **Fix:** explicitly bypass graceful shutdown within the approved disposable-box scope; verify C owns a non-marker lock before and after fault injection. Observe through its recorded expiry to test expired refusal. Record termination confirmation and restore duration separately: §9.8 describes estimates, not an unconditional three-minute guarantee.
+
+ **Fault family:** drill validity and recovery measurement.
+
+The no-marker restore path itself checks out: the acquired view reaches `restoreHA`, `DecideKeep` rejects a missing marker, and restoration replaces the database, files, platform env and wake state ([backend_exec.go:844](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/activator/backend_exec.go:844), [hawake.go:434](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/activator/hawake.go:434), [hawake.go:605](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b1/internal/activator/hawake.go:605)). No P3 findings.
+
+**NOT READY**
\ No newline at end of file