| 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. |