carlos / platform Public

region HA: a files-only unclean release opens at once

Follow-up to b126ea5. An unclean marker records finalized when the
release's replica finalization and its final files commit both
succeeded: it is unclean only for a local reason (an incomplete files
tree, a failed release record), its storage exposure equals a clean
marker's, and it opens at once like one. A failed or uncertain files
commit, a failed sync and G6's fence still wait a lease term.

Files cannot collide the way L0 can: objects are create-only at
objects/<seq>-<sha256> and the manifest moves by CAS. Only
releaseHAClean sets finalized; every other release path clears it.
Spec rev 6.8. Astra one round (no P1; P2 negative test and P3 fixes
applied); census approved on #280.

Inventory 2026-11-12 (last marker per host): dev IE 35 prefixes, 3
unclean (never-replicated G2 drill releases); flagship US 10, none
unclean. No host affected today.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from ha-unclean-files-only into main.
claude agent, operated by paul@keymail.dev ab4d773b5bea4ed13aa823adb17af42d8961a1e7 parent b126ea5
12 files changed, +152 −20
  • docs/superpowers/notes/census-proposal-ha-unclean-files-only.md +19 −0
  • docs/superpowers/reviews/ASTRA-FINDINGS-ha-unclean-files-only.md +17 −0
  • docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md +6 −5
  • internal/activator/hadrainmove_linux_test.go +60 −0
  • internal/activator/harelease.go +6 −1
  • internal/hafresh/acquire_test.go +1 −0
  • internal/hafresh/lock.go +12 −2
  • internal/lease/release.go +6 −4
  • internal/lease/unclean_marker_test.go +16 −7
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-ha-unclean-files-only.tsv +7 −0
  • internal/sim/regionha/actions_test.go +1 −1

CI passed — run details

