Skip to content

Commit c66cf6a

Browse files
ryansolidClaude via Cursorcursoragent
committed
fix(signals): lanes stage — an optimistic derivation is an override (#3479 review)
A lane pass on a memo publishes its speculative result into the override slot (`laneOverride`, CONFIG_DERIVED_OVERRIDE) instead of direct-committing `_value`, so the committed view a reader off the lane is served (#3460) is a whole frame: the held source and its derivations together, never a committed shadow beside a speculative memo (gabbev's fuzzer, latest cohort: 57 -> 5 published-derivation disagreements, torn tuples to an effect 26 -> 0). - Off the lane is provenance, not membership: a pass under the lane's own transaction (its async's landing re-entering it) is the lane's work — the `1:0` frame of an optimistic value that never finished preparing. - The revert PROMOTES a derived override the truth confirmed instead of re-deriving (no re-ask waterfall after the reveal); a superseded one drops. - A derived override is a plain member: merges lanes through itself, does not stop pending propagation, suspends its lane readers on its re-ask, is skipped by body-end supersession and the authoritative-blockage census, carries no `_overrideTime` or provenance stamp, is no acknowledgement to the hold census. - Every pass over a live lane member carrying a derived override is the lane's pass, whatever channel dirtied it (a boundary reset re-running a lane-born memo read its re-derived lane view as a differing truth and demoted the lane; fuzzer latest-1 #2481). A fresh lane publish clears a supersession in force. Pins in tests/lane-outside-view.test.ts; A17 and INV-11 amended; size caps ratcheted (isPending/latest 11.90 -> 12.05, store app 29.60 -> 29.75, hydrating 19.60 -> 19.70 KB). Co-authored-by: Claude via Cursor <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 078078a commit c66cf6a

14 files changed

Lines changed: 448 additions & 78 deletions

‎.changeset/hold-consistency-batch-2.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Five hold-consistency fixes (#3456, #3458, #3460, #3463, #3469)
66

77
- #3456: a pass that re-parks on a new pending source set retires the sources it stopped carrying from its dependents, so a conditional whose async branch was cancelled no longer stays pending forever on a flight it has no path to.
88
- #3458: a stale render reader that is a flight's first observer registers the flight with the transaction it reveals a reader of (INV-3, via the reader's queue chain), so the transaction waits for it instead of revealing its other inputs beside the reader's pre-flight value.
9-
- #3460: lanes mirror transitions from the outside — a render effect off a held lane (mounted mid-hold, or re-run by an unrelated sync write) is served the committed value, publishes at once, entangles nothing, and re-runs at the lane's release; `latest()` and `createOptimistic` sources alike. Only direct reads return the override while the lane holds.
9+
- #3460: lanes mirror transitions from the outside — a render effect off a held lane (mounted mid-hold, or re-run by an unrelated sync write) is served the committed value, publishes at once, entangles nothing, and re-runs at the lane's release; `latest()` and `createOptimistic` sources alike. Only direct reads return the override while the lane holds. Off the lane is provenance, not membership: a pass under the lane's own transaction (its async's landing) is the lane's work.
10+
- Lanes stage (#3479 review): an optimistic derivation is an override. A lane pass on a memo publishes its speculative result as a _derived override_ instead of direct-committing `_value`, so the committed view an outsider sees is a whole frame — the held source and its derivations together, never a committed shadow beside a speculative memo. The revert promotes a derived override the truth confirmed (no re-ask waterfall) and re-derives one it superseded.
1011
- #3463: a reader whose removal is staged in a live transaction (a zombie) is still on screen and keeps holding until the commit that disposes it; it is moot only for that transaction's own verdict.
1112
- #3469 (A30): a pass that changed nothing replaced nothing either — its dependency trim waits on the flush's verdict (`heldTrims`), so a same-value branch switch under a hold still follows its committed inputs.

‎packages/signals/docs/INTERNALS-ASYNC-STATE.md‎

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,48 @@ Confidence: **high** = implementation self-consistency, assert now.
196196
verdict `true` forever (the declared-motion analogue of the INV-9 latch).
197197
- **INV-11 (high, structural — pinned, not asserted)** A recompute's equality
198198
gate compares the new result against the slot it is about to publish to:
199-
the override for an override-covered node, `_value` for a lane (OPT-dirty)
200-
direct commit, `_pendingValue` for a transaction-staged run. "Unchanged" is
199+
the override for an override-covered node (a written one, or the derived
200+
one a previous lane pass left — `CONFIG_DERIVED_OVERRIDE`, #3479), `_value`
201+
for a lane pass's FIRST publish (no override yet: the compare is against the
202+
committed value the override will shadow) and for an effect's or a
203+
reversion pass's direct commit, `_pendingValue` for a transaction-staged
204+
run. **Lanes stage (#3479):** a lane pass on a memo no longer direct-commits
205+
`_value`; it publishes into the override slot (`laneOverride`), so the
206+
committed view an outsider is served (`readsHeldCommitted`) is a whole frame
207+
— the source's shadow and its derivations — and the lane's own view is the
208+
override end to end. The reversion pass (OPT-dirty with no live lane, the
209+
override dropped) and an effect's lane pass still direct-commit. "Unchanged" is
201210
a statement about what the publishing view will show, so comparing against
202211
a different view produces torn frames: #3330 compared a lane recompute
203212
against a `_pendingValue` an earlier action write had staged, called the
204213
identical result unchanged, and revealed the override without its
205214
derivation. Pinned in `tests/spec-async-semantics.test.ts` (A17, #3330);
206215
not a runtime assertion because the publishing slot is decided inside the
207-
same branch that compares. Corollary (#3377): a lane direct commit also
208-
_retires_ the transaction-staged `_pendingValue` it supersedes, override
209-
or not — a node that adopted the lane through its deps (a `latest()` read;
210-
the companion is an optimistic node) may have staged a hold on an earlier,
216+
same branch that compares. Corollary (#3377): a lane pass also _retires_
217+
the transaction-staged `_pendingValue` it supersedes, override or not — a
218+
node that adopted the lane through its deps (a `latest()` read; the
219+
companion is an optimistic node) may have staged a hold on an earlier,
211220
lane-free pass of the same transaction, and left in place that older frame
212-
commits over the fresh `_value`.
221+
commits over the fresh one. Derived-override lifecycle (#3479): joins the
222+
lane's transaction's `_optimisticNodes` on its first publish (the ambient
223+
batch would revert an async landing's at its own end); reverts with it —
224+
_promoted_ to `_value` when not superseded (sources revert before their
225+
derivations in that list, and a source whose truth differs dirties them, so
226+
a derivation the revert did not dirty is what the truth yields), dropped
227+
when superseded (the truth is staged); the slot disarms to `undefined` for
228+
a plain memo and stays `NOT_PENDING` for a written node the lane corrected.
229+
Demoted by its source's supersession (A18), its plain re-derivation runs
230+
the sync twin and its landing takes `asyncWrite`'s hold-and-supersede
231+
branch (never the plain `setSignal`, which would read the armed slot as a
232+
fresh optimistic write and open a lane with the memo as source). Until then,
233+
_every_ pass over it is the lane's pass, whatever channel dirtied it
234+
(`recompute`'s derived-override branch): it is still a member, its inputs
235+
serve the lane's view, and its result is the lane's — run plain, the sync
236+
twin read a re-derived lane view (a fresh tuple) as a differing truth,
237+
superseded and demoted, and the lane's next pass dropped that staged
238+
"truth" and left the flag pointing at a `_value` never committed (fuzzer
239+
latest-1 #2481: a boundary reset re-ran a lane-born memo). A fresh lane
240+
publish clears `CONFIG_OVERRIDE_SUPERSEDED` for the same reason.
213241

214242
Rejected for assertion (state space too dynamic, would need semantic rulings):
215243
whether `_optimisticLane` must always resolve to a live lane (stale lanes are

0 commit comments

Comments
 (0)