carlos / platform Public

member backups: plans rev 3, group drill assignment source (#898)

Slice 2a: the agent writes a per-host drill assignment from the same
DutySnapshot view and HRW the HA duties use; dutyHRW stays as a wrapper;
every publish merges into the run-start record. Slice 1: exact key sets
per response class. Briefs for Astra plan round 3 and Fable.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev ee211a5f0e2f824508840170db1aaa425720b422 parent fe0e106
5 files changed, +110 −12
  • docs/superpowers/notes/reviews/member-backups/CODEX-FINDINGS-member-backups-plans-R2.md +40 −0
  • docs/superpowers/notes/reviews/member-backups/CODEX-REVIEW-BRIEF-member-backups-plans-R3.md +13 −0
  • docs/superpowers/notes/reviews/member-backups/FABLE-GUIDANCE-BRIEF-group-assignment.md +40 −0
  • docs/superpowers/plans/2026-11-11-member-backups-slice1.md +2 −2
  • docs/superpowers/plans/2026-11-11-member-backups-slice2a.md +15 −10

CI cancelled — superseded by a newer push — run details

Intent

Human

<task-notification> <task-id>bj8rf0mwh</task-id> <tool-use-id>toolu_01DuZVoEtqU4eacM4kHFquoG</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ab362fc0-f177-4a7f-a92e-4a29ea210aad/tasks/bj8rf0mwh.output</output-file> <status>completed</status> <summary>Background command "Run Astra plan review round 2" completed (exit code 0)</summary> </task-notification>

Human

Have Fable 5.2 weigh in too on that.

Attributed to this commit: 25.1 g CO₂e (2,894,599 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-member-backups, 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/notes/reviews/member-backups/CODEX-FINDINGS-member-backups-plans-R2.md b/docs/superpowers/notes/reviews/member-backups/CODEX-FINDINGS-member-backups-plans-R2.md
new file mode 100644
index 000000000..0061e3478
--- /dev/null
+++ b/docs/superpowers/notes/reviews/member-backups/CODEX-FINDINGS-member-backups-plans-R2.md
@@ -0,0 +1,40 @@
+| R1 finding | Disposition | Evidence in rev 2 |
+|---|---|---|
+| 1 — Function signatures | **FIXED** | Slice 1:58 supplies the logger; :153 separates the CLI adapter from the testable runner. |
+| 2 — Authorization expectations | **FIXED** | Slice 1:116 distinguishes middleware 403s from scope-related 404s. |
+| 3 — Parity and CLI documentation | **FIXED** | Slice 1:149 adds the handwritten parity row and CLI documentation before regeneration. |
+| 4 — API path | **FIXED** | Slice 1:155–157 adds the leading slash and an exact-path test. |
+| 5 — Shared restore boundary | **FIXED** | Slice 1:53–69 includes CLI restore and shares both boundary rules across all three callers. |
+| 6 — Shared intrinsic classification | **FIXED** | Slice 1:81–93 explicitly refactors both existing callers and tests their preserved behavior. |
+| 7 — Duplicate replica listing | **FIXED** | Slice 1:58–69 specifies one cached listing snapshot, listing-count tests and both file-cap boundaries. |
+| 8 — Census claims input | **FIXED** | Slice 1:163 creates the CLAIMS file and supplies it to `census-propose`. |
+| 9 — Group-box assignment | **PARTLY** | HRW selection and tests are added, but the proposed roster source is host-specific and demand-driven. Details below. |
+| 10 — Active-drill deadline | **FIXED** | Slice 2a:22, :85 and :127–136 propagate cancellation, use `CheckDBContext`, and test cleanup and separately bounded publication. |
+| 11 — Closing identity check | **FIXED** | Slice 2a:21 and :127–133 require confirmation for replica-derived failures and test identity changes during planning and download. |
+| 12 — Last-decided age | **FIXED** | Slice 2a:100–107 adds `LastDecidedAt`, preserves it through unverified attempts and resets it on identity changes. |
+| 13 — Empty contribution | **FIXED** | Slice 2a:129 and :138 explicitly clear the prior bucket record and local alert copy. |
+| 14 — Live lease proof | **FIXED** | Slice 2a:19 and :127–134 require a successful, held, parseable self-owned lock and test the refusal cases. |
+
+Reviewed `fe0e10645f81372f1e9081a5def330eaa95e3751` on `design-member-backups`. Static review only; no tests run or files changed. The existing `go.mod` modification was excluded.
+
+For **R1-9**, [Task 2](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/docs/superpowers/plans/2026-11-11-member-backups-slice2a.md:69) calls `haduties.go:233–242` a roster refresh. It is inside [`dutyInput`](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/activator/haduties.go:199), which returns before that lookup for non-HA routes. The resulting [`DutySnapshot`](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/edge/wakeplacement.go:201) is explicitly per-host: serving candidates are filtered by pool, host advertisement, account and app at lines 177–191. Writing whichever lookup ran last into one `Self.Serving` does not establish `serving(region)`. Quiet boxes can also lack a recent timestamp despite healthy membership. The test at slice 2a:137 supplies a shared roster directly, bypassing this production wiring.
+
+**Repeated family: complete, deterministic group assignment.** Before another fix attempt, choose the repository’s prescribed cut: refuse unsupported group cases with an operator report; defer group drilling; or establish one authoritative assignment source and test it through the producer and drill. I recommend the third option using existing roster evidence, including quiet boxes and differing host advertisements.
+
+15. **P1 — Slice 2a, Task 2: moving `dutyHRW` leaves test references unresolved.**
+ **Invariant:** the HRW extraction must preserve buildable callers.
+ [Task 2](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/docs/superpowers/plans/2026-11-11-member-backups-slice2a.md:69) moves the function to `boxchoice` without covering two existing consumers. [`haduties_test.go:122`](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/activator/haduties_test.go:122) calls the private function directly. More subtly, [`hadrain_twobox_minio_linux_test.go:85`](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/host/hadrain_twobox_minio_linux_test.go:85) uses `go:linkname` to that exact activator symbol, called at line 518. Removing it breaks test compilation/linking, including the host package checked by Task 2.
+ **Fix:** retain `dutyHRW` as a thin wrapper around `boxchoice.HRW`, or explicitly migrate both test consumers to the exported function and remove the obsolete linkname declaration.
+
+16. **P2 — Slice 2a, Tasks 4–5: repeated publication needs a once-per-run streak contract.**
+ **Invariant:** three unverified runs means three runs, regardless of publication count.
+ [`Merge`’s contract](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/docs/superpowers/plans/2026-11-11-member-backups-slice2a.md:102) increments `UnverifiedRuns` from the supplied prior record. [Task 5](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/docs/superpowers/plans/2026-11-11-member-backups-slice2a.md:139) repeatedly publishes cumulative results, but does not specify whether each merge uses the run-start record or the last publication. The latter counts the same attempt repeatedly and can trigger the three-night alert during one night. Separate merge and callback-count tests do not catch that integration error.
+ **Fix:** require every cumulative merge within a run to use the immutable run-start baseline. Test one unverified host across several periodic publications and the final publication: its streak advances exactly once.
+
+17. **P2 — Slice 1, Tasks 2–3: the exact-key test contradicts the response schema.**
+ **Invariant:** the contents-free response has one explicit, testable schema.
+ [Task 2](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/docs/superpowers/plans/2026-11-11-member-backups-slice1.md:86) requires the `files` field. [Task 3’s member test](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/docs/superpowers/plans/2026-11-11-member-backups-slice1.md:115) names only `class`, `copied_to` and `history_from`, then requires no other keys. A conforming replicated response therefore fails the stated test.
+ **Fix:** enumerate the complete allowed key set per response class, including `files`, with explicit omission rules for optional fields. Keep the exact-key assertion.
+
+Slice 1 — **READY AFTER FIXES**
+Slice 2a — **NOT READY**
\ No newline at end of file
diff --git a/docs/superpowers/notes/reviews/member-backups/CODEX-REVIEW-BRIEF-member-backups-plans-R3.md b/docs/superpowers/notes/reviews/member-backups/CODEX-REVIEW-BRIEF-member-backups-plans-R3.md
new file mode 100644
index 000000000..08bf7e8bc
--- /dev/null
+++ b/docs/superpowers/notes/reviews/member-backups/CODEX-REVIEW-BRIEF-member-backups-plans-R3.md
@@ -0,0 +1,13 @@
+# Plan review brief, round 3: member backups slices 1 and 2a
+
+Same plans, now rev 3 (slice 2a) and rev 3 (slice 1). Round 1 and 2 findings:
+`CODEX-FINDINGS-member-backups-plans.md` and `-plans-R2.md` in this directory. For the group-assignment family Paul chose to build the authoritative source now (slice 2a Task 2). The original
+brief, `CODEX-REVIEW-BRIEF-member-backups-plans.md`, still applies.
+
+1. First a disposition table: for each finding not FIXED in round 2 (R1-9, 15, 16, 17), FIXED,
+ PARTLY (say what is missing) or NOT FIXED. The plans mark their fixes
+ (P-N).
+2. Then only NEW findings in rev 3, same format. Verify every citation.
+ Prefer cuts and refusals over new mechanism.
+3. End with one line per plan: READY, READY AFTER FIXES, or NOT READY.
+ Round 3, the last. Do not spawn other models or reviewers.
diff --git a/docs/superpowers/notes/reviews/member-backups/FABLE-GUIDANCE-BRIEF-group-assignment.md b/docs/superpowers/notes/reviews/member-backups/FABLE-GUIDANCE-BRIEF-group-assignment.md
new file mode 100644
index 000000000..f59105414
--- /dev/null
+++ b/docs/superpowers/notes/reviews/member-backups/FABLE-GUIDANCE-BRIEF-group-assignment.md
@@ -0,0 +1,40 @@
+# Guidance brief for Fable: who drills which instance on group boxes
+
+Context: slice 2a of `docs/superpowers/specs/2026-11-11-member-backups-design.md`
+arms a nightly restore drill on every box. On group (region HA) boxes every
+box adopts every host of the region, so exactly one box must test each
+host. Plan: `docs/superpowers/plans/2026-11-11-member-backups-slice2a.md`
+rev 3, Task 2 and Task 5 (marked P2-9). Astra's round 2 finding that
+forced this is R1-9 in
+`docs/superpowers/notes/reviews/member-backups/CODEX-FINDINGS-member-backups-plans-R2.md`.
+Paul chose to build an authoritative assignment source now rather than
+defer group boxes.
+
+The design in rev 3: the agent, every 5 minutes, runs the same per-host
+view function it gives the HA duties (`internal/host/agent.go:1267`,
+`Edge.DutySnapshot` / `SidecarDutySnapshot`, `internal/edge/wakeplacement.go`)
+over every HA route, takes `boxchoice.HRW(host, Serving refs)` (today's
+`dutyHRW`, `internal/activator/haduties.go:401`), and writes the result to
+`<data>/monitor/verify-assign.json`. The nightly oneshot drills only hosts
+assigned to its own ref; stale, missing or unusable assignments become
+`not_reached`/`no_assignment`, which the 7-day coverage alert eventually
+surfaces.
+
+Questions:
+1. Is this sound? Will boxes in one region compute the same winner for a
+ host from their own edges snapshots, and what happens when they
+ disagree briefly (a host drilled twice, or by none, for a night)? Is
+ that acceptable, or does it need more?
+2. Is reusing the HA duty's evidence and HRW the right call, or is there a
+ simpler, more authoritative source already in the repo (verify in the
+ code)? Could it be simpler still, e.g. the box holding the host's
+ lease or last release marker drills it?
+3. Failure modes we are missing: draining boxes, a box joining or leaving,
+ sidecars, hosts only some boxes advertise, a quiet region, clock skew.
+4. Is the end-to-end test in Task 2 (edges-file fixture through
+ `computeAssignment` to the drill) the right proof?
+
+Verify claims against the code (file:line). Under 700 words: a verdict
+(SOUND, SOUND WITH CHANGES, or RETHINK), then numbered recommendations,
+most important first. Read-only: change no files. Do not spawn other
+models.
diff --git a/docs/superpowers/plans/2026-11-11-member-backups-slice1.md b/docs/superpowers/plans/2026-11-11-member-backups-slice1.md
index df48e4aa5..99e940154 100644
--- a/docs/superpowers/plans/2026-11-11-member-backups-slice1.md
+++ b/docs/superpowers/plans/2026-11-11-member-backups-slice1.md
@@ -4,7 +4,7 @@
**Goal:** Owners, members and release automation can read, for one instance, the last change saved to its copy, how far back history reaches, and what isn't copied, through a console door, a section on the instance page and `carlos instances backups`.
-**Plan rev 2** (2026-11-11): Astra plan round 1 (`docs/superpowers/notes/reviews/member-backups/CODEX-FINDINGS-member-backups-plans.md`, NOT READY) fully applied; findings marked **(P-N)**.
+**Plan rev 3** (2026-11-11): Astra plan round 2's one slice 1 finding applied (P2-17). **Plan rev 2**: Astra plan round 1 (`docs/superpowers/notes/reviews/member-backups/CODEX-FINDINGS-member-backups-plans.md`, NOT READY) fully applied; findings marked **(P-N)**.
**Architecture:** One intrinsic classifier, shared with `db pull`'s `resolveReplica`, decides what is known about an instance's copy. One door, `GET /api/cli/apps/{account}/{app}/instances/{host}/backups`, answers a fixed, contents-free schema built from one bounded listing (`dbdoor.PositionAndHistory`), memoised. The instance page calls the same function in-process; the CLI prints the door's answer.
@@ -112,7 +112,7 @@
- Produces: `{Pattern: "GET /api/cli/apps/{account}/{app}/instances/{host}/backups", Kind: kindCLI, Allow: svcrole.Allow(svcrole.Deploy, svcrole.Operate), Handler: (*Server).handleAPIInstanceBackups}`; JSON body = `backupsView`.
- [ ] **Step 1: Failing tests.**
- - `TestAPIInstanceBackupsMember`: member token, replicated host → 200 with `class`, `copied_to`, `history_from`; the body has no other keys (decode into `map[string]any` and compare key set).
+ - `TestAPIInstanceBackupsKeySets` (P2-17): decode into `map[string]any` and compare the exact key set per class. `replicated`: `class`, `copied_to`, `files`, plus `history_from` only when known. `no_copy`: `class`, `reason`, `files`. `not_shown`: `class`, `reason`, `files`, plus `region` only for `other_region`. No other keys ever; `copied_to` has exactly `transaction` and `written_at`. Use a member token.
- `TestAPIInstanceBackupsRoles` (P-2): deploy, operate, admin → 200; every other role → the `kindCLI` middleware's 403 (`authcli.go:524-544`), asserted as that middleware writes it; an admitted-role token bound to another app, an app-less token where the gate requires an app, and another account's member → the byte-identical 404 the instance gate gives.
- `TestAPIInstanceBackupsBadHostAndMissing`: bad shape and unknown host → the instance gate's standard 400/404.
- `TestAPIInstanceBackupsOtherRegion`: `not_shown`/`other_region` with the region label; and `db pull`'s forward for the same host still admits (call the existing forward door and assert it is not refused).
diff --git a/docs/superpowers/plans/2026-11-11-member-backups-slice2a.md b/docs/superpowers/plans/2026-11-11-member-backups-slice2a.md
index d8d4b0e35..b25650927 100644
--- a/docs/superpowers/plans/2026-11-11-member-backups-slice2a.md
+++ b/docs/superpowers/plans/2026-11-11-member-backups-slice2a.md
@@ -4,7 +4,7 @@
**Goal:** Every box with sleeping instances runs the restore drill nightly and publishes its own record, `control/verify/<ref>.json`, whose verdicts are bound to the instance identity they tested, and operators are alerted when a test fails, keeps being unverified, or falls more than 7 days behind.
-**Plan rev 2** (2026-11-11): Astra plan round 1 (`docs/superpowers/notes/reviews/member-backups/CODEX-FINDINGS-member-backups-plans.md`, READY AFTER FIXES) fully applied; findings marked **(P-N)**.
+**Plan rev 3** (2026-11-11): Astra plan round 2 (`CODEX-FINDINGS-member-backups-plans-R2.md`) applied, marked **(P2-N)**; for the repeated group-assignment family Paul chose to build an authoritative assignment source now (2026-11-11), Task 2. **Plan rev 2**: Astra plan round 1 (`docs/superpowers/notes/reviews/member-backups/CODEX-FINDINGS-member-backups-plans.md`, READY AFTER FIXES) fully applied; findings marked **(P-N)**.
**Architecture:** `hibernate-verify` stops sharing one deployment-wide key. Each run opens the `dbreads` identity bracket per host, plans with `dbdoor.PlanFrom`, restores pinned to that TXID, closes the bracket, and records a v2 verdict. It works oldest first inside a 45-minute budget, publishes every 10 minutes, and leaves a local copy the box agent turns into alert rules. Freshness is compared only when this box holds the host's live lease.
@@ -20,7 +20,7 @@
- Budget: drills oldest first (never verified, then stalest `VerifiedAt`), 45 minutes per run by default (`-budget`), `-max` default 0 (no count cap). Publish every 10 minutes and at the end.
- The bracket: identity captured before planning, confirmed after the last replica byte AND before every replica-derived outcome is recorded (empty plan, restore error, integrity failure, stale), as `dbreads` does (`read.go:119-135,174-179`) (P-11). Any difference discards the restore and records `unverified` with reason `record_changed` (from `dbreads.CodeRecordChanged`, `"record-changed"`) or `moving`.
- The budget is a deadline, not just a start cut-off: the run context's deadline reaches planning, download, restore and `CheckDBContext`; publishing uses its own 30-second context (P-10).
-- Group boxes (`CARLOS_BOX_REFERENCE=group`): a host is drilled only by `boxchoice.HRW(host, serving) == self`, over the serving roster the agent writes (Task 2); fixed boxes drill every local sleeping host as today (P-9).
+- Group boxes (`CARLOS_BOX_REFERENCE=group`): a host is drilled only by the box its assignment names, where the assignment is `boxchoice.HRW(host, refs)` over that host's own `Serving` set from `Edge.DutySnapshot` (`internal/edge/wakeplacement.go:202`), the same per-host evidence and choice the HA duties use (`haduties.go:233-242`). The agent computes it for every HA host on a 5-minute timer, not on demand, and writes it locally (Task 2). Fixed boxes drill every local sleeping host as today (P-9, P2-9).
- Scratch stays on disk (`TMPDIR=%C/carlos-verify`, `TestVerifyDrillsRestoreToDiskNotTmpfs`).
- Alert thresholds: `verify_failed@<host>` on a failed verdict; `verify_unverified@<host>` after 3 consecutive unverified runs for any reason except `not_reached`; `verify_coverage` when any host's last decided verdict (passed or failed) is older than 7 days, or it has none and was first seen more than 7 days ago.
- Copy: only strings approved in Task 0, verbatim; no em dashes.
@@ -64,14 +64,18 @@
- [ ] **Step 4:** `go test ./internal/dbreads -run 'Identity|Agent|Read'` → PASS (the existing `agent_test.go:31` recreation cases unchanged).
- [ ] **Step 5:** Commit.
-### Task 2: The box's own reference and serving roster, readable by the drill (P-9)
+### Task 2: The box's own reference and the drill assignment, readable by the drill (P-9, P2-9)
-**Files:** Create `internal/boxself/boxself.go` (leaf package) and test; modify the agent start in `internal/host` where `haSelfNow` is applied (`lease.SetSelf`) to call `boxself.Write`, and the place the HA duty view refreshes (`internal/activator/haduties.go:233-242`, `boxchoice.WakeSnapshot.Serving`) to rewrite it with the roster; move `dutyHRW` (`haduties.go:401`) to `internal/boxchoice` as exported `HRW(host string, refs []string) (string, bool)`, with the activator calling it.
+**Files:** Create `internal/boxself/boxself.go` (leaf package) and test; create `internal/host/verifyassign.go` and test; modify the agent start in `internal/host/agent.go` (beside `lease.SetSelf` and `svc.SetDutyView`, `:1267`) to write the self file and start the assignment loop. Add exported `HRW(host string, refs []string) (string, bool)` to `internal/boxchoice` with today's `dutyHRW` body; `dutyHRW` (`haduties.go:401`) stays as a one-line wrapper calling it, so `haduties_test.go:122` and the `go:linkname` in `internal/host/hadrain_twobox_minio_linux_test.go:85` keep working (P2-15).
**Interfaces:**
-- Produces: `type Self struct { Ref string; Group bool; Serving []string; ServingAt time.Time }`; `func Write(dataDir string, s Self) error` (atomic write of `<dataDir>/monitor/self.json`, `v: 1`, mode 0644); `func Read(dataDir string) (Self, error)` (`os.ErrNotExist` when absent; refuses an empty or invalid ref). `boxchoice.HRW` byte-identical to today's `dutyHRW`.
+- Produces:
+ - `type Self struct { Ref string; Group bool }`; `func Write(dataDir string, s Self) error` (atomic `<dataDir>/monitor/self.json`, `v: 1`, mode 0644); `func Read(dataDir string) (Self, error)` (`os.ErrNotExist` when absent; refuses an empty or invalid ref).
+ - `type Assignment struct { At time.Time; Hosts map[string]string /*host -> winning ref*/; Unknown []string /*HA hosts whose snapshot was not Usable or had no serving box*/ }`; `func WriteAssignment(dataDir string, a Assignment) error` and `func ReadAssignment(dataDir string) (Assignment, error)` (atomic `<dataDir>/monitor/verify-assign.json`).
+ - In `internal/host`: `func computeAssignment(routes []registry.Route, snap func(registry.Route) boxchoice.WakeSnapshot, now time.Time) boxself.Assignment`: for each route with `rt.HA`, take `snap(rt)`; if `!Usable` or `len(Serving) == 0`, list it in `Unknown`; else `Hosts[rt.Host] = boxchoice.HRW(rt.Host, refs of Serving)`. The agent runs it every 5 minutes over the registry's routes with **the same view function it passes to `svc.SetDutyView`** (`agent.go:1267`: `SidecarDutySnapshot` for sidecars, `DutySnapshot` otherwise), named once and used by both, on group boxes only.
+ - `boxchoice.HRW` byte-identical to today's `dutyHRW`.
-- [ ] **Step 1: Failing tests:** `TestBoxSelfRoundTrip`, `TestBoxSelfReadMissing`, `TestBoxSelfRefusesEmpty`; in `internal/host`, `TestAgentWritesSelfRefEqualToLeaseRef` (fixed and group fixtures); `TestHRWMatchesDutyHRW` (golden values from the old function); `TestHRWAssignsEachHostOnce` (three refs, 1,000 hosts: each host has exactly one winner; removing one ref moves only that ref's hosts).
+- [ ] **Step 1: Failing tests:** `TestBoxSelfRoundTrip`, `TestBoxSelfReadMissing`, `TestBoxSelfRefusesEmpty`, `TestAssignmentRoundTrip`; in `internal/host`, `TestAgentWritesSelfRefEqualToLeaseRef` (fixed and group fixtures); `TestHRWMatchesDutyHRW` (golden values); `TestHRWAssignsEachHostOnce` (three refs, 1,000 hosts; removing one ref moves only its hosts); `TestComputeAssignmentFromEdgesFiles` — **end to end through the producer (P2-9):** three boxes' edges files in one region (built with the same fixture helpers the `wakeplacement` tests use), one box advertising a subset of hosts, one quiet box with no recent duty activity; each box's `computeAssignment` over `Edge.DutySnapshot` gives the same `Hosts` map, every HA host appears exactly once across `Hosts` and `Unknown`, a host advertised by only two boxes is never assigned to the third, and the result equals what `DecideDuty`'s absent-view branch picks for the same host.
- [ ] **Step 2:** Run → FAIL.
- [ ] **Step 3:** Implement. Write after the group-reference wait, alongside `lease.SetSelf`.
- [ ] **Step 4:** `go test ./internal/boxself ./internal/host -run 'BoxSelf|SelfRef'` → PASS.
@@ -99,7 +103,7 @@
- `func KeyFor(ref string) string` → `"control/verify/" + ref + ".json"`; refuses an invalid ref. The old `Key` constant is removed.
- `Verdict` v2 fields: `Result string` (`passed|failed|unverified`), `Reason string`, `Identity Identity` (a struct in `dbverify` mirroring `dbreads.Identity` field for field, so the leaf package imports nothing new; Task 5 converts), `Prefix string`, `BracketOpenedAt, VerifiedAt time.Time`, `TXID uint64`, `WrittenAt time.Time`, `RestoredBytes int64`, `Freshness string` (`stale|unknown|not_stale`), `UnverifiedRuns int`, `FirstSeen time.Time`, `LastDecidedAt time.Time` (advanced only by `passed`/`failed`) (P-12). `OK`/`Unverified` stay as derived accessors for `Failures()`/`Unverified()`.
- `Record{V: 2, Box: ref, CheckedAt, Hosts map[string]Verdict}`.
- - `func Merge(prior *Record, ref string, now time.Time, fleet []string, results map[string]Verdict) *Record`: keeps unvisited fleet hosts, drops hosts not in the fleet, adds never-seen fleet hosts as `unverified`/`not_reached` with `FirstSeen = now`, carries `FirstSeen`, and sets `UnverifiedRuns` to prior+1 for an unverified result (except `not_reached`), else 0. `LastDecidedAt` carries over through unverified results; when a result's identity differs from the prior verdict's, `FirstSeen`, `LastDecidedAt` and `UnverifiedRuns` reset (P-12).
+ - `func Merge(prior *Record, ref string, now time.Time, fleet []string, results map[string]Verdict) *Record` (callers pass the run-start record as `prior` on every publish within a run, P2-16): keeps unvisited fleet hosts, drops hosts not in the fleet, adds never-seen fleet hosts as `unverified`/`not_reached` with `FirstSeen = now`, carries `FirstSeen`, and sets `UnverifiedRuns` to prior+1 for an unverified result (except `not_reached`), else 0. `LastDecidedAt` carries over through unverified results; when a result's identity differs from the prior verdict's, `FirstSeen`, `LastDecidedAt` and `UnverifiedRuns` reset (P-12).
- `func Load(ctx, s release.Store, ref string) (*Record, error)`, `func Publish(ctx, s release.Store, rec *Record) error` (CAS on `KeyFor(rec.Box)`), `func RemoveHost(ctx, s release.Store, ref, host string) error`.
- `ChangeScope("control/verify/<ref>.json")` → `"control/verify/<ref>", true`; anything deeper or without `.json` → false.
- The mutation classifier gains `{prefix: "control/verify/"}` in place of the old exact row.
@@ -122,7 +126,7 @@
- Flags: `-budget` (default `45m`), `-max` (default 0), `-publish-every` (default `10m`, hidden).
- The local alert copy: after each publish, the record is also written atomically to `<data>/monitor/verify.json`.
-Host selection: fixed box, every local sleeping host; group box, only hosts with `boxchoice.HRW(host, self.Serving) == self.Ref`, and none if `self.ServingAt` is older than 15 minutes (those become `not_reached`, reason `no_roster`) (P-9).
+Host selection: fixed box, every local sleeping host; group box, only hosts whose `ReadAssignment(dataDir).Hosts[host] == self.Ref`. An assignment older than 15 minutes, missing, or listing the host in `Unknown`: the host is not drilled and is recorded `not_reached` with reason `no_assignment`. A host assigned to another box is not in this box's record at all (P-9, P2-9).
Per host, in order: `CaptureIdentity` (on a code: `unverified` with that reason, next host) → `PlanFrom(ctx, rd, time.Time{})` → `VerifyReplicaAt(ctx, ..., plan.TXID)` → **`ConfirmIdentity` before any outcome is recorded**, including an empty plan, a plan error, a restore error and an integrity failure (on a code: discard, `unverified`) (P-11) → only then: `ErrNothingReplicated` → `unverified`/`nothing_replicated`; restore or integrity error → `failed`/`restore_error`; otherwise freshness: `lease.LockState` must return no error and `held`, `hafresh.ParseOwner` must succeed and `Ref == self.Ref`, then the existing `hibernateFreshness` (stale → `failed`/`stale`); in every other case `unknown`, with no local database read (P-14) → verdict with the plan's `TXID`, `At`, `RestoredBytes`. The run context carries the budget's deadline into every step (P-10); when it expires, the host in progress is abandoned (scratch removed, no verdict) and the rest become `not_reached` through `Merge`.
@@ -134,14 +138,15 @@ Empty fleet (P-13): if this box has no hosts to drill but `dbverify.Load` finds
- `TestVerifyHibernatingFreshnessOnlyOnLeaseHolder`: lock held by another ref, expired self-owned lock, absent lock, malformed owner, unreadable lock → `unknown`, the local source never opened; held by self → stale detected as today (P-14).
- `TestVerifyHibernatingBudget` (fake clock; budget reached after N hosts; the rest `not_reached`; oldest first kept).
- `TestVerifyHibernatingDeadlineStopsBlockedWork`: a reader that blocks during download; at the deadline the step returns, scratch is empty, and the hosts finished before it are published through the separate publish context (P-10).
- - `TestVerifyHibernatingGroupAssignment`: three boxes sharing a serving roster each drill a disjoint set covering every host; a stale roster drills none and marks them `no_roster` (P-9).
+ - `TestVerifyHibernatingGroupAssignment`: three boxes, each reading the assignment file its own `computeAssignment` wrote from the shared edges-file fixture (Task 2), drill disjoint sets covering every host; a stale or missing assignment drills none and marks them `no_assignment` (P-9, P2-9).
+ - `TestVerifyHibernatingStreakOncePerRun`: one host unverified throughout a run with four periodic publishes and a final one: its `UnverifiedRuns` rises by exactly one (P2-16).
- `TestRunHibernateVerifyEmptyFleetClearsPrior`: a prior record with one host, then a run with none, publishes an empty record and an empty local copy; with no prior record nothing is published (P-13).
- `TestVerifyHibernatingPublishesPeriodically` (publish called at each 10-minute mark and at the end with everything finished so far).
- `TestRunHibernateVerifyRefusesWithoutSelfRef` (no `self.json`: no publish, non-zero exit, log names the file).
- `TestRunHibernateVerifyWritesLocalAlertCopy`.
- Update `TestVerifyHibernatingHonoursTheCap` for `-max` default 0.
- [ ] **Step 2:** `go test ./internal/ops -run 'Hibernat'` → FAIL.
-- [ ] **Step 3:** Implement. The self ref comes from `boxself.Read(dataDir)`; the region from `CARLOS_REGION` (the unit loads `/etc/carlos/host.env`).
+- [ ] **Step 3:** Implement. The self ref comes from `boxself.Read(dataDir)`; the region from `CARLOS_REGION` (the unit loads `/etc/carlos/host.env`). **Every periodic and final publish merges the run's cumulative results into the record loaded at run start**, never into the last publish (P2-16).
- [ ] **Step 4:** PASS, including `TestVerifyDrillsRestoreToDiskNotTmpfs`.
- [ ] **Step 5:** Commit.