diff --git a/docs/superpowers/notes/census-proposal-ha-unclean-files-only.md b/docs/superpowers/notes/census-proposal-ha-unclean-files-only.md
new file mode 100644
index 000000000..f904b9d4f
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-ha-unclean-files-only.md
@@ -0,0 +1,19 @@
+# Census approval: ha-unclean-files-only
+
+Ruling `census-ruling-ha-unclean-files-only`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/activator/harelease.go` `Service.releaseHAClean` | body | unchanged (7) | 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. |
+
+Envelopes re-pinned: `internal/activator`, `internal/hafresh`, `internal/lease`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Recorded dispositions, which each change must still satisfy:
+
+- `internal/activator/harelease.go` `Service.releaseHAClean`: legacy, task accepted-legacy. Basis: 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
+
+Seal: `821598970e60a776d4a62138d5adbfa393cd30bc1ec1f266d290e5b6d4e12c42` → `bc138ce5435f3ab37f6adff46656eea1c20f48168c569550fe94e390c69ba309`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-ha-unclean-files-only.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
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 be26949f0..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
@@ -1,6 +1,6 @@
# Region HA without claims: N-box regions behind a load balancer
-Design, 2026-10-26, **rev 6.7** (rev 6.7: the unsettled-marker wait, Paul's containment ruling 2026-11-12; §25 held requests during a planned handover, 2026-11-08, APPROVED by Paul 2026-11-08 ~22:15Z as r4 (§25.15); Astra rounds 1-3 spent, no fourth round; rev 6.5 added §7.5 DR-5): rev 6 APPROVED by Paul on 2026-10-26, plus his ruling N-HA7 the same day (a scope ruling, not a redesign: §2.1, §8.4, §13, §19). Astra rounds 1 to 3 are complete, and the review budget is spent (AGENTS.md, stopping rules). Branch `design-region-ha-no-claims`, cut from `origin/main` at ddf3b929. Nothing here is built.
+Design, 2026-10-26, **rev 6.8** (rev 6.8: finalized files-only releases open at once; rev 6.7: the unsettled-marker wait, Paul's containment ruling 2026-11-12; §25 held requests during a planned handover, 2026-11-08, APPROVED by Paul 2026-11-08 ~22:15Z as r4 (§25.15); Astra rounds 1-3 spent, no fourth round; rev 6.5 added §7.5 DR-5): rev 6 APPROVED by Paul on 2026-10-26, plus his ruling N-HA7 the same day (a scope ruling, not a redesign: §2.1, §8.4, §13, §19). Astra rounds 1 to 3 are complete, and the review budget is spent (AGENTS.md, stopping rules). Branch `design-region-ha-no-claims`, cut from `origin/main` at ddf3b929. Nothing here is built.
This spec supersedes every claim-dependent part of "Region HA, spec 2: two-box regions" (`2026-10-15-region-ha-two-box-regions-design.md`, rev 21, cited **S2 §n**) and of spec 1 (`2026-10-04-region-ha-box-placement-design.md`, cited **S1 §n**). §16 lists what it reuses from S2, plan 2a (6834659c) and plan 2b (b1118925), and the removals this series owns. Line citations are to this worktree unless they name a module path.
@@ -15,6 +15,7 @@ This spec supersedes every claim-dependent part of "Region HA, spec 2: two-box r
- **Rev 6.5** records DR-5: a departure finishes when no surviving box serves a departed box's pool, and departures finish within 3 minutes of proof (§7.5, 2026-11-08).
- **Rev 6.6** adds §25: a planned member replacement (terminate, roll, resize, scale-in) holds requests for a few seconds instead of answering 503. Unplanned deaths are unchanged. Not built; Paul approves before any build.
- **Rev 6.7** (2026-11-12, Paul's containment ruling in the HA session, after the wake-race review's P1): an unclean release after replication no longer allows immediate takeover. Its marker is not *settled*, and every box waits a lease term from the marker's time (§5.2, §9.4, §9.8, §9.9). Built on branch `ha-unclean-marker-waits`; storage generations, the fix, are designed separately (`2026-11-12-region-ha-storage-generations-design.md`).
+- **Rev 6.8** (2026-11-12, follow-up): an unclean release whose replica finalization and files commit both succeeded (only the tree was incomplete, or the local record failed) is *finalized* and opens at once (§5.2): files cannot collide like L0, and its exposure is a clean marker's.
Under stopping rule 2, the families I2, I3 and I4 drew findings two rounds running. I2 and I4 are now stated as invariants, enforced in one place and checked by the simulation (§3.1). I3 drew a P1 in all three rounds, so rev 6 cuts its transfer protocol and restates I3 over the scan alone.
@@ -195,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`).
- - Every unclean release after replication now waits, including one where only the files publish fell short. A host whose files publish is never complete (a file over the size limit) therefore waits a lease term on every handover, drain included, until its files are fixed.
+ - **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).
@@ -444,8 +445,8 @@ On an HA box, the lease package's acquire reads first: one GET of `lock.json` wi
| Lock state | Action |
|---|---|
| Absent | Create, with `If-None-Match: *`. |
-| A release marker, clean or settled | Conditional PUT, with `If-Match`. |
-| A release marker, unclean and not settled (§5.2, rev 6.7) | Held, naming the marker, until its `at` plus the lease term; then a conditional PUT. No termination proof applies: the releaser usually lives, and a proof would not stop a request S3 already has. |
+| A release marker, clean, settled or finalized | Conditional PUT, with `If-Match`. |
+| A release marker, unclean, neither settled nor finalized (§5.2, rev 6.7, 6.8) | Held, naming the marker, until its `at` plus the lease term; then a conditional PUT. No termination proof applies: the releaser usually lives, and a proof would not stop a request S3 already has. |
| Held and unexpired | A held answer naming the owner (§6.2). |
| Expired, owner is this box's instance id | Conditional PUT, only with the emptiness proof of §9.6. Otherwise refused. |
| Expired, owner confirmed terminated (§9.2, N-HA9) | Conditional PUT: the takeover. A terminated owner's unexpired lock is held until it expires, because a write the dead process already sent can still land. |
@@ -495,7 +496,7 @@ These are estimates; dev measures each one (§21).
| First request: acquire, describe, takeover, restore | about a second, plus the restore | the same |
| **Total, request-driven instances** | **about 1 to 3 min** | **about 2 to 5 min** |
| Until storage fencing (N-HA9) | takeover also waits for the lease to expire, so the totals above are up to about 15 minutes after the last renewal | the same |
-| After an unclean release that replicated (§5.2, rev 6.7) | no box takes the host until 15 minutes after the marker: a release that could not finish cleanly costs that host a lease term | the same |
+| After an unclean release that replicated and was not finalized (§5.2, rev 6.7 and 6.8) | no box takes the host until 15 minutes after the marker: a release whose final sync or files commit failed costs that host a lease term | the same |
| Always-on workers, ticks, due wakes | one sweep (30 s or less) after confirmation; backoffs cancelled | the same |
| Worst case, event lost | the next request's dial failure confirms at once; with no requests, view ageing (15 min) | the same |
diff --git a/internal/activator/hadrainmove_linux_test.go b/internal/activator/hadrainmove_linux_test.go
index 108e90d0f..96f50c8e2 100644
--- a/internal/activator/hadrainmove_linux_test.go
+++ b/internal/activator/hadrainmove_linux_test.go
@@ -4,10 +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
@@ -24,4 +30,58 @@ func TestDrainStopFilesFinalIncomplete(t *testing.T) {
if err != nil || !rel.Marker || rel.Clean {
t.Fatalf("drain stop: %+v %v, want an unclean marker", rel, err)
}
+ // Only the tree was incomplete: the files commit and the replica's
+ // finalization succeeded, so the marker is finalized and opens at once.
+ if m := s.lockView(t).Lock.Release; m == nil || m.Clean || !m.Finalized || !hafresh.MarkerOpensAt(*m, lease.LeaseTTL).IsZero() {
+ 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/activator/harelease.go b/internal/activator/harelease.go
index 90178f966..c2f1fb8b0 100644
--- a/internal/activator/harelease.go
+++ b/internal/activator/harelease.go
@@ -167,7 +167,8 @@ func haEntryRep(e *actEntry) (haRep, bool) {
// close, so the successor restores one file (§25.4 step 3.3). A
// snapshot that fails is logged and changes nothing else;
// 5. ReleaseMarker, clean only when Final was complete, Finish succeeded
-// and the record was written.
+// and the record was written; finalized when Final's commit and Finish
+// succeeded (it then opens at once even if unclean).
//
// Any other error is returned for the log: the marker was still written,
// or, if its PUT failed, lease has persisted the obligation
@@ -222,6 +223,10 @@ func (a *Service) releaseHAClean(ctx context.Context, e *actEntry) error {
m := hb.haReleaseBase(rt)
m.TXID, m.FilesGen, m.At = txid, gen, time.Now().UTC()
m.Clean = complete && ferr == nil && finErr == nil
+ // Finalized (hafresh.Marker.Finalized): the files commit and the
+ // replica finalization both succeeded, so an incomplete tree or a
+ // failed record leaves the marker unclean but opening at once.
+ m.Finalized = ferr == nil && finErr == nil
rerr := hb.writeHARecord(rt, m, files)
if rerr != nil {
// Without the record nothing could keep on this copy: the marker
diff --git a/internal/hafresh/acquire_test.go b/internal/hafresh/acquire_test.go
index 5e4befb7f..dabc21bb9 100644
--- a/internal/hafresh/acquire_test.go
+++ b/internal/hafresh/acquire_test.go
@@ -231,6 +231,7 @@ func TestDecideAcquireUnsettledMarkerWaitsALeaseTerm(t *testing.T) {
{"unsettled, this box's own", at(mine, now.Add(-time.Minute), false, false), ActHeld, MarkerOwner(mine), now.Add(term - time.Minute)},
{"unsettled, no At", at(other, time.Time{}, false, false), ActTake, ReasonMarker, time.Time{}},
{"settled, no At", at(other, time.Time{}, false, true), ActTake, ReasonMarker, time.Time{}},
+ {"unclean, finalized (files only)", func() Marker { m := at(other, now, false, false); m.Finalized = true; return m }(), ActTake, ReasonMarker, time.Time{}},
} {
d := DecideAcquire(view(c.m), self, now, term, p)
if d.Action != c.action || d.Reason != c.reason || !d.Until.Equal(c.until) {
diff --git a/internal/hafresh/lock.go b/internal/hafresh/lock.go
index a04b46801..2cc57624d 100644
--- a/internal/hafresh/lock.go
+++ b/internal/hafresh/lock.go
@@ -36,17 +36,27 @@ type Marker struct {
At time.Time `json:"at"`
Clean bool `json:"clean"`
Settled bool `json:"settled,omitempty"`
+ // Finalized says the release's replica finalization (final sync and
+ // store close) and its final files commit both succeeded: the marker is
+ // unclean only for a reason that left no storage write outstanding (a
+ // files tree that could not be published completely, a local release
+ // record that could not be written). Its storage exposure is then a
+ // clean marker's, and it opens at once like one (2026-11-12 follow-up:
+ // files objects are create-only and the manifest moves by CAS, so a
+ // files-only release cannot collide the way an L0 can).
+ Finalized bool `json:"finalized,omitempty"`
}
// MarkerOpensAt is when m lets another holder take the lock, for a lease
-// term of term: at once (the zero time) when m is clean or settled;
+// term of term: at once (the zero time) when m is clean, settled or
+// finalized;
// otherwise At plus term, the same margin an expired lock gives a write
// its dead owner already sent (N-HA9). At is written after the holder's
// finalization, so every replica request it sent was sent before At.
// Every marker the lease package writes carries an At (releaseWithMarker
// stamps it); one without reads as written at the zero time, long open.
func MarkerOpensAt(m Marker, term time.Duration) time.Time {
- if m.Clean || m.Settled || m.At.IsZero() {
+ if m.Clean || m.Settled || m.Finalized || m.At.IsZero() {
return time.Time{}
}
return m.At.Add(term)
diff --git a/internal/lease/release.go b/internal/lease/release.go
index ffc43c1e1..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)
}
@@ -285,7 +285,9 @@ func (r *Replicator) finalize(ctx context.Context, sync, snapshot bool) (uint64,
// It finalizes first (waiting for a Finish already running) if Finish has
// not run. The TXID is always the finalization's, and a marker is clean
// only if m says so and the finalization succeeded. It is never settled,
-// whatever m says (hafresh.Marker.Settled). Otherwise the marker written
+// whatever m says (hafresh.Marker.Settled), and finalized only if m says
+// so (the caller's files commit succeeded) and the finalization did too
+// (hafresh.Marker.Finalized). Otherwise the marker written
// is m: pool withdrawal compares it with the local release record built
// from the same m. A failure is a persisted *ObligationError.
func (r *Replicator) ReleaseMarker(ctx context.Context, m hafresh.Marker) error {
@@ -304,7 +306,7 @@ func (r *Replicator) ReleaseMarker(ctx context.Context, m hafresh.Marker) error
m.TXID = txid
m.Settled = false
if err != nil {
- m.Clean = false
+ m.Clean, m.Finalized = false, false
}
return releaseWithMarker(ctx, r.leaser, r.region, r.rn.stop(), m)
}
diff --git a/internal/lease/unclean_marker_test.go b/internal/lease/unclean_marker_test.go
index a15da3c35..8ebbc57d5 100644
--- a/internal/lease/unclean_marker_test.go
+++ b/internal/lease/unclean_marker_test.go
@@ -66,13 +66,22 @@ func TestCleanAndNeverReplicatedMarkersAreTakenAtOnce(t *testing.T) {
t.Fatal(err)
}
},
+ "unclean, finalized (files only)": func(t *testing.T, fx *locktest.LockFixture, prefix string) {
+ r := haReplicatorTTL(t, fx, prefix, ttl)
+ if _, err := r.Finish(ctx); err != nil {
+ t.Fatal(err)
+ }
+ if err := r.ReleaseMarker(ctx, hafresh.Marker{V: 1, Finalized: true}); err != nil {
+ t.Fatal(err)
+ }
+ },
} {
t.Run(name, func(t *testing.T) {
haBox(t)
fx := locktest.NewLockFixture(t)
release(t, fx, "instances/h")
m := lockView(t, fx, "instances/h").Lock.Release
- if m == nil || !(m.Clean || m.Settled) || m.At.IsZero() {
+ if m == nil || !(m.Clean || m.Settled || m.Finalized) || m.At.IsZero() {
t.Fatalf("marker %+v: want clean or settled, with its time", m)
}
boxB()
@@ -110,20 +119,20 @@ func TestReplicatedUncleanMarkersAreNotSettled(t *testing.T) {
t.Fatal(err)
}
},
- "abandoned": func(t *testing.T, fx *locktest.LockFixture, prefix string) {
+ "abandoned, claiming clean and finalized": func(t *testing.T, fx *locktest.LockFixture, prefix string) {
r := haReplicatorTTL(t, fx, prefix, ttl)
r.Abandon(ctx)
- if err := r.ReleaseMarker(ctx, hafresh.Marker{V: 1, Clean: true}); err != nil {
+ if err := r.ReleaseMarker(ctx, hafresh.Marker{V: 1, Clean: true, Finalized: true}); err != nil {
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)
}
},
@@ -134,8 +143,8 @@ func TestReplicatedUncleanMarkersAreNotSettled(t *testing.T) {
release(t, fx, "instances/h")
v := lockView(t, fx, "instances/h")
m := v.Lock.Release
- if m == nil || m.Clean || m.Settled || m.At.IsZero() {
- t.Fatalf("marker %+v: want unclean, not settled, with its time", m)
+ if m == nil || m.Clean || m.Settled || m.Finalized || m.At.IsZero() {
+ t.Fatalf("marker %+v: want unclean, not settled, not finalized, with its time", m)
}
boxB()
_, err := acquireAsB(fx, "instances/h", ttl)
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 0c07a0be7..0071eacfe 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -198,3 +198,4 @@ plan14-root-reads-stateless-replicas-4-drill3.tsv d0773df1895af8ab5e402e9caceb90
plan14-root-reads-stateless-replicas-4-r28.tsv 55d66980f8db645c762b56e20b5eabba09d8e1f2ab79de5e089ff087ad677bc3
plan14-root-reads-stateless-replicas-4-merge-main3.tsv 55d66980f8db645c762b56e20b5eabba09d8e1f2ab79de5e089ff087ad677bc3
plan14-root-reads-ha-unclean-marker-waits.tsv 821598970e60a776d4a62138d5adbfa393cd30bc1ec1f266d290e5b6d4e12c42
+plan14-root-reads-ha-unclean-files-only.tsv bc138ce5435f3ab37f6adff46656eea1c20f48168c569550fe94e390c69ba309
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
new file mode 100644
index 000000000..b3d983fec
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-ha-unclean-files-only.tsv
@@ -0,0 +1,7 @@
+# Census overlay ha-unclean-files-only, written by census-propose (#369). census-ruling-ha-unclean-files-only, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-ha-unclean-files-only.md.
+# 1 body, 0 sites, 3 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@legacy 29acf7650de6bddd49fb9516618950e21be6ad9bf7c143fe989e9b7acbfef166 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
+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 1404400a7f954f5674b3c792faba6038b443382fd4127ce9dd0115a8ae161b5c
diff --git a/internal/sim/regionha/actions_test.go b/internal/sim/regionha/actions_test.go
index 082b1dfbd..ab522e429 100644
--- a/internal/sim/regionha/actions_test.go
+++ b/internal/sim/regionha/actions_test.go
@@ -581,7 +581,7 @@ func (w *world) tryRelease(b *box, h string) {
gen, complete := w.stopAndFinal(b, h, e, o.FinalIncomplete)
txid, synced := w.finish(b, h, e, o.SyncFails)
m := base
- m.TXID, m.FilesGen, m.Clean = txid, gen, complete && synced
+ m.TXID, m.FilesGen, m.Clean, m.Finalized = txid, gen, complete && synced, synced
w.writeRecord(l, m)
w.putMarker(b, h, e, m, o.MarkerFails)
delete(b.Entries, h)