@@ -1631,6 +1631,50 @@ export function enterStagedRead(
16311631 globalQueue . initTransition ( t ) ;
16321632}
16331633
1634+ /**
1635+ * Rule 1 (value selection), the full arm: does this reader see a STAGED
1636+ * node's COMMITTED value? One implementation of the rule the fast paths
1637+ * (readNodeFast, read's fast block) carry as their trivial ternary and that
1638+ * every slow site — read's tail, the store's backing selection, the lane and
1639+ * verdict arms — used to restate by hand (DESIGN-CONSOLIDATION, move 3b). In order:
1640+ * - no reader at all (an untracked read) — the committed frame;
1641+ * - a reader under an optimistic lane the engine says reads committed
1642+ * (laneReadsCommitted: another lane's hold, #3460);
1643+ * - nothing staged;
1644+ * - a children-forbidden reader (createTrackedEffect / onSettled: the frame,
1645+ * never the graph — A32);
1646+ * - a stale reader (render effect) of a FOREIGN transaction's staged write —
1647+ * committed, no entanglement (heldFromStale registers the replay; a node
1648+ * born held has no committed frame to fall back to, `noCommitted`);
1649+ * - A17 for HELD truth (#3164, CONFIG_HELD_TRUTH): staged confirming truth —
1650+ * fold-staged onto an armed family, or entangle-stolen by an awaited
1651+ * until() — is masked from ordinary readers until its transaction's
1652+ * reveal, the retaining transaction's own speculative recomputes included
1653+ * (partial override coverage would otherwise compose override + staged
1654+ * truth into a state no timeline contains). Authoritative readers
1655+ * (until()'s predicate) and latest() see the staged truth — the tunnel that
1656+ * keeps the hold deadlock-free.
1657+ * False means the reader derives from the staged value and enters its
1658+ * transaction (enterStagedRead, A29).
1659+ */
1660+ export function readerSeesCommitted (
1661+ el : Signal < any > | Computed < any > ,
1662+ c : Computed < any > | null ,
1663+ owner : Signal < any > | Computed < any > ,
1664+ noCommitted : boolean
1665+ ) : boolean {
1666+ return ! ! (
1667+ ! c ||
1668+ ( currentOptimisticLane !== null && GlobalQueue . _laneReadsCommitted ! ( el , owner , c ) ) ||
1669+ el . _pendingValue === NOT_PENDING ||
1670+ c . _config & CONFIG_CHILDREN_FORBIDDEN ||
1671+ ( stale && ! noCommitted && heldFromStale ( el , c ) ) ||
1672+ ( el . _config & CONFIG_HELD_TRUTH &&
1673+ ! latestReadActive &&
1674+ ! ( c . _config & CONFIG_AUTHORITATIVE_READ ) )
1675+ ) ;
1676+ }
1677+
16341678/** A28 — set when a node is staged (queuePendingNode) or a held node rewritten
16351679 * (stashHeldRewrite) OUTSIDE a flush; cleared when the next flush begins. The
16361680 * read sites test this one module boolean instead of `globalQueue._running`:
@@ -1685,6 +1729,22 @@ export function unflushedOverride(el: Signal<any> | Computed<any>): boolean {
16851729 // Companions are optimistic signals written by the engine (see unflushed).
16861730 return ! globalQueue . _running && el . _x ?. _overrideTime === clock && ! el . _x ?. _parentSource ;
16871731}
1732+ /** Active optimistic override on an armed node (an armed slot idles at
1733+ * NOT_PENDING; undefined = unarmed plain node). The writer's own channels —
1734+ * the draft, `in`/keys inside the setter — compose on this regardless of
1735+ * flush state. */
1736+ export function hasActiveOverride ( el : Signal < any > | Computed < any > ) : boolean {
1737+ const x = el . _x ;
1738+ return x !== null && x . _overrideValue !== undefined && x . _overrideValue !== NOT_PENDING ;
1739+ }
1740+ /** The override a READER sees: installed, and carried by a flush (A28 (5) —
1741+ * an optimistic write is a write; until its flush no reader sees it). One
1742+ * implementation for read()'s override arm, the verdict channels
1743+ * (latestRead, computePendingState) and the store's selection
1744+ * (DESIGN-CONSOLIDATION, move 3b). */
1745+ export function visibleOverride ( el : Signal < any > | Computed < any > ) : boolean {
1746+ return hasActiveOverride ( el ) && ! unflushedOverride ( el ) ;
1747+ }
16881748/** A derivation served the committed value because of an unflushed write
16891749 * (A28) must run again in the flush that carries it — the late-linker case
16901750 * (#3337's reason to defer the walk): it linked after the write walked. */
@@ -1933,7 +1993,7 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
19331993 nodeName : ( owner as any ) ?. _name
19341994 } ) ;
19351995
1936- if ( el . _x ?. _overrideValue !== undefined && el . _x ?. _overrideValue !== NOT_PENDING ) {
1996+ if ( hasActiveOverride ( el ) ) {
19371997 // A17: the override IS the value for every reader — except an authoritative
19381998 // reader (until()'s predicate carries CONFIG_AUTHORITATIVE_READ): it must
19391999 // observe independently-arriving truth, and serving it the caller's own
@@ -1997,26 +2057,9 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
19972057 if ( pendingCheckActive ) GlobalQueue . _recordFresh ! ( el , u ) ;
19982058 return u as T ;
19992059 }
2000- const value =
2001- ! c ||
2002- ( currentOptimisticLane !== null &&
2003- GlobalQueue . _laneReadsCommitted ! ( el , owner , c as Computed < any > ) ) ||
2004- el . _pendingValue === NOT_PENDING ||
2005- c . _config & CONFIG_CHILDREN_FORBIDDEN ||
2006- ( stale && ! noCommitted && heldFromStale ( el , c as Computed < any > ) ) ||
2007- // A17 for HELD truth (#3164, see CONFIG_HELD_TRUTH): staged confirming
2008- // truth — fold-staged onto an armed family, or entangle-stolen by an
2009- // awaited until() — is masked from ordinary readers until its
2010- // transaction's reveal; the retaining transaction's own speculative
2011- // recomputes included (partial override coverage would otherwise
2012- // compose override + staged truth into a state no timeline contains).
2013- // Authoritative readers (until()'s predicate) and latest() see the
2014- // staged truth — the tunnel that keeps the hold deadlock-free.
2015- ( el . _config & CONFIG_HELD_TRUTH &&
2016- ! latestReadActive &&
2017- ! ( ( c as Computed < any > ) . _config & CONFIG_AUTHORITATIVE_READ ) )
2018- ? el . _value
2019- : ( enterStagedRead ( el ) , el . _pendingValue as T ) ;
2060+ const value = readerSeesCommitted ( el , c as Computed < any > | null , owner , noCommitted )
2061+ ? el . _value
2062+ : ( enterStagedRead ( el ) , el . _pendingValue as T ) ;
20202063 // Record that this isPending() probe observed the fresh pending value, so
20212064 // the probe doesn't pair "pending" with the new value (#2831).
20222065 if ( pendingCheckActive ) GlobalQueue . _recordFresh ! ( el , value ) ;
0 commit comments