carlos / platform Public

design: storage generations rev 4 (Astra R3 applied, budget spent)

Round 3 resolved every earlier finding. Its two new P1s are applied with
the reviewer's remedies and no fourth round: a create-only files fence for
an absent manifest, and moves of generations hosts refused in v1. The P2:
a first wake creates an empty generation outside the start rule.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 5b3c80c7ad74aef71a736cafef9acda8d38375b6 parent c746bfc
2 files changed, +53 −13
  • docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R3.md +34 −0
  • docs/superpowers/specs/2026-11-12-region-ha-storage-generations-design.md +19 −13

CI passed — run details

Intent

Human

<task-notification> <task-id>bd5p41t02</task-id> <tool-use-id>toolu_01JXdPMqAMfjXNXJfGEVWycj</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/18c2ef37-6ec3-4dcd-8be8-7eed9ce0123f/tasks/bd5p41t02.output</output-file> <status>completed</status> <summary>Background command "Poll the CI rerun" completed (exit code 0)</summary> </task-notification>

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
index 8226ac415..9c150d95d 100644
--- 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
@@ -1,6 +1,6 @@
# Region HA: per-holder storage generations
-Design, 2026-11-12, **rev 3** (Astra rounds 1 and 2 answered; round 3 is the last). 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**.
+Design, 2026-11-12, **rev 4** (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`).
@@ -17,6 +17,11 @@ Sources: the wake-race review (`~/.cache/ha-flakes/wake-race/FINDINGS.md`, Astra
- **(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).
@@ -74,12 +79,14 @@ The claim code uses the same `<location>/g-<gen>/` shape (`BindGeneration`, `cla
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; 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.
+ - **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.
@@ -130,19 +137,15 @@ With every take in its own generation, `hafresh.DecideAcquire` drops the rev 6.7
### 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, or before the instance landed from a move (§6.3), is refused, as a T before the oldest retained file is today.
+`--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
-A move carries the instance's **current state only**:
-- **Source side** (legacy and offline moves): the staging copy (`MirrorPrefix` today) copies `head.json` and the **current generation** only, through the resolver. Seal and report (`movesoffline_seal.go:391/432/488`, `movesreport.go:599`) read positions from the resolved generation instead of parsing root keys.
-- **Landing side:** a §4 start whose predecessor is the staged generation: copy at its L0 position into a new `g-N` named by the landing lock's own counter, write a fresh head.json with an empty `history`. Nothing under the live `<loc>` is deleted or exact-mirrored. `promoteStagedReplica` (`backend_exec.go:4105`) becomes exactly this.
-- **What is not carried:** the source's earlier generations. Point-in-time reads on the landed instance reach back to its landing; earlier ones are refused (§6.2). Today's whole-prefix mirror already rewrites `LastModified`, so a pre-move `--at` is not reliable today either; this makes the boundary explicit. The source's retained prefix stays readable by an operator until §8 retires it.
-- **Claim moves** already copy one generation with a keep function (`moves/source.go:30`); unchanged.
+**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, the successor rewrites the manifest unchanged with its lock generation in it, `If-Match` the ETag it restored from. A late CAS conditioned on that ETag then fails. 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.
+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
@@ -169,14 +172,15 @@ A binary that predates this design reads and writes the root. Once a host has he
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 moves carrying current state only** (§6.3)? Recommended: yes. Both cases are rare, and each refusal is visible rather than a silent wrong history.
+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. **Moves** (§6.3) and retirement (§8).
+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.
@@ -190,11 +194,13 @@ Later, its own design: reuse a generation after a release proven to have no requ
- 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: only the current generation is staged; landing starts a fresh generation with empty history; a pre-landing `--at` is refused; nothing live is deleted.
+- 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). This is rev 3 after round 2; round 3 is the last. A P1 in round three cuts scope or goes to Paul.
+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.