fix(signals): a projection's leaf companions die with the projection; latest() of a dead leaf creates none (spec O5) - #3505
Merged
Conversation
… latest() of a dead leaf creates none (spec O5, INV-4) Disposing a store whose async source was mid-refetch left the latest() shadow of a leaf orphaned: never derived (its compute read through the projection in flight, the backfilled override stood in), its override dropped at the settle, NotReady/uninitialized forever against a leaf whose committed value differed — INV-4 at the next quiescence. Externally coherent (latest() fell back to the committed value), but a companion outliving its source, which is what INV-9's rationale forbids. The disposal snap covered the disposed computed's own companions only; a projection's leaves hang off the firewall, not the child chain. Two parts: - disposeChildren(self) snaps the companions of the firewall's _companionChildren (the set markFirewallChildCompanions maintains, #3038); snapCompanionsToState retires a shadow whose owner's firewall is disposed — a disposed shadow reads as absent, a later read recreates it from the committed view. The isPending signal snaps as the owner's does. - latestRead of a leaf whose firewall is disposed serves the committed value and creates no shadow: a boundary's content re-running after the teardown recreated one that no teardown would ever retire. That recreated shadow was the posture matrix's actual trigger. Surfaced once #3495 stopped leaking parked transactions, which had kept `transitions.size > 0` and masked every __TEST__ quiescence check in the matrix. All 621 matrix cells run with zero invariant violations; the two excluded cells are back. Pin flipped from it.fails and extended with the post-disposal read. +104 B minified (owner.ts, core floor); five brotli caps +13…+43 B. Co-authored-by: Claude via Cursor <noreply@cursor.com> Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: c827758 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Coverage Report for CI Build 35171726315Coverage remained the same at 71.46%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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 spec O5 (the INV-4 surfaced by #3495).
Bug
Disposing a store whose async source was mid-refetch left the
latest()shadow of a leaf orphaned. The shadow had never derived a value — its compute reads through the projection in flight (NotReady), so the backfilled override stood in — and the settle after disposal dropped the override, leaving it NotReady/uninitialized forever against a leaf whose committed value differed. The__TEST__quiescence invariant INV-4 fired on the next flush. Externally coherent (latest()fell back to the committed value), but a companion outliving its source is exactly what INV-9's rationale forbids.Why it was invisible until now: the posture matrix had been leaking parked transactions (the bug #3495 fixed), which kept
transitions.size > 0and silenced every quiescence check for the rest of each run.Fix — two parts, found in two rounds
disposeChildren(self)now snaps the companions of the firewall's_companionChildren(the setmarkFirewallChildCompanionsalready maintains, 2.0.0-rc.1 | flush cost scales with total materialized store signals (async-companion walk in sync-only apps) #3038), andsnapCompanionsToStatedisposes a shadow whose owner's firewall is disposed — a disposed shadow reads as absent, so a later read recreates it from the committed view. The isPending signal snaps as the owner's own does.owner.tsgets one line; the logic lives inverdict.ts, outside the core floor.latest()of a dead leaf creates nothing. With (1) alone the standalone pin passed but the matrix still tripped: tagging shadows by creating cell showed the orphan was a second shadow, created bylatest()inside boundary content re-running after the projection's teardown — nothing would ever retire it.latestReadnow serves the committed value for a leaf whose firewall is disposed (a read of a disposed node freezes at its last commit, 2.0.0-rc.1 | signal source function revaluates when derived from a component prop - on component cleanup #3024).Gate
it.fails, extended with the post-disposal read (tests/inv4-projection-dispose-shadow.test.ts).owner.ts, core floor); five brotli caps +13…+43 B.