Repository navigation
#722 #668 The cluster visibility summary latched permanently, and its watermark had to be published before the bit - #795
Merged
Conversation
… watermark had to be published before the bit The per-cluster H1 summary lets a scan skip the per-entity EntityMap probe for a whole cluster. Its death side was a sticky bit — "has anything ever died here" — and that question can only be un-asked by a full rescan, so the bit was never cleared and a churning archetype latched onto the probe forever. The question a reader actually needs answered is not whether something died but whether every death here is already visible to it, which is a maximum rather than a boolean. ClusterMaxDiedTsn replaces ClusterAnyDied: a maximum only ever rises, so it needs no rescan to fall, and the gate recovers on its own as snapshots advance past the last death. Count()'s fast path inherits the same recovery. That change makes something load-bearing that was not before. The sticky bit denied the gate forever, which is safe by being useless; a recovering watermark can grant, and it is only correct because ReleaseSlot clears the occupancy bit at destroy commit, so a reader past the last death sees a word that already reflects it. Two callers of NoteClusterDied do not clear the bit — WAL replay, whose cleanup is deferred to the orphan sweep, and cluster migration, which sets a destination bit and releases only the source slot. Both now fold VisibilityUnknown, restoring the permanent deny the sticky flag gave for free, for exactly those two cases and nothing else. Without that, every post-recovery reader satisfies the watermark and TryCountViaOccupancy popcounts a tombstone with no per-entity probe to catch it. The summary is also now folded before the store that publishes the slot rather than after the claim returns. bornTsn is threaded into both ClaimSlot overloads, both ClaimSlotInCell overloads and TryClaimSlotInCluster, so NoteClusterBorn precedes the publishing CAS; NoteClusterDied precedes ReleaseSlot's clear. Published the other way round, a reader that sees the bit can still see a maximum predating the entity, and the gate vouches for a cluster holding an entity born after that reader's snapshot. The two directions need opposite treatment and doing the same thing to both is a bug either way: for an existing cluster the hazard is an older reader, fixed by raising first; for a freshly allocated one it is a newer reader seeing a bit whose EntityId tail and EntityMap record do not exist yet, fixed by leaving the cluster unestablished until the caller has written the slot's contents. Establishing from the sentinel is sound only on a fresh cluster, which holds exactly one entity. Chunk ids are recycled through a free list, so ResetClusterVisibility now runs at every site that frees a cluster chunk. Without it a fresh cluster inherits the previous occupant's watermarks and the fresh-cluster rule above silently does nothing. Both folds became Interlocked on the element and re-read the array reference after the CAS. Concurrent claimants fold into the same cluster — #708 records that Transient spawns commit concurrently from independent transactions — and a plain read-modify-write of a maximum loses updates, while a fold taken against an array a grower has already copied lands somewhere nobody will read again. Serialising growers against each other does not cover the second one. The growth path itself is now double-checked; no caller holds the finalize latch across it. TryCountViaOccupancy read the active-cluster list's (count, array) pair with plain loads, which CLUSTERWALK-02 forbids for a reason that needs no instruction reordering to bite: read the length-16 array, let a concurrent spawn resize and bump the count to 17, read 17, index 16. The rule requires every site to come through one reader rather than get the order right independently, so ReadActiveClusterList moved from a private static on TyphonRuntime onto ArchetypeClusterState, where it reads the fields it belongs to, and both TyphonRuntime and EcsQuery now go through it. The SoA and Path-A scans additionally acquire the occupancy word before consulting the gate, since an acquire inside the gate does not stop an earlier plain load from sinking past it. A fold guard on the destroy path is deleted rather than kept. It claimed to serve the legacy non-cluster-backed shape, but destroyClusterState is non-null only when the archetype is cluster-eligible, and every ArchetypeClusterState carries at least one segment, so one of the two accessor flags is always set and the branch was unreachable. In the genuine legacy shape destroyClusterState is null and the branch was excluded by its own first conjunct. Had it ever run it would have decoded a cluster chunk id out of a legacy record's bytes. Two new rules, CLUSTERVIS-01 and CLUSTERVIS-02, state the publication ordering and the tombstone-keeps-its-bit case. Neither was written down anywhere; both defects were found by review rather than by tests, because 5 300 tests pass with the fold on either side of the publish — both states are momentary and both settle correct. #668: two of RefreshFull's three branches were unreachable and are gone, along with the EcsView constructor that produced the only shape one of them handled, which had no callers. The surviving branch is asserted rather than selected. Dead code shaped like a fallback hides how narrow the live path is, and one of the dead branches was the correct one for cluster-backed archetypes, which is how #663 read as "correct or broken depending on whether a plan exists" when it was always broken. Closes #668. #722 keeps its remaining half — the O(changed) refresh and the test that pins it — on the membership branch.
…list [no-ut] The banner over the finalize latch enumerates every acquisition and calls itself exhaustive. It is what the next person reasons about lock order from, so a new acquisition without a line here is worse than one with a wrong line — and this change added one, behind a double-checked length compare on the visibility-array growth path. Also states what that lock does NOT buy, since serializing growers against each other is only half the fix: a fold can still land in an array a grower has already copied and is about to replace, which is why both folds re-read the array reference after their CAS. [no-ut] because this commit is comment-only — the identical logic already passed the full gate on the parent, and the run this push triggers is needed for the closing-keywords job, which reads the PR description from the event payload and so could not pick up a description fix without a new push.
This was referenced Aug 13, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #668. #722 stays open — its remaining half (the O(changed) refresh and the test that pins it) lives on the membership branch, and the
[Ignore]inSystemInputViewLivenessTestsstill cites it, correctly.Second of three splits off
feature/feat-790, after #794. This is the visibility-gate work; the occupancy-delta membership path is deliberately not here (see the last section).The sticky bit never recovered
The per-cluster H1 summary lets a scan skip the per-entity
EntityMapprobe for a whole cluster. Its death side was a sticky flag — "has anything ever died here" — and that question can only be un-asked by a full rescan, so the bit was never cleared and a churning archetype latched onto the probe forever.The question a reader actually needs answered is not whether something died but whether every death here is already visible to it — a maximum, not a boolean.
ClusterMaxDiedTsnreplacesClusterAnyDied: a maximum only rises, so it never needs a rescan to fall, and the gate recovers on its own as snapshots pass the last death.Count()'s fast path inherits the same recovery.…which made something load-bearing that wasn't
A sticky bit denies forever, which is safe by being useless. A recovering watermark can grant, and it is only correct because
ReleaseSlotclears the occupancy bit at destroy commit, so a reader past the last death sees a word that already reflects it.Two callers of
NoteClusterDiednever held that. WAL replay (ApplyDestroyToExisting, cleanup deferred to the orphan sweep) and cluster migration (sets a dst bit, releases only the src slot) both leave a set bit for a dead entity. Under the sticky flag the gate stayed shut and the per-entity probe caught it; under a plain watermark every reader past that TSN is granted, andTryCountViaOccupancypopcounts a tombstone with nothing to catch it — a permanent over-count after any recovery replaying a below-frontier destroy. Both now foldVisibilityUnknown.Fold before publish, and the two directions need opposite treatment
bornTsnis threaded into bothClaimSlotoverloads, bothClaimSlotInCelloverloads andTryClaimSlotInCluster, soNoteClusterBornprecedes the publishing CAS andNoteClusterDiedprecedesReleaseSlot's clear.Doing the same thing to both is a bug either way round. Establishing from the sentinel is sound only on a fresh cluster, which holds exactly one entity.
Chunk ids are recycled through a free list, so
ResetClusterVisibilityruns at every chunk-free site — without it a "fresh" cluster inherits the previous occupant's watermarks and the rule above silently does nothing.Both folds are now
Interlockedon the element and re-read the array reference after the CAS. Concurrent claimants fold into the same cluster (#708: Transient spawns commit concurrently), so a plain read-modify-write of a maximum loses updates; and a fold taken against an array a grower has already copied lands where nobody will read it. Serialising growers against growers does not cover the second.A rule this was violating
TryCountViaOccupancyread the active-cluster(count, array)pair with plain loads. CLUSTERWALK-02 forbids that, for a fault needing no reordering: read the length-16 array, let a concurrent spawn resize and bump the count to 17, read 17, index 16. The rule requires every site to come through one reader rather than get the order right independently — "the two sites that already loaded count-first were right by ACCIDENT".So
ReadActiveClusterListmoved from aprivate staticonTyphonRuntimeontoArchetypeClusterState, where it reads the fields it belongs to;TyphonRuntimenow delegates andEcsQuerygoes through it. The SoA and Path-A scans additionally acquire the occupancy word before consulting the gate, since an acquire inside the gate doesn't stop an earlier plain load sinking past it.Dead code removed
A destroy-path fold guard claimed to serve the legacy non-cluster shape. It was unreachable:
destroyClusterStateis non-null only when the archetype is cluster-eligible, and everyArchetypeClusterStatecarries at least one segment (a non-pure-Transient archetype throws if its cluster segment can't be allocated; a pure-Transient one hastransientSlotMask != 0by construction), so an accessor flag is always set. In the genuine legacy shapedestroyClusterStateis null and the branch was excluded by its own first conjunct. Had it run, it would have decoded a cluster chunk id out of a legacy record's bytes.#668: two of
RefreshFull's three branches were unreachable and are gone, with theEcsViewconstructor producing the only shape one of them handled — no callers. The survivor is asserted rather than selected. One of the dead branches was the correct one for cluster-backed archetypes, which is how #663 read as "correct or broken depending on whether a plan exists" when it was always broken.Rules
Two new: CLUSTERVIS-01 (publication ordering) and CLUSTERVIS-02 (a tombstone keeping its bit must deny outright). Neither was written down anywhere, and both defects were found by review, not by tests — 5 300 tests pass with the fold on either side of the publish, because both states are momentary and both settle correct. CLUSTERWALK-02's scope updated for the moved reader.
Gate
All 6 policy jobs pass · Workbench 605/605 · engine 5289/1 in Release, the failure being a
TickFenceSingleVersion_…_Crashparameterisation from the #720 flake band (different parameterisation each run, green in isolation).What is deliberately not here
The occupancy-delta membership refresh (#790). Three review rounds found ~22 correctness defects concentrated in that path, and successive fixes kept producing new ones, because it rests on two engine facts that don't hold: the active-cluster list isn't safely walkable (CLUSTERWALK-01, open), and a set occupancy bit doesn't imply a live, committed, fully-written entity. It needs a design change — running the refresh only under the tick fence's exclusion guarantee — rather than more patching.