design: storage generations rev 3 (Astra R2: refuse and cut)
Stopping rule 2 for history continuity and relocation: a generation starts exactly at the predecessor's newest L0 TXID or the wake is refused; every take starts a new generation (the drain is cut: 0.5.14 cannot prove request completion); moves carry the current state only; one read binds one generation.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/reviews/ASTRA-FINDINGS-ha-generations-R2.md+30 −0docs/superpowers/specs/2026-11-12-region-ha-storage-generations-design.md+43 −42
CI cancelled — superseded by a newer push — run details
Intent
<task-notification> <task-id>b960j5t1l</task-id> <tool-use-id>toolu_011tA7Si9PKdiUsiLKDnZPLk</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/18c2ef37-6ec3-4dcd-8be8-7eed9ce0123f/tasks/b960j5t1l.output</output-file> <status>completed</status> <summary>Background command "Poll CI on the new tip" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 19.5 g CO₂e (2,257,539 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-ha-generations, 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/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/specs/2026-11-12-region-ha-storage-generations-design.md b/docs/superpowers/specs/2026-11-12-region-ha-storage-generations-design.md| index 5c40181c4..8226ac415 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 2** (Astra round 1 answered; max three rounds). 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 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**. |
| 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`). |
| @@ -9,7 +9,13 @@ Sources: the wake-race review (`~/.cache/ha-flakes/wake-race/FINDINGS.md`, Astra |
| - **(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 starts a generation only when the predecessor did not release cleanly, and makes "clean" mean every replica request was answered (§5.2, Astra option 1). This answers rev 1 §10 Q3 and changes Q1. |
| +- 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). |
| ## 1. The problem, and what this retires |
| @@ -23,7 +29,7 @@ Today time is the only fence: |
| **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 clean now proves every request was answered. |
| +- 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`). |
| @@ -31,10 +37,10 @@ Out of scope: hung but live boxes (still terminated by the group, RHA §9.5); th |
| | ID | Invariant | Enforced by | |
| |---|---|---| |
| -| G1 | **No shared writing.** A holder writes replica objects only into its generation prefix `<loc>/g-<id>/`. It continues an existing generation only after a **drained** clean release (§5.2), when no earlier request can still land. Otherwise it starts a new one. Nothing it does writes, compacts or deletes outside its generation. | The replica client the lease package builds (§5.1); the take decision (§4). | |
| +| 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.** A new generation starts as a server-side copy of exact object versions of its predecessor, taken at the take. A later write anywhere in the predecessor prefix cannot change the copy. | `CopyObject` with a source version id (§4 step 4). | |
| -| G4 | **One reader.** Every reader of an instance's replica resolves it through head.json, by one function. | §6, and a test that no caller builds a replica client at `<loc>` directly. | |
| +| 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 |
| @@ -69,21 +75,20 @@ 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: |
| 1. **Read head.json** with its ETag `E` (absent: the current generation is `@root`; step 5 uses `If-None-Match: *`). |
| -2. **Continue or start.** Continue the current generation G only if the lock the take replaced was a **drained clean** marker naming G (§5.2). Everything else starts a new generation `g-N`: an unclean marker, a clean marker from before the drain existed, a crash or termination takeover, a same-box recovery, `@root` (the migration, §9), a staged move (§6.3). |
| -3. **Continue:** restore from G as today's restore does (the keep rule, RHA §5.3, unchanged), then step 6. head.json is unchanged. |
| -4. **Start:** list G with versions (`ListObjectVersions` under G's prefix; a paged listing that fails fails the wake). Compute Litestream's restore plan over G's **current** versions to the highest contiguous TXID `T`, and add G's newest L0 file at or below `T` (Litestream reads positions from L0 only, `db.go:1414`, `replica.go:210`). 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: no download, no upload from the box. |
| - - A clean marker of G records its TXID. `T` below it means a file the marker covers is missing: refuse the wake (`genselect.ErrPinnedMissing`'s meaning). `T` above it means G wrote more before its marker: those files are G's history and are copied. |
| - - An unclean marker or a crash: `T` is what G managed to store. Anything G sent that is not visible now is lost, as today (RHA §5.2), and never enters `g-N` (G3). |
| - - An empty plan on a host with data is a refusal, never a fresh boot. |
| - - If G holds no L0 at or below `T` (only compacted levels remain), the new generation needs a position file: the take restores locally, then lets Litestream write its baseline into `g-N` before step 5 (its "database behind replica" path). Slice 1 proves which of the two holds for 0.5.14 with witnesses for a snapshot-only, a compacted-only and a drain-snapshot predecessor; a full snapshot upload from the box is the fallback for that case only. |
| -5. **Switch.** Restore locally from `g-N` (the keep rule still applies: a drained clean marker naming this box with 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). |
| +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. |
| + - 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.** Continue (the common case: sleep then wake after a clean release): one GET of head.json more than today. Start: one GET, the listing, one `CopyObject` per planned file (the plan is typically one snapshot, a few compacted files and some L0), one PUT. Copy time is S3-internal; it grows with the database (a multipart copy above 5 GB). |
| +**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 |
| @@ -93,29 +98,21 @@ A late switch PUT from a holder that lost its lock lands either before N's step |
| - 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 started generation holds a copy of the predecessor's plan plus its newest L0, Litestream sees exactly what it sees today after a restore: a replica at `T` with an L0 position. Retention and compaction work inside the generation as today, including on the copied files. |
| - |
| -### 5.2 Clean means drained |
| +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. |
| -A clean release (RHA §5.2) additionally proves that every replica request the holder sent was answered: |
| -- the lease package runs compaction, snapshot and L0-retention passes itself, by calling `Store.CompactDB`, `Store.EnforceSnapshotRetention` and `DB.EnforceL0RetentionByTime` from its own scheduler, with Litestream's monitors off (`CompactionMonitorEnabled = false`, `L0RetentionCheckInterval = 0`, snapshot level driven by the same scheduler). The passes keep today's intervals (`lease.go` `compactionLevels`, `SnapshotInterval`); |
| -- at release, the scheduler stops starting passes and waits, up to a bound (10 s), for the pass in flight to return. Then the final sync, then `Store.Close` (which now has no monitor to cancel); |
| -- a pass that returns an error, a pass still running at the bound, or a final sync that fails makes the release unclean. |
| +### 5.2 Release |
| -The marker records `drained: true` only then. A clean marker without it (a binary before this design) starts a new generation (§4 step 2), so a rollout needs no flag day. |
| +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 Release and the acquire table |
| +### 5.3 The acquire table |
| -- **Drained clean:** the successor continues the generation (fast, as today; the drain's `FinishSnapshot` still leaves one L9 for its restore). |
| -- **Anything else** (unclean, crash, G6's fence, an old clean marker): the successor starts a new generation. Whatever the old holder sent late lands in its own generation, which is no longer current. |
| - |
| -`hafresh.DecideAcquire` then 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. |
| +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 (absent: `@root`) and returns a read-only Litestream client confined to the current generation, plus head's ETag. Every reader below switches to it (G4). Inventory (2026-11-12, at 08aed1c1): |
| +`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 | |
| |---|---|---| |
| @@ -133,13 +130,14 @@ The marker records `drained: true` only then. A clean marker without it (a binar |
| ### 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. |
| +`--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. |
| ### 6.3 Moves |
| -Generations are ordinary prefixes under `<loc>/`, and head.json names them by name only. So: |
| -- **Legacy and offline moves** keep their whole-prefix mirror (`MirrorPrefix`), which copies head.json, every generation and the root. The landing side reads head.json through the resolver. `newestLTX` and `replicaPosition` (`movesoffline_seal.go:391/432/488`, `movesreport.go:599`) read the resolved current generation instead of parsing root keys. |
| -- **Promote staged replica** stops exact-mirroring onto a live `<loc>`. The staged prefix becomes the predecessor of a §4 start: its resolved generation is copied into a new `g-N` under `<loc>` and head.json switches to it, with the staged head's `history` carried over (the copied history generations come along by the same mirror). Nothing under the live `<loc>` is deleted by a move. |
| +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. |
| ## 7. Files, wake state and other colocated objects |
| @@ -153,7 +151,7 @@ The data bucket is versioned; noncurrent versions expire after `data_noncurrent_ |
| - **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:** a new generation copies one restore plan (about one database's size, compressed) and exists only after an unclean release, a crash, a fence or a move, so the steady cost is near zero; it is bounded by those events inside 7 days. |
| +- **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 |
| @@ -168,32 +166,35 @@ A binary that predates this design reads and writes the root. Once a host has he |
| ## 10. Questions for Paul |
| -1. **How does a new generation get its start?** Recommended: a server-side copy of the predecessor's restore plan (§4 step 4): seconds for typical databases, no upload from the box, and nothing ever refers back to another generation. Rejected: references to pinned versions (rev 1), because the bucket's noncurrent expiry could delete a referenced version (gen-1.2); a full snapshot upload from the box before serving, because it adds the upload time (over a minute at 1.6 GB) to every failover. |
| -2. **Drop N-HA9's expiry wait once this is live?** Recommended: yes, for confirmed-terminated owners and same-box recovery (§5.3). The wait exists only because storage had no fence. Hung boxes are unchanged. Astra round 1 agreed. |
| -3. **Continue the generation after a drained clean release?** Recommended: yes (§5.2): sleep and wake, and planned handovers, then cost nothing extra, and the clean exposure is closed by the drain instead of a copy per wake. The alternative, a generation per take, copies the database on every wake. |
| +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. |
| ## 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 copy and switch, the confined client (§5.1), the drained release (§5.2), the resolver with wake restore and seed placement (§6.1), the files fence (§7), the gate and lock formats (§9). Behind the gate; dev only. |
| +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). |
| 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. |
| -- Litestream continues at `T + 1` with no gap after a start from a snapshot-only, a compacted-only and a drain-snapshot predecessor (§4 step 4). |
| -- The drain: a pass in flight at release is waited for; one past the bound makes the release unclean and the next take starts a generation. |
| +- 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: whole-prefix mirror then resolve on landing; promote creates a new generation and deletes nothing live. |
| +- 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. |
| +- 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 2 after round 1. A P1 in round three cuts scope or goes to Paul. |
| +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. |