Repository navigation
Description
This issue was originally filed as "the coverage gate has no liveness guarantee". That framing is SUPERSEDED — see Root cause below. The gate is correct; it is being lied to by a leaked counter. The original analysis (per-page
recLSNrefinement, the three correctness gaps in it, the rules/TLA+ impact) is preserved at the bottom because it remains valid as an assessment of that refinement — it is simply not the fix for this bug.
Symptom
WAL grows without bound until the process dies. No segment is ever recycled.
CHECKPT running True checkpoints 40 segments recycled 0 pages written 8866 consecutive gated cycles 40
WAL: 22 GB across 86 segments after ~4 min — perfectly linear, nothing reclaimed
A ~10 minute interactive run died with:
Typhon.Engine.WalBackPressureTimeoutException: WAL back-pressure timeout after 30010ms waiting for 130696 bytes
at WalCommitBuffer.TryClaim (WalCommitBuffer.cs:497)
at DurabilityLog.AppendFenceBlocks (DurabilityLog.cs:54)
at DatabaseEngine.FinalizeArchetypeFence (DatabaseEngine.TickFence.cs:823)
Root cause — a leaked ActiveChunkWriters, in the migration path
The coverage gate at CheckpointManager.cs:462 skips any page whose ActiveChunkWriters != 0 (PagedMMF.cs:2081) and gates the whole cycle if even one page is skipped. That behaviour is correct. The defect is that ACW never returns to zero on pages touched by cluster migration.
Measured, with the workload quiescent — tick loop finished, no transaction open, nothing running:
skipped 458 repeated-from-previous-cycle 450 longest single-page streak 40
causes: ACW 24738 writer-held>100ms 0 stale-counter 0
QUIESCENT non-zero ACW: 458 of 458 139:acw=1 140:acw=2 162:acw=1 163:acw=4 164:acw=3 186:acw=11
Every skipped page still holds writer registrations with nothing running. Page 186 holds eleven. Counts accumulate over the run.
Supporting evidence:
- Streak 40 of 40 cycles — no page ever came free across 40 cycles × 3 retry passes.
- Skip cause is exclusively the ACW check.
writer-held>100msandstale-counterare both zero across every run, so the seqlock mechanisms are refuted. - Per-page increment/decrement trace on one page: 210 increments, 209 decrements — net 1, exactly matching its observed quiescent
acw=1. The arithmetic closes.
Isolated to migration by A/B (identical config, only cell size changed so that one giant cell means zero migrations):
| migrations/tick | pages with quiescent ACW ≠ 0 | consecutive gated cycles | |
|---|---|---|---|
cellSize=2000 |
24 | 45 of 45 | 12 |
cellSize=200000 |
0 | 0 of 0 | 0 |
Zero migrations ⇒ zero leak ⇒ the gate opens normally and the WAL reclaims.
Call stacks registering ACW on an affected page are all under the tick fence / migration machinery:
DatabaseEngine.ExecuteMigrations · ExecuteMigrationsSlice · ProcessArchetypeFence · WriteClusterTickFence
ArchetypeClusterState.ClaimSlotInCell · TryClaimSlotInCluster · AllocateNewCluster
ArchetypeClusterState.DrainPendingClusterFinalizations
net in that trace as a pairing. Increments originate in ChunkAccessor.MarkSlotDirty; decrements in CommitChanges / Dispose / ChangeSet.FlushDeferredEvictions. The stacks differ structurally, so a signature showing inc 11 dec 0 is not itself a leak — only the total is meaningful.
Where to look
ChunkAccessor increments ACW once per dirty slot (ChunkAccessor.cs:159, guarded by _dirtyFlags), and the three release paths each clear the matching bit:
| Path | Site |
|---|---|
CommitChanges (also called from Dispose) |
ChunkAccessor.cs:281 |
EvictSlot, standalone |
ChunkAccessor.cs:522 |
EvictSlot, transaction — deferred |
ChunkAccessor.cs:509 → ChangeSet.cs:131 |
All four are balanced on inspection, so the leak is a migration path that dirties a slot through an accessor that is neither committed nor evicted — or one where the page's slot is re-pointed before the bit is cleared.
Impact
- WAL grows at the full write rate forever; the database is otherwise healthy (
datafile 120 MB against 22 GB of log). MarkReclaimablehas only two call sites, both driven byCheckpointLSN, so there is no secondary path that recovers.- No
ResourceOptionsknob changes the outcome. Triggers are the timer (CheckpointIntervalMs, default 30 000), page-cache back-pressure (DatabaseEngine.cs:1137),ForceCheckpoint, BulkLoad and shutdown — more cycles against a gate held shut by a leaked counter simply yields more gated cycles. 04-checkpoint.md:74states WAL growth "is bounded by disk monitoring + backpressure". There is no disk monitoring, and the back-pressure is a 30 s timeout that terminates the process.
Repro
cd demo/SpaceBattle
dotnet run -c Release -- --autoTicks=2000 --initialShipsPerFaction=6000 --forceCheckpointEveryTicks=50
Reports CHECKPT / SKIPS lines including the quiescent ACW read. --cellSize=200000 makes it disappear; --acwTracePage=N buckets ACW increments and decrements for one page by call stack. bin/Release/net10.0/SpaceBattle.typhon afterwards.
Diagnostics used are additive and behaviour-neutral: PagedMMF.ActiveChunkWritersOf / skip-cause counters / AcwTracePage, CheckpointManager.LastSkippedPages / RepeatSkippedPages / MaxConsecutiveSkipsForOnePage / SkipCauses.
Fix
Find and close the unbalanced increment in the migration path. That is the whole bug — with it fixed, the gate opens, segments recycle, and WAL growth is bounded.
Worth adding regardless, because this was invisible for so long:
- A liveness clause in CK-03 and an assertion or health signal when
ConsecutiveGatedCyclesexceeds a threshold. The engine already tracked the number; nothing surfaced it. - A debug-mode check that ACW returns to zero for all pages at quiesce.
- Fix
ADR-037, which documents a "WAL pressure (segments > 50 % consumed)" checkpoint trigger that is not implemented.
Superseded analysis — the per-page recLSN refinement
Retained because the assessment stands on its own merits, and because 04-checkpoint.md:75-77 specifies this refinement as future work gated on ConsecutiveGatedCycles telemetry. It would NOT have fixed this bug — min(recLSN) would freeze at the leaked pages' stamps and the WAL would still grow unbounded, just from a later start. Same for the hard-pass valve at 04-checkpoint.md:71-74, which spins waiting for ACW == 0 — a wait that never succeeds against a leak.
If the refinement is ever built, three correctness gaps in it are not addressed by the design doc:
- The stamp is not "the current LSN". PREPARE → APPEND → PUBLISH are separate and the chain lock is per-entity, so page-apply order ≠ LSN order: Tx A appends at 100 and stalls; Tx B appends at 200, publishes, dirties clean page P →
recLSN(P) = 200; A then publishes into P. Trimming to 200 deletes A's record ⇒ committed data loss. ARIES is immune because the log record is generated under the same page latch as the update; Typhon deliberately is not. The correct stamp is a low-water of appended-but-unpublished LSNs,min(LastAppendedLsn + 1, min{lsn(T) : T appended, not published})— a watermark that does not exist today. - Mandatory clamp.
min(recLSN)can exceedbarrierLsn, pushingCheckpointLSNpastDurableLsnand violating WP-01 and CK-02. Must bemin(barrierLsn, minRecLsn). BulkManifestis not page-attributable. Recovery's orphan detection needsBulkBeginretained untilBulkEndis durable; a page-derived watermark needs an explicit floormin(safeLsn, oldestOpenBulkBeginLsn).
Scope it would carry: rules CK-02/03/04, CP-11, CP-05/06, WP-01/09, BL-02, REC-04, PS-01; re-modelling rules/tla/CheckpointProtocol.tla (S1) and re-validating its BreakCoverageGate mutant; and a conflict with 06-durability.md principle #6 ("zero Wal/Lsn/Fpi identifiers in Storage/") that the invariants CI job would not catch, since it greps only for RecordFormat.
Related doc drift found while investigating
- ADR-037 documents a WAL-pressure checkpoint trigger that is not implemented.
src/Typhon.Schema.Definition/ClusterDurability.cs:31-35says FenceWal's ≤1-tick window is "nominal, not currently delivered… tracked by Recovery silently drops SV value updates for pre-existing entities (no ApplySlotToExisting) — TickFence does not deliver its documented ≤1-tick window #569" — stale;RecoveryApplier.ApplySlotToExistingexists atRecoveryApplier.cs:323citing Recovery silently drops SV value updates for pre-existing entities (no ApplySlotToExisting) — TickFence does not deliver its documented ≤1-tick window #569.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Estimate
Area
Start date
Target date
Bug status
Product
Projects
- StatusShow more project fieldsDone
Activity
[-]Checkpoint coverage gate has no liveness guarantee — WAL grows unbounded until the process dies[/-][+]Spatial cluster migration leaks ActiveChunkWriters — checkpoint gate never opens, WAL grows unbounded until the process dies[/+]nockawa commentedon Aug 15, 2026
Root cause found and fixed — one missing
usingArchetypeClusterState.DrainPendingClusterFinalizations(ArchetypeClusterState.cs:386) created twoChunkAccessors, dirtied pages through them, and never disposed either:GetChunkAddress(chunkId, dirty: true)→MarkSlotDirty→IncrementActiveChunkWriters. The release is driven only byCommitChanges/Dispose, so every drained cluster leaked one ACW on its page, permanently. That is why counts accumulated (acw=11on a page drained eleven times), why it was exclusively the migration path, and why zero migrations meant zero leak.Fix
Disposing a
defaultaccessor is safe —Disposereturns immediately when_segmentis null.How it was isolated
An outstanding-increment ledger: push the call stack on every ACW increment for one page, pop on every decrement, and print whatever survives to a quiesced end of run. The bucket-by-stack table could not pair anything (increments originate in
MarkSlotDirty, decrements inCommitChanges/Dispose/FlushDeferredEvictions— structurally different stacks), but the ledger names the site directly:Verification — same workload, 40 checkpoints, 51 migrations/tick
WAL is bounded again — segments recycle and the file count stays flat instead of climbing linearly.
Suite
5287 passed / 1 failed / 16 skippedboth with and without the fix, and the single failure is a different test each run (OverloadThrottleTests.SkippedSystem_SuccessorsStillExecutewith the fix,TickFenceSingleVersion_…AcrossAHardCrash_…on the baseline). That is the known random-victim flake band, not a regression — the victim passes 5/5 in isolation.ClusterMigrationTestsis 25/25 green.New rule + regression test
Neither CP-11 nor CP-12 required that a registration is ever released — CP-11 constrains when ACW may be observed non-zero, CP-12 when the decrement may be deferred. The conservation invariant was simply absent, which is why 5 000+ tests walked past this. Added:
CP-13: ActiveChunkWriters conservation
[fatal][silent](rules/durability.md)[VerifiesRule("CP-13")] ClusterMigrationTests.ClusterFinalization_ReleasesEveryActiveChunkWriter— spawns 24 entities in one cell, moves them all out so the source cluster empties and is drained, then assertsCountPagesWithActiveChunkWriters() == 0with nothing in flight. Quiescence is the whole trick: while a workload is running, a leaked registration is indistinguishable from a busy page.Confirmed genuine — red without the fix (
Expected: 0, But was: 1), green with it.Still open from the original report
ConsecutiveGatedCycles; nothing surfaced it, so a permanently-shut gate looked identical to a healthy one. A health downgrade or assertion past a threshold would have caught this in minutes rather than via a 22 GB WAL.ClusterDurability.cs:31-35stale Recovery silently drops SV value updates for pre-existing entities (no ApplySlotToExisting) — TickFence does not deliver its documented ≤1-tick window #569 note.#817 DrainPendingClusterFinalizations never disposed its accessors, s…
#845 #824 #837 #838 #839 #568 Five leaks, a durability guarantee that…