spec rev 4: region HA without claims, Astra round 2
Scope cuts: the N-box moves and seed-import design leaves this spec (section 14 keeps N-HA4's gate, the up-front refusals and six requirements for the P4 and P5 designs); automatic replacement on S3 loss (rev 3's A22) is cut; the removals this series needs are its own P0, not parked cleanup rows. Fixes: failed marker PUTs carried into a durable retry queue that expiry never discharges; clean markers only after a complete publish; duty entries written before the marker; same-box recovery only with an emptiness proof; a launch lifecycle hook and a 60 s grace; H4 placement with affinity only for proven reuse; an NLB security group; mutation costs budgeted. astra-1.5 declined (A16, for Paul to confirm).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+173
−196
docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md+173 −196
diff --git a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md| index 2a690cefd..a0d3265e0 100644 |
| --- a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md |
| +++ b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md |
| @@ -1,45 +1,36 @@ |
| # Region HA without claims: N-box regions behind a load balancer |
| -Design, 2026-10-26, **rev 3**. Branch `design-region-ha-no-claims`, cut from `origin/main` at ddf3b929. Status: draft for Astra round 2. Nothing here is built. |
| +Design, 2026-10-26, **rev 4**. Branch `design-region-ha-no-claims`, cut from `origin/main` at ddf3b929. Status: draft for Astra round 3, the last. Nothing here is built. |
| -**Rev 3** folds in Paul's two answers of 2026-10-26: |
| -- **N-HA4:** N-box offline moves and seed import join this series. §14 is now their design, and the gates in §19 hold back each old box's retirement until both work. |
| -- **N-HA5:** the files sync cadence (§8.2, §18). |
| +This spec supersedes every claim-dependent part of "Region HA, spec 2: two-box regions" (`2026-10-15-region-ha-two-box-regions-design.md`, rev 21, cited **S2 §n**) and of spec 1 (`2026-10-04-region-ha-box-placement-design.md`, cited **S1 §n**). §16 lists what it reuses from S2, plan 2a (6834659c) and plan 2b (b1118925), and the removals this series owns. Line citations are to this worktree unless they name a module path. |
| -It also replaces the operator runbook for a box that is alive but has lost S3 with an automatic, peer-guarded health answer (A22, §9.5). No open questions remain. |
| - |
| -This spec supersedes every claim-dependent part of "Region HA, spec 2: two-box regions" (`2026-10-15-region-ha-two-box-regions-design.md`, rev 21, cited **S2 §n**) and of spec 1 (`2026-10-04-region-ha-box-placement-design.md`, cited **S1 §n**). §16 lists what it reuses from S2, plan 2a (6834659c) and plan 2b (b1118925), and gives claims-cleanup step R3 its exact deletion list. New plans start from this document. |
| - |
| -Line citations are to this worktree unless they name a module path. |
| - |
| -**Rev 2** answers Astra round 1 (`docs/superpowers/notes/reviews/ASTRA-FINDINGS-region-ha-no-claims-r1.md`, 66721809, NOT READY, cited **astra-1.N**) and a builder check (cited **builder-N**), with the coordinator's dispositions. Its central change is that a local copy is kept only on positive proof: a release marker in the lease object (§5). Rev 1's checksum comparison is cut. Rev 2 also cuts scope: |
| -- moves into and out of HA regions, and seed imports, were refused (rev 3 designs them in §14); |
| -- same-box takeover (rev 1's A16) is dropped; |
| -- the write fence (rev 1's A11) is dropped, because no other box can now acquire while the owner may still run. |
| +**How it got here:** |
| +- **Rev 2** answered Astra round 1 (66721809, cited **astra-1.N**) and a builder check (**builder-N**). A local copy is kept only on positive proof, a release marker in the lease object (§5), and expiry no longer lets another box acquire. |
| +- **Rev 3** folded in Paul's N-HA4 and N-HA5. |
| +- **Rev 4** answers Astra round 2 (`docs/superpowers/notes/reviews/ASTRA-FINDINGS-region-ha-no-claims-r2.md`, 8e144c82, cited **astra-2.N**; its "partly" verdicts on round 1 are cited **astra-1.N r2**). It cuts scope: |
| + - the N-box moves and seed-import design leaves this spec. §14 keeps only N-HA4's gate, the refusals and the requirements their own designs must meet; |
| + - automatic replacement on S3 loss (rev 3's A22) is cut; |
| + - the removals this series needs are its own P0, not the parked cleanup rows. |
| | Finding | Disposition | Where | |
| |---|---|---| |
| -| astra-1.1 checksum proof absent in litestream v0.5.14 | Accepted. Checksum reuse is cut; the release marker replaces it. | §5 | |
| -| astra-1.2 expiry bypasses "never take over a hung box" | Accepted. Expiry never lets another box acquire. Clock-skew bound added. | §9.4, §9.7 | |
| -| astra-1.3 A16 relies on a proof that skips nested and unit layouts | Accepted. A16 dropped; listed as a later improvement. | §9.6 | |
| -| astra-1.4 files marker does not prove the tree | Accepted. A stat digest at release, else a restore into a clean tree. | §5.3, §8 | |
| -| astra-1.5 the ~1 s loss window is not implemented | Accepted in part. The stream class captures every second; the other classes' loss is stated, not refused. | §5.5 | |
| -| astra-1.6 key and token producers missed | Accepted. Every producer is listed and moved to the holder after restore. | §7.3 | |
| -| astra-1.7 HRW strands once-timers | Accepted. Duties belong to the holder or the releaser. | §7 | |
| -| astra-1.8 due handoff can delete the only trigger | Accepted. Duty files, an acknowledged transfer, and sidecars carried. | §7.4 | |
| -| astra-1.9 timeline omits backoffs and the boot grace | Accepted. Backoffs follow holder identity; grace kept separate; new test. | §7.2, §9.8, §10, §21 | |
| -| astra-1.10 forwarded requests cannot take over | Accepted. The receiving box takes over locally; cross-region views defined. | §4.3, §6.4 | |
| -| astra-1.11 records carrying `Unit` are adopted | Accepted. Unit, platform and non-hibernating socket records are excluded from serving boxes. | §6.1 | |
| -| astra-1.12 relaxing offline moves is unsafe | Accepted. Rev 2 refused them. Rev 3 gives N-box moves a full contract: an S3 seal, a region target, and promotion before any keep. | §14 | |
| -| astra-1.13 rollback uses a terminated box | Accepted. The old box is stopped, and terminated after acceptance. | §13 | |
| -| astra-1.14 #199 not closed | Accepted. The marker carries the lifetime; reused names with leftovers are refused. | §5.3, §11 | |
| -| astra-1.15 backfill cannot acquire a held lease | Accepted. Publish through the live handle; readiness is publication success. | §8.4 | |
| -| astra-1.16 budgets understated | Accepted. Pagination, the expired-lock acquire, reader amplification. | §18 | |
| -| astra-1.17 A8 does not honour H4; drain blocks on headroom | Accepted. The chooser, and drain always forwards. | §6.3 | |
| -| builder-1 warm wakes need a positive local proof | Accepted. The release marker. | §5 | |
| -| builder-2 cold wakes scatter, so copies rarely match | Accepted. The HRW box is the preferred wake box. | §6.3 | |
| -| builder-3 NLB hairpin with client IP preserved | Accepted. Ingress addresses are redirected to the local edge. | §12.4 | |
| -| builder-4 edges writes fan out to every reader | Accepted. Duty files stay outside the change index; costs counted. | §7.4, §18 | |
| +| astra-1.1 checksum proof absent in litestream v0.5.14 | Closed in r2. The release marker replaces checksums. | §5 | |
| +| astra-1.2 expiry bypasses "never take over a hung box" | Closed in r2. Expiry never lets another box acquire; skew bound. | §9.4, §9.7 | |
| +| astra-1.3 r2 same-box recovery without an emptiness proof | Accepted. Only after the agent stops the host's units and proves its cgroups empty. Layouts with no proof are refused and alarmed. | §9.6 | |
| +| astra-1.4 r2 skipped or unreadable entries still allowed "clean" | Accepted. Clean means a complete publish; otherwise not clean, and not ready to retire. | §5.2, §8.4 | |
| +| astra-1.5 r2 batched and daily classes miss H3 | **Declined.** Under H6 durability follows the plan, so the class is the plan's choice. H3's ~1 s applies to the stream class; the others lose up to their interval, stated plainly. Author's call A16, for Paul to confirm. | §5.5 | |
| +| astra-1.6, 1.7, 1.10, 1.11, 1.13, 1.14, 1.15 | Closed in r2. | §7.3, §7, §6.4, §6.1, §13, §5.3, §8.4 | |
| +| astra-1.8 r2 a host can die before its first duty publication | Accepted. The duty entry is written synchronously before the release marker; until it lands, the box keeps the lease. | §7.4 | |
| +| astra-1.9 r2 the boot grace protects a box that already served | Accepted. A launch lifecycle hook holds new boxes out of service until healthy; the ASG grace drops to 60 s. | §9.8, §10, §12.1 | |
| +| astra-1.12 r2 the moves design opened new blockers | Accepted by scope cut. §14 is refusals and requirements only. | §14 | |
| +| astra-1.16 r2 mutations not budgeted | Accepted. Change-index GET and PUT, and CAS retries, on every edges write and delete. | §18 | |
| +| astra-1.17 r2 HRW preference contradicts H4 | Accepted. New placement uses `ChooseRoomiest`. Affinity only for proven reuse, from the marker the acquire already reads. | §6.3 | |
| +| astra-2.1 a failed marker PUT never reaches the retry path | Accepted. Carried from replicator shutdown into the retry queue with the exact marker and ETag; expiry never discharges it; witness. | §5.2, §21 | |
| +| astra-2.2 A22 can fire during a regional S3 outage | Accepted. A22 cut; alarm and runbook kept; listed as a later improvement. | §9.5 | |
| +| astra-2.3, 2.4, 2.5, 2.7, 2.8 moves and import blockers | Accepted by scope cut. Each becomes a requirement on P4 or P5. | §14 | |
| +| astra-2.6 target SGs block public NLB traffic | Accepted. The NLB gets a security group, targets allow it, and cross-region backhaul is kept. Drills check from outside the VPC. | §12.1, §21 | |
| +| astra-2.9 the cleanup plan no longer deletes what this spec needs | Accepted. The needed removals are tasks of this series' P0. | §16 | |
| +| builder-1 to builder-4 | Accepted in r2. builder-2's HRW preference is replaced by proven-reuse affinity (astra-1.17 r2). | §5, §6.3, §12.4, §7.4 | |
| ## 1. Intent |
| @@ -84,31 +75,32 @@ Each is the author's or the coordinator's. Paul can overturn any of them. |
| | A5 | Takeover is per lease, at the first need after confirmation. There is no bulk pass. | Nothing lists a box's leases cheaply, and the first need comes within seconds. | |
| | A6 | The box that confirms a termination adopts the dead box's duties (§7.4) and only then deletes its duty and edges files. | The transfer is acknowledged before the source goes. | |
| | A7 | A box learns a lease holder from the lease itself and from a peer's 503 header. Awake sets are not published. | No steady-state requests. | |
| -| A8 | Each instance's HRW box (A10) is its **preferred** cold-wake box when serving. If it is ineligible, `ChooseRoomiest` over the cached eligible serving set chooses. | The preferred box usually holds the matching release marker, so wakes stay warm. | |
| +| A8 | A cold wake goes to the box a clean release marker names, when that box is serving and eligible, so its proven copy is reused. Otherwise `ChooseRoomiest` over the cached eligible serving set chooses (H4). | Affinity only where reuse is proven; everything else follows H4. | |
| | A9 | The receiving box may forward once more, to the holder a 503 names, for a GET or HEAD with no body. The cross-region bounce, and a rare 503 for a POST during a membership change, are accepted. | Removes most stale-cache bounces without a new hop protocol. | |
| -| A10 | Rendezvous hash (HRW) over a region's serving boxes chooses where an instance with no holder and no releaser starts, including always-on workers. | One deterministic starter per instance. | |
| +| A10 | Rendezvous hash (HRW) over a region's serving boxes is used only where nothing else picks a box: the duty owner and the starter of an instance with no holder and no releaser, such as a new always-on worker. | One deterministic actor, without a placement round trip. | |
| | A11 | While an instance is awake its duties belong to its lease holder. While it sleeps they belong to the box that released it. | Duties follow the copy that has the state. | |
| | A12 | Box roles `serve`, `drain` and `platform` are control objects set through an operator console door, with their own change-index scope. | Replaces plan 2a's roster roles. | |
| | A13 | The platform box adopts tenant records but never wakes a tenant, and it is not a load balancer target. | The console's local-registry reads keep working. | |
| | A14 | Region membership is "a verified box with a fresh edges file in that region". Auto Scaling membership is not an input, and nothing is enrolled. | Enrolment was the claim's. | |
| -| A15 | `CARLOS_REGION_HA` stays the box switch, redefined claim-free, once the claim code under it is deleted. | It already gates plan 2a's claim-free parts. | |
| -| A16 | H3's window applies to the stream replication class, whose local capture runs every second under HA. Other classes lose up to their interval, stated plainly. | The capture cadence costs CPU, not S3. | |
| +| A15 | `CARLOS_REGION_HA` stays the box switch, redefined claim-free, once P0 has removed the claim code that acts under it (§16.3). | It already gates plan 2a's claim-free parts. | |
| +| A16 | H3's window applies to the stream replication class, whose local capture runs every second under HA. The batched and daily classes lose up to their interval, stated plainly, and are not refused (astra-1.5 declined). **Paul to confirm.** | Under H6 the class is the plan's choice. The capture cadence costs CPU, not S3. | |
| | A17 | Files sync is plan 1a's `hostfiles`, under the instance's hibernate prefix with one fixed generation. | Plan 1a's code without the claim's generations. | |
| | A18 | Spec 1's H7 (ticks are at least once) and H8 (`files_durability` defaults to `snapshot`) carry over. | Both are claim-free. | |
| | A19 | The old box drains before the EIP cut-over, and is then stopped, not terminated, until acceptance. | Rollback inside the window just starts it again. | |
| | A20 | The no-capacity refusal applies at create only. A wake of an existing instance is never refused for headroom: drain and platform ingress always forward to a serving peer. | An existing instance down is worse than an overfull box. | |
| | A21 | Each box redirects traffic it sends to its own region's ingress addresses to its local edge. | NLB hairpin connections fail when the client IP is preserved. | |
| -| A22 | A box whose own S3 access has failed for 3 minutes answers unhealthy, so its group replaces it. It does so only while a peer's private probe shows S3 working for that peer, and while no other box of the region is already unhealthy for S3. | It replaces an operator runbook. The peer guard keeps a regional S3 outage from churning the group. | |
| +| A22 | Cut in rev 4 (astra-2.2): automatic replacement of a box that has lost S3. | A later improvement (§9.5). | |
| +| A23 | A launch lifecycle hook keeps a new box out of service until its health answer is ready. The ASG health-check grace is then 60 s. | A hang after first service is replaced within the few-minute bound (astra-1.9 r2). | |
| ## 3. Model |
| -Every box in a region adopts every tenant host record of its region, as today (`internal/provision/reconcile.go:443-457`), except records the serving boxes must not run (§6.1). An instance has no home box. It runs on whichever box holds its Litestream lease, and only there. A box that receives a request for a host it is not running either takes the lease and wakes the host, or forwards the request once to the box that holds it. It forwards a cold wake to the host's preferred box first. A graceful sleep leaves a release marker in the lease object, naming the box and the exact state it released. Only that box, with that state untouched, may reuse its local copy. Every other wake restores from S3 into a clean tree. Another box may take a lease only from a release marker, or from an owner EC2 has confirmed terminated. Expiry alone is never enough. A hung box therefore keeps its instances down until its group terminates it. A sleeping instance's timers belong to the box that released it, and they are handed on, with an acknowledgement, when that box leaves. |
| +Every box in a region adopts every tenant host record of its region, as today (`internal/provision/reconcile.go:443-457`), except records the serving boxes must not run (§6.1). An instance has no home box. It runs on whichever box holds its Litestream lease, and only there. A box that receives a request for a host it is not running either takes the lease and wakes the host, or forwards the request once to the box that holds it. A cold wake goes where the release marker proves a reusable copy, or else to the roomiest eligible box. A graceful sleep leaves a release marker in the lease object, naming the box and the exact state it released. Only that box, with that state untouched, may reuse its local copy. Every other wake restores from S3 into a clean tree. Another box may take a lease only from a release marker, or from an owner EC2 has confirmed terminated. Expiry alone is never enough. A hung box therefore keeps its instances down until its group terminates it. A sleeping instance's timers belong to the box that released it, and they are handed on, with an acknowledgement, when that box leaves. |
| ## 4. Identity, lease owner and views |
| ### 4.1 Box reference |
| -Fixed boxes keep their status label. Group boxes use `g-` plus a hash of account and instance id (`internal/host/boxreference.go`, `GroupBoxReference`; R1 moves it into `internal/host`). Each box publishes its signed identity record, `control/boxes/<ref>.json` (`internal/boxid/record.go:21-35`), at start when `CARLOS_REGION_HA` is on (`internal/host/boxrecord.go:163`). |
| +Fixed boxes keep their status label. Group boxes use `g-` plus a hash of account and instance id (`internal/host/boxreference.go`, calling `hostactors.GroupBoxReference`, a pure hash that P0 moves into `internal/host`). Each box publishes its signed identity record, `control/boxes/<ref>.json` (`internal/boxid/record.go:21-35`), at start when `CARLOS_REGION_HA` is on (`internal/host/boxrecord.go:163`). |
| ### 4.2 Lease owner |
| @@ -138,7 +130,7 @@ Rev 1 compared checksums. Litestream v0.5.14 writes LTX files with no database c |
| ### 5.2 Writing the marker at release |
| -Today a graceful release deletes `lock.json` (`Replicator.Close`, `internal/lease/lease.go:497-524`, through `ReleaseLease`, `s3/leaser.go:171-200`). On an HA box it instead does the following, in order, after the final database sync and the final files and wake-state publish have both succeeded: |
| +Today a graceful release deletes `lock.json` (`Replicator.Close`, `internal/lease/lease.go:497-524`, through `ReleaseLease`, `s3/leaser.go:171-200`). On an HA box it instead does the following, in order, after three things: the final database sync, the final files and wake-state publish, and, for a host with a duty, the acknowledged duty-file write (§7.4): |
| 1. **The local record.** Write `<db>.release.json` beside the database, and fsync it. It holds: |
| - the marker fields below; |
| - the database file's identity: inode, size, `mtime_ns`, `ctime_ns`, and that its `-wal` is absent or empty after the checkpoint; |
| @@ -156,8 +148,14 @@ So old binaries and non-HA boxes see a marker as a released lease. |
| **Failures.** |
| - A 412 means the lease is no longer ours: no marker, and the local copy will be set aside next time. |
| -- A failed PUT is retried by the existing owed-release path (#292, `lease.go:326-358`), with the same condition. |
| -- If the final sync or publish failed but S3 is reachable, the marker is written with `clean: false`. Another box may then acquire, but nobody keeps a local copy, and the writes that did not reach S3 are lost. |
| +- **A failed marker PUT is an obligation that outlives the replicator** (astra-2.1). Today `Replicator.Close` returns the release error (`lease.go:497-524`) and the activator logs it and forgets the entry (`activator.go:4401`). The existing owed-release path (#292) belongs to `Held.Release` and retires itself after expiry (`lease.go:341-350`), which would strand an HA lease forever. |
| + - On HA boxes, `Close` returns the exact marker body and the ETag it was conditioned on. |
| + - The activator keeps both in a retry queue, persisted beside the local record so an agent restart resumes it. It retries with the same condition and backoff. |
| + - **Expiry never discharges the obligation.** It ends only on success, or on a 412 (someone else has the lease now). |
| + - Until then the host stays unacquirable by other boxes, which is safe. |
| +- **What `clean` means** (astra-1.4 r2). The marker is `clean: true` only if the final sync succeeded and the final files publish was complete: no entry skipped or unreadable (`internal/hostfiles/sync.go:126-175`). |
| + - Otherwise it is written with `clean: false`. Another box may then acquire, nobody keeps a local copy, and writes or files that did not reach S3 are lost. |
| + - A host whose last marker is not clean is not ready for retirement (§13). |
| - If S3 is unreachable, no marker is written. The lease stays held until it expires, and then only this box may take it again (§9.4). |
| ### 5.3 Keeping or restoring at wake |
| @@ -171,10 +169,10 @@ The HA acquire (§9.4) reads `lock.json` anyway, so the decision costs no extra |
| `ctime` cannot be set from userspace, so a write, rename or chmod since the release breaks the proof. |
| -**In every other case,** it renames the local database and files directory aside (`<db>.stale`, `<host>.stale/`, newest kept), purges litestream's local state (`PurgeLocalDBArtifacts`, `backend_exec.go:831`), and restores. That covers no marker, another box's marker, an expired lease, a crash, a different lifetime, `clean: false`, and no replica. The database restores as today (`backend_exec.go:853`). The files restore into a new empty directory, which then takes the old one's place. So `hostfiles.Restore`'s preservation of unlisted paths (`internal/hostfiles/restore.go:42-47`) never applies (astra-1.4). |
| +**In every other case,** it renames the local database and files directory aside (`<db>.stale`, `<host>.stale/`, newest kept), purges litestream's local state (`PurgeLocalDBArtifacts`, `backend_exec.go:831`), and restores. That covers no marker, another box's marker, an expired lease, a crash, a different lifetime, `clean: false`, and no replica. The database restores as today (`backend_exec.go:853`). The files restore into a new empty directory, which then takes the old one's place. So `hostfiles.Restore`'s preservation of unlisted paths (`internal/hostfiles/restore.go:42-47`) never applies (astra-1.4). On HA boxes the move-staging fallback (`backend_exec.go:833-851`, `:3509-3529`) does not run: staging leftovers never authorize a promotion (§14). |
| **What this loses, stated plainly.** |
| -- After an agent crash, the box re-takes its own lease when it expires (§9.4). It then restores, losing the writes not yet in S3: about a second for the stream class. |
| +- After an agent crash, the box re-takes its own lease when it expires, and only with an emptiness proof (§9.6). It then restores, losing the writes not yet in S3: about a second for the stream class. |
| - An instance whose box crashed before its first replication starts fresh. Everything it wrote is lost. |
| - No copy is ever kept because it is "ahead" of S3. |
| @@ -218,11 +216,12 @@ An awake instance runs only on its lease holder. At box A, for a request to tena |
| ### 6.3 Where a cold wake happens (A8, astra-1.17) |
| -1. H's **preferred box** is its HRW box: the box in serving(region) with the highest `sha256(H + "\x00" + ref)`. If it is eligible, the wake happens there. A forwards to it, or wakes locally if A is it. Eligible means the existing policy: at least 15% of memory and 10% of disk free, and a fresh edges file (`policy.go`). |
| -2. If the preferred box is ineligible, `boxchoice.ChooseRoomiest` over the cached eligible serving set chooses (`policy.go:77-99`). |
| -3. If no box is eligible, an existing instance is still woken, on the preferred box, and the over-capacity alert fires (A20). |
| +1. **Proven reuse.** The acquire's first step is a GET of `lock.json` (§9.4), so A reads the lock at no extra cost. If it is a clean release marker naming a serving, eligible box B, the wake goes to B: A forwards, or wakes locally if A is B. Only B can keep its copy. |
| + |
| + Eligible means the existing policy: at least 15% of memory and 10% of disk free, and a fresh edges file (`policy.go`). |
| +2. **Otherwise H4.** `boxchoice.ChooseRoomiest` over the cached eligible serving set chooses (`policy.go:77-99`). A wakes H if it is the choice, and otherwise forwards to the choice, which runs its own acquire. Spread follows from H4's roomiest choice. |
| +3. **If no box is eligible,** an existing instance is still woken, on the roomiest serving box, and the over-capacity alert fires (A20). |
| 4. **Drain and platform ingress always forward** an existing instance to a serving peer, whatever its headroom. |
| -5. Spread comes from the hash, which scatters an app's instances across boxes. |
| ### 6.4 Forwarded requests (astra-1.10) |
| @@ -287,8 +286,12 @@ Every producer of `<host>.env` secrets runs **only on the lease holder, after th |
| ### 7.4 Duty files and their transfer (astra-1.8, builder-4) |
| **The file.** Each box keeps `control/duties/<ref>.json`: one entry per host whose duties it owns while asleep, `{host, kind, next_due, released_at, lifetime}`. |
| -- It is written when the set changes, batched to at most once a minute. |
| -- It is **not** a change-index scope, so no reader re-reads anything when it changes. |
| +- **Written before responsibility is given up** (astra-1.8 r2). A release of a host with any duty (a `next_due`, a once-timer, a declared schedule, or a sidecar due wake) first rewrites this box's duty file with the entry, and waits for the PUT's success. Only then does it write the release marker (§5.2). |
| + - If the PUT fails, the box keeps the lease, so it is still the holder and still responsible, and it retries. A box that dies before the PUT dies as a holder, so its duties pass by termination. |
| + - Releases arriving close together share one PUT, so a burst of sleeps is one write. |
| + - A host with no duty writes nothing. |
| + - Removals (a host this box no longer owns) are batched to once a minute, since a stale entry is harmless: §7.1's acquire drops it. |
| +- It is **not** a change-index scope (`changeindex.go:53-76`), so writing it costs no index GET or PUT, and no reader re-reads anything. |
| - Only a box adopting another box's duties reads it. |
| **Transfer.** When a box leaves, through termination confirmed (§9.3) or `drained: true` (§13), its **adopter** takes over. The adopter is the serving box with the highest `sha256(departing ref + "\x00" + ref)`. It: |
| @@ -299,7 +302,7 @@ Every producer of `<host>.env` secrets runs **only on the lease holder, after th |
| If the adopter dies part way, the source is still there, and the next adopter repeats the transfer. The merge is idempotent. An adopted host's marker still names the departed box, which counts as a release, so the adopter's acquire succeeds and restores from S3. |
| -**Delay.** A due entry released in the last minute before a termination can be up to a minute stale in the file. Its wake state in S3 is current, and the adopter's first acquire for the host brings its timers back. |
| +**No gap.** Every sleeping host with a duty is in a durable duty file before any marker names its releaser. So an adopter finds every host the departed box was responsible for, and its first acquire for each brings the timers back from the wake state. |
| ## 8. Per-instance files (H6) |
| @@ -328,7 +331,7 @@ When `CARLOS_REGION_HA` turns on: |
| - for each **awake** instance, the activator's files publisher runs an initial full publish through the live lease handle it already holds; |
| - for each **sleeping** instance, the box runs the HA acquire, publishes, and releases with a marker. |
| -Each host records `files_published_at` only on a successful publish. Readiness counts only that, so a skipped or failed publish keeps it false. |
| +Each host records `files_published_at` only on a complete publish, with no entry skipped or unreadable. Readiness counts only that, so a skipped, partial or failed publish keeps it false. |
| ## 9. Termination, takeover and expiry |
| @@ -360,9 +363,9 @@ On an HA box, the lease package's acquire reads first: one GET of `lock.json` wi |
| | Absent | Create, with `If-None-Match: *`. | |
| | A release marker, clean or not | Conditional PUT, with `If-Match`. | |
| | Held and unexpired | A held answer naming the owner (§6.2). | |
| -| Expired, owner is this box's instance id | Conditional PUT. This is today's same-box recovery after an agent crash, which waits out the TTL. | |
| +| Expired, owner is this box's instance id | Conditional PUT, only with the emptiness proof of §9.6. Otherwise refused. | |
| | Expired or unexpired, owner confirmed terminated (§9.2) | Conditional PUT: the takeover. | |
| -| A lifted tombstone, or a staging marker (§14) | Conditional PUT. Never keep the local copy; promote any staging first. | |
| +| A lifted tombstone, left by a move before the region went HA | Conditional PUT; never keep the local copy. | |
| | Anything else | Refused: another box's expired lease, an old-format owner, or a live tombstone. | |
| The refused cases keep the instance down until its owner is terminated or the owner itself re-takes the lease. **Expiry alone never lets another box acquire.** That holds for a stopped agent whose app processes still run, a frozen process, and a box that has lost S3. |
| @@ -376,22 +379,18 @@ The refused cases keep the instance down until its owner is terminated or the ow |
| ### 9.5 The cost of the rule |
| -A hung box's instances wait for the group to replace it. That takes 2 to 5 minutes once the box is past its boot grace, and the grace remainder plus that inside it (§9.8). |
| - |
| -**A box that is alive but has lost S3 (A22).** Its leases are stuck, because its renewals fail but no other box may take them until it is terminated. So it reports itself unhealthy and lets its group replace it. A shared outage must still never churn the group (S2 §6), so it does this only when all of these hold: |
| -- **Its own S3 is failing.** For 3 minutes, every request it made to the data bucket or the deployment bucket failed on transport, a 5xx or a timeout. A 412 or 404 is an answer, not a failure. The serial GET every 2 s (AGENTS.md) gives the deployment bucket a steady signal, and lease renewals give the data bucket one. |
| -- **A peer shows S3 working.** At least one serving peer answers a private probe on the backhaul listener, signed like a hop, with a successful request to each bucket within its last 2 minutes. A peer with no recent data-bucket request is not evidence. |
| -- **No other box is already unhealthy for S3.** No probed peer reports that it is. On a tie, the lower reference goes first. |
| +**A hung box's** instances wait for the group to replace it: 2 to 5 minutes (§9.8). |
| -Then: |
| -- the probe runs once a minute, and only while the box's own condition holds, so the steady state costs nothing; |
| -- if no peer can give evidence, as in a regional outage or an idle two-box region, the box stays healthy, and the suspect-holder alarm (§20) remains the backstop, with a runbook step to terminate it. |
| +**A box that is alive but has lost S3** keeps its instances down until someone terminates it. Its renewals fail, but no other box may take its leases. Its health stays 200 by design, because a shared dependency must never terminate boxes (S2 §6). The suspect-holder alarm (§20) fires after 10 minutes, and the runbook step is to terminate that instance in its group, which H1 counts as death. |
| -Its instances are back in about 3 minutes plus the hung-box time. |
| +Rev 3's automatic replacement (A22 of rev 3) is cut (astra-2.2): a peer's recent success does not prove S3 is up now, and two failing boxes had no atomic way to decide which goes. **A later improvement** may bring it back, with a bounded decision protocol and witnesses for staggered outages. |
| -### 9.6 Same-box takeover: dropped (astra-1.3) |
| +### 9.6 Same-box recovery after expiry (astra-1.3 r2) |
| -Rev 1's A16 is dropped. After an agent crash, a box re-takes its own lease only when it expires, so instances wait up to 15 minutes, as today. **A later improvement** may shorten that, once a real emptiness proof exists for nested, rootfs and unit layouts; `wakeHostProven` skips those (`internal/activator/opset.go:437-453`). |
| +After an agent crash, a box may re-take its own expired lease only once it has proven the old writer gone. Its agent stops the host's units, and proves the host's cgroups empty. |
| +- **No proof, no recovery.** Layouts with no such proof are refused: nested and rootfs instances, `Backing=unit`, and boxes without cgroup delegation. `wakeHostProven` accepts all of those today (`internal/activator/opset.go:437-453`), and startup cleanup is best-effort (`internal/host/agent.go:592-598`). |
| +- **What a refusal does.** It raises the suspect-holder alarm. The runbook step terminates the box, which then makes the takeover path apply. |
| +- **Same-box takeover before expiry** stays a later improvement. |
| ### 9.7 Clock skew |
| @@ -404,18 +403,18 @@ Expiry now matters only for a box re-taking its own lease, which uses one clock. |
| These are estimates; dev measures each one (§21). |
| -| Phase | Box terminated through the API | Box hung after its boot grace | |
| +| Phase | Box terminated through the API | Box hung, including just after its first service | |
| |---|---|---| |
| | The load balancer stops new connections | 20 to 30 s | 20 to 30 s | |
| -| The group terminates the box | not needed | typically 1 to 2 min after it turns unhealthy | |
| +| The group terminates the box | not needed | typically 1 to 2 min after it turns unhealthy, at most the 60 s grace after first service | |
| | EC2 reports `terminated`; the event arrives | 30 s to 2 min | 30 s to 2 min after the group's terminate | |
| | First request: acquire, describe, takeover, restore | about a second, plus the restore | the same | |
| | **Total, request-driven instances** | **about 1 to 3 min** | **about 2 to 5 min** | |
| | Always-on workers, ticks, due wakes | one sweep (30 s or less) after confirmation; backoffs cancelled | the same | |
| | Worst case, event lost | the next request's dial failure confirms at once; with no requests, view ageing (15 min) | the same | |
| -- **A hang inside the boot grace.** The group's grace period suppresses replacement after the box is in service (AWS documents this), so the box is down for the rest of the grace plus the hung-box time. The grace is kept as short as the measured boot (§10), and it is reported apart from the serving bound. |
| -- **A box that has lost S3 (A22)** is back in about 5 to 8 minutes: 3 minutes to detect, then the hung-box time. That needs a peer to give evidence; otherwise it is the alarm and the runbook. |
| +- **A hang just after first service** (astra-1.9 r2). The launch lifecycle hook (§12.1) keeps a booting box out of service until it is healthy, so the group's health-check grace is only 60 s. A box that hangs right after its first service is replaced within the same bound, plus at most that minute. |
| +- **A box that has lost S3** waits for the alarm and the runbook (§9.5). |
| - **A graceful termination** needs no takeover: the shutdown sleeps every instance and writes markers (`activator.go:5186-5194`). |
| ## 10. Load balancer health |
| @@ -425,8 +424,11 @@ Keep `internal/lbhealth`, with its six conditions (`internal/lbhealth/lbhealth.g |
| - **Set** once all of these hold: `host.env` loaded; the first reconcile pass for the region done; the first edges file published with the box's role; and the termination consumer started. |
| - **Cleared** first in shutdown (`activator.go:5190`). |
| - A `drain` box stays healthy until it is removed, because it forwards. The `platform` box is not a target. |
| -- **The boot grace** is the measured boot time plus a small margin, starting at 8 minutes, since there is no enrolment. It is kept separate from the serving failure bound. |
| -- **Added as a seventh condition:** "not failing on S3 under the peer guard" (§9.5). Plain S3 reachability is still not a condition (S2 §6). |
| +- **Boot** is covered by a launch lifecycle hook, not by the health-check grace (A23, astra-1.9 r2): |
| + - the box completes the hook when the latch is set, and only then does the group put it in service and register it; |
| + - the hook's timeout is the measured boot time plus a margin, starting at 15 minutes, and abandons a box that never completes it; |
| + - the health-check grace is 60 s, which covers the target group's first two checks. |
| +- **Not added:** S3 reachability (S2 §6). |
| ## 11. Placement inputs, capacity and create refusals |
| @@ -444,21 +446,34 @@ Keep `internal/lbhealth`, with its six conditions (`internal/lbhealth/lbhealth.g |
| Today the module makes one `aws_instance` and one `aws_eip` (`main.tf:536-587`). Group mode adds: |
| - **A launch template,** as S2 §4: the same AMI, type, root volume with delete on termination, security group and profile; IMDSv2 with hop limit 1; an auto-assigned public IPv4 for cross-region dials. The user data names the deployment, bucket, region and AWS region. |
| -- **An Auto Scaling group:** `min = max = desired = box_count` (H5); at least two zones; health checks ELB plus EC2; the grace from §10; no instance refresh; `AZRebalance` suspended. |
| -- **A Network Load Balancer:** one subnet mapping per group zone. Zone A carries the region's existing EIP, as a standalone `aws_eip` with `prevent_destroy`. Other zones get new, unpublished EIPs. Cross-zone on; TCP 80 and 443; instance targets, so the client IP is kept; deregistration delay 30 s; health HTTP on 80 at `/.carlos/lb-health`, every 10 s, 2 healthy and 2 unhealthy. |
| -- **The security group:** 80, 443 and the backhaul port from the VPC CIDR. |
| +- **An Auto Scaling group:** |
| + - `min = max = desired = box_count` (H5), across at least two zones; |
| + - health checks ELB plus EC2, with a 60-second grace; |
| + - a launch lifecycle hook (`autoscaling:EC2_INSTANCE_LAUNCHING`, default result `ABANDON`), which the box completes when its latch is set (§10); |
| + - no instance refresh, and `AZRebalance` suspended. |
| +- **A Network Load Balancer, with its own security group** (astra-2.6): |
| + - one subnet mapping per group zone. Zone A carries the region's existing EIP, as a standalone `aws_eip` with `prevent_destroy`. Other zones get new, unpublished EIPs; |
| + - cross-zone on; TCP 80 and 443; instance targets, so the client IP is kept; |
| + - deregistration delay 30 s; health HTTP on 80 at `/.carlos/lb-health`, every 10 s, 2 healthy and 2 unhealthy; |
| + - its security group admits 80 and 443 from anywhere. |
| +- **The target security group:** |
| + - admits 80 and 443 from the NLB's security group, which covers both traffic and health checks (AWS: register targets with a load balancer security group); |
| + - keeps 443 from anywhere, as today (`main.tf:97-107`), because cross-region backhaul dials each box's own public address on 443 (`internal/edge/edge.go:3056`) from boxes whose addresses change. That path is hop-signed; |
| + - keeps the backhaul port from the VPC CIDR for private dials. |
| + |
| + Drills check public traffic from outside the VPC. |
| - **The termination rule and queue:** unchanged. **Alarms:** §20. |
| ### 12.2 IAM |
| -- **Box role:** SSM reads on `/carlos/<deployment>/<region>/*` and `/shared/*`, with `kms:Decrypt` under the `ViaService` and `PARAMETER_ARN` conditions; the existing SSM Deny; an explicit HA statement for `ec2:DescribeInstances`. No Auto Scaling, ELB or EC2 write right. |
| +- **Box role:** SSM reads on `/carlos/<deployment>/<region>/*` and `/shared/*`, with `kms:Decrypt` under the `ViaService` and `PARAMETER_ARN` conditions; the existing SSM Deny; an explicit HA statement for `ec2:DescribeInstances`; and `autoscaling:CompleteLifecycleAction` on its own group's ARN only. No other Auto Scaling, ELB or EC2 write right. |
| - **Console:** nothing new. **Operator seeding:** `ssm:PutParameter` and the KMS actions (S2 §5 step 2). |
| ### 12.3 Boot |
| 1. **Harden.** This includes the nftables gate that keeps tenants away from IMDS credentials. |
| 2. **Configure.** Fetch the bootstrap binary and check its SHA-256 from SSM. Then `carlos system host-env write` (`internal/hostenv`, plan 2b), minus `CARLOS_HOST_CLAIM*`. |
| -3. **Install.** `carlos bootstrap`, then `carlos system install-channel` (`internal/host/installchannel.go`), without its guard and floor checks. |
| +3. **Install.** `carlos bootstrap`, then `carlos system install-channel` (`internal/host/installchannel.go`), as built. Its floor check is a no-op while no moves floor is published. |
| 4. **Start the agent.** No joining mode, enrolment or guard-arm. |
| A failed step leaves the box never healthy, and the group replaces it. |
| @@ -483,17 +498,17 @@ This is the sequence for UK, US and AU; IE differs in step 5. |
| 1. The HA release runs on the old box and the console. |
| 2. `CARLOS_REGION_HA=1` is set on the old box. With one box every rule is a no-op beyond the markers and one restore per instance (§5.4). |
| 3. Readiness, from `carlos system region readiness <region>`, reports: |
| - - every instance has a replica and a successful `files_published_at` (§8.4); |
| + - every instance has a replica, a complete `files_published_at` (§8.4), and no unclean last marker (§5.2); |
| - no old-format lock (§9.4); |
| - no non-hibernating socket instance (§6.1). |
| 4. The group is built, healthy behind zone B's address, and rehearsed there, including the hairpin check. |
| -5. Gate G5 holds (§19): N-box offline moves and seed import work, so the region is never left unable to move or import (N-HA4). |
| +5. Gate G5 holds (§19): P4 and P5 are designed, shipped and rehearsed, so the region is never left unable to move or import (N-HA4). |
| **Steps:** |
| 1. **Join.** Register the old box in the target groups as an ordinary member. |
| 2. **Drain.** `carlos system box role <old> drain`. The box stops waking, forwards everything to serving peers whatever their headroom (A20), and sleeps its awake instances one at a time: |
| - a graceful stop with a marker, a 5-second pause, then the next; |
| - - a request for a host mid-stop waits for the stop, then goes to the host's preferred box, which restores it: a few seconds down per app; |
| + - a request for a host mid-stop waits for the stop, then goes to the box §6.3 chooses, which restores it: a few seconds down per app; |
| - always-on workers move to their HRW box. |
| When nothing is awake, the box publishes `drained: true`, and its adopter takes its duties (§7.4). |
| @@ -513,75 +528,30 @@ Its local copies are older than the markers in S3, so each wake there restores. |
| **Cost.** During the window there is one extra box, stopped after step 4. Each region adds a load balancer (about $20 a month before traffic) and EIPs for its extra zones. |
| -## 14. Offline moves and seed import in N-box regions (N-HA4) |
| - |
| -**Until plans P4 and P5 ship (§19),** the offline-move door refuses any move whose source or destination region is HA, and the seed-import door refuses an HA region. Both refusals come up front and name the region. Rev 1's relaxed predicates stay withdrawn (astra-1.12). |
| - |
| -This section is the spec-level contract. P4 and P5 hold the detail. Today's single-box path (`internal/host/movesoffline*.go`) stays for non-HA regions, so a move between an HA and a non-HA region uses the HA rules on its HA side only. |
| - |
| -### 14.1 Source: stop and seal from S3 |
| - |
| -1. **Stop.** |
| - - If the instance is awake, its lease holder sleeps it gracefully, which writes a clean release marker (§5.2). |
| - - The move then writes its tombstone, `moved:<id>` (`internal/lease/tombstone.go`), by a conditional PUT over that marker's ETag. The same applies over an absent lock, or over a lease whose owner §9.2 has confirmed terminated. A live holder is never tombstoned; the move waits for the stop. |
| - - Every box of the source region reports that it does not serve the host, as the per-box reports do today. |
| -2. **Seal from S3 alone.** A clean marker means the final database sync, files publish and wake-state export all reached S3 before it was written (§5.2). So the seal is three things, all already in S3, and no box is a sealer: |
| - - the replica up to the marker's `txid`; |
| - - the files manifest `files_gen`, which carries the H6 trio and the wake state; |
| - - the marker's lifetime. |
| - |
| - No box-local data is ever trusted. Today's sealer checkpoint (`internal/host/movesoffline_seal.go:398-408`) and its local archive of files and env do not run on an HA source. |
| - |
| - With `clean: false`, an absent marker, or a terminated owner, the seal is S3 as it stands. Writes that never reached S3 are lost, as in a failover (H3, §5.5), and the move's report says so. |
| -3. **Box selection** (`internal/console/apiinstancemove_offline.go:1024-1049`). On an HA source it becomes region-level: |
| - - every box in the source region's view has reported the stop; |
| - - the lock is the move's tombstone. |
| - |
| - "Local data on more than one box" and the sealer choice go, because local data no longer decides anything. The stager is the HRW box over the move id among the source region's serving boxes. It is re-chosen if it leaves the view, and its copy is idempotent. |
| +## 14. Offline moves and seed import (N-HA4) |
| -### 14.2 Target: the region |
| +**The ruling and its gate.** N-box offline moves and seed import belong to this series (N-HA4), as plans P4 and P5. Each gets its own design document, reviewed before it is planned. Dev and the first test region may go HA without them. No carloku.com region retires its old box until both have shipped and been rehearsed (gate G5, §19). |
| -1. **Stage.** The stager copies the replica and the files objects named by the sealed manifest to the destination region's staging prefix. It then writes a **staging marker** into the destination's `lock.json` with `If-None-Match` or `If-Match`: `{owner: "staged/v1;move=<id>", expires_at: 1970-01-01T00:00:00Z, carlos_staged: {move, lifetime, txid, files_gen}}`. It refuses to overwrite anything but an absent lock, a lifted tombstone, or its own staging marker. |
| -2. **Land.** No box is chosen. The destination's console door requires at least one serving box with the offline-stage capability. The first serving box to wake the host runs the HA acquire (§9.4), sees the staging marker, and promotes the staging before anything else: it never keeps a local copy, then restores the database and files into a clean tree. |
| +**Refusals in force until then.** Each is made up front, before anything stops or is written, and names the region: |
| +- the offline-move door refuses a move whose source or destination region is HA, which includes every mixed HA and non-HA move; |
| +- the seed-import door refuses an HA region; |
| +- on HA boxes, the activator's move-staging fallback does not run (§5.3). |
| - This fixes the promotion order: today the warm-cache return (`internal/activator/backend_exec.go:819-820`) runs before the promotion (`:833-851`). On HA boxes, the keep decision is reached only from a clean release marker naming this box, so a staging marker always reaches promotion first. Non-HA boxes keep today's single-target path. |
| -3. **Duties and timers.** The wake state travels in the manifest and is imported at the first wake. Until then the host has no holder and no releaser, so its HRW box owns its duties (§7.1) and wakes it for its first due time. |
| - |
| - On the source, each box drops the host's duties when it finds the tombstone at its next acquire, or when the move reports "gone". The source's duty-file entries go at that point. |
| -4. **Keys.** `<host>.env` is restored from the staged manifest before any launch. Because a manifest exists, no box mints a key or token (§7.3). The key survives the move. |
| - |
| -### 14.3 Rollback and failure cases |
| - |
| -**Rollback** depends on how far the move got: |
| -- **Before land:** delete the destination staging and its staging marker (conditional on the marker's ETag), then lift the source tombstone (`LiftTombstone`). The HA acquire table treats a lifted tombstone as "acquire and restore, never keep" (§9.4). |
| -- **After open in the destination:** a move back. |
| - |
| -**Failure cases:** |
| - |
| -| Failure | What happens | |
| -|---|---| |
| -| The stager dies | It is re-chosen, and the copy resumes. | |
| -| The landing box dies after promotion, before release | §9's takeover. The staging marker is gone, so the box restores from the promoted replica. | |
| -| A destination box holds a leftover copy | It never matches a staging marker or a release marker naming it, so it is set aside. | |
| -| The source holder is hung | The move waits for its termination (§9.4), and the console shows why. | |
| - |
| -### 14.4 Seed import through the same path |
| - |
| -Today an import swaps the seed in beside the legacy row on one box, and keeps its journal and rollback there (`internal/console/seedfloor.go:25-29`). In an HA region, an import becomes a region-target landing whose source is the uploaded seed: |
| -1. stop and tombstone, as in §14.1; |
| -2. copy the current replica and manifest to `imports/<id>/previous/` in S3; |
| -3. stage the seed as the new replica; |
| -4. replace the tombstone with a staging marker (§14.2), by a conditional PUT on the tombstone's ETag. |
| - |
| -The first waker promotes the seed. The journal is the import record in the console's store plus those S3 prefixes, so no box holds state the import needs. Rollback stages `previous/` back the same way. Seeds that are not imports already land under the lease on whichever box wakes. |
| +**Requirements P4 and P5 must meet** (from astra-2.3, 2.4, 2.5, 2.7 and 2.8): |
| +1. **Durable identity through promotion.** The pending move and its sealed source identity stay durable through acquisition and renewal until promotion is verified complete. Staging leftovers never authorize a promotion: today's fallback mirrors whatever staging remains and ignores delete errors (`internal/activator/backend_exec.go:3509-3529`, `:3555`). Crash witnesses: before promotion, mid-copy, and mid-cleanup. |
| +2. **A pinned stager.** The stager stays pinned, as today (`internal/host/movesoffline_stage.go:59-80`, `:222-228`). It is replaced only after an acknowledged stop or a confirmed termination (§9.2), never because it left a view. Otherwise the move does not advance. |
| +3. **Seed import replaces the route it replaces.** The import is the replacement of an unprovisioned address route identified by `Replaces` (`internal/provision/seedswap.go:28-53`). Its ownership checks, verification gate and `EnvBefore` provenance (`internal/registry/importjournal.go:45`) are persisted region-wide, durably, before the imported route is exposed. Unsupported legacy layouts are refused up front. |
| +4. **The destination writes its own lock.** A destination-region actor validates the completed staging and writes the destination lock. No new cross-bucket rights: the source keeps its push-only grant under `moves/*` (`infra/modules/region-host/main.tf:236-247`). |
| +5. **Mixed moves.** A move between an HA and a non-HA region either has an explicit transport conversion in each direction, or stays refused. A non-HA source makes an encrypted archive and a timer snapshot (`internal/host/movesoffline_seal.go:716-767`), and a non-HA target needs them (`movesoffline_land.go:812`, `:1071`). A conversion covers keys, platform files, timers, and manifest keys made staging-relative (`internal/hostfiles/manifest.go:26-32`). |
| +6. **Direction, not design.** A clean release marker (§5.2) plus a tombstone over it could let an HA source be sealed from S3 alone, trusting no box-local data. P4 may start from that idea. |
| ## 15. S2 §8's single-box rows, restated |
| | Row | Status | Answer | |
| |---|---|---| |
| -| Move door and `selectMoveBoxes` (`internal/console/apiinstancemove.go:687-713`, `boxselect.go:78-140`, `internal/host/movesphase1.go:502-518`) | Dropped | Phase 1 is deleted by R4a. Offline moves: §14. | |
| -| Seed import (`internal/console/seedfloor.go:25-29`, `:88-89`) | Rebuilt | Region-target import with an S3 journal (§14.4); refused until P5. | |
| -| `CheckOneBoxRegion` (`internal/hostfence/onebox.go:12-35`) | Dropped | Its callers are claim-only, deleted by R6. | |
| +| Move door and `selectMoveBoxes` (`internal/console/apiinstancemove.go:687-713`, `boxselect.go:78-140`, `internal/host/movesphase1.go:502-518`) | Inert | Phase 1 runs only with `CARLOS_MOVES_PHASE1`, which is off. Offline moves: §14. | |
| +| Seed import (`internal/console/seedfloor.go:25-29`, `:88-89`) | Refused | Refused in HA regions until P5 (§14). | |
| +| `CheckOneBoxRegion` (`internal/hostfence/onebox.go:12-35`) | Inert | Its callers are claim-only, and claims are off. | |
| | Warm cache (`activator.go:2302-2311`, `backend_exec.go:819-820`) | Built | §5. | |
| | Hosts unique to one box (`internal/console/apiinstances.go:523-527`) | Rewrite | Show the box whose snapshot reports the host awake, or none. | |
| | EIP list (`internal/console/view.go:178-237`, `server.go:1301-1376`) | Rewrite | The region ingress list (`CONSOLE_REGION_INGRESS`, from tofu) plus `PLATFORM_EDGE_IPS`. Copy review. | |
| @@ -595,29 +565,26 @@ The first waker promotes the seed. The journal is the import record in the conso |
| ### 16.1 Kept |
| -`internal/lbhealth`, `internal/edge/lbhealth.go`, `privateDial` and `dialAddress`, `internal/edgesfile/private.go`, `awsaddr.go`, `boxaddress.go`, `headroom.go`, `internal/boxid`, `boxrecord.go`, `boxreference.go` with `GroupBoxReference`, `internal/boxchoice`, `internal/termfence` (with `Box` cut to `{Ref, Cloud}`), `internal/hostfiles`, `internal/hostenv` (minus the claim keys), `installchannel.go` (minus its guard), the termination rule and queue, and plan 2a's approved no-capacity copy. |
| +`internal/lbhealth`, `internal/edge/lbhealth.go`, `privateDial` and `dialAddress`, `internal/edgesfile/private.go`, `awsaddr.go`, `boxaddress.go`, `headroom.go`, `internal/boxid`, `boxrecord.go`, `boxreference.go` with `GroupBoxReference`, `internal/boxchoice`, `internal/termfence` (with `Box` cut to `{Ref, Cloud}`), `internal/hostfiles`, `internal/hostenv` (minus the claim keys), `installchannel.go`, the termination rule and queue, and plan 2a's approved no-capacity copy. |
| ### 16.2 Rewritten |
| The `SetHosting` caller becomes the latch (§10). The address source moves out of `edgesclaims.go`. The role door (§4.4). `nocapacity.go`, `regioncapacity.go` and where the metric starts (§11). `boxselect.go` keeps `liveEdges` and `verifiedRoster`. |
| -### 16.3 Handed to R3 for deletion |
| +### 16.3 P0: removals this series owns (astra-2.9) |
| -- `internal/hostrelocate`, and `internal/host/relocat*.go`; |
| -- `internal/hostactors/awsmembership`, `internal/console/awsmembership.go`, `internal/console/enrollpass.go`, and `hostactors`' `autoenroll.go`, `membershipread.go` and `enrollment_confirmation.go` (or with R6); |
| -- `internal/host/joining.go`, `joinmode.go`, `joinroot.go`; `carlos system join`; `carlos-system-join.{service,path}`. `system apply` removes the installed units; |
| -- `internal/console/hostclaimexecutor.go` and the region-HA branches of `hostclaimops.go`; |
| -- `internal/host/edgesclaims.go`, after the address split; |
| -- `hostops/chosen.go`, plan 2a's `hostops/executor.go` additions, and `hostactors/roles.go` (with R6); |
| -- the `region-ha-2a` and `region-ha-2b` census rows of deleted units, retired the R0 way. |
| +The claims cleanup stopped after R0, R1, R2 and T1, and keeps HA 2a/2b (`origin/design-live-moves-ha`, `docs/superpowers/plans/2026-10-25-claims-cleanup.md`, "Change of course"). So this series does not depend on any parked row. P0 removes only what would act under the redefined `CARLOS_REGION_HA`: |
| +1. **Split the box address source** out of `internal/host/edgesclaims.go`, and delete the `hostclaim.Read` that runs with `CARLOS_REGION_HA` alone (`internal/host/edgesfile.go:983-988`), together with its claim filtering of relocatable hosts. |
| +2. **Delete joining mode:** `internal/host/joining.go`, `joinmode.go` and `joinroot.go`; the `carlos system join` verb; and `carlos-system-join.{service,path}`. `system apply` removes the installed units. |
| +3. **Delete the console's enrolment pass:** `internal/console/enrollpass.go`, `awsmembership.go`, `internal/hostactors/awsmembership`, and the region-HA branch of `StartClaimRecoveryPass` (`internal/console/hostclaimops.go:44-61`). The metric start moves to console start (§11). |
| +4. **Rewrite, not delete:** the `SetHosting` caller (`internal/host/claimwiring.go:102-106`) becomes the latch; `nocapacity.go`, `regioncapacity.go`, `apiboxroles.go` and `system_roles.go` lose their claim halves; `termfence.Box` is cut to `{Ref, Cloud}`. |
| +5. **Move `GroupBoxReference`** (a pure hash, inventory §3) into `internal/host`. |
| -### 16.4 Amendments to the cleanup plan |
| - |
| -R3 keeps `termfence`, `boxrecord.go`, `install-channel`, `CARLOS_REGION_HA`, `privateDial` and `edge/lbhealth.go`. R4a keeps `boxchoice`. Changes to root verbs and units need a census card and an approval (AGENTS.md). |
| +Every other claim package stays inert with claims off, and is left to opportunistic cleanup. P0 keeps the inventory's live helpers (`Incarnation`, the `park` region helpers, the offline door's absence checks, `ClaimUnitControlGroup`). Before deleting a file it moves out every claims-off witness test that file holds (inventory §4). Changes to root verbs and units need a census card and an approval (AGENTS.md). |
| ## 17. Interactions |
| -- **Moves and seed imports:** §14. The self-serve moves branches (`origin/self-serve-moves-2` to `-4`) build on the HA path for HA regions. |
| +- **Moves and seed imports:** refused in HA regions until P4 and P5 (§14). The self-serve moves branches (`origin/self-serve-moves-2` to `-4`) are the base for P4. |
| - **Nearest region and #199** (`origin/design-nearest-region-199`, rev 2): §5.3 closes the local-copy half with the lifetime in the marker. §11 refuses reused names with S3 leftovers in HA regions, including `files/0/` and the lock. |
| - **Static sites; the edge asset cache; rootfs apps (#366):** unchanged, except that a box materializes images on its first wake there. |
| - **`db pull`/`db query --at` and the cross-region db forward:** they read the replica, so any box of the region serves them. |
| @@ -625,17 +592,18 @@ R3 keeps `termfence`, `boxrecord.go`, `install-channel`, `CARLOS_REGION_HA`, `pr |
| - **The change index (#336):** one new scope, `control/box-roles`. Duty files are deliberately outside it. Edges deletions ride `control/edges`. |
| - **Housekeeper and certificates:** unchanged (S2 §6). |
| -## 18. Request budget (astra-1.16) |
| +## 18. Request budget (astra-1.16, astra-1.16 r2) |
| S3 prices: LIST and PUT $0.005 per 1,000; GET $0.0004 per 1,000; DELETE free. |
| +**Mutations of change-index scopes.** A write or delete under a scope (`control/edges`, `control/box-roles`) is followed by the index's read-modify-CAS: 1 GET and 1 PUT, with up to 4 retries of both on conflict (`internal/release/changeindex.go:108-150`). Every write below that touches such a scope counts that cost. Duty files and lease objects are not scopes, so they pay none. |
| + |
| **Steady state, per box per hour.** |
| -- **S3:** unchanged, at about 3,300 to 3,500 today. The edges timed pass is unchanged; duty files add at most 60 PUTs. |
| -- **SQS:** 180 long-poll receives (about $0.05 a month). **EC2:** describes only on suspicion, at most one per instance per 10 seconds. |
| -- **Peer probes (A22):** none in steady state; one private request a minute per peer while a box's own S3 is failing. |
| +- **S3:** unchanged, at about 3,300 to 3,500 today, including the edges timed pass and its index bump. |
| +- **SQS:** 180 long-poll receives, about $0.05 a month. **EC2:** describes only on suspicion, at most one per instance per 10 seconds. |
| - **The lease TTL** is unchanged (N-HA3). |
| -**Reader amplification** comes only from writes that bump `control/edges`: the timed passes, box start and stop, role changes, and the deletion of a dead box's file. Each makes every box in the deployment re-read at its next 30-second poll: one LIST per 1,000 keys, plus one GET per edges file (`homemap.go:456-491`). Readers coalesce, so the bound is 120 × (1 + B) requests per box per hour, for B boxes in the deployment. The timed passes already reach it today, so this spec adds none. |
| +**Reader amplification.** Each `control/edges` mutation makes every box in the deployment re-read at its next 30-second poll: one LIST per 1,000 keys plus one GET per edges file (`homemap.go:456-491`). Readers coalesce, so the bound is 120 × (1 + B) requests per box per hour for B boxes. The timed passes reach it today; this spec adds only rare mutations (role changes, a dead box's deletion). |
| **Per event.** |
| @@ -643,15 +611,19 @@ S3 prices: LIST and PUT $0.005 per 1,000; GET $0.0004 per 1,000; DELETE free. |
| |---|---| |
| | Wake, HA box, local copy kept | 1 GET + 1 PUT (acquire) | |
| | Wake, HA box, restore | 1 GET + 1 PUT, plus the restore: up to 5 LISTs, plus 1 LIST per extra 1,000 L0 files, plus GETs, plus 1 manifest GET and its objects | |
| +| Wake forwarded for reuse or placement (§6.3) | + 1 GET on the receiving box | |
| | Wake, non-HA box (today) | 1 PUT; an expired lock costs 2 PUTs + 1 GET (`lease.go:193-195`, `s3/leaser.go:114`) | |
| -| Sleep, HA box | as today, + files publish if changed, + 1 PUT (marker) in place of a free DELETE, + at most one duty-file PUT a minute | |
| +| Sleep, HA box | as today, + files publish if changed, + 1 duty-file PUT if the host has a duty (shared by releases close together), + 1 PUT (marker) in place of a free DELETE | |
| +| A failed marker PUT | 1 PUT per retry, with backoff, until success or a 412 | |
| | Probe of a held lease | 1 GET | |
| | Takeover | 1 GET + 1 PUT + 1 describe | |
| -| Termination or drain transfer | 2 GETs + 1 PUT + 2 DELETEs | |
| +| Termination transfer | 2 GETs + 1 duty-file PUT + 1 duty-file DELETE + 1 edges DELETE + index (1 GET + 1 PUT, up to 4 retries) | |
| +| Drain transfer | 1 GET + 1 duty-file PUT + 1 DELETE | |
| +| Role change (console) | 1 PUT + index (1 GET + 1 PUT, up to 4 retries) | |
| | Awake hour, snapshot plan | at most 4 publishes, none when unchanged | |
| | Awake hour, continuous plan | up to 720 PUTs per app file being rewritten (2 per 10 s), about $2.60 a month per such file. The H6 trio: up to 2 PUTs a second while written, which is rare | |
| -**Example.** 10,000 sleep-and-wake cycles a day on HA boxes add 10,000 GETs and 10,000 PUTs: about $0.054 a day. |
| +**Example.** 10,000 sleep-and-wake cycles a day on HA boxes, half of them hosts with a duty, add 10,000 GETs and 15,000 PUTs, or fewer with shared duty-file writes: about $0.08 a day. |
| ## 19. Switches and rollout |
| @@ -661,33 +633,34 @@ S3 prices: LIST and PUT $0.005 per 1,000; GET $0.0004 per 1,000; DELETE free. |
| | Plan | Scope | |
| |---|---| |
| -| P1 | Box core: owner format, HA acquire, release marker and keep rule (§5), forwarding (§6), duties and keys (§7), files sync (§8), takeover (§9), latch and A22 (§10), hairpin (§12.4), roles. | |
| -| P2 | Console: role and readiness doors, capacity metric, create refusals (§11), ingress list, the S2 §8 rewrites (§15). | |
| -| P3 | Infrastructure and boot (§12): group mode, boot script, IAM, alarms. | |
| -| P4 | N-box offline moves (§14.1 to §14.3), with the self-serve moves owner. | |
| -| P5 | Region-target seed import (§14.4), with the seeded-instances owner. | |
| +| P0 | The removals this series owns (§16.3). | |
| +| P1 | Box core: owner format, HA acquire, release marker, keep rule and retry queue (§5), forwarding (§6), duties and keys (§7), files sync (§8), takeover and same-box proof (§9), latch and lifecycle hook (§10), hairpin (§12.4), roles. | |
| +| P2 | Console: role and readiness doors, capacity metric, create refusals (§11), the HA move and import refusals (§14), ingress list, the S2 §8 rewrites (§15). | |
| +| P3 | Infrastructure and boot (§12): group mode, NLB security group, lifecycle hook, boot script, IAM, alarms. | |
| +| P4 | **Design, then plan:** N-box offline moves, meeting §14's requirements, with the self-serve moves owner. | |
| +| P5 | **Design, then plan:** seed import into N-box regions, meeting §14's requirements, with the seeded-instances owner. | |
| | P6 | Retirement (§13): runbook, drills, rollback rehearsal. | |
| -**Gates.** Each release rolls dev boxes, dev console, check, flagship boxes, flagship console. R3 (§16.3) lands before P1. |
| +**Gates.** Each release rolls dev boxes, dev console, check, flagship boxes, flagship console. P0 lands before P1. |
| | Gate | Allows | Needs | |
| |---|---|---| |
| -| G1 | `CARLOS_REGION_HA` on dev's two IE boxes (`platform-infrastructure/dev/region-ie-b.tf`), together, as the first N=2 test | P1 and P2 released; moves and imports refused | |
| +| G1 | `CARLOS_REGION_HA` on dev's two IE boxes (`platform-infrastructure/dev/region-ie-b.tf`), together, as the first N=2 test | P0, P1 and P2 released; moves and imports refused | |
| | G2 | A dev group region (P3) | G1; the terminate, hang, hang-after-first-service and S3-loss drills timed (§21) | |
| -| G3 | The first test region goes HA: the switch on its old box, then its group joins | G2; readiness green; moves and imports may still be refused (N-HA4) | |
| +| G3 | The first test region goes HA: the switch on its old box, then its group joins | G2; readiness green; moves and imports refused (N-HA4) | |
| | G4 | Other carloku.com regions go HA, one at a time: UK, US, AU, then IE | G3 accepted for seven days | |
| -| G5 | Any carloku.com region retires its old box (§13) | P4 and P5 shipped and rehearsed on dev's N-box region, moves in and out and an import with rollback (N-HA4); P6 rehearsed on dev | |
| +| G5 | Any carloku.com region retires its old box (§13) | P4 and P5 each designed, reviewed, shipped and rehearsed on dev's N-box region (N-HA4); P6 rehearsed on dev | |
| ## 20. Observability and alerts |
| - The load balancer's `UnHealthyHostCount > 0` for 10 minutes; `HealthyHostCount < box_count` for 25 minutes. |
| -- `EligibleBoxes < box_count` for 25 minutes, missing as breaching; `GroupInServiceInstances < desired`. |
| +- `EligibleBoxes < box_count` for 25 minutes, missing as breaching; `GroupInServiceInstances < desired`; abandoned lifecycle hooks. |
| - The termination queue's `ApproximateAgeOfOldestMessage` over 10 minutes. |
| - **Takeovers and transfers:** a metric and a log line each, with the host, the dead box, the instance id and the latency. |
| -- **Suspect holders:** any host refused for over 10 minutes for a lease whose owner is not confirmed dead. That is the backstop when A22's peer guard has no evidence; the runbook says terminate that box in its group (§9.5). |
| -- **S3-unhealthy boxes (A22):** each one, with the peer evidence it used. |
| +- **Suspect holders:** any host refused for over 10 minutes for a lease whose owner is not confirmed dead, including a refused same-box recovery (§9.6). The runbook says terminate that box in its group (§9.5). |
| +- **Marker obligations** older than 10 minutes (§5.2). |
| - **Local copies set aside,** by reason: no marker, another box, a different lifetime, an identity change, a digest change, or `clean: false`. |
| -- **Files:** the oldest unpublished change over 5 minutes, or over two intervals on the snapshot plan; failed backfills. |
| +- **Files:** the oldest unpublished change over 5 minutes, or over two intervals on the snapshot plan; failed or partial backfills. |
| - **Clock:** a chrony offset over 1 s on any box. |
| - **Over capacity:** a wake with no eligible box, at most once per region per hour. |
| - The memory alarm, on the group dimension. |
| @@ -698,31 +671,30 @@ S3 prices: LIST and PUT $0.005 per 1,000; GET $0.0004 per 1,000; DELETE free. |
| A seeded, invariant-based simulation, `internal/sim/regionha`, test only. |
| -**It models** 2 to 5 boxes, each with local DB and files state and a release record; one S3 with conditional writes, per-host replica chains, `lock.json` with markers, and duty files; EC2's state machine, the group's reaction and its grace period; and a lossy termination queue. |
| +**It models** 2 to 5 boxes, each with local DB and files state and a release record; one S3 with conditional writes, per-host replica chains, `lock.json` with markers, and duty files; EC2's state machine, the group's reaction, its lifecycle hook and its grace period; and a lossy termination queue. |
| -**Actions:** requests, sleeps, kills, hangs, a hang just after the first healthy service, one box losing S3, a regional S3 outage, agent crashes, concurrent cold wakes, drains, membership changes, recreated hostnames, offline moves and imports (with aborts and stager deaths), and clock offsets up to the bound. |
| +**Actions:** requests, sleeps, kills, hangs, a hang just after the first healthy service, one box losing S3, failed and delayed marker PUTs, agent crashes with and without surviving processes, concurrent cold wakes, drains, membership changes, recreated hostnames, and clock offsets up to the bound. |
| **Invariants:** |
| - **I1, single writer.** Every replica or manifest write came from the lease holder of the moment, and no two writes for one host share a transaction id. |
| -- **I2, no stale serving.** A box serves a host only from S3's state, or from a copy whose marker proved it unchanged since this box released it. |
| -- **I3, no wrong acquisition.** No box acquires another box's lease without a release marker or a confirmed termination. |
| +- **I2, no stale serving.** A box serves a host only from S3's state, or from a copy whose clean marker proved it unchanged since this box released it. |
| +- **I3, no wrong acquisition.** No box acquires another box's lease without a release marker or a confirmed termination, and no box re-takes its own without the emptiness proof. |
| - **I4, bounded forwarding.** At most two forward attempts, no onward forward, no cycle. |
| -- **I5, liveness.** After a termination, every host can be served within the modelled bound. |
| -- **I6, duties.** Every tick and due wake is delivered at least once while some serving box exists, and no transferred duty is lost when the adopter dies part way. |
| +- **I5, liveness.** After a termination, every host can be served within the modelled bound; a failed marker PUT followed by restored S3 lets another box acquire. |
| +- **I6, duties.** Every tick and due wake is delivered at least once while some serving box exists. No duty is lost when a box dies right after a release, or when an adopter dies part way. |
| - **I7, one key.** No host's instance key is minted twice. |
| - **I8, lifetimes.** No copy is reused across lifetimes. |
| -- **I9, moves.** A landed instance holds exactly the sealed `txid` and manifest, and no box keeps a local copy past a staging marker. |
| -- **I10, no churn.** A regional S3 outage makes no box unhealthy; at most one box per region is unhealthy for S3 at a time. |
| **Mutation checks.** Each of these must make the sweep fail: |
| -- keep a copy without the marker; |
| +- keep a copy without the marker, or with a marker written after an incomplete publish; |
| - let expiry authorize another box; |
| +- re-take the box's own lease without the proof; |
| - accept `shutting-down`; |
| +- write the marker before the duty file; |
| - delete the source duty file before the adopter's PUT succeeds; |
| +- drop a marker obligation on expiry; |
| - mint before the restore; |
| -- let a forwarded request be forwarded again; |
| -- keep a local copy before promoting staging; |
| -- report S3-unhealthy without peer evidence. |
| +- let a forwarded request be forwarded again. |
| One 3,000-seed sweep per revision, run serially at nice 19. |
| @@ -730,18 +702,23 @@ One 3,000-seed sweep per revision, run serially at nice 19. |
| - **Unit tests:** |
| - the marker: litestream's decoder accepts its JSON, and `LockState` and `leaseFree` read it as expired; |
| - - every keep and restore reason (§5.3), the acquire table (§9.4), and staging and lifted-tombstone rows; |
| - - termination verification, the duty-file merge, HRW, the latch, A22's guard, and the hairpin rule. |
| -- **Against MinIO:** the HA acquire, the marker PUT, the takeover, the tombstone and staging-marker writes. |
| + - every keep and restore reason (§5.3), the acquire table (§9.4), and the lifted-tombstone row; |
| + - termination verification, the duty-file merge, HRW, the latch, and the hairpin rule. |
| +- **Witnesses:** |
| + - a failed marker PUT, then restored S3, then acquisition by another box (astra-2.1); |
| + - a refused same-box recovery for each unproven layout; |
| + - a partial files publish leaving the marker unclean; |
| + - the HA refusals for moves, mixed moves and imports, each made before anything stops. |
| +- **Against MinIO:** the HA acquire, the marker PUT and its retry, and the takeover. |
| - **Dev drills, each timed:** |
| - terminate a box, measuring committed-write loss per replication class; |
| - hang one (`SIGSTOP` the agent, or black-hole its health port), including just after its first healthy service; |
| - - black-hole S3 for one box (A22 replaces it), and for every box (none is replaced); |
| + - black-hole S3 for one box (alarm, then the runbook terminate); |
| - concurrent cold wakes; |
| - - offline moves in and out of the N-box region, an import with rollback, and an abort at each phase; |
| - drain, stop, rollback restart, and the EIP cut-over; |
| + - public traffic from outside the VPC through the NLB's security group, and cross-region backhaul; |
| - the hairpin, from the agent, a tenant and a sidecar. |
| ## 22. Open questions for Paul |
| -None. Paul's rulings N-HA4 and N-HA5 answered rev 2's two questions. |
| +None. A16, the declined astra-1.5, is an author's call for Paul to confirm (§2.2). |