spec rev 5: region HA without claims, Astra round 3 applied (for Paul's review)
Invariants I1-I4 stated, each enforced in one place and checked by the N-box simulation with mutation checks (stopping rule 2); disposition table gains round 3 and a fault-family column. Round 3: termination reconciliation of omitted duty hosts (3.1); no serving or tenant acquisition before lifecycle-hook admission on the full health predicate (3.2); one-time per-host migration with three conditions, ambiguous hosts refused (3.3); first slice P1a switches on per host after migration and carries migration, files, trio, duty-before-marker and the move/import refusals (3.4); per-app awake counts feed ChooseRoomiest (3.5); beginExecutableChange's HA arm dropped in P0 (3.6); GroupBoxReference already local (3.7).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+130
−80
docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md+130 −80
CI failed — run details
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 0512559a6..e0bb1e797 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,36 +1,52 @@ |
| # Region HA without claims: N-box regions behind a load balancer |
| -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. |
| +Design, 2026-10-26, **rev 5**, for Paul's review. Astra rounds 1 to 3 are complete, and the review budget is spent (AGENTS.md, stopping rules). Branch `design-region-ha-no-claims`, cut from `origin/main` at ddf3b929. Nothing here is built. |
| This spec supersedes every claim-dependent part of "Region HA, spec 2: two-box regions" (`2026-10-15-region-ha-two-box-regions-design.md`, rev 21, cited **S2 §n**) and of spec 1 (`2026-10-04-region-ha-box-placement-design.md`, cited **S1 §n**). §16 lists what it reuses from S2, plan 2a (6834659c) and plan 2b (b1118925), and the removals this series owns. Line citations are to this worktree unless they name a module path. |
| **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 2** answered Astra round 1 (66721809, **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 | 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. Paul confirmed it as N-HA6. | §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 | |
| +- **Rev 4** answered round 2 (8e144c82, **astra-2.N**, partlies **astra-1.N r2**). It cut the moves and import design, automatic replacement on S3 loss, and the dependence on parked cleanup rows. |
| +- **Rev 5** applies round 3 (`docs/superpowers/notes/reviews/ASTRA-FINDINGS-region-ha-no-claims-r3.md`, 11ad7337, **astra-3.N**) directly, with Paul's approval of 2026-10-26. |
| + |
| +Under stopping rule 2, the families I2, I3 and I4 drew findings two rounds running. So each is now stated as an invariant, enforced in one place and checked by the simulation (§3.1), not patched again. |
| + |
| +The fault families used below: |
| +- **I1 to I4:** the invariants of §3.1; |
| +- **moves:** §14; |
| +- **infra:** §12; |
| +- **budget:** §18; |
| +- **H4:** placement inputs; |
| +- **scope:** what the redefined switch touches. |
| + |
| +| Finding | Family | Disposition | Where | |
| +|---|---|---|---| |
| +| astra-1.1 checksum proof absent in litestream v0.5.14 | I2 | Closed in r2: the release marker replaces checksums. | §5 | |
| +| astra-1.2 expiry bypasses "never take over a hung box" | I1 | 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 | I1 | Closed in r3: only after the agent stops the host's units and proves its cgroups empty; unproven layouts refused. | §9.6 | |
| +| astra-1.4 r2 incomplete publish still "clean" | I2 | Closed in r3: clean means a complete publish. | §5.2, §8.4 | |
| +| astra-1.5 r2 batched and daily classes miss H3 | I4 | **Declined;** Paul confirmed it as N-HA6. | §5.5 | |
| +| astra-1.6 key producers, 1.11 unit records | I1 | Closed in r2. | §7.3, §6.1 | |
| +| astra-1.7 once-timers, 1.8 r2 death before the first duty write | I3 | 1.7 closed in r2. 1.8 r2 closed in r3 for released hosts; the death-before-first-write gap is astra-3.1. | §7.4 | |
| +| astra-1.9 r2 the boot grace protects a box that already served | I4 | Closed in r3: lifecycle hook, 60 s grace. Pre-admission serving is astra-3.2. | §10 | |
| +| astra-1.10 forwarded takeover | I4 | Closed in r2. | §6.4 | |
| +| astra-1.12 r2, 2.3, 2.4, 2.5, 2.7, 2.8 moves and import | moves | Closed in r3 by scope cut: refusals and requirements only. | §14 | |
| +| astra-1.13 rollback to a terminated box, 2.6 target security groups | infra | Closed. | §13, §12.1 | |
| +| astra-1.14 hostname reuse, 1.15 held-lease backfill | I2 | Closed in r2. Backfill's authority is astra-3.3. | §5.3, §8.4 | |
| +| astra-1.16 r2 mutations not budgeted | budget | Closed in r3. | §18 | |
| +| astra-1.17 r2 HRW preference contradicts H4 | H4 | Closed in r3, except the app-spread input, which is astra-3.5. | §6.3 | |
| +| astra-2.1 a failed marker PUT never reaches the retry path | I4 | Closed in r3: a persisted retry queue that expiry never discharges. | §5.2 | |
| +| astra-2.2 A22 fires during a regional S3 outage | I4 | Closed in r3: A22 cut. | §9.5 | |
| +| astra-2.9 dependence on parked cleanup rows | scope | Closed in r3 by P0, except `beginExecutableChange`, which is astra-3.6. | §16.3 | |
| +| **astra-3.1** death before the first duty-file PUT strands duties | I3 | Accepted: a termination reconciliation reads every region host's lock once and adopts what the dead box's file omits. Witness added. | §9.3, §18, §21 | |
| +| **astra-3.2** service before lifecycle-hook admission | I4 | Accepted: until the hook completes on the full health predicate, a box is no one's serving peer and acquires no tenant lease, forwarded requests included. Witness added. | §4.3, §10 | |
| +| **astra-3.3** backfill can publish a stale copy | I2 | Accepted: a one-time per-host migration with three conditions; ambiguous hosts are refused and stay out of HA. | §8.4 | |
| +| **astra-3.4** the first slice lacks its prerequisites | I2, I3, moves | Accepted: the first slice switches on per host after migration and carries the migration, files, trio, duty-before-marker and the move and import refusals. Activation is refused during a move or import. | §19 | |
| +| **astra-3.5** no input for `running[box].Apps` | H4 | Accepted: per-app awake counts in each box's headroom record; missing or stale counts as 0. | §6.3, §11 | |
| +| **astra-3.6** `beginExecutableChange` gated by the HA switch | scope | Accepted: P0 drops the HA arm, keeps root-participation protection, and takes a census card. | §16.3 | |
| +| **astra-3.7** `GroupBoxReference` already moved | scope | Accepted: §4.1 corrected, P0 item removed. | §4.1 | |
| +| builder-1, builder-2 local reuse; builder-3 hairpin; builder-4 fan-out | I2; infra; budget | Closed in r2 and r3. | §5, §6.3, §12.4, §7.4 | |
| ## 1. Intent |
| @@ -97,11 +113,22 @@ Each is the author's or the coordinator's. Paul can overturn any of them. |
| 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. |
| +### 3.1 Invariants |
| + |
| +Each invariant is enforced in one place and checked by the seeded N-box simulation (§21.1), with a mutation check that must make the sweep fail. This is stopping rule 2's third option, which Paul approved on 2026-10-26 for families that drew findings two rounds running. |
| + |
| +| # | Invariant | Enforced only in | Checked by | |
| +|---|---|---|---| |
| +| I1 | **Single writer.** At most one box runs an instance. Another box acquires its lease only from a release marker written by the previous holder, or after EC2 confirms the owner terminated. A box re-takes its own expired lease only with a cgroup-empty proof. | The HA acquire, one function (§9.4). | Sim I1 and I3. Mutations: expiry authorizes; `shutting-down` accepted; same-box without proof. | |
| +| I2 | **Positive-proof local copy.** A box uses a local DB or files only when a clean release marker names it, its lifetime matches, the publish was complete, and the local state is unchanged since. The only other path that publishes local state is the one-time migration (§8.4), under its own three conditions. | The keep decision, one function (§5.3), and the migration gate (§8.4). | Sim I2 and I8. Mutations: keep without a marker; keep after an incomplete publish; migrate with two copies. | |
| +| I3 | **Duty coverage.** Every sleeping instance with a due time, a once-timer, a declared schedule or a sidecar due wake is listed in a live box's duty file, or in an adopter's durable merge. When listed twice, the newest `released_at` wins and the older entry is dropped at its next acquire. | The release step (duty before marker, §7.4) and the termination handoff with its reconciliation (§9.3). | Sim I6. Mutations: marker before duty file; source deleted before the adopter's ack; reconciliation skipped. Witness: death before the first duty-file PUT. | |
| +| I4 | **Failover bound.** A terminated or hung box's instances serve again within §9.8's bound. | Not by prose: the drills are G2's acceptance gate (§19, §21.2). | Dev drills, timed. Sim I5 for the logic. Witness: a hang just after first service reached by direct backhaul. | |
| + |
| ## 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`, 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`). |
| +Fixed boxes keep their status label. Group boxes use `g-` plus a hash of account and instance id (`groupReferenceOf`, already local in `internal/host/boxreference.go:91`). 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 |
| @@ -113,7 +140,7 @@ The parser is strict. Old `hostname:pid` owners, tombstones (`moved:<id>`, `inte |
| For any region r, a box's **view(r)** is the set of boxes whose edges file is no older than 15 minutes (`internal/boxchoice/policy.go:16-83`), with region r, the same placement and data bucket, and the deployment's secrets-key fingerprint. Every box folds every region's edges files already (`internal/edge/homemap.go:464-527`, `:791-867`), so a view costs nothing new. |
| -**serving(r)** is view(r) minus boxes whose role is `drain` or `platform`. A box validates a holder named for a host in region r against view(r), for its own region and for cross-region callers alike (astra-1.10). The console also verifies identity records, as `internal/console/boxselect.go:147-174` does without a roster. |
| +**serving(r)** is view(r) minus boxes whose role is `drain` or `platform`, and minus any box not yet **admitted** (astra-3.2). A box publishes role `booting` until its lifecycle hook has completed on the full health predicate (§10), or, for a fixed box, until that predicate first holds. Until then it is no one's serving peer, and it refuses to acquire any tenant lease, including for forwarded requests: it answers 503 and names no holder. A box validates a holder named for a host in region r against view(r), for its own region and for cross-region callers alike (astra-1.10). The console also verifies identity records, as `internal/console/boxselect.go:147-174` does without a roster. |
| ### 4.4 Box roles |
| @@ -170,7 +197,7 @@ 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). On HA boxes the move-staging fallback (`backend_exec.go:833-851`, `:3509-3529`) does not run: staging leftovers never authorize a promotion (§14). |
| +A host not yet migrated (§8.4) follows today's path. **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, 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. |
| @@ -220,7 +247,7 @@ An awake instance runs only on its lease holder. At box A, for a request to tena |
| 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. |
| +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. `ChooseRoomiest`'s spread input, `running[box].Apps[app]` (`policy.go:83`), comes from per-app awake counts in each box's headroom record (§11), not from the claim's producer (`internal/hostops/loads.go:18`). They are as fresh as the box's last edges publication: 5 to 6 minutes, plus a 30-second fold. Missing or stale counts are read as 0, and the spread stays soft: it never refuses. |
| 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. |
| @@ -326,13 +353,26 @@ The location is the host's hibernate prefix (`activator.go:138-150`) plus `files |
| `files_durability` (`continuous` or `snapshot`, default `snapshot`, H8) and `files_snapshot_interval` become per-app platform settings, read with the app's configuration. An operator door sets them; Carloku maps its plans to them. Console text goes through copy review. |
| -### 8.4 Backfill (astra-1.15) |
| +### 8.4 Migration, then backfill (astra-1.15, astra-3.3) |
| -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. |
| +**Migration.** Each host is migrated once, before any HA wake of it. Migration publishes the host's baseline: the files manifest, the H6 trio and the wake state; the database is already in S3. A box may publish it only if all three of these hold: |
| +- its local TXID equals the newest TXID in S3 (one LIST of level 0, once per host); |
| +- the lifetime matches: its registry row was minted for the current record and never re-pointed (`reconcile.go:2300-2320` re-points rows; such a row is not migratable); |
| +- it is the only box in the region holding a local copy. Each HA box publishes a one-time inventory, `control/ha-migration/<region>/<ref>.json`, listing the hosts it holds copies of and their TXIDs. A box migrates a host only once every box in view(region) has published its inventory. |
| -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. |
| +**Ambiguous hosts are refused.** A host with more than one copy, or none that matches, is reported in readiness for the operator. It stays out of HA: its wakes follow today's path. Flagship regions have one box each today, so ambiguity can only arise on dev. |
| + |
| +**After migration.** |
| +- The migrating box writes the host's first release marker, clean, naming itself. From then on the host is HA-on, and the acquire's GET of `lock.json` tells every box so. |
| +- A host created after activation has no copy anywhere, so its first HA wake migrates an empty baseline. |
| +- Readiness counts migrated hosts. |
| +- Migration refuses a host with a live tombstone or move staging. |
| + |
| +**Backfill** obeys §5.3 like every other writer: |
| +- an awake HA-on instance publishes through its live lease handle; |
| +- a sleeping one is published only by a box that holds a proven copy, or after a restore. |
| + |
| +`files_published_at` is recorded only on a complete publish, with nothing skipped or unreadable. A skipped, partial or failed publish keeps readiness false. |
| ## 9. Termination, takeover and expiry |
| @@ -352,8 +392,11 @@ One `DescribeInstances` for the owner's instance id in this box's AWS region (`i |
| The confirming box: |
| 1. becomes the adopter or tells the adopter (§7.4); |
| -2. the adopter deletes the dead box's edges file on its ETag once its duties are durable. That bumps `control/edges` (`changeindex.go:71`), and every box drops the dead box from its views within about 30 seconds; |
| -3. the box counts the confirmation (§20) and cancels any duty backoff keyed to that box (§7.2). |
| +2. **reconciles** (astra-3.1). The adopter reads `lock.json` once for every host of the region (every box adopts every region host record, so it has the list). |
| + - It looks for hosts whose lease or marker names the dead box but which have no entry in the dead box's duty file. That is the case of a box that died before its first duty-file PUT. |
| + - For each, it reads the wake state from S3, and takes on any due time, once-timer, declared schedule or sidecar due wake into its own duty file, waiting for the PUT's acknowledgement; |
| +3. only then deletes the dead box's duty file, and its edges file on its ETag. That bumps `control/edges` (`changeindex.go:71`), and every box drops the dead box from its views within about 30 seconds; |
| +4. counts the confirmation (§20), and cancels any duty backoff keyed to that box (§7.2). |
| ### 9.4 The HA acquire, and why expiry is not enough (astra-1.2) |
| @@ -426,14 +469,14 @@ Keep `internal/lbhealth`, with its six conditions (`internal/lbhealth/lbhealth.g |
| - **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. |
| - **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 box completes the hook only when the full health predicate holds: the latch and all six conditions. Only then does the group put it in service and register it, and only then does the box publish role `serve` (§4.3); |
| - 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 |
| -- **Published by each box:** headroom in its edges file (`internal/host/headroom.go:13-16`), whenever `CARLOS_REGION_HA` is on; its role; and its private address. The private address comes from plan 2a, split out of the claim code (§16.2). |
| +- **Published by each box:** headroom in its edges file (`internal/host/headroom.go:13-16`), whenever `CARLOS_REGION_HA` is on, with a new additive `apps` map of per-app awake counts for apps it runs (§6.3); its role; and its private address. The private address comes from plan 2a, split out of the claim code (§16.2). |
| - **The console** reads live edges files and verifies identity records (`boxselect.go:147-174`). It publishes `Carlos/Region EligibleBoxes` (`internal/console/awsregionmetric.go:56-70`) from console start when `CARLOS_REGION_METRICS=cloudwatch`, instead of from `StartClaimRecoveryPass` (`internal/console/hostclaimops.go:44-61`). `regioncapacity.go` counts with the shared policy. |
| - **The create door,** for an instance, a standalone sidecar, or a first route through domain attach, in an HA region: |
| - refuses with 503 and the approved no-capacity message when no serving box is eligible, alerting at most once per region per hour (A20); |
| @@ -447,20 +490,15 @@ 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), 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. |
| +- **An Auto Scaling group:** `min = max = desired = box_count` (H5), across at least two zones. Health checks are ELB plus EC2, with a 60-second grace. A launch lifecycle hook (`autoscaling:EC2_INSTANCE_LAUNCHING`, default result `ABANDON`) is completed by the box when the full health predicate holds (§10). No instance refresh, and `AZRebalance` is suspended. |
| +- **A Network Load Balancer, with its own security group** (astra-2.6), admitting 80 and 443 from anywhere. |
| + - 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 checks are HTTP on 80 at `/.carlos/lb-health`, every 10 s, 2 healthy and 2 unhealthy. |
| +- **The target security group** admits: |
| + - 80 and 443 from the NLB's security group, for both traffic and health checks; |
| + - 443 from anywhere, as today (`main.tf:97-107`), because cross-region backhaul dials each box's public address on 443 (`internal/edge/edge.go:3056`) from changing addresses. That path is hop-signed; |
| + - the backhaul port from the VPC CIDR. |
| Drills check public traffic from outside the VPC. |
| - **The termination rule and queue:** unchanged. **Alarms:** §20. |
| @@ -579,7 +617,12 @@ The claims cleanup stopped after R0, R1, R2 and T1, and keeps HA 2a/2b (`origin/ |
| 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`. |
| +5. **`beginExecutableChange`** (astra-3.6). With `regionHA` set it writes the legacy marker and checks claim participation, even with claims off (`internal/host/systemparticipation.go:47-53`; `internal/hostfloor/participation.go:25`). A retained or unreadable `.hostexec` would then defer platform updates. |
| + - P0 drops the `regionHA` arm, so an HA box takes the same path as any other. |
| + - Root-participation protection (`ParticipationRequired`) is kept. |
| + - The census row is touched, so it needs a card. |
| + |
| +`GroupBoxReference` needs no move: `internal/host/boxreference.go:91` already holds it (astra-3.7). |
| 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). |
| @@ -587,11 +630,11 @@ Every other claim package stays inert with claims off, and is left to opportunis |
| - **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. |
| +- **Static sites, the edge asset cache and rootfs apps (#366):** unchanged, except that a box materializes a rootfs image on its first wake there. |
| +- **`db pull`, `db query --at` and the cross-region db forward:** unchanged. They read the replica, so any box of the region serves them. |
| - **Litestream #284** (`origin/litestream-oom-284`): restores get more frequent, so land slice A before small group instances. |
| - **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). |
| +- **The housekeeper election and certificates:** unchanged (S2 §6). |
| ## 18. Request budget (astra-1.16, astra-1.16 r2) |
| @@ -619,6 +662,8 @@ S3 prices: LIST and PUT $0.005 per 1,000; GET $0.0004 per 1,000; DELETE free. |
| | Probe of a held lease | 1 GET | |
| | Takeover | 1 GET + 1 PUT + 1 describe | |
| | Termination transfer | 2 GETs + 1 duty-file PUT + 1 duty-file DELETE + 1 edges DELETE + index (1 GET + 1 PUT, up to 4 retries) | |
| +| Termination reconciliation | 1 GET per host of the region (500 hosts: $0.0002), + 1 to 2 GETs of wake state per omitted host | |
| +| Migration (once per host) | 1 LIST (L0) + the baseline publish; 1 PUT per box for its inventory | |
| | 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 | |
| @@ -628,45 +673,47 @@ S3 prices: LIST and PUT $0.005 per 1,000; GET $0.0004 per 1,000; DELETE free. |
| ## 19. Switches and rollout |
| -**Switches.** On the box, `CARLOS_REGION_HA` gates everything in P1; only the owner format is unconditional. On the console: `CARLOS_REGION_METRICS` (exists), `CONSOLE_REGION_INGRESS` (new), and the role, readiness and refusal doors. Per app: `files_durability` and `files_snapshot_interval`. |
| +**Switches.** On the box, `CARLOS_REGION_HA` gates P1a and P1b, staged so P1a can run alone, and P1a acts per host only after migration. Only the owner format is unconditional. On the console: `CARLOS_REGION_METRICS` (exists), `CONSOLE_REGION_INGRESS` (new), and the role, readiness and refusal doors. Per app: `files_durability` and `files_snapshot_interval`. |
| **Plans.** |
| | Plan | Scope | |
| |---|---| |
| -| 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. | |
| +| P0 | The removals this series owns (§16.3); rides in P1a. | |
| +| P1a | **First slice.** Owner format, HA acquire, release marker, keep rule, retry queue (§5); migration (§8.4); files and wake-state publication and the H6 trio (§8); key producers (§7.3); duty files with duty-before-marker (§7.4); the move and import refusals for HA-on hosts and boxes (§14). | |
| +| P1b | Forwarding (§6), the rest of the duties (§7), takeover, reconciliation and same-box proof (§9), admission, latch and lifecycle hook (§10, §4.3), 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. | |
| -**First slice and switch-on dates (AGENTS.md stopping rules 5 and 6).** The first merge is something Paul can see: P1's freshness slice (owner format, HA acquire, release marker, keep rule, retry queue) with P0's removals riding in it, released and switched on at once on dev's two IE boxes, ahead of G1 (the plan stages `CARLOS_REGION_HA` so this slice can be on while the rest is off). That closes today's stale-copy hazard there, and each wake logs `kept local` or `restored` with the reason, which the dev wake check shows. No plan merges dormant without a date: the rest of P1 and P2 switch on at G1, P3 at G2, and P6 at G5. P4 and P5 are written only after P1 merges, so they are never reviewed against unmerged work (rule 4). |
| +**First slice and switch-on dates (stopping rules 4 to 6).** The first merge is something Paul can see: P1a, with P0 riding in it, released and switched on at once on dev's two IE boxes. |
| +- **Per host.** It switches on host by host, after migration has validated each one (§8.4). Each wake logs `kept local` or `restored` with the reason, and the dev wake check shows it. That closes today's stale-copy hazard on those boxes. |
| +- **Moves and imports.** The slice also withdraws the box's offline-move capability (`internal/host/movesoffline.go:59`), and the console refuses a move or import for an HA-on host or box before `OfflineStart` (`apiinstancemove_offline.go:610`). So no move starts against a migrated host. |
| +- **Activation** is refused while a move or import touches the region. |
| +- **Switch-on dates.** No plan merges dormant without a date: P1b and P2 switch on at G1, P3 at G2, and P6 at G5. |
| +- **Unmerged work.** P4 and P5 are written only after P1 merges (rule 4). #199 is handled by this spec's own refusal (§11), not by the nearest-region design. |
| -**Gates.** Each release rolls dev boxes, dev console, check, flagship boxes, flagship console. P0 lands with or before the first P1 slice. |
| +**Gates.** Each release rolls dev boxes, dev console, check, flagship boxes, flagship console. P0 lands in P1a. |
| | 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 | 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) | |
| +| G1 | All of `CARLOS_REGION_HA` on dev's two IE boxes (`platform-infrastructure/dev/region-ie-b.tf`), as the first N=2 test | P1a on and every dev IE host migrated or reported; P1b and P2 released | |
| +| G2 | A dev group region (P3) | G1; I4's drills pass within §9.8's bound: terminate, hang, hang after first service through direct backhaul, S3 loss (§21) | |
| | 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 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`; abandoned lifecycle hooks. |
| -- The termination queue's `ApproximateAgeOfOldestMessage` over 10 minutes. |
| +- **Infrastructure:** the load balancer's `UnHealthyHostCount > 0` for 10 minutes and `HealthyHostCount < box_count` for 25 minutes; `EligibleBoxes < box_count` for 25 minutes, missing as breaching; `GroupInServiceInstances < desired`; abandoned lifecycle hooks; the termination queue's oldest message 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, 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). |
| +- **Marker obligations** older than 10 minutes (§5.2), and hosts refused by migration (§8.4). |
| - **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 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. |
| +- **Box health:** a chrony offset over 1 s on any box; a wake with no eligible box, at most once per region per hour; the memory alarm, on the group dimension. |
| ## 21. Tests |
| @@ -676,9 +723,9 @@ 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, 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, 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. |
| +**Actions:** requests, sleeps, kills, hangs, a hang just after the first healthy service reached by direct backhaul, death before the first duty-file PUT, migrations with one, two or no copies, 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:** |
| +**Invariants** (§3.1 maps I1 to I4 onto these): |
| - **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 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. |
| @@ -697,20 +744,23 @@ A seeded, invariant-based simulation, `internal/sim/regionha`, test only. |
| - 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. |
| +- let a forwarded request be forwarded again; |
| +- skip the termination reconciliation; |
| +- migrate a host held by two boxes; |
| +- let a box serve a tenant before admission. |
| One 3,000-seed sweep per revision, run serially at nice 19. |
| ### 21.2 Other tests |
| -- **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 the lifted-tombstone row; |
| - - termination verification, the duty-file merge, HRW, the latch, and the hairpin rule. |
| +- **Unit tests:** litestream's decoder accepts the marker's JSON, and `LockState` and `leaseFree` read it as expired. Also every keep and restore reason (§5.3), the acquire table (§9.4), 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; |
| + - death before the first duty-file PUT, recovered by reconciliation (astra-3.1); |
| + - a booting box refusing a forwarded request, and a hang just after first service reached by direct backhaul (astra-3.2); |
| + - migration refused for two copies, for none matching, and for a re-pointed row (astra-3.3); |
| + - the move capability withdrawn, and the console refusing before `OfflineStart` (astra-3.4); |
| + - a refused same-box recovery for each unproven layout, and a partial 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:** |