region HA: a files-only unclean release opens at once
Follow-up to b126ea5 (8a3d302's question). An unclean marker now 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 is exactly a clean marker's, and it opens at once like one. Files cannot collide the way an L0 can: objects are create-only (If-None-Match) at objects/<seq>-<sha256>, and the manifest moves by CAS, so a late write fails its condition or makes the successor's next commit fail loudly (ErrSuperseded); a finalized release has no commit outstanding. Replicator.ReleaseMarker clears finalized (and clean) when its finalization failed; releaseHAClean sets it from Final's error and Finish's. A host whose files are never complete keeps the drain's fast handover. Spec rev 6.8. Inventory (read-only, last marker per host, 2026-11-12): dev IE 35 prefixes, 3 unclean markers, all never-replicated G2 drill releases; flagship US 10 prefixes, 5 clean, none unclean. No host today has a files publish that never completes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8 files changed,
+52
−16
docs/superpowers/specs/2026-10-26-region-ha-without-claims-design.md+6 −5internal/activator/hadrainmove_linux_test.go+8 −0internal/activator/harelease.go+6 −1internal/hafresh/acquire_test.go+1 −0internal/hafresh/lock.go+12 −2internal/lease/release.go+4 −2internal/lease/unclean_marker_test.go+14 −5internal/sim/regionha/actions_test.go+1 −1
CI cancelled — superseded by a newer push — run details
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..218a91e90 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`); 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. |
| - 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..338992311 100644 |
| --- a/internal/activator/hadrainmove_linux_test.go |
| +++ b/internal/activator/hadrainmove_linux_test.go |
| @@ -8,6 +8,9 @@ import ( |
| "syscall" |
| "testing" |
| "time" |
| + |
| + "github.com/carlosframework/platform/internal/hafresh" |
| + "github.com/carlosframework/platform/internal/lease" |
| ) |
| // Files Final incomplete: the marker is unclean, and the drain stop says |
| @@ -24,4 +27,9 @@ 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) |
| + } |
| } |
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..d36e10a82 100644 |
| --- a/internal/lease/release.go |
| +++ b/internal/lease/release.go |
| @@ -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..d52d33616 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,10 +119,10 @@ 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) |
| } |
| }, |
| @@ -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/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) |