Repository navigation
Closed
Copy link
Labels
documentationImprovements or additions to documentation
Description
Found while analysing #582. These are wrong today, independent of whether #582 lands, and one of them is why the hazard went unnoticed through a dedicated review.
Design docs / rules
| Doc | Claim | Reality |
|---|---|---|
claude/design/Runtime/10-fence-parallelisation.md:121 |
ActiveClusterIds/ActiveClusterCount "mutated under _finalizeLock … Already solved." |
Wrong three ways: the destroy path (ReleaseSlot:2544/:2582) takes no lock; the non-spatial ClaimSlot spawn path takes no lock; and no reader anywhere takes _finalizeLock, so even a fully-locked writer wouldn't make the walk safe. This is the cell that let the fence-parallelisation review conclude the hazard was handled. |
claude/rules/spatial.md:292-294 (MD-02) |
The drain path "enters per-archetype _finalizeLock exclusive section before CellClusterPool.RemoveCluster, RemoveFromActiveList, ClusterSegment.FreeChunk" |
Describes code that does not exist. Every _finalizeLock acquisition is at ArchetypeClusterState.cs:141, 213, 321, 1205, 1291, 2336 — none on the drain-finalize path. Scope also omits the caller (Transaction.ECS.cs). |
claude/design/Runtime/09-tick-pipelining.md:28 (N8), :281 |
"D's core is a parameter flip plus a drain call, not new machinery"; "Destroy just needs the flag flipped" | Refuted — see #582. N8's sub-claim that spawn's AddToActiveList is under _finalizeLock is true only for the spatial path. |
Code comments (all in src/Typhon.Engine/Ecs/internals/ArchetypeClusterState.cs)
| Site | Claim | Reality |
|---|---|---|
:2485-2488 |
"Caller owns the writer mutex … when deferFinalize = false" |
No caller does. FlushPendingDestroys takes only EpochGuard.Enter, which gates page eviction, not chunk-id recycling |
:2471-2472 |
"Safe because no concurrent claimer can CAS a slot back in" | The premise is #582 |
:46-51 |
PaddedFinalizeLock banner — the draining worker "enters the finalize section (FinaliseEmptyClusterCellState + RemoveFromActiveList + segment FreeChunk)" |
The lock is never taken on that path. Almost certainly the origin of MD-02's stale text — fix both together |
:2689-2690 |
FinaliseEmptyClusterCellState "called inside the per-archetype _finalizeLock" |
Neither caller holds it |
:2710-2711 |
ClearSlotMetadata's "last-bit-wins signal … decide which worker enters the finalize section under _finalizeLock" |
No worker enters any such section; it records a drain instead |
:310 vs :352-354 |
"re-checks occupancy under the finalize lock" vs "the per-archetype lock is unnecessary here" | Direct self-contradiction. The code takes no lock — keep one, delete the other |
:37 |
ActiveClusterIds is "clusters with occupancy > 0" |
Already false during the migrate drain window; ClusterRef.cs:504-508 documents the opposite |
:68-69 |
Capacity "pre-sized by PreSizeMigrationBuffers" |
Bounds migration-sourced drains only |
Why this is worth its own issue
Six of these comments describe a _finalizeLock-protected finalize section that does not exist anywhere in the code. They corroborate each other, which is what made the wrong model survive: a reader checking one comment against another gets consistent confirmation of a fiction. MD-02 then encoded it as a correctness rule, and 10-fence-parallelisation.md marked the hazard closed on that basis.
Fix these regardless of #582's outcome — a stale comment that asserts a lock is worse than no comment.
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentation
Type
Fields
Priority
None yet
Estimate
None yet
Area
None yet
Product
None yet
Projects
- StatusShow more project fieldsDone
Activity
#582 #623 Bug bash: 17 correctness fixes across durability, spatial, …
nockawa commentedon Aug 11, 2026
Re-verified against
main@640e1a2b(2026-08-11) — still valid. #582 is still open.The load-bearing finding is intact verbatim.
ArchetypeClusterState.csstill contradicts itself about the same lock, in two comments ~40 lines apart:RecordClusterDrain's summary: "DrainPendingClusterFinalizationsre-checks occupancy under the finalize lock and skips non-empty entries"DrainPendingClusterFinalizations' own remarks: "The occupancy re-read is therefore single-threaded and the per-archetype lock is unnecessary here" — and the body takes no lockThe
PaddedFinalizeLockbanner (:46-51) still asserts the draining worker "enters the finalize section (FinaliseEmptyClusterCellState+RemoveFromActiveList+ segmentFreeChunk)", which is the section the method above says it does not enter.rules/spatial.mdMD-02 still encodes it as a rule — "cluster-fully-drains path … enters per-archetype_finalizeLockexclusive section beforeCellClusterPool.RemoveCluster,RemoveClusterFromPerCellIndex,RemoveFromActiveList,ClusterSegment.FreeChunk" — andclaude/design/Runtime/10-fence-parallelisation.mdstill marks theActiveClusterIds/ActiveClusterCountrow "Already solved."Path correction for the fixer: the rule now lives at
rules/spatial.mdin the Typhon repo, notclaude/rules/spatial.md— rules moved in #747 and are CI-checked there (scripts/check-rule-scopes.py), so an MD-02 edit belongs in the same commit as the code/comment fix.Note the code has moved since this was filed and the issue's line numbers are stale —
_finalizeLockis now acquired at:141,:213,:321,:1410,:1496,:2541, and:2905documents a genuine "called inside the per-archetype_finalizeLock" path. So the per-site table needs re-walking line by line before editing; what is confirmed today is that the drain/finalize path the comments and MD-02 describe still does not take the lock.PR #701 did not address this — it is
doc/-only and touched neitherclaude/,rules/, norsrc/.#628 The finalize lock never guarded the finalize section (#782)