G6 design: capacity card, F-C write fence, pool path (rev 1)
Three short specs for the first customer app in pool ha on flagship US, plus the Astra review brief.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+545
−0
docs/superpowers/reviews/CODEX-REVIEW-BRIEF-G6.md+26 −0docs/superpowers/specs/2026-11-11-g6-pool-path-design.md+189 −0docs/superpowers/specs/2026-11-11-g6-us-capacity-design.md+135 −0docs/superpowers/specs/2026-11-11-g6-write-fence-design.md+195 −0
CI failed — run details
Intent
Attributed to this commit: 91.0 g CO₂e (8,772,416 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-g6, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-G6.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-G6.md| new file mode 100644 |
| index 000000000..2e4400821 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-G6.md |
| @@ -0,0 +1,26 @@ |
| +# Review brief: G6 design (three short specs), round N |
| + |
| +You are an independent reviewer (GPT-6 Astra). Read cold; the repo is checked out at the commit named in the prompt. |
| + |
| +Specs under review (all on branch design-g6): |
| +1. docs/superpowers/specs/2026-11-11-g6-us-capacity-design.md (capacity card for the flagship US HA group) |
| +2. docs/superpowers/specs/2026-11-11-g6-write-fence-design.md (F-C minimal write fence) |
| +3. docs/superpowers/specs/2026-11-11-g6-pool-path-design.md (per-account allowlist + born-HA app create option) |
| + |
| +Parent spec: docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md (RHA). Roll verb: docs/superpowers/specs/2026-11-09-group-roll-verb-design.md. Runbook: docs/region-ha-runbook.md. |
| + |
| +Fixed rulings (do NOT re-argue; report only mechanisms that fail to honour them): |
| +- First customer app = a FRESH create in pool "ha" on flagship US; no migration of existing instances. |
| +- F-C: a holder whose replica sync fails for about 30 s stops serving (503 + Retry-After) and releases UNCLEAN. Late flush, storage fencing, batched/daily classes in the pool are deferred. |
| +- Pool creates sit behind a per-account allowlist. |
| +- A resize adds a member first; counted applies (re-pin, pin-back, box_count with no instance change) have standing approval; first-of-kind applies need a GO. |
| +- User-facing strings are DRAFTS for Paul's copy review; do not review wording style, only factual accuracy against the code and specs. |
| + |
| +What to check: |
| +- Every code citation (file:line, function names) against the tree. Litestream is github.com/benbjohnson/litestream v0.5.14 in the Go module cache (go env GOMODCACHE). |
| +- Fence: is the trip condition (pending = DB.Pos().TXID > highest non-zero Replica.Pos().TXID seen; age = now - max(LastSuccessfulSyncAt, start) > 30 s; checked every 5 s) correct and is the stated loss bound (~35 s of acknowledged writes) true? Can it fail to trip (e.g., positions, WAL checkpoints, snapshot/compaction resetting TXIDs, restore at wake), or trip spuriously? Does latching via renewer.loseLocked actually give immediate 503 + unclean marker + owed retry through existing paths? Does the Lost() watcher race the existing stop paths? Is restricting to stream class enforceable as stated? |
| +- Capacity: arithmetic, the rule, and whether the apply sequence is executable with the verb and module as written (min=max=desired=box_count; remove's two-member rule). |
| +- Pool path: does the allowlist gate cover every door that can create a record in a scoped HA pool (including paths the spec does not list: seeds, demo claim seed/target, moves, sidecars, domain attach, app region set, manifest updates)? Is the app-create-plus-manifest write coherent with how manifests and the enable door work today? Any way an unlisted account lands a record in the pool? |
| +- Cross-spec consistency and anything that would make the exit tests unable to pass or unable to fail. |
| + |
| +Output format: a findings file. For each finding: ID (G6-<round>.<n>), severity P1 (blocks build: wrong mechanism, unsafe, or exit test cannot work) / P2 (must fix in text before build) / P3 (minor), spec + section, the claim, the evidence (file:line), and a concrete fix. Then a verdict line: READY, READY AFTER FIXES, or NOT READY. Be concise; no praise; at most 15 findings, most severe first. If a prior findings file is named in the prompt, begin with a disposition table for its findings (fixed / not fixed / partly), then only NEW findings. |
diff --git a/docs/superpowers/specs/2026-11-11-g6-pool-path-design.md b/docs/superpowers/specs/2026-11-11-g6-pool-path-design.md| new file mode 100644 |
| index 000000000..590cf3949 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-11-g6-pool-path-design.md |
| @@ -0,0 +1,189 @@ |
| +# G6 slice 3: the pool path, born-HA apps for allowed accounts (design, rev 1, 2026-11-11) |
| + |
| +Design only. Paul approves before any build, and every user-facing string in |
| +§5 goes through Paul's copy review before it is written into code or docs. |
| +Parent: region HA spec `2026-10-26-region-ha-without-claims-design.md` |
| +(**RHA §n**), especially §23 (B10, born HA only in a named HA pool). Line |
| +citations are to `origin/main` at 01d6ca78. |
| + |
| +**Paul's rulings (2026-11-11, via 8a3d302):** the first app is a fresh create |
| +in pool `ha` on flagship US, with no migration; creates in the pool sit behind |
| +a per-account allowlist; the copy states what HA does and does not promise, |
| +including that an unplanned death can take up to about 15 minutes to recover |
| +until storage fencing exists. |
| + |
| +## 1. How a record lands in a pool today |
| + |
| +- A record's pool is never taken from a create request. The instance create |
| + door stamps it from the app's manifest (`instances.json`): |
| + `internal/console/apiinstances.go:1531` ("stamped from the MANIFEST ... the |
| + body below has no pool field"), `:2160`. |
| +- Only an operator sets `Manifest.Pool`: `carlos instances enable --pool` in |
| + store mode (`instances_cli.go:51`, refused when signed in). The console's |
| + enable door leaves Pool untouched on update (`apiinstances.go:3592`). |
| +- B10 decides "born HA": `haCreate(region, pool)` (`internal/console/seedmove.go:40`), |
| + true in a scoped region only when the pool is in the region's `ha_pools` |
| + (`CONSOLE_HA_CAPACITY_CONFIG`, parsed in `hacapacity.go`). |
| + `shouldStampHA` (`seedmove.go:63`) stamps `rec.HA`. |
| +- Nobody but an operator can put an account into pool `ha`, and the web UI |
| + never mentions pools or HA. On the flagship the canaries (account `bab`) got |
| + there by store-mode manifests. |
| + |
| +So the path needs two things: a way for an allowed account to ask for HA at |
| +app creation, and a gate that keeps everyone else out of the pool, whoever |
| +writes the manifest. |
| + |
| +## 2. The allowlist |
| + |
| +`CONSOLE_HA_POOL_ACCOUNTS`: a comma-separated list of account sqids, parsed |
| +and validated exactly like `CARLOS_SIDECAR_ACCOUNTS` (`cmd/console/main.go:1157-1191`, |
| +strict, a bad entry stops the console at start). Set by the console's drop-in; |
| +changing it is a console restart. |
| + |
| +One difference from the sidecar list, on purpose: **unset or empty means |
| +nobody**. The pool is closed by default. |
| + |
| +The gate, `haPoolAllowed(acct, region, pool)`: true unless `pool` is in the |
| +region's `ha_pools` (a scoped HA pool), in which case the account's sqid must |
| +be on the list. It is checked: |
| +- at every create door that can write a record into a scoped HA pool: instance |
| + create, standalone sidecar create and domain-attach first route, the same |
| + doors B10 lists (RHA §23), immediately after the door's authentication, |
| + membership and validation and before any write, as `refuseSidecarsPaused` |
| + does (`sidecarsgate.go:51-60`); |
| +- at the app create option (§3). |
| + |
| +Refusal: 403 with machine code `ha-pool-not-allowed` and the §5 sentence. |
| +Non-members still get the door's identical 404 first, so the gate never |
| +confirms that an account exists. |
| + |
| +Removing an account from the list stops its new records in the pool. Its |
| +existing records keep running and keep their HA flag (records are immutable |
| +in this respect, RHA §23). Operators are not exempt: the canary account `bab` |
| +goes on the flagship list, and an operator who writes a store-mode manifest |
| +with pool `ha` for an unlisted account gets the refusal at instance create. |
| + |
| +Dev's IE entry carries `ha_pools: ["hapair"]`, so the gate applies on dev |
| +too; the dev list names the dev canary account. |
| + |
| +## 3. The create option: a born-HA app in a region |
| + |
| +### 3.1 API and CLI |
| + |
| +`POST /api/cli/apps/{account}` (`handleAPICreateApp`, `internal/console/apicli.go:411`) |
| +takes an optional `"ha": true`. With it: |
| +1. `region` is required and must be explicit (not `@auto`), in |
| + `CONSOLE_HA_REGIONS` and scoped with a non-empty `ha_pools`; otherwise 400 |
| + with the §5 "not in this region" sentence. |
| +2. `haPoolAllowed` must hold for the region's pool; otherwise 403 as above. |
| +3. The console creates the app with that region (the existing region path, |
| + `newAppRegionReq`), then writes the app's instances manifest create-only, |
| + with the default domain and `Pool` = the region's first `ha_pools` entry |
| + (`ha` on the flagship). This is the enable door's own create, with the pool |
| + supplied by the console instead of by an operator. |
| +4. If the manifest write fails after the app exists, the answer is 500 naming |
| + the half-done state, and a retry of the same request (app exists, no |
| + manifest) completes it. A retry when a manifest already exists with a |
| + different pool is 409. |
| + |
| +CLI: `carlos apps create <app> --region us --ha`. Nothing else in the CLI |
| +changes; `carlos deploy` into the app then creates the default instance, which |
| +the manifest makes born HA (`haCreate(us, ha)`), as the canaries showed in G5. |
| + |
| +### 3.2 The web UI |
| + |
| +On "Create an app" (`templates/app_new.html`, `handleNewApp`, |
| +`server.go:5590`), when the account is allowed and at least one region it can |
| +pick has an HA pool: |
| +- below the region picker, one checkbox, "High availability", with the §5 |
| + explainer and a link to the docs page; |
| +- it is enabled only while the picked region supports HA (the picker's region |
| + list gains an `ha` boolean; `regionpicker.go`); the server checks everything |
| + again (§3.1); |
| +- the form posts `ha=1`, and the handler runs the §3.1 steps. |
| + |
| +App settings (`templates/app_settings.html`) shows one read-only line for an |
| +app whose manifest pool is a scoped HA pool: the §5 status sentence. The |
| +region form on that page refuses a change for such an app (409, §5): moves |
| +into, out of and within HA regions stay refused (N-HA4), and this makes the |
| +refusal say so before anything is attempted. |
| + |
| +Accounts not on the list see no change at all. |
| + |
| +### 3.3 What is not offered |
| + |
| +- Turning HA on for an existing app or instance (the migration slice, deferred). |
| +- Choosing a pool by name: the option picks the region's pool. |
| +- HA in a region without an HA pool (dev IE has one; flagship US only). |
| +- Another replication class: every born-HA route is stream (fence spec §3.3). |
| + |
| +## 4. What HA promises, for the copy |
| + |
| +The facts the §5 strings must state, each from a measured or specified bound: |
| + |
| +| Situation | What the app sees | Source | |
| +|---|---|---| |
| +| Planned work: a release, a member replaced or removed | requests wait a few seconds, then succeed; no errors | G5 exit bar (holds ≤ 10 s, 0 non-2xx), RHA §25 | |
| +| A server dies without warning | requests get 503 with `Retry-After` until another server takes over; **up to about 15 minutes** until storage fencing exists | RHA §9.8 | |
| +| A server loses its storage connection | the app stops answering (503) within about 30 seconds; writes from the last ~35 seconds before that can be lost | fence spec §4 | |
| +| A server dies | writes from about the last second can be lost | RHA §5.3 | |
| +| The whole region fails | not covered | out of scope | |
| +| Existing apps | cannot be moved into HA yet | §3.3 | |
| + |
| +## 5. Strings for copy review (drafts, not approved) |
| + |
| +These go to Paul's copy review before the build writes any of them. Drafts |
| +follow the house voice: plain, no em dashes. |
| + |
| +1. Checkbox label: `High availability` |
| +2. Checkbox explainer: `Runs this app on two servers in this region. Releases and server maintenance don't interrupt it. If a server fails without warning, the app can be unavailable for up to 15 minutes while another server takes over.` |
| +3. Docs link text: `What high availability covers` |
| +4. Refusal, account not allowed (403 `ha-pool-not-allowed`): `high availability isn't available for this account yet.` |
| +5. Refusal, region without HA (400): `high availability isn't available in %s.` (region label, e.g. `N. Virginia (US)`) |
| +6. Refusal, `--ha` without an explicit region (400): `choose a region to turn on high availability.` |
| +7. Settings status line: `High availability is on in %s.` |
| +8. Region change refused for an HA app (409): `this app has high availability on, so its region can't be changed.` |
| +9. CLI flag help for `--ha`: `turn on high availability (needs --region; only for accounts that have it)` |
| +10. Docs page `docs/site/high-availability.md`, short: the §4 table in prose, written with the writing pipeline after the strings above are approved, and reviewed in the same copy pass. |
| + |
| +The checkbox string (2) leaves out the storage and write-loss rows on purpose; |
| +the docs page carries them. Paul decides in the review whether that is the |
| +right split. |
| + |
| +## 6. Tests and the exit test |
| + |
| +Unit, `internal/console` (model: `ha_pool_scope_test.go` and the sidecar gate |
| +tests): |
| +- allowlist parse: strict; empty means nobody; |
| +- `haPoolAllowed` at each create door for a scoped pool: listed account |
| + passes, unlisted gets 403 `ha-pool-not-allowed` before any bucket write, |
| + non-member gets 404; legacy creates and unscoped regions unchanged; |
| +- app create with `ha`: explicit region required; unscoped region refused; the |
| + manifest is written with the pool; the retry rules of §3.1 step 4; |
| +- web form: checkbox hidden for unlisted accounts, disabled for a non-HA |
| + region, server rejects a forged `ha=1`; |
| +- approved-copy tests for the §5 strings once Paul approves them (the pattern of |
| + `approved_region_ha_copy_test.go`). |
| + |
| +**Exit test (dev, then flagship):** |
| +1. An allowed account creates an app with HA in US (dev: IE, pool `hapair`) from |
| + the web form, then deploys; its default instance record has `ha: true`, |
| + `pool: ha`, region `us`, and it serves from a group member. |
| +2. An unlisted account sees no checkbox, and a forged API request gets 403; |
| + a store-mode manifest with pool `ha` for it still gets 403 at instance create. |
| +3. A plain create in US by any account stays legacy and lands on adi-knitting, |
| + exactly as before. |
| + |
| +## 7. Provider boundary |
| + |
| +Console-only and provider-neutral. The allowlist, the create option and the |
| +gate read console configuration and the bucket; nothing calls a cloud API. A |
| +self-hosted fleet with a scoped HA pool gets the same path. |
| + |
| +## 8. Open for Paul |
| + |
| +1. The env list (recommended, matching `CARLOS_SIDECAR_ACCOUNTS`) or a stored |
| + per-account grant an operator approves (the objstore entitlement pattern, |
| + `apistore_entitlement.go`). The env list needs a console restart per change; |
| + the grant needs a table and an operator door. |
| +2. Whether the checkbox text (§5 string 2) names the 15-minute bound, as drafted. |
diff --git a/docs/superpowers/specs/2026-11-11-g6-us-capacity-design.md b/docs/superpowers/specs/2026-11-11-g6-us-capacity-design.md| new file mode 100644 |
| index 000000000..cbc729cb8 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-11-g6-us-capacity-design.md |
| @@ -0,0 +1,135 @@ |
| +# G6 slice 1: capacity of the flagship US HA group (design, rev 1, 2026-11-11) |
| + |
| +Design only. Paul approves before any apply. Parent: region HA spec |
| +`2026-10-26-region-ha-without-claims-design.md` (cited **RHA §n**), the roll |
| +verb spec `2026-11-09-group-roll-verb-design.md` (**verb §n**), and Fable 5.2's |
| +G6 recommendation (`~/.cache/region-ha-next/fable52-g5g6/out.md` §3, approved by |
| +Paul 2026-11-11: "capacity spend per recommendation"). |
| + |
| +## 1. The question |
| + |
| +The first customer app goes into pool `ha` on the flagship US group |
| +(`carlos-flagship-us-ha`). During a member replace (verb `replace`, RHA §25) |
| +the member being replaced is drained and terminated before its replacement |
| +serves, so with two members **one member carries the whole pool**. The same |
| +holds after an unplanned death until the group replaces the member. What |
| +size must a member be, what does it cost, and how is a change applied? |
| + |
| +## 2. What the flagship shows now (read-only, profile keymail, 2026-11-11 ~17:15Z) |
| + |
| +| Item | Value | Source | |
| +|---|---|---| |
| +| Group | 2/2/2, LT 10, both `t4g.small`, InService, Healthy | `describe-auto-scaling-groups` | |
| +| Member memory | `mem_total_mib` 1858; free 1459 and 1479 MiB with nothing awake (about 390 MiB baseline) | `control/edges/g-*.json` headroom | |
| +| Member memory under the G5 probe (canaries awake) | daily minimum `MemAvailablePercent` 61.7% and 75.1%, so the canaries take about 300 MiB at most | `Carlos/Host MemAvailablePercent`, 3 days | |
| +| Member CPU | hourly average 1.5-1.8%, hourly maximum 18.7-22.4%; credit mode `unlimited`; credit balance near 0 (new members start with none) | `AWS/EC2 CPUUtilization`, `CPUCreditBalance`, 3 days | |
| +| Disk | 20 GiB gp3; 17.4 GiB free | LT 10, edges files | |
| +| Pool `ha` hosts | 4, all account `bab`: `g3r-ha`, `heldwitness`, `held-1`, `held-2` (the G3/G5 canaries) | member edges files | |
| +| adi-knitting (fixed, not in the pool) | `t4g.small`, 59 awake, memory available falling 75% to 70% (daily average) over a week | edges file, CloudWatch | |
| + |
| +Per-instance memory ceilings are the cgroup sizes (`internal/cgroup/sizes.go:18-20`): |
| +`small` 256 MiB, `standard` 512 MiB (the default, `cgroup.go:105`), `large` 1 GiB. |
| +`memory.max` equals `MemorySwapMax`, so an instance never exceeds its size. |
| + |
| +## 3. The rule |
| + |
| +Usable memory on a member = `mem_total` − baseline (390 MiB) − the eligibility |
| +floor (15% of `mem_total`, RHA §6.3, `policy.go`). Wakes are never refused |
| +for headroom (RHA §11), so exceeding it is not a refusal: it is OOM risk on |
| +the survivor while it carries everything. So: |
| + |
| +> **One member's usable memory ≥ the canaries' 300 MiB + the sum of the |
| +> sizes of every pool instance that may be awake at once.** |
| + |
| +Counting sizes, not observed use, is deliberate: the first app's real |
| +footprint is unknown, and a replace is exactly when every instance lands on |
| +one box. |
| + |
| +| Member type | `mem_total` (est.) | Usable | Fits besides the canaries | |
| +|---|---|---|---| |
| +| t4g.small (now) | 1858 MiB | ~1190 MiB | one `standard` app (512) with ~380 MiB spare; **not** one `large` app | |
| +| t4g.medium | ~3800 MiB | ~2840 MiB | four `standard`, or two `large` | |
| +| t4g.large | ~7750 MiB | ~6200 MiB | eleven `standard`, or five `large` | |
| + |
| +The medium and large `mem_total` values are estimated at the small's ratio |
| +(91% of nominal); the first medium member's edges file gives the real number, |
| +and the card records it. |
| + |
| +CPU is not the constraint today: all three types have 2 vCPU, and t4g.small |
| +and t4g.medium earn the same 24 credits an hour (t4g.large 36). In unlimited |
| +mode a CPU-heavy app costs surplus credits ($0.04 per vCPU-hour) rather than |
| +throttling. If the first app is CPU-bound, revisit with `m7g` or `t4g.large`. |
| + |
| +## 4. Cost (us-east-1 on-demand, AWS Price List API, 730 h/month) |
| + |
| +| Shape | Instances | EBS (20 GiB gp3 at $0.08) | Per month | Change from now | |
| +|---|---|---|---|---| |
| +| 2 × t4g.small (now) | $24.53 | $3.20 | **$27.73** | — | |
| +| 3 × t4g.small | $36.79 | $4.80 | $41.59 | +$13.86 | |
| +| **2 × t4g.medium** | $49.06 | $3.20 | **$52.26** | **+$24.53** | |
| +| 2 × t4g.large | $98.11 | $3.20 | $101.31 | +$73.58 | |
| + |
| +The NLB, alarms and SNS are unchanged by any of these. |
| + |
| +A third small member does not help the rule in §3: it adds redundancy (two |
| +members serve during a replace) but not the memory one member has after an |
| +unplanned death during a replace, or in any one-member moment. |
| + |
| +## 5. Recommendation |
| + |
| +**2 × t4g.medium (+$24.53 a month), applied before the first app is created.** |
| + |
| +- It carries the canaries plus any first app up to two `large` instances, so |
| + the choice of first app (still open) does not reopen this card. |
| +- It leaves room for a promote that briefly runs an old and a new process of |
| + the same app (counted at twice its size). |
| +- The trigger for the next step is written down now: when the §3 sum for the |
| + pool passes the medium's 2840 MiB, the next resize is due (t4g.large, or a |
| + third member if the extra redundancy is wanted then). |
| + |
| +If Paul prefers to spend nothing yet: 2 × t4g.small fits a single `standard` |
| +first app (§3), and the card applies only once a second app, a `large` app, |
| +or a promote overlap is in prospect. The cost of being wrong is OOM on the |
| +survivor during a replace, which is the moment G6 exists to make safe, so this |
| +is not the recommendation. |
| + |
| +## 6. How it is applied (a resize = add a member) |
| + |
| +The module sets `min = max = desired = box_count` (`infra/modules/region-host/group.tf:241-243`), |
| +and `instance_type` feeds the launch template (`variables.tf:16`). Running |
| +members never change type in place. Per Paul's G5 ruling, a resize adds a |
| +member first, so that at least two members serve at every step: |
| + |
| +| Step | Who | What | Expected counts / result | |
| +|---|---|---|---| |
| +| 0 | release agent | Pin-back if the group's LT and the observation differ (as every G5 roll needed). | 0/1/0, standing approval | |
| +| 1 | carloku-infrastructure PR | `instance_type = "t4g.medium"` and `box_count = 3` for `host_us_group`, targeted. A new LT version with the type change, ASG sizes 3. **First-of-kind apply: needs a GO** (Fable process rules, Paul 2026-11-11). | 0/2/0; the group launches one medium member; the two smalls are untouched | |
| +| 2 | operator | Wait for the medium member to pass the lifecycle hook and publish its edges file; record its `mem_total_mib`. | 3 members serving | |
| +| 3 | verb | `carlos system group replace --member <small A>`: drained; its replacement boots on the new LT (medium). | holds ≤ 10 s, 0 non-2xx (G5 bar) | |
| +| 4 | verb | `carlos system group remove --member <small B>`: drained scale-in (verb §3, `remove`). | holds ≤ 10 s, 0 non-2xx; 2 medium members | |
| +| 5 | carloku-infrastructure PR | `box_count = 2` to match the live group. | 0/1/0, no instance change, standing approval | |
| + |
| +The capacity alarm fires once per launch until the damping pin (4fe12300, |
| +v0.34.46) reaches the flagship; that is expected noise, not a finding. |
| + |
| +Steps 1 to 5 run in one flagship window under the #421 lock, with the G5 |
| +probe running against the canaries. The exit test: **one medium member |
| +carries the canaries plus a `large` heldwitness load through step 4's remove, |
| +the capacity alarm is quiet after the last launch, and the probe shows 0 |
| +non-2xx.** |
| + |
| +Rollback before step 3: revert step 1 (box_count 2 and t4g.small), then |
| +`remove` the medium member. After step 3, roll forward. |
| + |
| +## 7. Provider boundary |
| + |
| +Instance types, launch templates, Auto Scaling sizes and EC2 prices are the |
| +AWS adapter (RHA §12, `infra/modules/region-host`). The rule in §3 is |
| +provider-neutral: a self-hosted fleet sizes each box so that one box carries |
| +its pool's instance sizes above the 15% floor. A deployment without AWS adds |
| +or retires boxes by hand and runs the verb's provider-neutral phases (verb §5.4). |
| + |
| +## 8. Open for Paul |
| + |
| +1. 2 × t4g.medium now (recommended), or stay on 2 × t4g.small until the first |
| + app's size is known. |
diff --git a/docs/superpowers/specs/2026-11-11-g6-write-fence-design.md b/docs/superpowers/specs/2026-11-11-g6-write-fence-design.md| new file mode 100644 |
| index 000000000..9d4d3ac89 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-11-g6-write-fence-design.md |
| @@ -0,0 +1,195 @@ |
| +# G6 slice 2: the minimal write fence (F-C) (design, rev 1, 2026-11-11) |
| + |
| +Design only. Paul approves before any build. Parent: region HA spec |
| +`2026-10-26-region-ha-without-claims-design.md` (**RHA §n**). Evidence: |
| +`~/.cache/region-ha-next/G2-FINDINGS.md` (F-C, F-A) and |
| +`~/.cache/region-ha-next/G2-RERUN-RESULTS.md` (drill 4 rerun, v0.34.14). |
| +Line citations are to `origin/main` at 01d6ca78. |
| + |
| +**Paul's ruling (2026-11-11, via 8a3d302, approving Fable 5.2 §3 decision 2):** |
| +a holder whose replica sync fails for about 30 s stops serving (503 with |
| +`Retry-After`) and releases unclean. This spec builds exactly that and nothing |
| +more. The late-flush redesign, storage fencing and the batched and daily |
| +classes in a pool stay deferred. |
| + |
| +## 1. The problem, measured |
| + |
| +| Run | Class | Acknowledged and lost | Why it stopped | |
| +|---|---|---|---| |
| +| G2 drill 4 (v0.34.7) | batched | 341 of 1109, over 340 s | lease loss after a hung renewal (F-A) | |
| +| G2 rerun drill 4 (v0.34.14), during the cut, before the latch | **stream** | **131 of 131** (20:35:04-20:37:14Z) | the next renewal failed its bounded attempt | |
| +| same | batched | 129 of 129, plus 187 from before the cut | same | |
| + |
| +The stream class is the class the pool will carry (§4). It lost every write it |
| +acknowledged for 130 s, because nothing reads replica health. The holder stops |
| +acknowledging only when a lease renewal fails, and renewals run every TTL/3, |
| +5 minutes at the 15-minute TTL (`internal/lease/health.go`, `lease.go:40`). |
| +So the stream loss window under an S3 cut is anywhere from 0 to about 5 |
| +minutes, set by where the cut falls against the renewal. RHA §5.3 promises |
| +"about a second for the stream class". |
| + |
| +## 2. What already exists (verified) |
| + |
| +- **One trigger.** Every serving decision asks `servingError(e)` |
| + (`internal/activator/stateless.go:226`), which returns the replicator's |
| + `Err()` (`internal/lease/lease.go:539`, the renewer's latched error). |
| + A non-nil answer already gives everything F-C asks for: |
| + - requests answer at once with `edge.HAUnavailableResponse`: 503, |
| + `Retry-After: 10`, `X-Carlos-Holder: none` (`internal/edge/haingress.go:15`, |
| + via `haLeaseRefusalLocked` in `haleaseloss.go` and `serveWakeError`); |
| + - the entry stops (`beginStopLocked(e, StopLeaseLost)`), and the final |
| + release joins `rn.Err()` into `finishErr` (`internal/lease/release.go:254`), |
| + so the marker is written `clean: false` (RHA §5.2); |
| + - a marker PUT that fails is kept as an owed release and retried until it |
| + lands or is answered 412 (RHA §5.2, `owed.go`). |
| +- **The latch is permanent.** `renewer.loseLocked` sets the error once and |
| + closes `lost` (`health.go:137-142`); `checkLocked` returns it forever, and |
| + the renewer's watch goroutine cancels renewals when it sees it. |
| +- **Litestream already tracks sync success.** `DB.LastSuccessfulSyncAt()` |
| + (litestream v0.5.14 `db.go:625`) is set at the end of every successful |
| + `Replica.Sync` (`replica.go:179`). `Replica.Pos()` and `DB.Pos()` give the |
| + replicated and local transaction ids. A failed sync resets the replica |
| + position to zero (`replica.go:139-145`). Nothing in the platform reads any of |
| + them. |
| +- **The stream case is known at wake.** For an HA lease with sync interval 0 |
| + the activator sets the 1 s WAL monitor (`internal/activator/activator.go:3335`). |
| + |
| +## 3. The change |
| + |
| +### 3.1 The fence (internal/lease) |
| + |
| +When `Held.Replicate` starts a replicator for an **HA lease in the stream |
| +class** (sync interval 0), it also starts a fence check that runs every 5 s |
| +until the replicator closes: |
| + |
| +1. `synced` = the highest non-zero `Replica.Pos().TXID` seen so far (kept by the |
| + check, because a failed sync zeroes the position); |
| +2. `pending` = `DB.Pos().TXID > synced`, that is, transactions committed |
| + locally and not yet in the store; |
| +3. `since` = the later of `LastSuccessfulSyncAt()` and the replicator's start; |
| +4. **if `pending` and `now − since > 30 s`:** under `rn.mu`, `loseLocked(ErrReplicaStale)` |
| + and log once: |
| + `lease: <path>: replica sync has not succeeded for <age> with transactions <synced+1>-<db> unsynced; standing down (write fence)`. |
| + |
| +`ErrReplicaStale` is a new sentinel, distinct from `ErrLost`, so the journal |
| +and metrics tell a fence from a lost lease. No caller tests |
| +`errors.Is(err, lease.ErrLost)` on this path (the one `ErrLost` match in |
| +`internal/hostexec/rootbroker.go:795` is a different package's sentinel), so |
| +every existing consumer treats the fence exactly as a lost lease. |
| + |
| +Why these inputs: |
| +- An idle instance during an outage has nothing pending, so it is never fenced. |
| + Its lease renewal handles the outage as today. |
| +- A sync that hangs (the F-A case: litestream's background upload can block |
| + for up to its 24 h HTTP timeout) never records a success, so it trips the |
| + fence like an error does. |
| +- Every commit not yet in the store happened after `since`, so at the moment |
| + the fence trips, all acknowledged-but-unsynced writes are from the last |
| + `30 s + 5 s` (one check interval). That is the bound. |
| + |
| +The 30 s and 5 s are constants with a test seam, not settings. A self-hoster |
| +with a slow store gets the same bound; §6 says what that costs. |
| + |
| +### 3.2 Stopping every writer promptly (internal/activator) |
| + |
| +Requests are fenced at once through `servingError`. Background writers |
| +(always-on workers, ticks, sidecars) are caught today only by the sweep, every |
| +`min(Idle/4, 30 s)` (`activator.go:5401-5406`). That could stretch the window. |
| +So for each awake HA entry the activator waits on `rep.Lost()` |
| +(`lease.go:545`) and, when it fires, takes `a.mu` and calls |
| +`beginStopLocked(e, StopLeaseLost)` if the entry is still the same incarnation. |
| +That reuses the existing stop, which stops the process, its co-spawned |
| +sidecar, workers and holds, and requires the host slice to be empty before |
| +release (`harelease.go`, `haHostEmpty`). The same goroutine helps lease loss |
| +too: today a lease lost while no request arrives also waits for the sweep. |
| + |
| +### 3.3 Only the stream class in an HA pool (cli.go, registry) |
| + |
| +The fence covers the stream class only. The pool must therefore carry only |
| +the stream class: |
| +- `replicationRail` (`cli.go:2086`), the door for `carlos route --replication`, |
| + refuses `batched` and `daily` on a route with `HA` set: |
| + `route <host> has high availability on: only the stream class is allowed` |
| + (operator text; copy review with the build's other strings). |
| +- Every route born HA by the pool path (slice 3) has the default class, `""`, |
| + which is stream (`activator.go:459-467`). |
| +- Existing HA routes with another class keep it and are not fenced. Today these |
| + are only dev's G2 fixtures `g2-batched` and `g2-daily` in pool `hapair`. The |
| + build's flagship check reads the class of every pool `ha` route through |
| + `carlos routes` on a member and expects none. |
| +- Moves into an HA region stay refused (N-HA4), so a move cannot land another |
| + class on an HA route. HA wake-state import (`hawake.go:832`) carries the |
| + class it was given, which by the rail above is stream for every new route. |
| + |
| +## 4. What changes for the pool, stated plainly |
| + |
| +For a stream instance on an HA box: |
| + |
| +| Event | Before | After | |
| +|---|---|---| |
| +| Box dies | about 1 s of writes lost (RHA §5.3) | unchanged | |
| +| Box loses the store, with writes arriving | every write acknowledged until the next renewal fails: 0 to about 5 min | at most the writes of the last 35 s before the fence; then 503 with `Retry-After: 10` | |
| +| Box loses the store, idle | nothing lost; lease renewal handles it | unchanged | |
| +| Store outage shorter than 30 s | nothing lost | unchanged | |
| +| Store outage longer than 30 s, with writes, no renewal inside it | nothing lost: the sync catches up when the store returns | **the instance stops, and the unsynced tail (≤ 35 s) is lost** when the unclean marker lands and the instance restores from the store; the local copy is set aside as `<db>.stale` (RHA §5.3), so an operator can still recover it by hand | |
| + |
| +The last row is the price Paul's ruling accepts: a bounded loss in place of an |
| +unbounded one. Without the late flush (deferred), a fenced holder cannot hand |
| +its tail over cleanly. |
| + |
| +After the store returns, the owed unclean marker lands, and any eligible pool |
| +member (the old holder included) acquires and restores. The service comes back |
| +without a terminate, which is the drill 4 rerun's behaviour after its fault |
| +ended. If the box never gets the store back, RHA §9.5 is unchanged: the |
| +suspect-holder page at L+10 and the runbook terminate. |
| + |
| +RHA §5.5 gains one sentence: "On an HA box, a stream instance whose replica |
| +sync has not succeeded for 30 seconds while it has unsynced writes stops |
| +serving and releases unclean, so a storage outage loses at most about the last |
| +35 seconds of acknowledged writes." |
| + |
| +## 5. Tests and the exit test |
| + |
| +Unit (no AWS, run under `-run`): |
| +- `internal/lease`: with `SetReplicaClientForTest` (`export_test.go:34`) and a |
| + failing upload, a pending transaction trips `ErrReplicaStale` after 30 s on |
| + the seam clock; no pending transaction never trips; a sync that blocks trips; |
| + a success at 29 s resets the age; the latch is permanent; the fence is off for |
| + batched, daily and non-HA leases. |
| +- `internal/activator`, modelled on `haleaseloss_test.go` (`lossTestRep`, |
| + `assertLostResponse`, `TestHALostLeaseAnswersImmediately`): a replicator whose |
| + `Err()` becomes `ErrReplicaStale` answers 503, `Retry-After: 10`, |
| + `X-Carlos-Holder: none` with no proxy; the release marker is `clean: false`; |
| + a worker-only entry is stopped by the `Lost()` watcher without a request or |
| + sweep. |
| +- `cli`: the rail refuses `batched` and `daily` on an HA route and allows them |
| + on a non-HA route. |
| + |
| +**Exit test: rerun dev drill 4** (`~/.cache/region-ha-next/G2-CARD.md` drill 4, |
| +the fault harness with its 35-minute expiry timer), on the dev IE group, pool |
| +`hapair`, fixture `g2-stream` written to about once a second through both |
| +entries: |
| +1. Cut outbound 443 on the holder for 10 minutes. |
| +2. **Pass:** the fence line appears between t0+30 s and t0+40 s; from it every |
| + request gets 503 with `Retry-After: 10` and no hangs; acknowledged and lost |
| + writes (probe acks against `/ranges`) are all from the 35 s before the fence |
| + line, and number at most 40 (was 131); after the fault ends the unclean |
| + marker lands and the fixture serves again within the bound of RHA §9.8; no |
| + other box takes the lease before the marker or a terminate; F-A, F-B and F-D |
| + rows of the rerun still pass. |
| +3. Two controls in the same window: a 20 s cut with writes (no fence, 0 lost) |
| + and a 2-minute cut with the fixture idle (no fence). |
| + |
| +## 6. Provider boundary and cost |
| + |
| +Core only. The fence reads litestream's in-memory positions and timestamps; |
| +it makes no request and adds no S3 cost. It behaves the same on MinIO or any |
| +S3-compatible store. A store slower than 30 s per sync under load would fence |
| +spuriously; the drill's 20 s control and the dev metrics show the margin on |
| +AWS, and a self-hoster's store needs the same margin. |
| + |
| +## 7. Out of scope |
| + |
| +Late flush before release (the redesign F-C named), storage fencing (N-HA9), |
| +batched and daily classes in a pool, automatic replacement of a box that lost |
| +the store (RHA §9.5), and the W5 tolerance question. |