region HA files-only release: Astra review fixes
Astra one round: no P1, READY AFTER FIXES. - P2: activator test that a final files commit refused, or applied with its reply lost, leaves the marker unclean and not finalized, held a lease term. - P3: Held.ReleaseMarker and uncleanMarker clear finalized, so only releaseHAClean can set it (test: a checkpointed handle claiming it). - P3: the spec says a finalized release's exposure equals a clean one's, not that nothing is outstanding. Census proposal re-run for the lease envelope.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/superpowers/reviews/ASTRA-FINDINGS-ha-unclean-files-only.md+17 −0docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md+1 −1internal/activator/hadrainmove_linux_test.go+52 −0internal/lease/release.go+2 −2internal/lease/unclean_marker_test.go+2 −2internal/provision/testdata/plan14-root-reads-ha-unclean-files-only.tsv+1 −1
CI passed — run details
Intent
Continue the ha-unclean task: check CI on ha-unclean-marker-waits, the Astra generations review (~/.cache/ha-unclean/ASTRA-FINDINGS-gen-R1.md), and the runbook copy review result.
<task-notification> <task-id>bfbkc4e8b</task-id> <tool-use-id>toolu_017mPwUxp2RiXh9Rf6SuzWJ5</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/18c2ef37-6ec3-4dcd-8be8-7eed9ce0123f/tasks/bfbkc4e8b.output</output-file> <status>completed</status> <summary>Background command "Run Astra's one-round review of the files-only change" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 40.3 g CO₂e (5,132,313 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on ha-unclean-files-only, 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-unclean-files-only.md b/docs/superpowers/reviews/ASTRA-FINDINGS-ha-unclean-files-only.md| new file mode 100644 |
| index 000000000..f3473b81b |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/ASTRA-FINDINGS-ha-unclean-files-only.md |
| @@ -0,0 +1,17 @@ |
| +**P1: none found.** |
| + |
| +- **P2 — missing test for the files-error boundary.** [hadrainmove_linux_test.go:32](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-files/internal/activator/hadrainmove_linux_test.go:32) covers incomplete-tree success, but no activator test proves a failed final object/manifest PUT leaves `Finalized=false` and blocks acquisition. Removing `ferr == nil` at [harelease.go:229](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-files/internal/activator/harelease.go:229) would escape the added coverage. Add that negative case, including a timed-out publication. |
| + |
| +- **P3 — “none is outstanding” overstates the guarantee.** [Design:199](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-files/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md:199). After an uncertain earlier PUT, refresh can read the old manifest; `Final` can then succeed through `Commit`’s no-op at [publisher.go:327](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-files/internal/hostfiles/publisher.go:327). Earlier requests can remain outstanding. Clean releases share this exposure; describe equivalence rather than completion. |
| + |
| +- **P3 — other APIs preserve caller-supplied `Finalized`.** [release.go:174](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ha-files/internal/lease/release.go:174) clears `Clean` but not `Finalized` on `Held.ReleaseMarker`; `uncleanMarker` also preserves it from `base`. A checkpointed handle supplied `Finalized:true` bypasses the wait. **No current production caller supplies it through these paths.** Clear it defensively and test that case. |
| + |
| +**A:** The current production path has the same storage exposure as a clean release, under Paul’s accepted exception. Publisher shutdown joins both passes; files, wake state and sealed escrow use immutable objects plus conditional manifest publication. I found no additional outstanding-write hazard unique to finalized-but-unclean releases. |
| + |
| +**B:** Successful local records still match remote markers: `Finalized` is set before recording, and replica finalization returns its cached result. Unclean or failed-record releases remain ineligible for pool withdrawal. |
| + |
| +**C:** Positive acquisition and abandonment coverage is useful; the files-error boundary needs the P2 test. |
| + |
| +Static review only; no edits or tests run. |
| + |
| +**READY AFTER FIXES** — address P2 within this round; P3s are follow-ups. |
| \ No newline at end of file |
diff --git a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md| index 218a91e90..576c6dc51 100644 |
| --- a/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md |
| +++ b/docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md |
| @@ -196,7 +196,7 @@ So old binaries and non-HA boxes see a marker as a released lease. |
| - **What `settled` means** (rev 6.7, 2026-11-12). The marker records `settled: true` only when the releasing holder never replicated under the lease: a failed wake before replication, an acquire's late-acknowledgement cleanup, an adoption. A holder that replicated never writes it, even after a final sync that succeeded: Litestream's store close cancels its monitors' compaction, snapshot and retention requests without proving S3 did not receive them (Astra containment review R1 P1). |
| - An unclean marker that is not settled may have an upload in flight that S3 applies after the marker, into the very prefix and TXID range the successor writes next. That is the wake-race review's P1: the late object replaces the successor's, and history diverges silently. |
| - So such a marker opens only a lease term (`LeaseTTL`, 15 minutes) after its `at`, for every box, the releaser's own included (§9.4). `at` is written after the finalization returns, so every request the holder sent was sent before it, and each has had at least the margin N-HA9 gives a dead owner's writes. An owed marker keeps its first `at` when it is retried. A clean marker opens at once whatever it says, by Paul's ruling: the drain's fast handover (§25) stays. It carries the same monitor exposure; storage generations close it (`2026-11-12-region-ha-storage-generations-design.md`). |
| - - **Finalized** (rev 6.8, 2026-11-12). An unclean marker also records `finalized: true` when the release's replica finalization and its final files commit both succeeded, so that it is unclean only for a local reason: a files tree that could not be published completely (a file over the size limit, an unreadable or non-regular entry), or a release record that could not be written. Its storage exposure is then exactly a clean marker's, and it opens at once like one. Files cannot collide the way an L0 can: each object is written create-only under `objects/<seq>-<sha256>`, and the manifest moves only by compare-and-swap, so a late files write either fails its condition or makes the successor's next commit fail loudly (`ErrSuperseded`); in a finalized release the commit had succeeded, so none is outstanding. A host whose files are never complete therefore keeps the drain's fast handover. |
| + - **Finalized** (rev 6.8, 2026-11-12). An unclean marker also records `finalized: true` when the release's replica finalization and its final files commit both succeeded, so that it is unclean only for a local reason: a files tree that could not be published completely (a file over the size limit, an unreadable or non-regular entry), or a release record that could not be written. Its storage exposure is then exactly a clean marker's, and it opens at once like one. Files cannot collide the way an L0 can: each object is written create-only under `objects/<seq>-<sha256>`, and the manifest moves only by compare-and-swap, so a late files write either fails its condition or makes the successor's next commit fail loudly (`ErrSuperseded`). A finalized release's exposure is therefore the same as a clean release's, not none: an earlier uncertain manifest PUT can still be outstanding after a final commit that had nothing new to write, exactly as in a clean release (Astra files-only review P3). A host whose files are never complete therefore keeps the drain's fast handover. Only `releaseHAClean` sets `finalized`; every other release path clears it. |
| - A marker written before the field reads as not settled. Old binaries ignore the field and still take every marker at once, so the containment holds only once every box of a pool runs it. |
| - A host whose last marker is not clean is not ready for retirement (§13). |
| - If S3 is unreachable, no marker is written. The lease stays held until it expires, and then only this box may take it again (§9.4). |
diff --git a/internal/activator/hadrainmove_linux_test.go b/internal/activator/hadrainmove_linux_test.go| index 338992311..96f50c8e2 100644 |
| --- a/internal/activator/hadrainmove_linux_test.go |
| +++ b/internal/activator/hadrainmove_linux_test.go |
| @@ -4,13 +4,16 @@ package activator |
| import ( |
| "context" |
| + "errors" |
| "path/filepath" |
| "syscall" |
| "testing" |
| "time" |
| "github.com/carlosframework/platform/internal/hafresh" |
| + "github.com/carlosframework/platform/internal/hostfiles" |
| "github.com/carlosframework/platform/internal/lease" |
| + "github.com/carlosframework/platform/internal/release" |
| ) |
| // Files Final incomplete: the marker is unclean, and the drain stop says |
| @@ -33,3 +36,52 @@ func TestDrainStopFilesFinalIncomplete(t *testing.T) { |
| t.Fatalf("files-only unclean marker %+v: want finalized, open at once", m) |
| } |
| } |
| + |
| +// filesCommitFails fails every manifest PUT once armed: refused (nothing |
| +// applied) or lost (applied, the reply lost: a timed-out publication). |
| +type filesCommitFails struct { |
| + release.Store |
| + manifest string |
| + mode string // "", "refused" or "lost" |
| +} |
| + |
| +func (s *filesCommitFails) Put(ctx context.Context, key string, body []byte, match string) (string, error) { |
| + if key != s.manifest || s.mode == "" { |
| + return s.Store.Put(ctx, key, body, match) |
| + } |
| + if s.mode == "lost" { |
| + if _, err := s.Store.Put(ctx, key, body, match); err != nil { |
| + return "", err |
| + } |
| + return "", errors.New("applied manifest PUT, reply lost") |
| + } |
| + return "", errors.New("manifest PUT refused") |
| +} |
| + |
| +// The files-error boundary of finalized (Astra files-only review P2): a |
| +// final files commit that fails or whose outcome is unknown leaves the |
| +// marker unclean and NOT finalized, so it waits a lease term. |
| +func TestDrainStopFilesCommitFailureNotFinalized(t *testing.T) { |
| + for _, mode := range []string{"refused", "lost"} { |
| + t.Run(mode, func(t *testing.T) { |
| + s := haService(t, "shop.example.com") |
| + store := &filesCommitFails{Store: s.b.FilesStore, manifest: hostfiles.ManifestKey(s.b.filesPrefix(s.rt.Host))} |
| + s.b.FilesStore = store |
| + if _, err := s.wakeForTest(context.Background()); err != nil { |
| + t.Fatalf("wake: %v\nroot was asked:\n%s", err, s.ctl.joined()) |
| + } |
| + writeFiles(t, s.b, s.rt, map[string]string{"a.txt": "changed after the wake"}) |
| + store.mode = mode |
| + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) |
| + defer cancel() |
| + rel, _ := s.a.DrainStop(ctx, s.rt.Host) |
| + if !rel.Marker || rel.Clean { |
| + t.Fatalf("drain stop: %+v, want an unclean marker", rel) |
| + } |
| + m := s.lockView(t).Lock.Release |
| + if m == nil || m.Clean || m.Finalized || hafresh.MarkerOpensAt(*m, lease.LeaseTTL).IsZero() { |
| + t.Fatalf("marker %+v: want unclean, not finalized, held a lease term", m) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/lease/release.go b/internal/lease/release.go| index d36e10a82..ab980e73b 100644 |
| --- a/internal/lease/release.go |
| +++ b/internal/lease/release.go |
| @@ -117,7 +117,7 @@ func conditionFailed(err error) bool { |
| // settled says the handle never replicated (hafresh.Marker.Settled). |
| func uncleanMarker(base hafresh.Marker, txid uint64, settled bool) hafresh.Marker { |
| m := base |
| - m.V, m.TXID, m.FilesGen, m.Clean, m.Settled, m.At = 1, txid, "", false, settled, time.Now().UTC() |
| + m.V, m.TXID, m.FilesGen, m.Clean, m.Settled, m.Finalized, m.At = 1, txid, "", false, settled, false, time.Now().UTC() |
| return m |
| } |
| @@ -171,7 +171,7 @@ func (h *Held) ReleaseMarker(ctx context.Context, m hafresh.Marker) error { |
| defer h.finish(true, nil) |
| lease := h.rn.stop() |
| m = withBase(h.base, m) |
| - m.Clean = false |
| + m.Clean, m.Finalized = false, false |
| m.Settled = !h.wroteReplica() |
| return releaseWithMarker(ctx, h.leaser, h.region, lease, m) |
| } |
diff --git a/internal/lease/unclean_marker_test.go b/internal/lease/unclean_marker_test.go| index d52d33616..8ebbc57d5 100644 |
| --- a/internal/lease/unclean_marker_test.go |
| +++ b/internal/lease/unclean_marker_test.go |
| @@ -126,13 +126,13 @@ func TestReplicatedUncleanMarkersAreNotSettled(t *testing.T) { |
| t.Fatal(err) |
| } |
| }, |
| - "checkpointed handle": func(t *testing.T, fx *locktest.LockFixture, prefix string) { |
| + "checkpointed handle, claiming finalized": func(t *testing.T, fx *locktest.LockFixture, prefix string) { |
| h := haHeldTTL(t, fx, prefix, ttl) |
| lease.SetReplicaClientForTest(h, lsfile.NewReplicaClient(t.TempDir())) |
| if _, err := h.Checkpoint(ctx, tempDB(t)); err != nil { |
| t.Fatal(err) |
| } |
| - if err := h.ReleaseMarker(ctx, hafresh.Marker{V: 1}); err != nil { |
| + if err := h.ReleaseMarker(ctx, hafresh.Marker{V: 1, Finalized: true}); err != nil { |
| t.Fatal(err) |
| } |
| }, |
diff --git a/internal/provision/testdata/plan14-root-reads-ha-unclean-files-only.tsv b/internal/provision/testdata/plan14-root-reads-ha-unclean-files-only.tsv| index 89fa350dd..b3d983fec 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-ha-unclean-files-only.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-ha-unclean-files-only.tsv |
| @@ -4,4 +4,4 @@ |
| internal/activator/harelease.go Service.releaseHAClean legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p1a;basis=new: an HA entry's release, in order: host slice read empty through haHostEmpty (else errHostSliceUnproven and nothing written; the same check, moved into that helper by final fix F1), stop and join the files publisher, its final publish (2 min budget), the replica's final sync (Finish, 30 s), the local release record, then the release marker PUT (10 s), clean only when the final publish was complete and the sync and record succeeded; a failed PUT is a persisted lease obligation; +registry:Host, +whole:Route x4;rev3=census-ruling-region-ha-p1b3b-t;basis=Record advisory local-release basis only after ReleaseMarker succeeds. Add a whole-route argument to local duty bookkeeping; release order and lease authority unchanged.;rev3=census-ruling-region-ha-g2-fixes;basis=Latch unexpected lease loss before release and mark intentional release so ErrSpent alone is not treated as loss; no new read.;rev3=census-ruling-region-ha-graceful-terminate-t2;basis=Cap Final, Finish and marker contexts by the shutdown deadline and reserves; keep calls synchronous and stop proof unchanged; record successful marker completion under the service mutex. No read added.;rev3=census-ruling-region-ha-held-build;basis=region HA held-requests Task 5: records the written marker's clean flag on the entry (haReleaseClean) beside haReleased, for the drain report; no read added;rev3=census-ruling-held-move-speed;basis=reads the entry's drainRelease flag under a.mu; for the drain's release calls the replica's FinishSnapshot (final sync, then a litestream snapshot at the final position, before the store's close; the snapshot reader pipe is closed on every outcome) instead of Finish, and logs a snapshot failure naming rt.Host (+registry:Host, the supplied route); marker order, budgets and clean rule unchanged; no new read;rev3=census-ruling-retry-after-503;basis=records four time.Now stamps and logs per-phase durations (files, sync, record, marker) on the existing marker log line; order, budgets and clean rule unchanged; no read added;rev3=census-ruling-ha-unclean-files-only;basis=Sets the marker field finalized from the errors of Final and Finish it already computes, before the record and marker writes it already makes. No new read, write or path. registry:Host@1584,registry:Host@3029,whole:Route@109,whole:Route@1710,whole:Route@2092,whole:Route@267,whole:Route@2868 e970ef6011466eb62a60a8d4e8468526167873539c08ab955786306f8a5d82d1 |
| @coverage internal/activator d2ae0333e9bb808bd422faca72ad7138851972dcb458416c871fa1500acec76f |
| @coverage internal/hafresh 6f4c0f2d8f2edbe59fbf08203d7642972c4d9c3e93c9c8e4c2bcfb93b2fd7e66 |
| -@coverage internal/lease b71b0f1d4f68d64c5e6b80e7a30ffa3935fbafc3821129d5760b94a8e301d617 |
| +@coverage internal/lease 1404400a7f954f5674b3c792faba6038b443382fd4127ce9dd0115a8ae161b5c |