You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b6d266e
Browse filesBrowse the repository at this point in the historyBrowse files
committed
fix(signals): store twins of the lane-authority fixes; late readers of a hold re-derive at the commit (#3330, #3331)
Every rule pinned for signals in #3335/#3334/#3330/#3331 is pinned against
the equivalent optimistic-store shape (tests/store/lane-authority-twins).
#3335 and #3334 already held; #3330 and #3331 did not.
#3330 store twin: an adoption under a live transaction now holds on
optimistic families too — a sync derive adopting truth under the action's
transaction is held truth, not lane business; unheld, handlers read the
swapped-in backing early, latest() inverted, and the optimistic write
compared equal to it and wrote no override. `notifyOptimisticWrites` judges
the write against the view readers see (`heldMaskView(t) ?? t.v`). A held
adoption notifies its nodes at the outermost setter exit
(`stageHeldAdoptions`), staged under the transaction, so the commit promotes
silently instead of delivering the adopted values as fresh writes that
re-ran every subscriber against a frame the lane had already published.
Plain-store reconcile inside an action holds the same way; a key first read
under a held adoption is born holding (one `stageHeldKey` with the #3336
fold case: committed from the view readers see, the held value staged).
#3331 store twin: the authoritative landing on an override-covered node
(setSignal under projectionWriteActive) dispatches to the engine
(`_landOnOverride` → supersedeOverride) instead of staging silently on the
plain path; `supersededRead` serves the committed truth once a mainline
landing has committed ahead of the override's revert.
Core, surfaced by the store twin and reproduced with a plain signal: a
reader that first links to a node while another transaction holds a staged
write read the committed value and never learned of the commit (commits are
silent; the staging walk was the notification). `heldFromStale` records such
readers for the transaction's commit replay, skipping effects the
transaction itself computed (parked run / contested re-derive) — replaying
those published the frame twice.
On the A28 write path the async landing's supersession decision runs at
the write's promotion (promoteUnflushed's override arm hands the node to
supersedeOverride, still under the flight's provenance). A settle that
reverts optimism re-derives its contested effects (#3322) after the revert,
with the gated replay: ahead of the heap run the truth is committed but the
overrides still display, and the re-derive composed the two — the #3164
tear, surfaced by deep() over an optimistic store whose held adoption the
committing transaction's own readers see. Core floor 22,252 → 22,638
(conscious).
Co-authored-by: Claude via Cursor <[email protected]>
Co-authored-by: Cursor <[email protected]>
Store twins of the lane-authority fixes. An optimistic store's optimistic write after a `yield` now reveals on its lane with its derivations when the action's transaction already holds the same truth (#3330 store twin): adoptions under a live transaction hold on optimistic families too, a held adoption notifies its nodes at write time so the commit promotes silently instead of re-running every subscriber, and a tentative write is judged against the view readers see rather than the swapped-in backing. A derived optimistic store's own truth landing a different value over a tentative edit supersedes the override for the graph now, with action provenance (#3331 store twin): the authoritative landing reaches the engine's supersession, and a tracked reader of a superseded node reads the committed truth once the landing has committed ahead of the override's revert. Surfaced alongside and fixed in core: a reader that first links to a node while another transaction holds a staged write (an effect created during the hold, a store key first read under it) read the committed value but never learned of the commit — such readers now re-derive when the transaction reveals. Plain-store `reconcile` inside an action, and store keys first read under a held adoption, hold like every other write: handlers read committed, `latest()` the staged value, and the reveal comes with the transaction.
Copy file name to clipboardExpand all lines: packages/signals/docs/INTERNALS-ASYNC-STATE.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,6 +68,15 @@ Semantics of the `(_pendingValue, _overrideValue)` pair for an optimistic node
68
68
refetch landing after a later action's override on the same node — the two transactions have
69
69
merged, so `_overrideOwner` cannot tell them apart) and returns before setting the bit: staged,
70
70
held to the commit, unobservable. `origin === 0` (mainline) is never stale.
71
+
**Store twin:** a derived optimistic store's truth lands on its nodes through `setSignal`
72
+
under `projectionWriteActive` (the authoritative posture); on an override-covered node that
73
+
dispatches to `GlobalQueue._landOnOverride` (optimistic.ts) — stage the truth whatever its
74
+
relation to the committed value (a landing equal to committed still differs from the override),
75
+
sync companions, then `supersedeOverride`. `supersededRead` serves the truth staged OR committed:
76
+
a mainline landing commits at the head of its flush, ahead of the heap run, and the override
77
+
drops only at the batch's end — in that window the graph must not fall back to the override it
78
+
has left (the store's async-derive landing reaches it; a node's `asyncWrite` rides its flight's
79
+
transaction and never does). Pinned in `tests/store/lane-authority-twins.test.ts`.
71
80
72
81
## 2. Lanes (`lanes.ts`)
73
82
@@ -76,6 +85,7 @@ Semantics of the `(_pendingValue, _overrideValue)` pair for an optimistic node
76
85
- Lane lifecycle: created on optimistic write → nodes join via `insertSubs(node, true)` → `assignOrMergeLane` → lane-routed effects run when the lane is not held (`runLaneEffects` → `laneHeld`) → cleaned up by `cleanupCompletedLanes` when the owning transition completes (or when orphaned, `_transition === null`).
77
86
-`_pendingAsync` add/delete sites: added in `recompute`'s async catch under a lane (core.ts ~264), removed on async resolution (`asyncWrite`, async.ts ~214) and on lane-corrected recompute (core.ts ~254). The set records the async the lane _owns_, not what holds it.
78
87
- Replay gating (#3330): `laneReadsCommitted` hands a lane reader the committed `_value` of a staged node and records the reader in the batch's `_gatedSubs` for a re-run at commit — only when `_pendingValue !== _value`. A lane recompute that already published the value (INV-11) leaves the two equal; recording the reader anyway replayed its effects against an unchanged frame.
88
+
- Late readers of a transaction hold (#3330 store twin → general): the stale-reader term of `read()`'s value selections (`heldFromStale`, core.ts — the fast paths and the slow path) serves a render effect the committed `_value` of a node another live transaction staged, and records the reader in that transaction's `_gatedSubs`. The commit is silent (the staging walk was the notification), so a reader that linked after the walk — an effect created during the hold, a store key first read under it — would otherwise show the old value past the reveal. An effect the transaction itself computed (`_valueTransition` resolves to it) is not recorded: it re-derives at the commit through its parked run or the contested re-derive (#3322), and a replay would publish the frame twice. Pinned in `tests/spec-async-semantics.test.ts` ("a reader that links to a held node during the hold").
79
89
- Hold rule (`laneHeld`, #3289; per-node lookup #3335): a lane is held iff some `_pendingAsync` node is in the `_asyncReporters` of **any live transaction** (`waitingTransition(node) !== null`) — i.e. a render effect observed it pending and no boundary consumed the status (INV-3, the one registration site). Not "its transaction's": lanes merge across transactions (#2912) and the merged root's transaction recorded only one member's observations. Same rule as `transitionComplete`: unrendered async and fallback-caught async hold nothing. The two facts arrive in either order (a node created by the lane's own reveal is observed first and stamped on a later re-ask), which is why the hold is a predicate over both records rather than a registration.
80
90
81
91
## 3. Transitions (`scheduler.ts`)
@@ -86,7 +96,7 @@ Semantics of the `(_pendingValue, _overrideValue)` pair for an optimistic node
86
96
-`_pendingNodes` — nodes whose `_pendingValue` commits when the transition completes (`commitPendingNodes` → `commitPendingNode`).
87
97
-`_optimisticNodes` — nodes whose override reverts at completion (`resolveOptimisticNodes`).
88
98
- Incomplete-transition flush stashes queues (`stashQueues`) and continues with a fresh view; completion restores them, commits pending, reverts optimistic, replays `_gatedSubs`, cleans lanes.
89
-
- `_contested` — effects whose single value slot was written under this transaction and then overwritten by another live transaction or by mainline (#3322). Effects are not shared state, so a shared effect never merges transactions (memos do, via their `_transition` stamp); instead `Effect._valueTransition` records which view produced `_value`, `recompute`, when that owner changes, registers the effect on every owed live transaction, and `finalizePureQueue` re-dirties them **before** its heap run so the re-derive and the effect phase land in the same pass — the other view's value is never published. Rules that fall out: a stale (render) reader with no transaction active is mainline and sees a foreign transaction's staged signal as committed (`read`'s fast path and `readNodeFast` apply `stale && el._transition !== null`, matching the slow path); a value computed mainline needs no protection (mainline publishes what it computes, and a transaction whose writes never touched the effect finds it still correct at commit).
99
+
- `_contested` — effects whose single value slot was written under this transaction and then overwritten by another live transaction or by mainline (#3322). Effects are not shared state, so a shared effect never merges transactions (memos do, via their `_transition` stamp); instead `Effect._valueTransition` records which view produced `_value`, `recompute`, when that owner changes, registers the effect on every owed live transaction, and `finalizePureQueue` re-dirties them **before** its heap run so the re-derive and the effect phase land in the same pass — the other view's value is never published. Exception: a settle that reverts optimism (a non-empty `_optimisticNodes`) re-dirties them **after** `_resolveOptimistic`, with the gated replay — between `commitPendingNodes` and the revert the truth is committed but the overrides still display, and a re-derive there composes the two (the #3164 tear; the reveal wake sits post-revert for the same reason). The slot meanwhile holds the frame already on screen, so nothing new is published early. Rules that fall out: a stale (render) reader with no transaction active is mainline and sees a foreign transaction's staged signal as committed (`read`'s fast path and `readNodeFast` apply `stale && el._transition !== null`, matching the slow path); a value computed mainline needs no protection (mainline publishes what it computes, and a transaction whose writes never touched the effect finds it still correct at commit).
90
100
- Finalize re-entry (#3319): `finalizePureQueue` can _enter_ a held transaction partway through — a store commit hook (`bumpDeep` on a node the transaction owns), a boundary `_checkSources` write, or a stamped recompute in its heap — and `initTransition` then adopts the batch being finalized. Two rules keep that consistent. **State:** finalize captures the batch it started with and, if `currentBatch` changed, commits/reverts nothing batch-derived (the entered transaction owns it now); a _completing_ transaction whose ambient batch was separate (the #2916 shape) still settles its own containers, since adoption never touched them. **Effects:** ownership. A run applies with the commit of the transaction that computed its value (`Effect._valueTransition`). The ordinary effect phase runs with `activeTransition` set only in a flush whose finalize entered one, so `runEffect` leaves runs owned by a still-held transaction queued — `_modified` stays set — for the next gate to stash with the owner, while everything computed mainline (the write that caused the flush) applies now. Lanes are exempt by construction: they apply their own effects ahead of their transaction (the optimistic view) and their runner ORs `LANE_RUN` into the `type` it passes; the creation-time immediate run in `effect()` passes it too. The exemption is keyed on the _effect_ still having a lane, not on the runner: after a supersession demotes the cascade (#3331, §1), a `LANE_RUN` runner reaching a now lane-less effect whose value was computed under a still-held transaction leaves it queued like any owned run — otherwise the lane would apply the corrected derivation ahead of the commit that is supposed to reveal it. Known residue: writes staged by a hook _before_ the entry are adopted (held) and, because finalize's heap runs after its hooks, their dependents recompute owner-stamped and park with them; an entry that happens _inside_ that heap can leave an earlier mainline-computed effect applied over an adopted source — narrow, and inherited from adoption rather than from this rule.
91
101
-`transitionComplete`: prunes dead reporters (`reporterBlocksSource`), transition is done when no live reporter still blocks a pending source and no active-override node is blocked on someone else's async.
92
102
- Reveal-hold (#3305, #3334): a render reader landing on a node with `STATUS_PENDING`**throws regardless of the node's `_transition` stamp** (`read`'s pending branch has no stale/foreign-transaction carve-out). The staged-_value_ rule above is separate and stands: a stale mainline reader sees a foreign transaction's staged signal as committed, but an in-flight async is never served as its pre-flight value — the stamp is pending-node bookkeeping and does not mean that transaction also holds the flight's inputs (they may be committed, lane-revealed, or held only by another reveal waiting on the same flight). The throw reaches `GlobalQueue.notify`, which opens a transaction for the reveal if none is active (#3305) and records the source as its reporter (INV-3); the reveal completes when the flight lands.
0 commit comments