carlos / platform Public

design: region HA storage generations spec, approved

Rev 4 of the per-holder storage generations design. Paul took all five
recommendations on 2026-11-15 (section 10). Docs only; the build waits
for G6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from design-ha-generations into main.
claude agent, operated by paul@keymail.dev 3edf8a4c33ca41ea7c230484f393314c31df6e39 parent 433fcf1
5 files changed, +313 −0
  • docs/superpowers/reviews/ASTRA-BRIEF-ha-generations.md +22 −0
  • docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R1.md +19 −0
  • docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R2.md +30 −0
  • docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R3.md +34 −0
  • docs/superpowers/specs/2026-11-12-region-ha-storage-generations-design.md +208 −0

CI passed — run details

diff --git a/docs/superpowers/reviews/ASTRA-BRIEF-ha-generations.md b/docs/superpowers/reviews/ASTRA-BRIEF-ha-generations.md
new file mode 100644
index 000000000..7cd83cd8c
--- /dev/null
+++ b/docs/superpowers/reviews/ASTRA-BRIEF-ha-generations.md
@@ -0,0 +1,22 @@
+# Astra design review: region HA per-holder storage generations (round N of max 3)
+
+Worktree /home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-generations, branch design-ha-generations.
+Spec: docs/superpowers/specs/2026-11-12-region-ha-storage-generations-design.md (read the commit named in the prompt).
+Reading only: no edits. Leave GOCACHE unset if you build anything.
+
+Context: this is your wake-race review's option 2 (~/.cache/ha-flakes/wake-race/FINDINGS.md). Paul ruled
+(2026-11-12): containment now (branch ha-unclean-marker-waits, region HA spec rev 6.7), this spec now, build
+after G6. Fixed decisions, do not re-argue: generations are per holder; build after G6; clean markers keep the
+drain's fast handover. The three questions in spec section 10 are open for Paul: give your recommendation.
+
+Review question: does the design guarantee G1-G5 (spec section 2) for every writer and reader, so that no
+successor's history can contain or be replaced by a write an earlier holder sent, without any time wait? Check
+against the code: the take protocol (section 4) and its races, Litestream 0.5.14 behaviour on a restored database
+with the union client (section 5.1, db.go checkDatabaseBehindReplica, Replica.Sync, compaction, retention), the
+reader inventory (section 6.1; is any reader missing?), PITR (6.2), moves (6.3), files (7), retention and the
+7-day noncurrent expiry (8), the old-binary fence and gate (9: verify old HAOn/ParseOwner really refuse).
+A mechanism that is named, bounded and assigned to a slice is complete at spec level; do not ask for plan detail.
+If this is round 2 or 3: first a disposition table of the previous round's findings, then only new findings.
+
+Output: findings P1/P2/P3 with file:line or spec section citations; verdict READY / READY AFTER FIXES / NOT READY.
+Concise.
diff --git a/docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R1.md b/docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R1.md
new file mode 100644
index 000000000..5f8b0026c
--- /dev/null
+++ b/docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R1.md
@@ -0,0 +1,19 @@
+Round 1, commit `b31a503b`. **Four P1 findings.**
+
+1. **P1 — A snapshot-only base resets replication to TXID 1.**
+ **Family: history continuity; §§3.1, 5.1.** The usual clean-handover base contains only L9. Both `checkDatabaseBehindReplica` ([db.go:1414](/home/paulca/go/pkg/mod/github.com/benbjohnson/litestream@v0.5.14/db.go:1414)) and `Replica.calcPos` ([replica.go:210](/home/paulca/go/pkg/mod/github.com/benbjohnson/litestream@v0.5.14/replica.go:210)) inspect **L0 only**. On a cold restore, neither establishes `base.txid`; the first local sync starts at 1. With a base snapshot through TXID 100, successor writes below 100 are then skipped by restore in favour of that snapshot. This is data loss, not merely extra snapshot bandwidth. Specify a bootstrap mechanism that establishes both local and replica positions at the pinned boundary, including snapshot-only and compacted-only bases.
+
+2. **P1 — The six-hour snapshot target does not guarantee pin survival.**
+ **Family: G5, referenced-version lifetime; §§5.3, 8.** A predecessor’s late overwrite makes a pinned version noncurrent. If its successor crashes before becoming self-contained and receives no wake for seven days, lifecycle can permanently delete the only baseline. Repeated short generations can also inherit an already-aged pin; their new take times do not restart its expiry. Historical restores still need earlier bases after the current generation becomes self-contained. The bucket’s [unconditional lifecycle rule](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-generations/infra/modules/deployment-buckets/main.tf:106) does not consult references. An alarm cannot enforce G5. Specify storage protection or durable immutable copies covering every live and historical dependency, including sleeping instances.
+
+3. **P1 — The old-binary fence opens the legacy acquire path.**
+ **Family: ownership compatibility boundary; §9.** The proposed formats correctly make old `HAOn` false and make `ParseOwner` reject `;gen=1`. However, [takeLegacy](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-generations/internal/lease/legacytake.go:61) accepts an expired lock precisely when `HAOn` is false. Thus an old legacy-route wake or [move checkpoint](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-generations/internal/lease/lease.go:531) can take a v2 release marker immediately and write the root layout. Preserve old HA recognition while making old HA acquisition refuse the payload. Test both acquisition paths, not just `DecideAcquire`.
+
+4. **P1 — Moving only the current generation loses retained restore history.**
+ **Family: G4/G5, history across relocation; §§6.2–6.3.** A self-contained current snapshot removes dependencies for latest restore only. Copying `head.json` and that generation omits earlier generations and historical head versions still required by `history`. Cross-bucket copies also receive new version IDs; copying JSON does not translate its pins. After landing, an otherwise valid `--at` request into a previous generation cannot resolve. Specify either copying and remapping the retained dependency graph, or retaining explicitly addressed source history until its restore window closes.
+
+For §10: **Q1:** prefer references once G5 has enforceable protection. **Q2:** remove the termination expiry wait once the complete fence works. **Q3:** keep one generation per holder; measure before considering coalescing.
+
+Source review only; no files changed, tests run, or oldest-live-binary verification performed.
+
+**NOT READY**
\ No newline at end of file
diff --git a/docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R2.md b/docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R2.md
new file mode 100644
index 000000000..626a805cf
--- /dev/null
+++ b/docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R2.md
@@ -0,0 +1,30 @@
+Round 2, commit `4d99ceca`.
+
+| Previous P1 | Disposition |
+|---|---|
+| **gen-1.1 — History continuity** | **Partly resolved; still P1.** §4 copies the newest L0 **at or below** `T`, but it must establish position **at `T`**. A predecessor can have L9 through 100 and L0 only through 90: snapshots use the [local DB position](/home/paulca/go/pkg/mod/github.com/benbjohnson/litestream@v0.5.14/db.go:2338), while [startup reads L0](/home/paulca/go/pkg/mod/github.com/benbjohnson/litestream@v0.5.14/db.go:1414). The successor resumes at 91; its writes through 100 are hidden by the copied L9. The no-L0 fallback does not cover this case. Require a baseline establishing both positions at `T`, or refuse before starting. |
+| **gen-1.2 — Referenced-version lifetime** | **Resolved.** Exact-version copies remove the long-lived noncurrent-version dependency. |
+| **gen-1.3 — Ownership compatibility boundary** | **Resolved at design level.** The revised release owner remains HA and fails old HA acquisition. Held-lock protection depends on the specified gate, floor and advance refusal release. |
+| **gen-1.4 — History across relocation** | **Partly resolved; still P1.** Copying every generation addresses missing objects and version-ID remapping. Namespace collisions and changed timestamps still break retained history; see gen-2.2 and gen-2.3. |
+
+New findings:
+
+1. **P1 — The drain does not prove every request completed.**
+ **Family: G1, predecessor-request completion; §5.2.** Disabling store compaction/retention monitors leaves `Replica.MonitorEnabled` on. [`DB.Close`](/home/paulca/go/pkg/mod/github.com/benbjohnson/litestream@v0.5.14/db.go:767) cancels its context; its [shutdown retry loop](/home/paulca/go/pkg/mod/github.com/benbjohnson/litestream@v0.5.14/db.go:884) can subsequently return success after an ambiguous attempt. Separately, [`FinishSnapshot` records snapshot failure outside `finishErr`](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-generations/internal/lease/release.go:243). Waiting for the scheduler and obtaining a successful final sync therefore permits a drained marker while an earlier request can still land in the reused generation. Require completion accounting for all mutation attempts, including replica sync, final snapshots and retries; uncertainty must permanently disqualify that release from reuse.
+
+2. **P1 — Imported generation names can collide with destination generations.**
+ **Family: G1/G3/G5, history across relocation; §§3, 6.3.** `g-N` is unique only within one lock’s counter. [`MirrorPrefix` deliberately excludes `lock.json`](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-generations/internal/lease/mirror.go:231), so destination counters remain independent. Imported history can already contain `g-2` when the destination creates its new `g-2`. Copying history then shares a prefix with the current writer; retained files can overwrite or outrank its baseline. Give imported generations collision-free identities and remap references, or refuse such moves before copying.
+
+3. **P1 — Whole-prefix copies destroy historical PITR timestamps.**
+ **Family: G4/G5, history across relocation; §§6.2–6.3.** Today’s [`ListLevel`](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-generations/internal/dbdoor/plan_from.go:30) explicitly uses S3 `LastModified` as `CreatedAt`. Copies receive new modification times, while copied `history` entries retain their old tenure intervals. After a move, an in-window `--at` before the move selects the correct historical generation but excludes its newly dated files. Preserve the original PITR timestamps through copying and require readers to use them.
+
+4. **P1 — One restore can resolve different generations.**
+ **Family: G4, reader history identity; §6.1.** The claim-free DB door resolves [each listing](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-generations/internal/lease/../console/apidb.go:307) and [each download](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-generations/internal/console/apidb.go:354) independently. Switching these calls to the current-head resolver allows a listing from G and a download from H. After an unclean fork, identical TXID coordinates can contain different histories. Specify one generation binding across the complete restore—listings, downloads and retries—with a refusal/restart on mismatch. Returning an ETag without that contract does not fence the read.
+
+**Stopping rule 2 applies:** history continuity and history across relocation remain faulty in consecutive rounds. Before a third fix, choose an upfront refusal, a feature cut, or one centrally enforced invariant with witnesses. I recommend refusing unsupported baseline shapes and generation-aware moves until their invariants are established.
+
+**§10 recommendations:** server-side copies; remove expiry waits only after the complete fence is verified; retain per-holder generations until the drain proves request completion.
+
+Source review only. No files changed, tests run, or oldest-live-binary verification performed.
+
+**NOT READY**
\ No newline at end of file
diff --git a/docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R3.md b/docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R3.md
new file mode 100644
index 000000000..27d71b215
--- /dev/null
+++ b/docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R3.md
@@ -0,0 +1,34 @@
+Round 3, commit `c746bfc3`.
+
+| Previous finding | Disposition |
+|---|---|
+| gen-1.1 — History continuity | **Resolved at design level.** §4 requires both positions at the newest L0 TXID and refuses unsupported baselines. |
+| gen-1.2 — Referenced-version lifetime | **Resolved.** Copies remove the enduring version-ID dependency. |
+| gen-1.3 — Ownership compatibility | **Resolved at design level.** Release-marker refusal matches `HAOn`/`ParseOwner`; held locks still require the specified gate and floor. |
+| gen-1.4 — History across relocation | **Resolved by scope cut.** Pre-landing history is explicitly unavailable. |
+| gen-2.1 — Drain completion | **Resolved by scope cut.** Every take creates a generation. |
+| gen-2.2 / gen-2.3 — Imported names and timestamps | **Resolved by scope cut.** Landing assigns its own generation and imports no history. |
+| gen-2.4 — Restore generation binding | **Resolved.** §6.1 binds listings, downloads and retries. |
+
+New findings:
+
+1. **P1 — The files fence does not cover an absent manifest.**
+ **Family: predecessor-request fencing; §7.** An absent manifest is a supported restore baseline, with no ETag ([publisher.go:153](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-generations/internal/hostfiles/publisher.go:153)). A predecessor’s first manifest PUT can remain outstanding while its successor restores an empty tree. The prescribed `If-Match` rewrite cannot fence that absence. Skipping it permits the predecessor’s manifest to appear after takeover; attempting it without an ETag cannot complete the wake.
+
+ Require an empty, generation-stamped manifest created with `If-None-Match: *` before serving. A conflict must fail/restart the wake, and the publisher must continue from the successful fence’s returned baseline.
+
+2. **P1 — The narrowed move drops current non-database state.**
+ **Family: complete state across relocation; §§6.3–7.** Staging now copies “head.json and the current generation only,” and landing replaces whole-prefix promotion with the database start protocol. This excludes `files/0/` and root-level build state. Today the move explicitly carries request state into the prefix before mirroring ([movespass.go:1616](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-generations/internal/host/movespass.go:1616)); files restoration treats a missing manifest as an empty tree ([hawake.go:715](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-generations/internal/activator/hawake.go:715)). A fresh destination loses that state; a returning destination can retain stale state.
+
+ Preserve transfer and authoritative installation of current non-database state, including the files manifest and its objects, while excluding old database generations. Alternatively, refuse generation-enabled moves in v1.
+
+3. **P2 — Distinguish first creation from predecessor restoration.**
+ **Family: bootstrap availability; §4.** The no-L0 refusal needs an explicit boundary around the existing proven-empty first-wake path ([hawake.go:525](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-generations/internal/activator/hawake.go:525)). State whether creation bypasses §4 or establishes an empty generation, including recovery before its first upload. Otherwise the universal start wording sends a new instance into the no-L0 refusal.
+
+**§10 recommendations:** server-side copies; remove waits only after the complete fence passes its drills; accept per-wake copies initially; accept unsupported-baseline refusals for existing data. Cut generation-enabled moves until current-state transfer is complete.
+
+The P1s have separate causes. Refusing absent-manifest wakes and generation-enabled moves would remove their affected cases. Round 3 exhausts the budget; further review requires Paul’s approval.
+
+Source review only. No files changed, tests run, or oldest-live-binary verification performed.
+
+**NOT READY**
\ No newline at end of file
diff --git a/docs/superpowers/specs/2026-11-12-region-ha-storage-generations-design.md b/docs/superpowers/specs/2026-11-12-region-ha-storage-generations-design.md
new file mode 100644
index 000000000..1806bdb0b
--- /dev/null
+++ b/docs/superpowers/specs/2026-11-12-region-ha-storage-generations-design.md
@@ -0,0 +1,208 @@
+# Region HA: per-holder storage generations
+
+Design, 2026-11-12, **rev 4**, **approved 2026-11-15** (§10) (Astra rounds 1 to 3 answered; the review budget is spent, and round 3's findings are applied as cuts without a fourth round: any further review is Paul's call). Branch `design-ha-generations`. Nothing here is built. Paul's ruling (2026-11-12, HA session, #421): contain the unclean-release late write now (branch `ha-unclean-marker-waits`, region HA spec rev 6.7), spec storage generations now, **build after G6**.
+
+Sources: the wake-race review (`~/.cache/ha-flakes/wake-race/FINDINGS.md`, Astra, 2026-11-11; its options 1 and 2 combined are this design), the containment review (`docs/superpowers/reviews/ASTRA-FINDINGS-ha-unclean-containment-R1.md`), region HA without claims (**RHA**, `2026-10-26-region-ha-without-claims-design.md`, §5, §9.4, N-HA9), and the dormant claim machinery whose shapes this reuses (`internal/genselect`, `internal/hostbox/restore.go`, `internal/moves/source.go`, `internal/lease/claimgeneration.go`).
+
+**Rev 2** answers Astra round 1 (`docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R1.md`), four P1s:
+- **(gen-1.1)** a snapshot-only base reset Litestream to TXID 1: the base is now a server-side **copy** of the predecessor's files into the new generation, the newest L0 included, so the new prefix looks exactly like a restored prefix does today (§4 step 4, §5.1);
+- **(gen-1.2)** pinned versions could expire under the bucket's noncurrent rule: nothing references a version id after the take; the copy is made from exact versions and then owned (§4, §8);
+- **(gen-1.3)** the old-binary fence opened the legacy acquire: old binaries now still read every lock as HA and refuse it (§9);
+- **(gen-1.4)** a move dropped history: generations are self-contained prefixes under `<loc>/`, so today's whole-prefix mirror copies all of them, and head.json names generations, not versions (§6.3).
+- Rev 1's per-take generation would copy the database on every wake. Rev 2 started a generation only when the predecessor did not release cleanly, and made "clean" mean every replica request was answered.
+
+**Rev 3** answers round 2 (`docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R2.md`) under stopping rule 2: history continuity and history across relocation drew P1s in both rounds, so rev 3 refuses up front and cuts instead of fixing a third time.
+- **(gen-2.1, gen-1.1)** one central rule: a new generation starts **exactly at the predecessor's newest L0 TXID**. Files above it are not copied; if no plan reaches it, the wake is refused (§4 step 4).
+- **(gen-2.1 new, the drain)** cut: Litestream's own replica monitor and its shutdown retries leave requests whose outcome is unknown, so "drained" cannot be proved in 0.5.14. **Every take starts a new generation** (per holder, rev 1's rule), and nothing depends on proving that requests completed. The drain is a later design (§11).
+- **(gen-2.2, gen-2.3, gen-1.4)** cut: a move carries the **current state only**, into a generation the landing side names. No history is imported, so no name can collide and no copied timestamp is read as history; point-in-time reads reach back to the landing (§6.3).
+- **(gen-2.4)** one restore binds one generation name for its listings, downloads and retries (§6.1).
+
+**Rev 4** applies round 3 (`docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R3.md`, every earlier finding resolved; two new P1s and a P2) with the reviewer's own remedies, no further round:
+- **(gen-3.1)** the files fence covers an absent manifest: a create-only empty manifest, `If-None-Match: *` (§7);
+- **(gen-3.2)** cut: **moves of a generations host are refused in v1** (§6.3); the current-state move is a later slice;
+- **(gen-3.3)** a first wake (proven-empty prefix) creates an empty generation and does not go through the start rule (§4 step 0).
+
+## 1. The problem, and what this retires
+
+Every holder of an HA instance's lease writes its Litestream replica into one shared prefix, `<loc>/` (`instances/<host>/`), with no ownership condition on the write (`litestream@v0.5.14/s3/replica_client.go:702`). Litestream's close cancels requests without proof that S3 did not receive them. So a request an earlier holder sent can be applied after a successor has restored and started its own history under the same keys. The late object replaces the successor's, and history diverges silently (wake-race P1 B; witness `internal/lease/unclean_marker_test.go`, adapted from 8e8a00a0).
+
+Today time is the only fence:
+- N-HA9: a terminated owner's lock is taken only after it expires (up to 15 minutes);
+- rev 6.7: an unclean release after replication waits a lease term from its marker;
+- a clean release opens at once, and still carries the exposure for cancelled compaction, snapshot and retention requests (containment R1 A). Paul kept that for the drain's fast handover.
+
+**Goal.** A successor never writes into a prefix an earlier holder can still write. Late writes may land; they land where nobody reads them as current. With that in place:
+- the rev 6.7 wait goes: an unclean marker opens at once, into a new generation;
+- N-HA9's expiry wait goes: a confirmed-terminated owner's lock is taken on the proof alone (RHA §9.8 totals become 1 to 5 minutes, not 15);
+- the clean marker's monitor exposure closes, because every take writes a new generation.
+
+Out of scope: hung but live boxes (still terminated by the group, RHA §9.5); the process single-writer rule (I1's cgroup and termination proofs stay); legacy non-HA hosts and the box-wide Litestream (`internal/ops/litestream.go`).
+
+## 2. Invariants
+
+| ID | Invariant | Enforced by |
+|---|---|---|
+| G1 | **Own prefix.** Every take starts a new generation `<loc>/g-<id>/`, and its holder writes replica objects only there. Nothing it does writes, compacts or deletes outside its generation. | The replica client the lease package builds (§5.1); the take (§4). |
+| G2 | **One authority.** `<loc>/head.json` names the one current generation and changes only by a conditional write of the lock holder. | §4 step 5, `If-Match`. |
+| G3 | **Frozen start, at a proven position.** A new generation starts as a server-side copy of exact object versions of its predecessor, ending exactly at the predecessor's newest L0 TXID. A later write anywhere in the predecessor prefix cannot change the copy, and Litestream's local and replica positions both start there. | `CopyObject` with a source version id; the start rule (§4 step 4). |
+| G4 | **One reader, one generation.** Every reader resolves the replica through head.json, by one function, and binds the generation it resolved for the whole read: listings, downloads and retries. | §6.1, and a test that no caller builds a replica client at `<loc>` directly. |
+| G5 | **Self-contained generations.** No generation, and no head, refers to another generation's object versions after its take. Each generation restores from its own prefix alone. | §4 (copy, not reference); §8 retention touches whole generations only. |
+
+## 3. Layout
+
+- `<loc>/lock.json`: the lease and release markers (format in §9).
+- `<loc>/head.json`: the pointer (§3.1). Absent means the legacy root layout.
+- `<loc>/g-<id>/<level>/<min>-<max>.ltx`: one generation's Litestream files, the tree Litestream writes today, one level down. `<id>` is the lock generation of the take that created it, zero-padded to 20 digits (`g-00000000000000000042`). The lock's conditional take makes it unique, and it sorts.
+- `<loc>/` root LTX files: the **root generation** (`@root`, as `hostclaim.RootGeneration` names it). A predecessor only; never written once head.json exists.
+- `<loc>/files/0/`: unchanged (§7).
+
+The claim code uses the same `<location>/g-<gen>/` shape (`BindGeneration`, `claimgeneration.go:31`; `moves.ReplicaSource`; `genselect`). Its three prefix twins (`hostbox.GenerationPrefix`, `moves.GenerationPrefix`, `genselect.prefix`) fold into one helper.
+
+### 3.1 head.json
+
+```json
+{
+ "v": 1,
+ "generation": "g-00000000000000000042",
+ "created_by": {"lock_generation": 42, "box": "box-a", "iid": "i-0abc", "lifetime": "<incarnation>", "at": "2026-11-12T10:00:00Z"},
+ "start_txid": 1234,
+ "predecessor": "g-00000000000000000037",
+ "history": [ {"generation": "g-00000000000000000037", "start_txid": 900, "created_at": "...", "ended_at": "2026-11-12T10:00:00Z"} ]
+}
+```
+
+- `start_txid` is the TXID the copy ends at; the generation's own writes begin after it.
+- `history` lists earlier generations still inside the restore window, newest first, with the time each stopped being current (`ended_at`). PITR uses it (§6.2); §8 trims it.
+- No version ids, so a move can copy head.json as it is (§6.3).
+
+## 4. The take
+
+The HA acquire is unchanged up to its conditional take of `lock.json` (RHA §9.4, `hafresh.DecideAcquire`). N is the lock generation the take wrote. Then, before the instance starts:
+
+0. **First wake.** If the acquire was a first wake (an absent lock over a proven-empty prefix, `hawake.go:525`), there is no predecessor: create head.json for an empty `g-N` with `If-None-Match: *`, boot fresh as today, and skip to step 6. A box that dies before its first upload leaves an empty current generation; the next take sees no L0 in it and, because head.json's `start_txid` is 0 and its `predecessor` is empty, starts another empty generation instead of refusing.
+
+1. **Read head.json** with its ETag `E` (absent: the current generation is `@root`; step 5 uses `If-None-Match: *`).
+2. **Start a generation.** Every take does, whatever the lock it replaced: a clean or unclean marker, a crash or termination takeover, a same-box recovery, `@root` (the migration, §9), a staged move (§6.3). G is the current generation from step 1.
+3. **List G** with versions (`ListObjectVersions` under G's prefix). A paged listing that fails fails the wake.
+4. **Plan at the L0 position, then copy.** Let `T` be the highest MaxTXID among G's current L0 files: the position Litestream reads on startup (`db.go:1414`, `replica.go:210`). Compute a restore plan over G's current versions using only files whose MaxTXID is at most `T`, ending exactly at `T`, and include the L0 file ending at `T`. Then `CopyObject` each planned file, by its exact version id, to the same level and name under `g-N/`. Copies run in parallel and are server-side.
+ - Files above `T` (a snapshot or compaction that ran ahead of the uploaded L0, as an unclean release can leave) are not copied. Their transactions are lost, the same loss class as an unclean release today (RHA §5.2).
+ - **Refusals, never a guess:** G holds no L0 file while it is not an empty first generation (step 0); no plan over files at most `T` reaches `T`; a clean marker of G records a TXID above `T` (a file it covers is missing). Each refuses the wake with its reason and raises the suspect-holder page (RHA §20); an operator restores by hand. An empty plan on a host with data is also a refusal, never a fresh boot.
+ - Whatever G sent that is not visible now never enters `g-N` (G3).
+5. **Switch.** Restore locally from `g-N` (the keep rule still applies: a clean marker naming this box, with `T` equal to its TXID and an unchanged local record, keeps the local copy and skips the download). Then write head.json for `g-N` (`predecessor` G, `history` = G prepended, trimmed by §8), `If-Match: E`, with the lease healthy (`Held.Err()` nil).
+ - **412:** head changed since step 1. Only a holder of an older lock generation can have written it, so its own switch was in flight when N took over, and it never served. N abandons: it deletes nothing (its `g-N` objects are unreferenced and §8 removes them), releases through a settled marker (it never replicated) and the wake retries once from the acquire.
+ - Any other failure: a failed wake, released settled.
+6. **Replicate** into the current generation (§5.1) and serve.
+
+A late switch PUT from a holder that lost its lock lands either before N's step 1 (then N copies from that generation: right, its switch was real) or after it (then one of the two conditional writes gets 412). Exactly one switch per ETag.
+
+**Cost per take.** One GET (head), the listing, one `CopyObject` per planned file (typically one snapshot, a few compacted files and some L0; a drain release leaves one snapshot and one L0), one PUT. Copy time is S3-internal and grows with the database (a multipart copy above 5 GB). Storage: §8.
+
+## 5. Writing a generation
+
+### 5.1 The replica client
+
+`Held.Replicate` builds a generation client (the existing `generationClient`, `claimgeneration.go:90`, widened):
+- every request (`WriteLTXFile`, `LTXFiles`, `OpenLTXFile`, `DeleteLTXFiles`) is confined to `<loc>/<generation>/`; a key outside it is refused;
+- every request first checks the lease's health, as `BindGeneration`'s check does.
+
+Because a generation starts with a copy that ends at an L0 file at `T`, Litestream sees what it sees today after a restore: a replica whose L0 position is `T`, matching the restored database. Retention, compaction and the monitors work inside the generation as today, including on the copied files.
+
+### 5.2 Release
+
+Releases are unchanged (RHA §5.2, rev 6.7's markers). Whatever a holder sent late, after any release, lands in its own generation, which the successor has already copied from and no longer reads as current.
+
+### 5.3 The acquire table
+
+With every take in its own generation, `hafresh.DecideAcquire` drops the rev 6.7 row (an unclean marker is taken at once) and N-HA9's expiry clause (a confirmed-terminated owner is taken at once). Same-box recovery still needs the emptiness proof, and no longer waits for expiry. These table changes ship only with the gate (§9), in slice 4.
+
+## 6. Readers
+
+### 6.1 One resolver
+
+`lease.ResolveReplica(ctx, store, loc) (Replica, error)` reads head.json once (absent: `@root`) and returns a read-only Litestream client **bound to that generation's name**, confined to its prefix. One restore uses one resolution for its listings, downloads and retries. A reader whose flow spans requests (the console DB door lists, then downloads, `apidb.go:307/354`) carries the generation name in its handle and refuses, then restarts the read, if a later step would need a different one. Generations are never rewritten by a later holder, so a bound read is consistent even after head moves on. Every reader below switches to it (G4). Inventory (2026-11-12, at 08aed1c1):
+
+| Reader | Today | With generations |
+|---|---|---|
+| Wake restore: `backend_exec.go:1074` `restorePlain`, `hawake.go:553` `restoreHA` → `lease.Restore` (`lease.go:636`) | root levels | §4; a non-HA host keeps today's root restore |
+| Seed placement `seedplace.go:173` `HasReplica` (`check.go:405`) | root levels | resolver; "no replica" only when head is absent and the root is empty |
+| Console DB door `apidb.go:73/171/503`, backups `backups.go:182`, seed copy `apiinstanceseed.go:286`, box db reads `dbreads/read.go:166` | `ReadReplicaClient` at root | resolver |
+| Restore drill `ops/hibernate_verify.go:139/385`, `lease.VerifyReplica` (`check.go:215/248`) | root | resolver |
+| Create leftovers `createleftovers.go:71-99` `hostHoldsReplicaData` | root levels | also refuses on head.json or any `g-*/` (`hacreate.go:29`'s whole-prefix check already does) |
+| First-wake `prefixEmpty` (`ha.go:264`) | whole prefix | unchanged (sees `g-*`: safe refusal) |
+| Legacy moves `movespass.go:1505-1630`; offline stage, seal, land (`movesoffline_*.go`) | whole-prefix mirror; `newestLTX` parses root keys | §6.3 |
+| Promote staged replica `backend_exec.go:4105` (`MirrorPrefix` onto `<loc>`) | exact mirror, deletes extras | §6.3 |
+| Seed deletes `seedfinish.go:271`, `seedwiring.go:243` | delete `<loc>/` | unchanged (whole prefix, lock-checked) |
+| Park sweep `park/sweep.go:227`, `park/remote.go:547` | `instances/<host>/` exact versions | unchanged: whole prefix, so every generation |
+| Claim paths (`apidbclaim.go`, `genselect`, claim moves) | generation-aware | unchanged; share the prefix helper |
+
+### 6.2 Point-in-time reads
+
+`--at T` (#262): if T is at or after the current generation's `created_by.at`, read the current generation. Otherwise walk `history` to the entry whose `created_at` ≤ T < `ended_at` and read that generation alone, with today's CreatedAt rule. Each generation is self-contained (G5), so this needs no other generation. Files a generation's holder wrote after its successor's copy (a late write, or writes lost in an unclean release) are visible to a T inside that holder's tenure, because that is what that holder had at T. Documented as such. A T older than every `history` entry still inside the restore window is refused, as a T before the oldest retained file is today.
+
+### 6.3 Moves
+
+**v1 refuses every move of a generations host** (legacy, offline, staged promotion), with a reason naming this design, before anything is copied (round 3, gen-3.2). Moves need the instance's whole current state, the files manifest and its objects and root-level build state as well as the database, installed authoritatively on the landing side; that is a later slice (§11). Today's moves are unchanged for hosts without head.json, and the claim moves (`moves/source.go:30`) are unaffected.
+
+## 7. Files, wake state and other colocated objects
+
+Files objects are immutable and the manifest moves by compare-and-swap (RHA §8.2), so a late write cannot replace a successor's object. A late manifest CAS can still land between the successor's read and its first publish; the successor's CAS then gets 412 and its publisher errs (containment R1 A). Slice 1 adds one fence at take step 5, before serving: if a manifest exists, the successor rewrites it unchanged with its lock generation in it, `If-Match` the ETag it restored from; if none exists (an empty tree), it creates an empty manifest stamped with its lock generation, `If-None-Match: *`. A late write of the predecessor's then fails its condition. A conflict on the fence fails the wake and retries from the acquire; the publisher continues from the fence's own write as its baseline (`publisher.go:153`). Build state, rootfs and demo markers (`rootfsmarker.go:74`, `buildstate.go:82`, `demo_durability.go:186`) are not part of the wake's history and stay at the root.
+
+## 8. Retention and retirement
+
+The data bucket is versioned; noncurrent versions expire after `data_noncurrent_days` (7, `infra/modules/deployment-buckets`). Nothing here depends on a noncurrent version surviving: each take's copy is made at the take, and every later read uses current versions of a generation's own files (G5).
+
+- **Inside a generation:** Litestream retention as today (snapshot retention, L0 retention), run by the §5.2 scheduler.
+- **History:** a `history` entry stays while its `ended_at` is inside the restore window (7 days, #263). At each switch (§4 step 5) the new head drops the expired entries.
+- **Retirement:** after its switch, the new holder deletes the current objects of generations that left `history`, and of abandoned `g-*` prefixes no head names (a §4 step 5 412), older than one day. Their versions then expire by lifecycle. The park sweep already covers the whole prefix.
+- **Storage:** every take copies one restore plan (about one database's size, compressed). A host's extra storage is about its database size times its takes inside the 7-day window. A 100 MB host that wakes 50 times a day keeps about 35 GB more (about $0.80 a month at S3 Standard); most hosts wake a few times a day. §10 Q3 and §11 name the later reduction.
+
+## 9. Rollout and the old-binary fence
+
+A binary that predates this design reads and writes the root. Once a host has head.json, such a binary would restore stale root data and append to it. Three layers:
+
+- **Gate.** A pool turns generations on only when every box serving it publishes capability `replica-generations-1` (as `offline-move-1`). With the gate on, nothing places on a box without it. The release that adds the capability is the **floor**: no HA box goes below it.
+- **Old binaries still see HA, and refuse.** Today's `HAOn` is true for a lock with `carlos_release`, an owner starting `released/v1;`, or a parsable `;ha=1` owner (`hafresh/lock.go:94`); an HA lock is never taken by the legacy acquire (`legacytake.go:61`). Today's `DecideAcquire` refuses (ReasonBadMarker) an owner starting `released/v1;` with no `carlos_release` record (`acquire.go:89-93`). So a generations host's locks use:
+ - release markers: owner `released/v1;ref=<box>;iid=<iid>;gen=1`, record field `carlos_release_g` (not `carlos_release`). Old HA acquire: bad marker, refused. Old legacy acquire: HA, refused.
+ - held locks: owner `box/v1;ref=…;iid=…;pid=…;ha=1`, unchanged, plus record field `carlos_generation` written into the lock body by the take. An old box's HA acquire would treat it as an ordinary HA lock: it waits for expiry and termination proof, then takes, and would then restore the root. That case is closed by the gate and the floor only, and by slice 0 below.
+- **Slice 0, ahead of everything (rides an early release):** `DecideAcquire` and the legacy take refuse any lock carrying a field they do not know from a fixed list (`carlos_generation`, `carlos_release_g`, and any future `carlos_*`). Every binary at or above the floor then refuses a generations lock outright, held or released. Verify against the oldest binary on any HA box when the gate turns on.
+- **Migration:** no copy job. A host's first take on the new code starts `g-N` from `@root` (§4) and writes head.json. The root files are then retired with §8 (as a `history` entry named `@root`).
+
+## 10. Questions for Paul
+
+**Decided (Paul, 2026-11-15, HA session, relayed by the release manager): all five recommendations taken.** Q1 a server-side copy, not references to pinned versions. Q2 yes, drop N-HA9's expiry wait once this is live and its drills pass (slice 4). Q3 yes, one copy per wake in v1, measured on dev. Q4 yes, the up-front refusals and no moves of generations hosts in v1. Q5 no fourth review round; the slice-1 plan gets the review instead. The questions are kept below as asked.
+
+1. **How does a new generation get its start?** Recommended: a server-side copy of the predecessor's plan at its L0 position (§4 step 4): seconds for typical databases, no upload from the box, nothing refers back to another generation. Rejected: references to pinned versions (rev 1; the bucket's noncurrent expiry could delete one); a full upload from the box before serving (over a minute at 1.6 GB on every wake and failover). Astra agrees (round 2).
+2. **Drop N-HA9's expiry wait once this is live and its drills pass?** Recommended: yes, for confirmed-terminated owners and same-box recovery (§5.3). Astra agrees once the complete fence is verified.
+3. **Accept a copy per wake (§8 storage) for v1?** Recommended: yes, and measure on dev. Reusing a generation after a clean release needs proof that every request the holder sent was answered, which Litestream 0.5.14 cannot give (round 2); that is its own later design.
+4. **Accept the up-front refusals** (§4 step 4: no L0, or no plan reaching it, refuses the wake and pages) **and no moves of generations hosts in v1** (§6.3)? Recommended: yes. The refusals are rare and visible rather than a silent wrong history; moves get their own slice.
+5. **A fourth review round?** The budget is spent; round 3's two P1s are applied with Astra's own remedies (gen-3.1 a create-only fence, gen-3.2 a cut). Recommended: no round now; review the slice-1 plan instead, where these become code.
+
+## 11. Slices (after G6, except slice 0)
+
+0. **Unknown-field refusal** (§9), now: small, inert, rides the next release, so the floor exists when slice 1 needs it.
+1. **Lease core:** head.json, the take (§4) with the start rule, copy and switch, the confined client (§5.1), the bound resolver with wake restore and seed placement (§6.1), the files fence (§7), the gate and lock formats (§9). Behind the gate; dev only.
+2. **Readers:** door, backups, seed copy, db reads, drill, leftovers (§6.1), PITR (§6.2).
+3. **Retirement** (§8), then **moves** of generations hosts: current state only (the generation, the files manifest and objects, root build state), installed by a §4 start on landing; until then refused (§6.3).
+4. **Table change:** drop the rev 6.7 wait and N-HA9's expiry clause (§5.3), with RHA §21's drills rerun and timed.
+
+Later, its own design: reuse a generation after a release proven to have no request outstanding (a Litestream change or wrapper that accounts for every mutation attempt, retries included), to remove the per-wake copy.
+
+## 12. Tests and witnesses
+
+- The late-write witness (`unclean_marker_test.go`) with no wait: B takes at once into a new generation; A's held upload lands afterwards in A's generation; B's restore, PITR and compaction never see it.
+- Crash takeover on termination proof alone, with an upload landing a minute later.
+- Head races: two takes; a late switch PUT before and after the successor's read (§4 step 5); the 412 path leaves no head change and an unreferenced prefix §8 removes.
+- The copy is immune: overwrite a copied source key after step 4, and restore of the new generation is unchanged.
+- The start rule: a predecessor with an L9 above its newest L0 (the L9 is not copied; Litestream continues at `T + 1`); a drain release (one L9 and one L0 at the same TXID); no L0, and no plan reaching `T` (both refused, nothing written, page raised).
+- Old binaries: the oldest live release refuses a `released/v1;…;gen=1` marker without `carlos_release`; a slice-0 binary refuses a held lock with `carlos_generation`. Both the HA and the legacy acquire.
+- PITR across a generation boundary, inside and outside a predecessor's late tail (§6.2).
+- Moves of a generations host are refused before anything is copied (v1).
+- First wake creates an empty generation; a box dying before its first upload leaves a host the next take starts afresh, not a refusal.
+- The files fence with and without a manifest; a predecessor's late first manifest PUT fails its condition.
+- Bound reads: head switches between the door's listing and its download; the download stays on the bound generation or the read restarts, never mixes.
+- Retirement removes only generations outside `history` and abandoned prefixes over a day old.
+- Simulation: model generations; I1 becomes "no late write lands in the current generation", with rules for §4 steps 2 to 5 and §5.2, and a witness for each.
+
+## 13. Review budget
+
+At most three Astra rounds (memory round-limit-anti-spin). Rounds 1 to 3 are spent (rev 4 applies round 3 without a fourth). Further review needs Paul's go. A P1 in round three cuts scope or goes to Paul.