From 41b6783a950a2628cb9fe92f08eb8dfc9b69c566 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 18 Nov 2026 19:40:20 -0800 Subject: [PATCH] docs: integrate local reclaim liveness model and mutant configs --- seaweed-block/docs/design/invariants.md | 7 +- seaweed-block/docs/spec/README.md | 28 +++++ seaweed-block/docs/spec/WALReclaim.tla | 119 ++++++++++++++++++ .../docs/spec/cfg/REC_red_noClamp.cfg | 12 ++ .../docs/spec/cfg/REC_red_noInternalSync.cfg | 13 ++ .../docs/spec/cfg/REC_red_pinForever.cfg | 13 ++ .../spec/cfg/REC_red_syncTakesCapture.cfg | 13 ++ .../spec/cfg/REC_red_syncTakesCapture_big.cfg | 13 ++ seaweed-block/docs/spec/cfg/REC_safe.cfg | 13 ++ seaweed-block/docs/spec/cfg/REC_safe_big.cfg | 13 ++ .../docs/spec/cfg/REC_wit_noGuestSync.cfg | 12 ++ 11 files changed, 253 insertions(+), 3 deletions(-) create mode 100644 seaweed-block/docs/spec/WALReclaim.tla create mode 100644 seaweed-block/docs/spec/cfg/REC_red_noClamp.cfg create mode 100644 seaweed-block/docs/spec/cfg/REC_red_noInternalSync.cfg create mode 100644 seaweed-block/docs/spec/cfg/REC_red_pinForever.cfg create mode 100644 seaweed-block/docs/spec/cfg/REC_red_syncTakesCapture.cfg create mode 100644 seaweed-block/docs/spec/cfg/REC_red_syncTakesCapture_big.cfg create mode 100644 seaweed-block/docs/spec/cfg/REC_safe.cfg create mode 100644 seaweed-block/docs/spec/cfg/REC_safe_big.cfg create mode 100644 seaweed-block/docs/spec/cfg/REC_wit_noGuestSync.cfg diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index dc1a52fe32..6ee4916e12 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -283,9 +283,10 @@ snapshot lifetime; local persistence does not bypass it. `TestWALStoreV3PressureSyncFaultDoesNotPublishFrontiers`, `TestWALStoreV3PressureSyncSkipsInstalling`, `TestWALStoreV3PressureProgressWithPendingCutOrClose` and - `TestWALStoreV3PressureWaitBudgetAndPin`. Model correspondence/receipt is pending - the parallel LIGHT internal-sync/reclaim liveness review; no model PASS is - claimed by this source change. + `TestWALStoreV3PressureWaitBudgetAndPin`. Model correspondence: `WALReclaim.tla` I1/I2/I3 and + `AllWritten`/`NoStuckWaiter` in `REC_safe`/`REC_safe_big`; the no-internal-sync + mutant violates liveness. Prior authored LIGHT receipts are referenced in + `docs/spec/README.md`; this change does not claim a new TLC execution. - The v3 pressure admission budget is four seconds of cooperative waiting. It cannot preempt a blocking occupancy/closed callback, lock acquisition or physical file I/O. An unresolved pin or local stall returns diff --git a/seaweed-block/docs/spec/README.md b/seaweed-block/docs/spec/README.md index ee2a896216..0e35840f6b 100644 --- a/seaweed-block/docs/spec/README.md +++ b/seaweed-block/docs/spec/README.md @@ -274,3 +274,31 @@ Recover/reset snapshot recheck and saved-file readers are covered by the native `TestCutCOWV3_*` caller controls, not claimed as model proofs. The earlier thirteen-spec parse statement above predates this imported model; no new independent TLC/parse or cloud run is claimed here. + + +### WAL pressure progress without guest Sync + +`WALReclaim.tla` models native local pressure persistence and checkpoint/reuse +progress. `InternalSync` is weakly fair and does not take the capture lock; +`GuestSync` has no fairness requirement. `REC_safe.cfg` and `REC_safe_big.cfg` +check I1/I2/I3, ring/pin safety, `AllWritten` and `NoStuckWaiter`. Removing internal +sync (`REC_red_noInternalSync.cfg`) violates liveness; removing the durable clamp +violates I2. The capture-lock mutant and permanently held pin also violate +liveness. The Go implementation bounds a permanent pin with retryable admission +expiry rather than assuming that it always releases. + +Run, from `docs/spec`, with the existing TLC tool: + +```sh +java -cp /path/to/tla2tools.jar tlc2.TLC -deadlock -config cfg/REC_safe.cfg WALReclaim +java -cp /path/to/tla2tools.jar tlc2.TLC -deadlock -config cfg/REC_red_noInternalSync.cfg WALReclaim +``` + +The authored LIGHT receipts report exhaustive safe searches at 2,700 and 25,550 +states, plus the expected mutant/witness failures. Source and configs are copied +from the sealed `claude05-walreclaim-tla-r0-20261119` artifact with line-ending +normalization only. Those are prior author runs, not a claim that this PR reran +TLC. This is an abstraction: physical fsync success, byte layout, crash recovery, +both-slot retirement, timing and multiple writers remain covered by their other +models and actual Go controls. Do not treat finite liveness checking as an +end-to-end wall-clock latency guarantee. Keep long model runs off tp04. diff --git a/seaweed-block/docs/spec/WALReclaim.tla b/seaweed-block/docs/spec/WALReclaim.tla new file mode 100644 index 0000000000..4895234f72 --- /dev/null +++ b/seaweed-block/docs/spec/WALReclaim.tla @@ -0,0 +1,119 @@ +----------------------------- MODULE WALReclaim ----------------------------- +(***************************************************************************) +(* Liveness of v3 WAL reclaim under write pressure (claude05, 2026-11-19). *) +(* Abstracts core/storage at seaweed-block main 39f11d6a: *) +(* head = WAL head LSN (records appended) *) +(* wack = durable WAL frontier; today advanced only by Sync *) +(* (walstore_v3.go:829) *) +(* flushed = records the flusher has written to the extent *) +(* ckpt = checkpoint = reuse floor, clamped to *) +(* min(flushed, wack, session pin) *) +(* (walstore_map_checkpoint_v3.go:57-62) *) +(* A writer may append only while head - ckpt < Cap (the hard watermark). *) +(* A blocked writer waits INSIDE the capture read lock *) +(* (walstore.go:829-832, admission at :850). A cut takes the capture *) +(* write lock; Go's RWMutex makes a pending writer block new readers. *) +(* *) +(* InternalOn: the fix under review (codex03 design r0) - under pressure *) +(* the store makes its own WAL durable (wack := head) with no guest Sync. *) +(* Mut: *) +(* "none" the design *) +(* "noClamp" checkpoint ignores wack (reclaims non-durable WAL) *) +(* "syncTakesCapture" the internal sync needs the capture read lock *) +(* (finding F2) *) +(* PinFair: a catch-up session pin is eventually released (finding F3). *) +(* The guest's Sync has NO fairness: a guest may never flush. *) +(***************************************************************************) +EXTENDS Naturals + +CONSTANTS Cap, MaxLSN, MaxCuts, MaxPins, InternalOn, Mut, PinOn, PinFair + +VARIABLES head, wack, flushed, ckpt, inside, cutPending, cuts, pin, pins, gsync + +vars == <> + +Min(a, b) == IF a < b THEN a ELSE b +NoPin == MaxLSN + 1 +Full == head - ckpt >= Cap + +Init == /\ head = 0 /\ wack = 0 /\ flushed = 0 /\ ckpt = 0 + /\ inside = FALSE /\ cutPending = FALSE /\ cuts = 0 /\ pin = NoPin /\ pins = 0 /\ gsync = FALSE + +\* A writer that finds the ring full enters the admission wait holding the +\* capture read lock; it can enter only if no cut is pending. +EnterWait == /\ head < MaxLSN /\ Full /\ ~inside /\ ~cutPending + /\ inside' = TRUE + /\ UNCHANGED <> + +\* Append: a fresh writer needs the read lock (blocked by a pending cut); a +\* writer already inside the wait holds it. +Append == /\ head < MaxLSN /\ ~Full /\ (inside \/ ~cutPending) + /\ head' = head + 1 /\ inside' = FALSE + /\ UNCHANGED <> + +\* Guest Flush/Sync: may happen or never (no fairness). +GuestSync == /\ wack < head + /\ wack' = head /\ gsync' = TRUE + /\ UNCHANGED <> + +\* The fix: internal sync on pressure. In the mutant it also needs the +\* capture read lock, so it is blocked while a cut is pending. +InternalSync == /\ InternalOn /\ wack < head /\ Full + /\ (Mut = "syncTakesCapture" => ~cutPending) + /\ wack' = head + /\ UNCHANGED <> + +Flush == /\ flushed < head + /\ flushed' = flushed + 1 + /\ UNCHANGED <> + +Target == IF Mut = "noClamp" THEN Min(flushed, pin) ELSE Min(Min(flushed, wack), pin) + +Checkpoint == /\ Target > ckpt + /\ ckpt' = Target + /\ UNCHANGED <> + +\* A cut requests the capture write lock; it completes once no reader holds +\* the lock (the waiting writer is a reader). +CutStart == /\ cuts < MaxCuts /\ ~cutPending + /\ cutPending' = TRUE /\ cuts' = cuts + 1 + /\ UNCHANGED <> +CutFinish == /\ cutPending /\ ~inside + /\ cutPending' = FALSE + /\ UNCHANGED <> + +\* An RF2 catch-up session pins the WAL at the current checkpoint, later +\* releases it. +PinSet == /\ PinOn /\ pin = NoPin /\ pins < MaxPins + /\ pin' = ckpt /\ pins' = pins + 1 + /\ UNCHANGED <> +PinRelease == /\ pin # NoPin + /\ pin' = NoPin + /\ UNCHANGED <> + +Next == \/ EnterWait \/ Append \/ GuestSync \/ InternalSync \/ Flush \/ Checkpoint + \/ CutStart \/ CutFinish \/ PinSet \/ PinRelease + +Fairness == /\ WF_vars(Append) /\ WF_vars(EnterWait) /\ WF_vars(Flush) /\ WF_vars(Checkpoint) + /\ WF_vars(InternalSync) /\ WF_vars(CutFinish) + /\ (PinFair => WF_vars(PinRelease)) + +Spec == Init /\ [][Next]_vars /\ Fairness + +\* ---- safety ---- +TypeOK == /\ head \in 0..MaxLSN /\ wack \in 0..MaxLSN /\ flushed \in 0..MaxLSN + /\ ckpt \in 0..MaxLSN /\ inside \in BOOLEAN /\ cutPending \in BOOLEAN + /\ cuts \in 0..MaxCuts /\ pin \in 0..(MaxLSN + 1) /\ pins \in 0..MaxPins /\ gsync \in BOOLEAN +I1 == wack <= head \* durable frontier never ahead of the head +I2 == ckpt <= wack \* never reclaim WAL that is not durable +I3 == ckpt <= flushed \* never reclaim a record not yet in the extent +IRing == head - ckpt <= Cap \* the ring never overflows +IPin == pin # NoPin => ckpt >= pin \* a pin never moves the floor backwards (sanity) + +\* ---- witness: all writes complete with NO guest Sync (must be violated = reachable when InternalOn) ---- +W_NeedsGuestSync == ~(head = MaxLSN /\ ~gsync) + +\* ---- liveness ---- +AllWritten == <>(head = MaxLSN) \* no write stalls forever +NoStuckWaiter == [](inside => <>(~inside)) \* a waiting writer is always admitted +============================================================================= diff --git a/seaweed-block/docs/spec/cfg/REC_red_noClamp.cfg b/seaweed-block/docs/spec/cfg/REC_red_noClamp.cfg new file mode 100644 index 0000000000..4008158c3f --- /dev/null +++ b/seaweed-block/docs/spec/cfg/REC_red_noClamp.cfg @@ -0,0 +1,12 @@ +\* REC_red_noClamp +SPECIFICATION Spec +CONSTANTS + Cap = 2 + MaxLSN = 5 + MaxCuts = 2 + MaxPins = 1 + InternalOn = TRUE + Mut = "noClamp" + PinOn = TRUE + PinFair = TRUE +INVARIANT TypeOK I1 I2 I3 IRing diff --git a/seaweed-block/docs/spec/cfg/REC_red_noInternalSync.cfg b/seaweed-block/docs/spec/cfg/REC_red_noInternalSync.cfg new file mode 100644 index 0000000000..26289b082d --- /dev/null +++ b/seaweed-block/docs/spec/cfg/REC_red_noInternalSync.cfg @@ -0,0 +1,13 @@ +\* REC_red_noInternalSync +SPECIFICATION Spec +CONSTANTS + Cap = 2 + MaxLSN = 5 + MaxCuts = 2 + MaxPins = 1 + InternalOn = FALSE + Mut = "none" + PinOn = TRUE + PinFair = TRUE +INVARIANT TypeOK I1 I2 I3 IRing +PROPERTY AllWritten diff --git a/seaweed-block/docs/spec/cfg/REC_red_pinForever.cfg b/seaweed-block/docs/spec/cfg/REC_red_pinForever.cfg new file mode 100644 index 0000000000..7875a2f210 --- /dev/null +++ b/seaweed-block/docs/spec/cfg/REC_red_pinForever.cfg @@ -0,0 +1,13 @@ +\* REC_red_pinForever +SPECIFICATION Spec +CONSTANTS + Cap = 2 + MaxLSN = 5 + MaxCuts = 2 + MaxPins = 1 + InternalOn = TRUE + Mut = "none" + PinOn = TRUE + PinFair = FALSE +INVARIANT TypeOK I1 I2 I3 IRing +PROPERTY AllWritten diff --git a/seaweed-block/docs/spec/cfg/REC_red_syncTakesCapture.cfg b/seaweed-block/docs/spec/cfg/REC_red_syncTakesCapture.cfg new file mode 100644 index 0000000000..937f32efb1 --- /dev/null +++ b/seaweed-block/docs/spec/cfg/REC_red_syncTakesCapture.cfg @@ -0,0 +1,13 @@ +\* REC_red_syncTakesCapture +SPECIFICATION Spec +CONSTANTS + Cap = 2 + MaxLSN = 5 + MaxCuts = 2 + MaxPins = 1 + InternalOn = TRUE + Mut = "syncTakesCapture" + PinOn = TRUE + PinFair = TRUE +INVARIANT TypeOK I1 I2 I3 IRing +PROPERTY AllWritten diff --git a/seaweed-block/docs/spec/cfg/REC_red_syncTakesCapture_big.cfg b/seaweed-block/docs/spec/cfg/REC_red_syncTakesCapture_big.cfg new file mode 100644 index 0000000000..e8d28ae290 --- /dev/null +++ b/seaweed-block/docs/spec/cfg/REC_red_syncTakesCapture_big.cfg @@ -0,0 +1,13 @@ +\* REC_red_syncTakesCapture_big +SPECIFICATION Spec +CONSTANTS + Cap = 3 + MaxLSN = 9 + MaxCuts = 3 + MaxPins = 2 + InternalOn = TRUE + Mut = "syncTakesCapture" + PinOn = TRUE + PinFair = TRUE +INVARIANT TypeOK I1 I2 I3 IRing +PROPERTY AllWritten diff --git a/seaweed-block/docs/spec/cfg/REC_safe.cfg b/seaweed-block/docs/spec/cfg/REC_safe.cfg new file mode 100644 index 0000000000..a5b4fbb84e --- /dev/null +++ b/seaweed-block/docs/spec/cfg/REC_safe.cfg @@ -0,0 +1,13 @@ +\* REC_safe +SPECIFICATION Spec +CONSTANTS + Cap = 2 + MaxLSN = 5 + MaxCuts = 2 + MaxPins = 1 + InternalOn = TRUE + Mut = "none" + PinOn = TRUE + PinFair = TRUE +INVARIANT TypeOK I1 I2 I3 IRing IPin +PROPERTY AllWritten NoStuckWaiter diff --git a/seaweed-block/docs/spec/cfg/REC_safe_big.cfg b/seaweed-block/docs/spec/cfg/REC_safe_big.cfg new file mode 100644 index 0000000000..ea144fc132 --- /dev/null +++ b/seaweed-block/docs/spec/cfg/REC_safe_big.cfg @@ -0,0 +1,13 @@ +\* REC_safe_big +SPECIFICATION Spec +CONSTANTS + Cap = 3 + MaxLSN = 9 + MaxCuts = 3 + MaxPins = 2 + InternalOn = TRUE + Mut = "none" + PinOn = TRUE + PinFair = TRUE +INVARIANT TypeOK I1 I2 I3 IRing IPin +PROPERTY AllWritten NoStuckWaiter diff --git a/seaweed-block/docs/spec/cfg/REC_wit_noGuestSync.cfg b/seaweed-block/docs/spec/cfg/REC_wit_noGuestSync.cfg new file mode 100644 index 0000000000..7d99e37c27 --- /dev/null +++ b/seaweed-block/docs/spec/cfg/REC_wit_noGuestSync.cfg @@ -0,0 +1,12 @@ +\* REC_wit_noGuestSync +SPECIFICATION Spec +CONSTANTS + Cap = 2 + MaxLSN = 5 + MaxCuts = 2 + MaxPins = 1 + InternalOn = TRUE + Mut = "none" + PinOn = TRUE + PinFair = TRUE +INVARIANT W_NeedsGuestSync