spec rev 6: cut the duty-file transfer protocol (Paul, 2026-10-26)
Duty handoff drew a P1 in all three Astra rounds, so under stopping rule 2 it is cut rather than fixed again. Duties stay in local registries as today; no duty files and no duty write before the release marker. The only transfer is one scan: on a confirmed termination (or drain completion) a box reads every region host's lock.json and imports the wake state of each host the departed box held or released, through one adoptHost function. I3 restated over that scan; loss bounded by the ~1 s wake-state sync. Disposition table, budget, plans and simulation updated; status rev 6 for Paul's review.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+46
−57
docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md+46 −57
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 e0bb1e797..428a1df7f 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,6 +1,6 @@ |
| # Region HA without claims: N-box regions behind a load balancer |
| -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. |
| +Design, 2026-10-26, **rev 6**, 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. |
| @@ -8,9 +8,10 @@ This spec supersedes every claim-dependent part of "Region HA, spec 2: two-box r |
| - **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** 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. |
| +- **Rev 5** applied 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. |
| +- **Rev 6** is a scope cut Paul approved on 2026-10-26. Duty handoff drew a P1 in all three rounds, so the duty-file transfer protocol is deleted, not fixed again (stopping rule 2). Duties stay in local registries, as today. One scan-and-import moves them when a box leaves (§7.4). |
| -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. |
| +Under stopping rule 2, the families I2, I3 and I4 drew findings two rounds running. I2 and I4 are now stated as invariants, enforced in one place and checked by the simulation (§3.1). I3 drew a P1 in all three rounds, so rev 6 cuts its transfer protocol and restates I3 over the scan alone. |
| The fault families used below: |
| - **I1 to I4:** the invariants of §3.1; |
| @@ -28,7 +29,7 @@ The fault families used below: |
| | 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.7 once-timers, 1.8 r2 death before the first duty write | I3 | **Cut:** replaced by the termination scan. | §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 | |
| @@ -39,10 +40,10 @@ The fault families used below: |
| | 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.1** death before the first duty-file PUT strands duties | I3 | **Cut:** replaced by the termination scan. No duty files exist, so there is no first write to die before. | §7.4, §9.3 | |
| | **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.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 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 | |
| @@ -90,7 +91,7 @@ Each is the author's or the coordinator's. Paul can overturn any of them. |
| | A3 | The lease owner string is `box/v1;ref=<ref>;iid=<instance id>;pid=<pid>`. | Litestream's default `hostname:pid` does not name the EC2 instance. | |
| | A4 | Boxes confirm terminations themselves, from the existing queue and `ec2:DescribeInstances`. One SQS long-poll per box is accepted (about $0.05 a month per box). | The box role holds both rights already. The console is one box in IE. | |
| | 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. | |
| +| A6 | The box that confirms a termination scans the region's locks, imports the wake state of every host the dead box held or released, and only then deletes the dead box's edges file (§7.4). | One import path for termination and drain. | |
| | 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 | 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. | |
| @@ -111,7 +112,7 @@ Each is the author's or the coordinator's. Paul can overturn any of them. |
| ## 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. 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. |
| +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 stay in the local registry of the box that released it, as today. When that box leaves, one scan of the region's locks imports them elsewhere from the wake state in S3. |
| ### 3.1 Invariants |
| @@ -121,7 +122,7 @@ Each invariant is enforced in one place and checked by the seeded N-box simulati |
| |---|---|---|---| |
| | 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. | |
| +| I3 | **Duty coverage.** An instance's duties run from the local registry of the box that holds its lease, or of the box that released or adopted it. When a box leaves, every host it held or released has its wake state imported by a live box. The loss is bounded by the ~1 s wake-state sync (N-HA5), as H3 states it for files. | The import function, one place, called by the termination scan and by drain completion (§7.4). | Sim I6. Mutations: skip the scan; match owners but not releasers; delete the edges file before the scan finishes. Witness: a box dies before any wake-state sync of a new timer. | |
| | 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 |
| @@ -158,7 +159,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 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): |
| +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: |
| 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; |
| @@ -282,19 +283,19 @@ Each box keeps an in-memory map from host to holder reference, fed by the owner |
| | Instance state | Owner of its duties | |
| |---|---| |
| | Awake | Its lease holder. | |
| -| Asleep | The box that released it. That box's unsuperseded local release record says so. | |
| -| Neither: never woken, or held by a dead box | Its HRW box in serving(region) (A10). | |
| +| Asleep | The box that released it, or that adopted it (§7.4). Its local registry rows say so, as today. | |
| +| Never woken | Its HRW box in serving(region) (A10). | |
| -A box acts on a duty only after an HA acquire, which every duty needs anyway, since each one wakes or reaches the instance. If the acquire shows the instance held by a live peer, or released by another box, this box drops the duty for that host. That is how an older copy of a due entry stops being acted on, at one GET per conflict. |
| +A box acts on a duty only after an HA acquire, which every duty needs anyway, since each one wakes or reaches the instance. If the acquire shows the instance held by a live peer, or released by another box, this box drops the duty for that host. That bounds any duplicate an adoption creates to one acquire, at one GET (H7 allows a duplicate tick). |
| ### 7.2 What the duties are |
| | Work | Today, with N boxes | Under this spec | |
| |---|---|---| |
| | **Schedule ticks.** The converger gives every box timer rows (`internal/schedule/converge.go:18-20`). | Every box delivers every tick. | Only the duty owner's runner delivers. A non-owner advances its own row past a tick once the tick is 15 minutes old. A new owner delivers every younger tick it has not advanced. A change of owner can deliver a tick twice (H7). | |
| -| **Due wakes** (`next_due`, `activator.go:4996-5050`) | Only the box that slept the instance knows the time. | The releaser keeps them, as today, and also lists them in its duty file (§7.4). | |
| -| **App once-timers** (`internal/schedule/control.go:15-19`) | Kept in the waking box's registry only. | They stay in the holder's or releaser's registry. Their earliest deadline goes into `next_due` and the duty file. The rows travel in the wake state (`hostfiles.ExportWake`/`ImportWake`, `internal/hostfiles/wake.go:47,84`), which is continuous (S1 §5.6). A new owner imports them before it delivers. | |
| -| **Sidecar due wakes**, a native sidecar's only timer source (`activator.go:5032-5044`) | Excluded from edges files (`internal/host/edgesfile.go:481-500`). | Carried in duty files as non-routable entries (`kind: sidecar`), never in the hosts map. | |
| +| **Due wakes** (`next_due`, `activator.go:4996-5050`) | Only the box that slept the instance knows the time. | The releaser keeps them, as today. A departure moves them by import (§7.4). | |
| +| **App once-timers** (`internal/schedule/control.go:15-19`) | Kept in the waking box's registry only. | They stay in the holder's or releaser's registry. Their earliest deadline goes into `next_due`. The rows travel in the wake state (`hostfiles.ExportWake`/`ImportWake`, `internal/hostfiles/wake.go:47,84`), which is continuous (S1 §5.6). A new owner imports them before it delivers. | |
| +| **Sidecar due wakes**, a native sidecar's only timer source (`activator.go:5032-5044`) | Excluded from edges files (`internal/host/edgesfile.go:481-500`). | In the releaser's registry, as today; the sidecar's wake state carries them, and the scan includes sidecar hosts. | |
| | **Always-on workers:** the boot pass (`internal/host/agent.go:705-724`) and the sweep (`activator.go:5052-5084`) | Every box tries; the rest retry every sweep. | The holder runs one. With no holder, its HRW box starts it. A box that met a live holder skips it until that holder leaves the view. Termination confirmation cancels the wait at once, with no periodic probing (astra-1.9). | |
| | **Co-spawn sidecars** (`activator.go:17-25`) | Start on the box that woke the instance. | Unchanged: the holder. | |
| | **`carlos run`:** the record names one picking box (`runexec.go:109-119`) | Any box may pick. | Only the duty owner picks. | |
| @@ -311,26 +312,18 @@ Every producer of `<host>.env` secrets runs **only on the lease holder, after th |
| `instance.key`, `report.token` and `<host>.env` are continuous on every plan (H6). A newly minted key is published durably, with the manifest PUT acknowledged, before the app starts. A failed publish fails the launch. |
| -### 7.4 Duty files and their transfer (astra-1.8, builder-4) |
| +### 7.4 The only transfer: scan and import (I3) |
| -**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}`. |
| -- **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. |
| +No duty files exist, and nothing is published for transfer. The wake state (timer rows, `next_due` and replication) still syncs to S3 at about 1 s (N-HA5), because restores need it. One import function moves duties when a box leaves: |
| +- **`adoptHost(host)`:** read the host's wake state from S3, import it into the local registry (`hostfiles.ImportWake`, `internal/hostfiles/wake.go:84`), and mark the host adopted. From then on this box's sweeper and runner act on it, after the HA acquire as §7.1 says. |
| +- **On a confirmed termination (§9.3)**, the confirming box reads `lock.json` once for every host of the region. It already has the list, because every box adopts every region host record. It calls `adoptHost` for each host whose owner, or whose release marker's releaser, is the dead box. |
| +- **On drain completion (§13),** the draining box has slept every instance with a clean marker. The serving box that is the HRW box over the drained box's reference runs the same scan, for hosts released by the drained box, when it sees `drained: true` on its fold. |
| -**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: |
| -1. reads the departing box's duty file (one GET); |
| -2. merges the entries into its own set, keeping the newest `released_at` per host; |
| -3. writes its own duty file, and waits for the PUT's success; |
| -4. only then deletes the departing box's duty file, and on termination its edges file. |
| +**Duplicates and failures.** |
| +- Two boxes may both scan the same departure. Their duplicate imports cost at most one extra acquire per host (§7.1), and H7 allows a duplicate tick. |
| +- A scanner that dies part way leaves the dead box's edges file in place, so the next confirmation repeats the scan. A drain scan repeats on the next fold while `drained: true` is still published. |
| -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. |
| - |
| -**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. |
| +**What can be lost.** A timer registered in the last second before a crash, before its wake state synced. The edges files' existing due entries for cross-box wake routing stay as they are, but failover does not depend on them. |
| ## 8. Per-instance files (H6) |
| @@ -391,12 +384,9 @@ One `DescribeInstances` for the owner's instance id in this box's AWS region (`i |
| ### 9.3 After confirmation |
| The confirming box: |
| -1. becomes the adopter or tells the adopter (§7.4); |
| -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). |
| +1. runs the scan and imports (§7.4); |
| +2. only then deletes the dead box's edges file on its ETag, and the queue message. That bumps `control/edges` (`changeindex.go:71`), and every box drops the dead box from its views within about 30 seconds; |
| +3. 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) |
| @@ -550,7 +540,7 @@ This is the sequence for UK, US and AU; IE differs in step 5. |
| - 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). |
| + When nothing is awake, the box publishes `drained: true`, and the scan moves its duties (§7.4). |
| 3. **Cut over.** Disassociate the region's EIP from the old box and add zone A's mapping with it (S2 §9 step 3). A few minutes down, announced. |
| 4. **Stop** (A19, astra-1.13). Deregister the old box, wait 30 seconds, and stop the EC2 instance. It holds no leases, its duties are adopted, and it is not a group member. |
| 5. **IE instead:** set role `platform`, deregister it, keep it running, and swap it to its new EIP, moving the relay and MX in the same window (S2 §6 and §9). |
| @@ -633,14 +623,14 @@ Every other claim package stays inert with claims off, and is left to opportunis |
| - **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`. |
| +- **The change index (#336):** one new scope, `control/box-roles`. Edges deletions ride `control/edges`. |
| - **The housekeeper election and certificates:** unchanged (S2 §6). |
| ## 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. |
| +**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. Lease objects are not a scope, so they pay none. |
| **Steady state, per box per hour.** |
| - **S3:** unchanged, at about 3,300 to 3,500 today, including the edges timed pass and its index bump. |
| @@ -657,19 +647,17 @@ S3 prices: LIST and PUT $0.005 per 1,000; GET $0.0004 per 1,000; DELETE free. |
| | 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 duty-file PUT if the host has a duty (shared by releases close together), + 1 PUT (marker) in place of a free DELETE | |
| +| Sleep, HA box | as today, + files publish if changed, + 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 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 | |
| +| Termination or drain scan | 1 GET per host of the region (500 hosts: $0.0002), + 1 to 2 GETs of wake state per adopted host; on termination, + 1 edges DELETE + index (1 GET + 1 PUT, up to 4 retries) | |
| | 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 | |
| | 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, 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. |
| +**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. |
| ## 19. Switches and rollout |
| @@ -680,8 +668,8 @@ S3 prices: LIST and PUT $0.005 per 1,000; GET $0.0004 per 1,000; DELETE free. |
| | Plan | Scope | |
| |---|---| |
| | 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. | |
| +| 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); the move and import refusals for HA-on hosts and boxes (§14). | |
| +| P1b | Forwarding (§6), duties and the scan (§7), takeover 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. | |
| @@ -721,9 +709,9 @@ 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, its lifecycle hook 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 wake state; 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 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. |
| +**Actions:** requests, sleeps, kills, hangs, a hang just after the first healthy service reached by direct backhaul, a box dying before a new timer's wake state syncs, 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** (§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. |
| @@ -731,7 +719,7 @@ A seeded, invariant-based simulation, `internal/sim/regionha`, test only. |
| - **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; 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. |
| +- **I6, duties.** Every tick and due wake whose wake state reached S3 is delivered at least once while some serving box exists, including when a scanner dies part way. |
| - **I7, one key.** No host's instance key is minted twice. |
| - **I8, lifetimes.** No copy is reused across lifetimes. |
| @@ -740,12 +728,12 @@ A seeded, invariant-based simulation, `internal/sim/regionha`, test only. |
| - 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; |
| +- delete the edges file before the scan finishes; |
| +- match only owners, not releasers, in the scan; |
| - drop a marker obligation on expiry; |
| - mint before the restore; |
| - let a forwarded request be forwarded again; |
| -- skip the termination reconciliation; |
| +- skip the scan; |
| - migrate a host held by two boxes; |
| - let a box serve a tenant before admission. |
| @@ -753,10 +741,11 @@ One 3,000-seed sweep per revision, run serially at nice 19. |
| ### 21.2 Other tests |
| -- **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. |
| +- **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, `adoptHost`, HRW, the latch, and the hairpin rule. |
| - **Witnesses:** |
| - a failed marker PUT, then restored S3, then acquisition by another box (astra-2.1); |
| - - death before the first duty-file PUT, recovered by reconciliation (astra-3.1); |
| + - a box dying before a new timer's wake state syncs: only that timer is lost, bounded by the 1 s sync; |
| + - a terminated box's held and released hosts all adopted by the scan, including when the scanner dies part way; |
| - 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); |