carlos / platform Public

docs: storage generations as built (spec rev 5, plan, runbook)

Spec: a rev 5 note listing the decisions taken during the build, and
corrections to section 4 (refusal reasons, take bound, ops recovery,
keep rule), 5.3 (fast), 6.1 (409), 6.2 (late tail not visible),
6.3 (#1253), 8 (store time, grace, abandoned prefixes) and 9
(carlos_min_txid, generations_floor at v0.39.0).

Plan: Task 14 from its brief, and an "As built" section with Tasks
11b and 11c, the 8a3d302 decisions and the follow-up list.

Runbook: the approved storage generations section, with additions
for a copy pass: two more refusal reasons, an L0 gloss, a link for
proven termination, the carlos ops ha-generations procedure, the
head_missing and lock_not_generations cases, #1253, and the fast
note in the 15-minute wait section.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev d6353c43b79306f3483a3cd336c685407cc62bb0 parent 1ab3b73
3 files changed, +138 −15
  • docs/region-ha-runbook.md +42 −1
  • docs/superpowers/plans/2026-11-17-region-ha-storage-generations.md +69 −0
  • docs/superpowers/specs/2026-11-12-region-ha-storage-generations-design.md +27 −14
diff --git a/docs/region-ha-runbook.md b/docs/region-ha-runbook.md
index b36721505..6e67a8995 100644
--- a/docs/region-ha-runbook.md
+++ b/docs/region-ha-runbook.md
@@ -325,12 +325,53 @@ If the box role itself must read it, widen `ssm_parameter_arn` to include that o
When a box lets a host go without a clean release, after the host's database had started replicating, no box can wake the host again until 15 minutes after that release. Requests to the host get 503 with a `Retry-After` that counts down to that time.
+On a group with storage generations set to `fast`, a host with storage generations does not wait. See [Storage generations](#storage-generations).
+
This happens when the release's final sync fails or times out, when the write fence stops an instance during a storage outage, or when the upload of the host's files fails or runs out of time. The wait gives any upload the old box still had in flight time to land before another box starts writing the same data.
-The host's lock reads `released/v1;…`, its `carlos_release` has `"clean": false` and neither `"settled": true` nor `"finalized": true`, and the journal of the box trying to wake it says `LEASE HELD` by that `released/v1` owner.
+The host's lock reads `released/v1;…`, its `carlos_release` (`carlos_release_g` on a host with storage generations) has `"clean": false` and neither `"settled": true` nor `"finalized": true`, and the journal of the box trying to wake it says `LEASE HELD` by that `released/v1` owner.
Nothing: the host wakes on the next request after the 15 minutes. Do not edit or delete the lock to hurry it, because that is exactly the race the wait prevents. If a host waits like this after every sleep, its release keeps failing at the same step. The old box's journal has the release error, starting `files:` or `final sync:`, which says which step failed and why.
+## Storage generations
+
+A holder is the box currently serving the host. A host with storage generations keeps each holder's copy of its database in its own folder, `instances/<host>/g-<number>/`. The file `instances/<host>/head.json` names the folder in use. A late upload from a box that lost the host stays in that box's folder and is not read.
+
+### Switching it on
+
+Set `CARLOS_HA_GENERATIONS` in the group's host.env, one group at a time:
+
+- `on`: Each wake copies the previous holder's data into a new folder before serving the host. Existing waits stay as they are.
+- `fast`: The same, and a host whose holder released uncleanly or was terminated wakes as soon as [the termination is proven](superpowers/specs/2026-10-26-region-ha-without-claims-design.md#92-confirmation) instead of waiting 15 minutes.
+
+Turn on `on` first and run the drills before `fast`. Never turn it off once a host has `head.json`. Those hosts keep using generations whatever the setting says.
+
+### The floor: nothing below v0.39.0
+
+Before switching a group on, set its `generations_floor` to v0.39.0. The group roll refuses any member below that release and any member that does not report `replica-generations-1`. A box older than v0.39.0 would read a generations host's lock as an ordinary lock and serve stale data. Do not lower or remove the floor while any host in the group has `head.json`.
+
+### A wake refused with ha_generation_refused
+
+The box refused to start the host because the previous holder's data does not reach the last safe point recorded for its release. The journal line names the reason: `no_l0`, `no_plan_to_l0`, `clean_marker_above_l0`, `empty_plan_with_data`, `file_over_5gib`, `head_missing` or `lock_not_generations`. L0 is the newest level of the host's database copy, where each uploaded change lands first. The host stays down and pages once an hour. Do not edit `head.json` or the lock to get past it.
+
+To restore the host, choose a folder to restart it from and point the host at it with `carlos ops ha-generations`. Run each step on a box as the carlos user.
+
+1. List the host's folders with `carlos ops ha-generations list <host>`. It shows the folder `head.json` names, the folders in its history, each folder's newest L0 transaction and the lock. Choose the folder `head.json` names or one marked `(in history)`. Point refuses any other folder.
+2. Check that folder with `carlos ops ha-generations verify <host> --gen <g-N>`. It restores the folder into a temporary file, checks it and removes the file.
+3. Do a dry run with `carlos ops ha-generations point <host> --gen <g-N> --accept-loss-after <txid>`, where `<txid>` is the folder's newest L0 transaction from `list`. It writes nothing. It prints the two files it would write and one sentence that says what is lost. Read that sentence.
+4. Run the same command again with `--yes`. Point keeps the host's data up to `<txid>` and permanently gives up every transaction after it. It writes `head.json`, then the lock. If it says that `head.json` was written and the lock was not, run `list` again, then point again.
+5. Wake the host by sending it a request.
+
+A host refused with `head_missing` has no `head.json`, and `carlos ops` has no recovery for it yet: point refuses it. A host refused with `lock_not_generations` was woken by a box with storage generations off, and point does not fix it. Set `CARLOS_HA_GENERATIONS` to `on` or `fast` in that group's host.env.
+
+### Old folders and the clock
+
+After each wake, the box deletes folders older than the 7-day restore window plus an hour. It also deletes folders that no `head.json` ever named once they are a day old. Age comes from the storage service's own clock, never the box's. A box with a wrong clock therefore cannot delete data still inside the window. If a storage response carries no time, the box keeps everything and logs `ha_generation_retire_failed`.
+
+### Moves
+
+Moves of a host with `head.json` are refused for now, before anything is copied. The follow-up is discussion #1253.
+
## Install chrony on a fixed box
Before G3 step 4 on the G3 card, install chrony on each named fixed box during an attended maintenance window. Use the reviewed `scripts/region-ha-g3/chrony-fixed-box.sh` through SSM as root, with approval for the named box. Group boxes already configure Amazon Time Sync at first boot.
diff --git a/docs/superpowers/plans/2026-11-17-region-ha-storage-generations.md b/docs/superpowers/plans/2026-11-17-region-ha-storage-generations.md
index c89f7d06e..f64345724 100644
--- a/docs/superpowers/plans/2026-11-17-region-ha-storage-generations.md
+++ b/docs/superpowers/plans/2026-11-17-region-ha-storage-generations.md
@@ -351,6 +351,50 @@ Rules: `ListDirs(<loc>/)`; for each `g-<M>/`: keep if it is the current generati
- [ ] **Step 3: Implement.** **Step 4: Run** → PASS, plus `go test ./internal/grouproll/ -count=1`.
- [ ] **Step 5: Commit** `grouproll: an enforced generations floor`.
+## Task 14: `carlos ops ha-generations` (list, verify, point): the by-hand restore
+
+Approved by 8a3d302 for Paul on 2026-11-19. It is the one operator path that accepts data loss.
+
+**Why:** a refused wake (`ha_generation_refused`, reasons `no_l0`, `no_plan_to_l0`, `clean_marker_above_l0`, `empty_plan_with_data`, `file_over_5gib`, `head_missing`, `lock_not_generations`) leaves the host down, and the page says an operator restores it by hand. No tool does that today. `carlos ops` help says to extend ops rather than hand-run sequences (internal/ops/ops.go ~94).
+
+**Files:**
+- Create: `internal/ops/hagenerations.go`, `internal/ops/hagenerations_test.go`
+- Modify: `internal/ops/ops.go` (register the verb and its help)
+- Modify: `internal/lease/` only for small exported helpers the verb needs. Candidates: listing a host's generations with their newest L0 TXID, or a point operation that does the two conditional writes. Prefer one lease function that owns all head and lock writes over raw writes from ops.
+
+**Verb (runs on a box, as the same user `ops hibernate-verify` runs as; refuse root like it does, ops.go ~430):**
+- `carlos ops ha-generations list <host>` is read-only.
+ - It prints head.json's current generation, its `start_txid` and `created_by`, and each history entry with its `created_at`/`ended_at`.
+ - It prints every `g-*` prefix under the host's location, with its newest L0 TXID and whether head names it.
+ - It prints the lock's state: held by whom, or released, plus the marker's clean flag, TXID and bound (TakeBound).
+- `carlos ops ha-generations verify <host> --gen g-<N>` is read-only.
+ - It restores that generation into a temp file through `lease.BindReplica` and runs the integrity check (`lease.CheckDB` / `VerifyClientAt`).
+ - It prints the restored TXID and the result, then removes the temp file.
+- `carlos ops ha-generations point <host> --gen g-<N> --accept-loss-after <txid> [--yes]` is a dry run unless `--yes`.
+ - **Refusals:**
+ - The lock is held by any box and not expired.
+ - g-N does not exist, or its newest L0 TXID differs from `<txid>`.
+ - g-N fails verify; point runs the same check first.
+ - `<txid>` is above the generation's newest L0.
+ - head.json or the lock changed between read and write (412).
+ - **Writes, with `--yes` only, both conditional:**
+ - head.json (If-Match) is rewritten so it names g-N. The previous head becomes a history entry, and times come from the store clock like the take's.
+ - The lock's released marker (If-Match on the lock) is rewritten so its take bound (TXID of a clean marker, `min_txid`, and any held-lock `carlos_min_txid`) is at most `<txid>`. Everything else stays: the generations format, `carlos_release_g`, and the owner.
+ - **Without `--yes`:** it prints exactly the two documents it would write and one plain sentence naming the loss. The draft sentence is: "Pointing <host> at g-<N> keeps its data up to transaction <txid> and permanently gives up every transaction after it (the old head reached <T_old>; the marker recorded <bound>)." That sentence goes through a Luna pass.
+ - It always prints what it changed, or would change.
+- Request budget: per invocation only, with no polling.
+
+**Tests (TDD):**
+- list and verify against the leasetest fake S3 with two generations and a history.
+- A point dry run writes nothing; assert the mutation request count is zero and the output is exact.
+- `point --yes` rewrites head and the marker, and the next take on that host then succeeds from g-N. This is an end-to-end witness through `StartGeneration`.
+- Refusals: lock held and live, txid mismatch, verify failure, a 412 on either write. Each one writes nothing.
+- Refuses root.
+
+**Environment:** the plan's Global Constraints apply.
+
+**Review:** Astra and Fable, both. The census runs at Task 12.
+
## Task 12: Whole-branch review, census, CI, merge
- [ ] Astra and Fable whole-branch review from `REVIEW-BRIEF-TEMPLATE.md` (round budget three, stopping rules apply); findings committed under `docs/superpowers/reviews/`.
@@ -362,3 +406,28 @@ Rules: `ListDirs(<loc>/)`; for each `g-<M>/`: keep if it is the current generati
## Switch-on (not this branch's to run)
Who asks: Paul (#421, generations approved 2026-11-15). What a user gets: an HA host recovers from a crash or an unclean release in 1 to 5 minutes, not 15, with no silent history divergence. When: dev the first window after the release that carries Task 12, flagship after the dev drills pass. The release manager (8a3d302) owns releases, the group env, and every drill window.
+
+## As built (2026-11-19)
+
+The ledger is `.superpowers/sdd/2026-11-17-region-ha-storage-generations/progress.md`; spec rev 5 records the same decisions.
+
+**Tasks added during the build:**
+- **Task 11b, the held lock carries the take bound** (1deae8f8, 060d13ac). The model found that a crash in the middle of a take dropped the `min_txid` bound. A held generations lock now carries `carlos_min_txid`, the higher of the marker's bound and its own, written by every CAS round, kept by renewals and dropped by the switch. A null or non-integer value makes the lock malformed. Slice-0 binaries refuse the field as unknown.
+- **Task 11c, retirement reads only store time** (a4690552). head.json's times and the history trim come from the holder's store clock (the Date of its latest lock write plus monotonic elapsed time); retirement's "now" is the switch PUT's own Date; a switch with no Date retires nothing, and a take with no store time fails its switch.
+- **Task 14** above (003e44ec, d64da458, 1ab3b731). As built, point accepts only head.json's generation or one in its history (an abandoned prefix is cut), sets the take bound exactly to `<txid>`, writes head.json before lock.json, and refuses a host with no head.json.
+
+**Decisions by 8a3d302 for Paul:**
+- Ruling A: `generations_floor` is enforced in the group roll and refuses outright (`floor_generations`), never DR-4 (Task 13).
+- Ruling B: an unbound console door read of a head.json host gets a 409 carrying the generation to bind (Task 8).
+- The floor is the slice-0 release, v0.39.0 (tag e1974e6c at 8c861346), not `ha_floor` at this branch's release as Task 12's switch-on order said.
+- The clock family: every retirement time is store time (option 1); the clock-skew check was cut before that.
+- Task 14 approved on conditions: point is a dry run unless `--yes`; Astra and Fable both review it; the dev drill exercises list, verify and point on a deliberately refused host (owed at switch-on); its CLI text goes through a copy pass.
+
+**Follow-ups (for the branch description):**
+- Retirement deletes one key at a time (no DeleteObjects).
+- Old CLI root-layout door reads cost one head GET per request until CLIs update.
+- Duty/always-on and due wakes still wait out the lease under `fast`; live-holder proof requests cost to measure on dev.
+- Moves of generations hosts: #1253.
+- No ops recovery for `head_missing` (point refuses no-head hosts).
+- The sweep never reaches the take-side switch 412 (witness only); the retirement guards are caught only together.
+- The replication-failure activator test skips as root.
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 1806bdb0b..1a86b7ec9 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 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**.
+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`. Built on branch `ha-generations` (plan `docs/superpowers/plans/2026-11-17-region-ha-storage-generations.md`); **rev 5** records what the build decided, and the sections below are corrected to match. 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`).
@@ -22,6 +22,18 @@ Sources: the wake-race review (`~/.cache/ha-flakes/wake-race/FINDINGS.md`, Astra
- **(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).
+**Rev 5 (as built, 2026-11-19)** records the decisions taken during the build (ledger `.superpowers/sdd/2026-11-17-region-ha-storage-generations/progress.md`), one line each, with who decided:
+- **Rulings A and B** (8a3d302 for Paul, 2026-11-17): A, the floor is an enforced `generations_floor` in the group roll that refuses outright, never DR-4 (§9); B, an unbound console door read of a host with head.json gets a 409 (§6.1).
+- **Slice 0 is the floor:** v0.39.0 (8a3d302, confirmed 2026-11-18) (§9).
+- **Point-in-time reads keep S3 LastModified as the CreatedAt rule**, so an earlier holder's late tail is not visible to a T inside its tenure; the §6.2 sentence that said otherwise is corrected (build ruling, reported to 8a3d302).
+- **The take bound survives refusals and crashes:** a release marker written before a switch carries `min_txid`, and a held generations lock carries `carlos_min_txid` until its switch (build rulings, Tasks 5 and 11b) (§4, §9).
+- **Retirement measures every age in store time, never the box clock** (8a3d302 for Paul, option 1 of the clock family): head.json times come from the store Date of the holder's latest lock write plus monotonic elapsed time; retirement's "now" is the switch PUT's own Date; no Date means no retirement. It replaced a clock-skew guard after the stopping rule (§8).
+- **Retirement waits the 7-day window plus a 1-hour grace** before a history entry leaves (build ruling, Task 9) (§8).
+- **`carlos ops ha-generations list|verify|point` is the operator recovery** for a refused wake (8a3d302 for Paul, Task 14). Point is a dry run unless `--yes`, targets only head.json's generation or one in its history, and sets the take bound exactly to the chosen TXID (§4).
+- **The keep rule applies only when head.json names the marker holder's generation** (build ruling, Task 14 R1) (§4 step 5).
+- **Moves of a generations host stay refused**; the follow-up is discussion #1253 (§6.3).
+- **The switch value `fast` gates §5.3**; `on` takes generations with today's acquire table (build plan, Task 10) (§5.3).
+
## 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).
@@ -86,9 +98,9 @@ The HA acquire is unchanged up to its conditional take of `lock.json` (RHA §9.4
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.
+ - **Refusals, never a guess:** G holds no L0 file while it is not an empty first generation (step 0) (`no_l0`); no plan over files at most `T` reaches `T` (`no_plan_to_l0`); the take bound is above `T` (`clean_marker_above_l0`: a file it covers is missing). The take bound is the highest of a clean marker's TXID, a marker's `min_txid` and the held lock's `carlos_min_txid` (§9), so a take that was refused or crashed before its switch passes its bound to the next one. An empty plan on a host with data is also a refusal, never a fresh boot (`empty_plan_with_data`); so is a planned file over the single-part copy limit (`file_over_5gib`), and a host with no head.json and no root LTX file but `g-*` prefixes under `<loc>/` (`head_missing`). Each refuses the wake with its reason (`ha_generation_refused reason=…`) and raises a page that repeats hourly while wakes are refused. An operator restores the host with `carlos ops ha-generations` (rev 5): `list` and `verify` read; `point --gen g-<M> --accept-loss-after <txid>` is a dry run unless `--yes`, accepts only head.json's generation or one in its `history`, and rewrites head.json to name it and the lock's take bound to exactly `<txid>`, that generation's newest L0 TXID, both by `If-Match`. A `head_missing` host has no such recovery yet (point needs head.json).
- 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).
+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, and only when head.json names the marker holder's generation, so a host an operator pointed elsewhere always restores). 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.
@@ -113,13 +125,13 @@ Releases are unchanged (RHA §5.2, rev 6.7's markers). Whatever a holder sent la
### 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.
+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, and apply only where the switch is `fast` (rev 5); `on` takes generations with today's table.
## 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):
+`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. A door read that names no generation, of a host with head.json, gets a 409 carrying the generation to bind (ruling B, rev 5): a current CLI binds it and reads again, an older CLI prints the message. 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 |
|---|---|---|
@@ -137,11 +149,11 @@ 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 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. That rule dates a file by its S3 LastModified, and a file a generation's holder wrote after its successor's copy (a late write, or writes lost in an unclean release) is modified after the switch, so a T inside that holder's tenure does not see it (rev 5). Today's root layout excludes a lagging upload the same way, and reading each file's own metadata instead would cost a header GET per file per read. The cost: a point-in-time read in the seconds before an unclean handover misses the old holder's unconfirmed tail, as today. head.json's times are store time (§8). 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.
+**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), discussion #1253. 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
@@ -152,19 +164,20 @@ Files objects are immutable and the manifest moves by compare-and-swap (RHA §8.
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.
+- **History:** a `history` entry stays while its `ended_at` is inside the restore window (7 days, #263) plus a one-hour grace. At each switch (§4 step 5) the new head drops the entries past that. The hour covers a point-in-time read that resolved an entry just before the switch that drops it.
+- **Retirement:** after its switch, in the background once it replicates, the new holder deletes the current objects of the generations its switch dropped from `history`, of the root layout's LTX files once `@root` has left `history`, and of abandoned `g-*` prefixes no head names (a §4 step 5 412, or a pass an earlier holder did not finish) whose every current object is over a day old. It never touches a generation at or above its own lock generation, head's generation, its predecessor or any `history` entry. Deletes are by bare key, so their versions then expire by lifecycle. It checks the lease before each generation; a failure is logged (`ha_generation_retire_failed`), never fails the wake, and the next take retries. The park sweep already covers the whole prefix.
+- **Store time only (rev 5):** every age retirement compares is the storage service's time, never the box's clock. head.json's `created_by.at`, `created_at` and `ended_at`, and the trim, come from the holder's store clock: the Date header of its latest lock write (the acquire's, then each renewal's) plus the monotonic time elapsed since. Retirement's "now" is the Date of the switch's own head.json PUT, and the abandoned cutoff compares objects' LastModified with it. A switch whose PUT carried no Date does no retirement (`reason=no_store_time`); a take with no store time at all fails its switch and writes nothing. This replaced a clock-skew guard (8a3d302 for Paul).
+- **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 (plus the grace hour, and abandoned prefixes for a day). 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.
+- **Gate.** Every box at this design's release publishes capability `replica-generations-1` (as `offline-move-1`), whatever its switch says. A group turns generations on by the box switch `CARLOS_HA_GENERATIONS` in its host.env (`on`, then `fast`, §5.3), only after its `generations_floor` is set. The **floor** is the slice-0 release, **v0.39.0**: the first release that refuses a generations lock (rev 5). The group roll enforces it outright (ruling A): a roll or replacement to a release below it, any present edges file whose capabilities lack `replica-generations-1`, or a `generations_floor` without the `ha_floor`, `data_bucket` and `data_prefix` it is read with, refuses with `floor_generations`, never DR-4. The floor is never lowered or removed while a host in the group has head.json.
- **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.
+ - release markers: owner `released/v1;ref=<box>;iid=<iid>;gen=1`, record field `carlos_release_g` (not `carlos_release`). A marker released before its holder's switch carries `min_txid`, the take bound that holder was given, so a refused or failed take passes its bound on (rev 5). Old HA acquire: bad marker, refused. Old legacy acquire: HA, refused.
+ - held locks: owner `box/v1;ref=…;iid=…;pid=…;ha=1`, unchanged, plus record fields written into the lock body by the take: `carlos_generation` (the holder's generation), and `carlos_min_txid`, the take bound (the higher of the marker's bound and the held lock's own). Every CAS round of the take writes `carlos_min_txid` and renewals keep it until the switch, which drops it, so a crash between the take and the switch keeps the bound (rev 5, Task 11b). A present `carlos_min_txid` that is not a non-negative integer makes the lock malformed, never unbounded. An old box's HA acquire would treat such a lock 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 (shipped in v0.39.0, the floor):** `DecideAcquire` and the legacy take refuse any lock carrying a field they do not know from a fixed list (`carlos_generation`, `carlos_release_g`, `carlos_min_txid` 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