@solidjs/signals 2.0.0-rc.11 → 2.0.0-rc.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/dev-shared.js +2056 -3773
  2. package/dist/dev.attribution.js +159 -91
  3. package/dist/dev.js +7263 -8384
  4. package/dist/observe/affects.js +125 -104
  5. package/dist/observe/boundaries.js +458 -665
  6. package/dist/observe/core/action.js +63 -66
  7. package/dist/observe/core/async.js +240 -383
  8. package/dist/observe/core/attribution-queries.js +1 -1
  9. package/dist/observe/core/attribution.js +271 -199
  10. package/dist/observe/core/constants.js +115 -178
  11. package/dist/observe/core/context.js +3 -3
  12. package/dist/observe/core/core.js +840 -1428
  13. package/dist/observe/core/dev.js +41 -18
  14. package/dist/observe/core/effect.js +75 -86
  15. package/dist/observe/core/external.js +5 -5
  16. package/dist/observe/core/graph.js +61 -70
  17. package/dist/observe/core/heap.js +75 -98
  18. package/dist/observe/core/invariants.js +1 -34
  19. package/dist/observe/core/lanes.js +704 -181
  20. package/dist/observe/core/owner.js +80 -101
  21. package/dist/observe/core/scheduler.js +708 -1351
  22. package/dist/observe/core/verdict.js +302 -621
  23. package/dist/observe/flatten.js +79 -0
  24. package/dist/observe/index.js +15 -13
  25. package/dist/observe/map.js +232 -235
  26. package/dist/observe/reveal.js +212 -0
  27. package/dist/observe/signals.js +133 -215
  28. package/dist/observe/store/affects.js +135 -0
  29. package/dist/observe/store/index.js +29 -24
  30. package/dist/observe/store/optimistic.js +538 -0
  31. package/dist/observe/store/projection.js +302 -0
  32. package/dist/observe/store/reconcile.js +257 -0
  33. package/dist/observe/store/store.js +1945 -277
  34. package/dist/observe/store/storePath.js +1 -1
  35. package/dist/{prod/store/next → observe/store}/target.js +17 -18
  36. package/dist/observe/store/types.js +73 -0
  37. package/dist/observe/store/utils.js +1 -13
  38. package/dist/prod/affects.js +127 -106
  39. package/dist/prod/boundaries.js +442 -654
  40. package/dist/prod/core/action.js +71 -74
  41. package/dist/prod/core/async.js +307 -442
  42. package/dist/prod/core/constants.js +112 -177
  43. package/dist/prod/core/context.js +3 -3
  44. package/dist/prod/core/core.js +852 -1448
  45. package/dist/prod/core/effect.js +88 -99
  46. package/dist/prod/core/external.js +5 -5
  47. package/dist/prod/core/graph.js +61 -70
  48. package/dist/prod/core/heap.js +75 -98
  49. package/dist/prod/core/invariants.js +1 -32
  50. package/dist/prod/core/lanes.js +666 -181
  51. package/dist/prod/core/owner.js +75 -96
  52. package/dist/prod/core/scheduler.js +677 -1332
  53. package/dist/prod/core/verdict.js +297 -621
  54. package/dist/prod/flatten.js +77 -0
  55. package/dist/prod/index.js +15 -13
  56. package/dist/prod/map.js +143 -146
  57. package/dist/prod/reveal.js +212 -0
  58. package/dist/prod/signals.js +144 -226
  59. package/dist/prod/store/affects.js +135 -0
  60. package/dist/prod/store/index.js +28 -19
  61. package/dist/prod/store/optimistic.js +533 -0
  62. package/dist/prod/store/projection.js +295 -0
  63. package/dist/prod/store/reconcile.js +257 -0
  64. package/dist/prod/store/store.js +1840 -272
  65. package/dist/prod/store/storePath.js +1 -1
  66. package/dist/{observe/store/next → prod/store}/target.js +13 -17
  67. package/dist/prod/store/types.js +73 -0
  68. package/dist/prod/store/utils.js +1 -11
  69. package/dist/types/affects.d.ts +11 -30
  70. package/dist/types/boundaries.d.ts +62 -176
  71. package/dist/types/carved.d.ts +1 -0
  72. package/dist/types/core/action.d.ts +5 -6
  73. package/dist/types/core/async.d.ts +10 -5
  74. package/dist/types/core/attribution-hooks.d.ts +48 -1
  75. package/dist/types/core/attribution.d.ts +29 -9
  76. package/dist/types/core/constants.d.ts +125 -171
  77. package/dist/types/core/core.d.ts +104 -264
  78. package/dist/types/core/dev.d.ts +60 -7
  79. package/dist/types/core/effect.d.ts +0 -7
  80. package/dist/types/core/graph.d.ts +7 -1
  81. package/dist/types/core/heap.d.ts +5 -7
  82. package/dist/types/core/index.d.ts +6 -6
  83. package/dist/types/core/invariants.d.ts +0 -29
  84. package/dist/types/core/lanes.d.ts +65 -87
  85. package/dist/types/core/owner.d.ts +3 -3
  86. package/dist/types/core/scheduler.d.ts +249 -331
  87. package/dist/types/core/types.d.ts +51 -85
  88. package/dist/types/core/verdict.d.ts +3 -0
  89. package/dist/types/flatten.d.ts +8 -0
  90. package/dist/types/index.d.ts +7 -5
  91. package/dist/types/reveal.d.ts +19 -0
  92. package/dist/types/signals.d.ts +53 -92
  93. package/dist/types/store/affects.d.ts +1 -0
  94. package/dist/types/store/index.d.ts +35 -15
  95. package/dist/types/store/optimistic.d.ts +23 -0
  96. package/dist/types/store/projection.d.ts +18 -0
  97. package/dist/types/store/reconcile.d.ts +3 -0
  98. package/dist/types/store/store.d.ts +165 -143
  99. package/dist/types/store/storePath.d.ts +1 -1
  100. package/dist/types/store/target.d.ts +151 -0
  101. package/dist/types/store/types.d.ts +84 -0
  102. package/package.json +1 -1
  103. package/dist/observe/core/optimistic.js +0 -669
  104. package/dist/observe/store/next/optimistic.js +0 -717
  105. package/dist/observe/store/next/projection.js +0 -266
  106. package/dist/observe/store/next/reconcile.js +0 -375
  107. package/dist/observe/store/next/store.js +0 -2480
  108. package/dist/prod/core/optimistic.js +0 -658
  109. package/dist/prod/store/next/optimistic.js +0 -710
  110. package/dist/prod/store/next/projection.js +0 -257
  111. package/dist/prod/store/next/reconcile.js +0 -373
  112. package/dist/prod/store/next/store.js +0 -2356
  113. package/dist/types/core/optimistic.d.ts +0 -6
  114. package/dist/types/store/next/optimistic.d.ts +0 -25
  115. package/dist/types/store/next/projection.d.ts +0 -27
  116. package/dist/types/store/next/reconcile.d.ts +0 -10
  117. package/dist/types/store/next/store.d.ts +0 -143
  118. package/dist/types/store/next/target.d.ts +0 -196
@@ -1,20 +1,16 @@
1
1
  import { releaseFlightTeardown, handleAsync, clearStatus, parkLoadingWindow, notifyStatus, settlePendingSource, settleErroredDependents } from "./async.js";
2
2
 
3
- import { NOT_PENDING, EFFECT_TRACKED, EFFECT_USER, REACTIVE_OPTIMISTIC_DIRTY, CONFIG_DERIVED_OVERRIDE, CONFIG_HELD_CHILDREN, CONFIG_LANE_FRAME, CONFIG_OPTIMISTIC, STATUS_UNINITIALIZED, STATUS_ERROR, STATUS_PENDING, REACTIVE_REASK, REACTIVE_RECOMPUTING_DEPS, REACTIVE_ZOMBIE, CONFIG_SYNC, CONFIG_HAS_LANE, REACTIVE_MISSED_WAKE, REACTIVE_DISPOSED, REACTIVE_SNAPSHOT_STALE, unwrapOverride, CONFIG_DIRECT_COMMIT, CONFIG_HAS_COMPANIONS, CONFIG_PROMOTED, CONFIG_ADOPTED_UNFLUSHED, CONFIG_CHILDREN_FORBIDDEN, CONFIG_FRESH_READ, CONFIG_INPUTS_PUBLISHED, CONFIG_AUTO_DISPOSE, REACTIVE_LAZY, REACTIVE_CHECK, REACTIVE_DIRTY, REACTIVE_IN_HEAP, REACTIVE_IN_HEAP_HEIGHT, REACTIVE_MANUAL_WRITE, CONFIG_AUTHORITATIVE_READ, CONFIG_OVERRIDE_SUPERSEDED, CONFIG_AUTHORITATIVE_OBSERVED, defaultContext, REACTIVE_NONE, CONFIG_HELD_TRUTH, CONFIG_TRANSPARENT, CONFIG_OWNED_WRITE, CONFIG_NO_SNAPSHOT, CONFIG_IN_SNAPSHOT_SCOPE, NO_SNAPSHOT, CONFIG_HAS_SNAPSHOT, CONFIG_FW_CHILDREN, CONFIG_SLOT_NODE, STORE_SNAPSHOT_PROPS } from "./constants.js";
3
+ import { STATUS_UNINITIALIZED, REACTIVE_LAZY, REACTIVE_NONE, defaultContext, CONFIG_TRANSPARENT, CONFIG_OWNED_WRITE, CONFIG_AUTO_DISPOSE, CONFIG_SYNC, CONFIG_NO_SNAPSHOT, CONFIG_IN_SNAPSHOT_SCOPE, NOT_PENDING, NO_SNAPSHOT, CONFIG_HAS_SNAPSHOT, CONFIG_HELD, REACTIVE_MANUAL_WRITE, REACTIVE_DIRTY, CONFIG_OVERRIDE, REACTIVE_DISPOSED, REACTIVE_CHECK, REACTIVE_IN_HEAP, REACTIVE_REASK, REACTIVE_SNAPSHOT_STALE, REACTIVE_LANE_DIRTY, CONFIG_GUESS, REACTIVE_RECOMPUTING_DEPS, EFFECT_RENDER, CONFIG_VERDICT, EFFECT_TRACKED, CONFIG_STAGED, STATUS_ERROR, STATUS_PENDING, REACTIVE_ZOMBIE, REACTIVE_MISSED_WAKE, REACTIVE_JOINED, REACTIVE_PROBED, REACTIVE_FRAME_READ, REACTIVE_STAGED_READ, REACTIVE_LANE_READ, REACTIVE_SCREEN_READ, REACTIVE_PROBE_UNANSWERED, CONFIG_CHILDREN_FORBIDDEN, CONFIG_PROMOTED, CONFIG_INPUTS_PUBLISHED, CONFIG_FRESH_READ, REACTIVE_IN_HEAP_HEIGHT, CONFIG_SLOT_NODE, EFFECT_USER } from "./constants.js";
4
4
 
5
5
  import { NotReadyError } from "./error.js";
6
6
 
7
7
  import { clearDeps, trimStaleDeps, link, dormantNodes } from "./graph.js";
8
8
 
9
- import { deleteFromHeap, queueFor, insertIntoHeapHeight, enqueueSub, markNode, markHeap, insertIntoHeap } from "./heap.js";
9
+ import { insertIntoHeap, deleteFromHeap, insertIntoHeapHeight, enqueueSub, markNode, markHeap } from "./heap.js";
10
10
 
11
- import { findLane } from "./lanes.js";
11
+ import { inheritId, disposeChildren, linkChild, markDisposal } from "./owner.js";
12
12
 
13
- import "./invariants.js";
14
-
15
- import { disposeChildren, markDisposal, linkChild, inheritId } from "./owner.js";
16
-
17
- import { GlobalQueue, bumpNotifyEpoch, activeTransition, globalQueue, clock, currentTransition, insertSubs, queuePendingNode, wakeParked, heldTrims, runInTransition, schedule, batchJoins, notifyEpoch, dirtyQueue, projectionWriteActive, reaskArmed, armReaskClear } from "./scheduler.js";
13
+ import { schedule, GlobalQueue, clock, txOf, flushTransaction, joinFuture, queuePendingNode, globalQueue, notifyEpoch, insertSubs, dirtyQueue, bumpNotifyEpoch, setPassLane, passLane, joinPassTx, passTx, holdNode, laneDirty, heldTrim, staleReader, stagedReaders, deferZombie } from "./scheduler.js";
18
14
 
19
15
  // The heap's per-node step. A tracked effect's heap visit is its compute
20
16
  // phase — empty, like a user effect whose compute reads nothing — and hands
@@ -24,62 +20,34 @@ import { GlobalQueue, bumpNotifyEpoch, activeTransition, globalQueue, clock, cur
24
20
  // render-effect callback stages its value for the next pass, but a wake pushed
25
21
  // directly into the user queue ran in the SAME pass, read the old value, and
26
22
  // nothing re-notified it when the value landed (#3291).
27
- GlobalQueue.Ke = e => {
28
- if (e.je === EFFECT_TRACKED) {
29
- deleteFromHeap(e, queueFor(e));
30
- e.Xe = true;
31
- e.T.enqueue(EFFECT_USER, e.$e);
32
- } else recompute(e);
23
+ GlobalQueue.Ce = e => {
24
+ if (e.i === EFFECT_TRACKED) {
25
+ deleteFromHeap(e, dirtyQueue);
26
+ e.Fe = true;
27
+ globalQueue.enqueue(EFFECT_USER, e.q);
28
+ }
29
+ // L2: a zombie's fate is the seam's — its owner's commit disposes it, or
30
+ // the park cancels the pass (the write that dirtied it is held). It runs
31
+ // only past a seam that left it alive (a live write to a frame whose
32
+ // owner is held in the future). Its lane's own re-staging is a live write
33
+ // (REACTIVE_LANE_DIRTY — a lane shows ahead of any park): it runs now, as
34
+ // the lane's work, for the reveal this seam (#3463).
35
+ else if (e.R & REACTIVE_ZOMBIE && !(e.R & REACTIVE_LANE_DIRTY)) deferZombie(e); else recompute(e);
33
36
  };
34
37
 
35
- GlobalQueue.en = disposeChildren;
38
+ GlobalQueue.he = disposeChildren;
36
39
 
37
40
  let tracking = false;
38
41
 
39
- /** @internal verdict-module glue */ function setPendingCheckActive(e) {
40
- pendingCheckActive = e;
41
- }
42
-
43
- /** @internal verdict-module glue */ function setLatestReadActive(e) {
44
- latestReadActive = e;
45
- }
46
-
47
- /** @internal verdict-module glue */ function setContextInternal(e) {
48
- context = e;
49
- }
50
-
51
- let stale = false;
52
-
53
- let pendingCheckActive = false;
54
-
55
- let latestReadActive = false;
56
-
57
42
  let context = null;
58
43
 
59
- let currentOptimisticLane = null;
60
-
61
- /** Notify `node`'s subscribers on `lane`'s channel: they recompute as the
62
- * lane's passes — a memo publishes a derived override (lanes stage, #3479),
63
- * an effect runs from the lane's queue, at the park, ahead of the
64
- * transaction — the display-ahead view. The write itself is already staged
65
- * (setSignal) and commits with the frame; this walk shows it now. Used by a
66
- * boundary re-armed from a lane pass (boundaries.ts `_swap`, #3540). */ function notifyOnLane(e, n) {
67
- const t = currentOptimisticLane;
68
- currentOptimisticLane = n;
69
- try {
70
- insertSubs(e, true);
71
- } finally {
72
- currentOptimisticLane = t;
73
- }
74
- }
75
-
76
44
  let snapshotCaptureActive = false;
77
45
 
78
46
  let snapshotSources = null;
79
47
 
80
48
  function ownerInSnapshotScope(e) {
81
49
  while (e) {
82
- if (e.nn) return true;
50
+ if (e.Ve) return true;
83
51
  e = e._parent;
84
52
  }
85
53
  return false;
@@ -91,34 +59,34 @@ function setSnapshotCapture(e) {
91
59
  }
92
60
 
93
61
  function markSnapshotScope(e) {
94
- e.nn = true;
62
+ e.Ve = true;
95
63
  }
96
64
 
97
65
  function releaseSnapshotScope(e) {
98
- e.nn = false;
66
+ e.Ve = false;
99
67
  releaseSubtree(e);
100
68
  schedule();
101
69
  }
102
70
 
103
71
  function releaseSubtree(e) {
104
- let n = e.tn;
105
- while (n) {
106
- if (n.nn) {
107
- n = n.un;
72
+ let t = e.ge;
73
+ while (t) {
74
+ if (t.Ve) {
75
+ t = t.me;
108
76
  continue;
109
77
  }
110
- if (n.he) {
111
- const e = n;
112
- e.C &= ~CONFIG_IN_SNAPSHOT_SCOPE;
113
- if (e.oe & REACTIVE_SNAPSHOT_STALE) {
114
- e.oe &= ~REACTIVE_SNAPSHOT_STALE;
115
- e.oe |= REACTIVE_DIRTY;
116
- if (dirtyQueue.ln > e.rn) dirtyQueue.ln = e.rn;
78
+ if (t.re) {
79
+ const e = t;
80
+ e.u &= ~CONFIG_IN_SNAPSHOT_SCOPE;
81
+ if (e.R & REACTIVE_SNAPSHOT_STALE) {
82
+ e.R &= ~REACTIVE_SNAPSHOT_STALE;
83
+ e.R |= REACTIVE_DIRTY;
84
+ if (dirtyQueue.He > e.Le) dirtyQueue.He = e.Le;
117
85
  insertIntoHeap(e, dirtyQueue);
118
86
  }
119
87
  }
120
- releaseSubtree(n);
121
- n = n.un;
88
+ releaseSubtree(t);
89
+ t = t.me;
122
90
  }
123
91
  }
124
92
 
@@ -129,246 +97,160 @@ function clearSnapshots() {
129
97
  // pre-initialized to undefined (see ext()), and every reader tests
130
98
  // `!== undefined` — assign, don't `delete`: deleting a field pushes the
131
99
  // object to dictionary mode for every later read of every field.
132
- const n = e.o;
133
- if (n != null) n.sn = undefined;
134
- // StoreNode targets share one pre-initialized hidden class (see
135
- // createStoreProxy) — same rule, and only when present so signal-node
136
- // sources don't grow the field.
137
- if (e[STORE_SNAPSHOT_PROPS] !== undefined) e[STORE_SNAPSHOT_PROPS] = undefined;
100
+ const t = e.m;
101
+ if (t != null) t.xe = undefined;
138
102
  }
139
103
  snapshotSources = null;
140
104
  }
141
105
  snapshotCaptureActive = false;
142
106
  }
143
107
 
144
- function recompute(e, n = false) {
108
+ function recompute(e, t = false) {
145
109
  // §12d: any recompute can clean a marked subscriber — invalidate skips.
146
110
  bumpNotifyEpoch();
147
- const t = e.je;
148
- // Lane posture is resolved BEFORE the previous frame is parked below: a
149
- // lane pass on an effect direct-commits (#3662, see the parking site), so
150
- // the decision must be known there. `lane` is applied to
151
- // `currentOptimisticLane` further down, once the previous posture is saved.
152
- let i = !!(e.oe & REACTIVE_OPTIMISTIC_DIRTY);
153
- let u = null;
154
- if (i) {
155
- u = GlobalQueue.an(e, true);
156
- // `false` = wake-only lane demotion: recompute plain so a mid-tick
157
- // latest()/isPending() pull stages instead of direct-committing (#3009).
158
- // The predicate lives with the engine (recomputeLane).
159
- if (u === false) i = false;
160
- } else if (e.C & CONFIG_DERIVED_OVERRIDE) {
161
- // Lanes stage (#3479): a pass over a live lane member carrying a derived
162
- // override is the lane's pass whatever channel dirtied it (a boundary
163
- // reset, an unrelated sync write) — its inputs serve the lane's view, so
164
- // its result is the lane's and belongs in the override slot. Run plain,
165
- // A18's sync twin below read that re-derived lane view as a differing
166
- // truth (a fresh array), superseded the override and demoted the lane;
167
- // the lane's next pass then dropped the staged "truth" and left the node
168
- // flagged superseded with nothing to serve (fuzzer latest-1 #2481). A
169
- // demoted node resolves no lane and stays plain: its pass IS the truth.
170
- u = GlobalQueue.an(e, true);
171
- if (u) i = true;
172
- } else if (activeTransition && !n && activeTransition.cn.length) {
173
- // Lane adoption: parent-deeper-than-owned-child can run before its OPT-dirty
174
- // child propagates. Walk deps once and inherit the OPT lane so this node
175
- // recomputes under the right posture and propagates correctly.
176
- u = GlobalQueue.an(e, false);
177
- if (u) i = true;
178
- }
179
- if (!n) {
180
- // A stamped memo re-enters its hold: its value is that transaction's work.
181
- // An effect's pass belongs to whatever dirtied it (A15 corollary: effects
182
- // don't entangle parallel transactions); it joins its stamp only when the
183
- // pass observes the held flight — queue notification (#3407).
184
- if (e.we && !t && activeTransition !== e.we) globalQueue.initTransition(e.we);
185
- deleteFromHeap(e, queueFor(e));
186
- if (e.o !== null) {
187
- e.o.Ce = null;
111
+ const n = e.i;
112
+ // Lanes (plan sec. 28): the seat of a pass is its node's. A node carrying a lane's
113
+ // derived value runs as the lane's whoever dirtied it — a sync write, a
114
+ // boundary reset, a frame rerun — so its children and its result are the
115
+ // lane's; so does a member the lane's own re-staging dirtied
116
+ // (REACTIVE_LANE_DIRTY, lanes.ts — a leaf the lane owns). A written guess's
117
+ // own pass is its truth arriving (A18), the frame's. A first pass is its
118
+ // creator's (ruling A: a lane pass's children are the lane's frame), and
119
+ // under a guess's lane it reads as the lane's too — a binding the lane
120
+ // mounts sees the screen, like the pass that mounted it (#3835). Not
121
+ // under a verdict lane, for its reads or its result: a verdict lane holds
122
+ // verdicts, and a mount it makes is a mainline mount (A29's boundary
123
+ // exemption, #3851). A tracked read of a lane's value moves a
124
+ // derivation's pass into the lane (`read`); a leaf's never moves.
125
+ // Restored at the end, after this pass's staging and runs have been
126
+ // routed.
127
+ const E = passLane;
128
+ setPassLane((e.R & REACTIVE_LANE_DIRTY || (e.u & (CONFIG_OVERRIDE | CONFIG_GUESS)) === CONFIG_OVERRIDE) && e.m?.ke?.Z ? e.m.ke : // Loose `!=`: false with no creator lane (undefined == null).
129
+ t && E?._parent.ye != E && (creatorPass(context)?.R ?? 0) & REACTIVE_RECOMPUTING_DEPS ? E : null);
130
+ // CARVE 2: lane posture resolution (OPTIMISTIC_DIRTY, derived-override
131
+ // re-derivation, lane adoption through deps) went with the optimistic engine.
132
+ if (!t) {
133
+ deleteFromHeap(e, dirtyQueue);
134
+ if (e.m !== null) {
135
+ e.m.De = null;
188
136
  // Supersede is where an iterator flight dies (#3122): close it now.
189
- // Its cleanup(close) registration may sit in a zombie-deferred
190
- // disposal list that a held transition only drains when the
191
- // SUPERSEDING flight settles — cancellation must not wait for the
192
- // work that replaced it. Idempotent with the cleanup-channel close.
137
+ // Idempotent with the cleanup-channel close.
193
138
  releaseFlightTeardown(e);
194
139
  }
195
- // Tracked effects run after finalizePureQueue, so dispose immediately
196
- // instead of deferring. Children built by an uncommitted recompute
197
- // (CONFIG_HELD_CHILDREN) die immediately too: no frame ever showed them.
198
- // Everything else is the committed frame's and is deferred as zombies
199
- // until this node's commit — a transaction-owned node included (#3404):
200
- // a parked node's children predate the hold, and tearing them down when
201
- // the source lands ran cleanups before the transaction's atomic reveal.
202
- // A lane pass on an effect parks a LANE frame instead (CONFIG_LANE_FRAME,
203
- // #3662; A15 lanes corollary): the frame it replaces leaves the screen
204
- // when the lane's queue applies this run (A30) — not at the action's
205
- // commit — and a held lane defers that with the frame still displayed.
206
- // The drain is the lane's first render entry for this pass, pushed before
207
- // the pass builds the new frame: cleanups before side effects — the
208
- // retired frame's `onCleanup`s run ahead of every effect callback of the
209
- // new frame. While the frame waits, the live children were never shown:
210
- // a superseding pass disposes them here like held children, and the
211
- // parked frame stays.
212
- if (t === EFFECT_TRACKED || e.C & (CONFIG_HELD_CHILDREN | CONFIG_LANE_FRAME)) disposeChildren(e); else if (e.tn !== null || e.qe !== null) {
213
- markDisposal(e);
214
- const n = ext(e);
215
- n.fn = e.qe;
216
- n._n = e.tn;
217
- e.qe = null;
218
- e.tn = null;
219
- e.En = 0;
220
- if (t && u) {
221
- e.C |= CONFIG_LANE_FRAME;
222
- findLane(u).dn[0].push(() => {
223
- e.C &= ~CONFIG_LANE_FRAME;
224
- disposeChildren(e, false, true);
225
- });
140
+ // L2: a pass over a held derivation joins its transaction — the
141
+ // propagation that reached this node reached the transaction, and this
142
+ // pass's answer replaces the held one there. A node held with nothing
143
+ // staged — pending when its flush parked, or a member of a held frame —
144
+ // joins all the same. Not a render effect (rule 3): it is the frame.
145
+ // Re-run outside its transaction's flush it publishes mainline — the
146
+ // value it staged there is superseded (`frameRead` remembers it for the
147
+ // landing). A frame born into the transaction (uninitialized: never run,
148
+ // A29) keeps staging: live writes keep it current, it effects at the
149
+ // swap (ruling A).
150
+ if (e.u & CONFIG_HELD) {
151
+ const t = txOf(e);
152
+ // Held by a blocked lane: the frame joins nothing — a lane never holds
153
+ // a sync write (#3460). The pass is the lane's if it reads the lane's
154
+ // world (`read`), and has left it otherwise.
155
+ if (t.Z) ; else if (n !== EFFECT_RENDER && !(e.u & CONFIG_VERDICT)) joinPassTx(t); else if (t !== flushTransaction && !(e.G & STATUS_UNINITIALIZED)) {
156
+ // Published mainline, it is not held: the frame this pass builds is
157
+ // replaced on the spot (#3404) — this flush's commit retires the
158
+ // committed frame the held pass had parked (`commitPendingNode`),
159
+ // after the new frame's first runs, and the held pass's own
160
+ // children die below (`disposeChildren`). The landing re-derives a
161
+ // fresh held frame for the reveal (`_reruns`).
162
+ e.Ae = NOT_PENDING;
163
+ if (n === EFFECT_RENDER) e.u &= ~CONFIG_HELD;
226
164
  }
227
- } else ;
165
+ }
166
+ // The previous pass's frame. If that pass is still awaiting its commit
167
+ // (CONFIG_STAGED) its children were never shown and die on the spot — the
168
+ // frame parked before it stays parked. Otherwise they ARE the frame:
169
+ // park them until this pass commits. Tracked effects run after the seam
170
+ // and own nothing to park.
171
+ if (n === EFFECT_TRACKED || e.u & CONFIG_STAGED) disposeChildren(e); else if (e.ge !== null || e.Pe !== null) parkChildren(e);
228
172
  }
229
- // A derived override (lanes stage, #3479) is override-covered like a written
230
- // one: a plain pass over it — its source superseded (A18) — stages the truth
231
- // and supersedes the override through the sync twin below.
232
- const l = (e.C & (CONFIG_OPTIMISTIC | CONFIG_DERIVED_OVERRIDE)) !== 0 && e.o?.Fe !== NOT_PENDING && e.o?.Fe !== undefined;
233
- const r = !!(e.h & STATUS_UNINITIALIZED);
173
+ const u = !!(e.G & STATUS_UNINITIALIZED);
234
174
  // Capture both error and pending status before the compute clears them.
235
175
  // A conditional can drop its pending source and recover to an unchanged
236
176
  // value, leaving blocked dependents outside that source’s settle walk.
237
- const o = e.h & STATUS_ERROR ? e.o?._ : undefined;
238
- const s = (e.h & STATUS_PENDING) !== 0;
239
- const a = s ? e.o?.ue : undefined;
177
+ const s = e.G & STATUS_ERROR ? e.m?.V : undefined;
178
+ const i = (e.G & STATUS_PENDING) !== 0;
179
+ const l = i ? e.m?.Se : undefined;
240
180
  // Pending SOURCE-hood, captured before the compute clears status: a node
241
181
  // whose own flight parked dependents self-registers in _pendingSources
242
182
  // (notifyStatus, isSource). If this recompute supersedes that flight and
243
183
  // settles synchronously, those dependents settle HERE — asyncWrite's
244
184
  // settlePendingSource walk never runs for a landing that was preempted
245
185
  // (#3181).
246
- const c = e.o?.ue?.has(e);
247
- // Re-ask classification lives in the verdict module; capture the flag before
248
- // the recompute wipes _flags below.
249
- const f = (e.oe & REACTIVE_REASK) !== 0;
250
- // Captured before the compute clears it on a sync landing: if that landing
251
- // is transition-held below, the window must stay open until the hold
252
- // commits (commitPendingNode) — a closed window plus a held value reads as
253
- // a pending frame to live observers of the verdict (#2990).
254
- const _ = e.ve;
255
- // Creation-time A29 (see enterStagedRead): a pass outside a flush that is
256
- // served a live transaction's staged value records the transaction here
257
- // and is staged INTO it below — "born held" — instead of committing.
258
- const E = stagedEntry;
259
- stagedEntry = null;
260
- const d = context;
186
+ const _ = e.m?.Se?.has(e);
187
+ // A19 exc. 2: a `refresh()` re-asks the question already answered — quiet
188
+ // for the verdict — unless the question in flight is a new one, which the
189
+ // re-ask does not launder (a poll during a quiet confirm stays quiet).
190
+ const o = (e.R & REACTIVE_REASK) !== 0 && !(e.G & STATUS_PENDING && e.m !== null && !e.m.be);
191
+ const r = context;
261
192
  context = e;
262
- e.Nn = null;
263
- e.Ye++;
264
- // REACTIVE_ZOMBIE is position, not scheduling state: it says the node sits
265
- // on its owner's `_pendingFirstChild` chain, and `disposeChildren` keys its
266
- // parent-chain splice off it. A zombie reruns for mainline writes until the
267
- // commit that disposes it (#3463), so the per-pass wipe here — and in the
268
- // finally below and in updateIfNecessary — must carry it (#3543): a
269
- // de-flagged zombie spliced itself out of the LIVE chain at disposal,
270
- // orphaning the owner's current child, which stayed subscribed forever.
271
- e.oe = REACTIVE_RECOMPUTING_DEPS | e.oe & REACTIVE_ZOMBIE;
272
- e.be = clock;
273
- let N = e._e === NOT_PENDING ? e.ce : e._e;
274
- let I = e.rn;
275
- let T = false;
276
- let S = tracking;
277
- let O = currentOptimisticLane;
193
+ e.S = null;
194
+ e.Ge++;
195
+ // REACTIVE_ZOMBIE is position: it says the node sits on its owner's parked
196
+ // frame, and the splice/reawaken paths key off it. A zombie reruns for
197
+ // live writes until the commit that disposes it, so every per-pass wipe
198
+ // — here, the finally below, updateIfNecessary — carries it (#3543).
199
+ e.R = REACTIVE_RECOMPUTING_DEPS | e.R & REACTIVE_ZOMBIE;
200
+ e.Ne = clock;
201
+ // The pass's previous value: its staging, else the lane's value for a
202
+ // lane's node (lanes.ts), else the committed one.
203
+ let I = e.Ae !== NOT_PENDING ? e.Ae : e.u & CONFIG_OVERRIDE ? e.m.Z : e.pe;
204
+ let a = e.Le;
205
+ let N = false;
206
+ // L2: did this pass read the future (REACTIVE_JOINED, set by read)?
207
+ let f = false;
208
+ let T = tracking;
278
209
  tracking = true;
279
- // A computed's fn establishes its OWN dependencies, so it must never run
280
- // inside a latest() read window: read() short-circuits through the
281
- // companion path before dependency linking, so a memo created (eagerly
282
- // computed) inside latest(fn) came out permanently dependency-less (#2926).
283
- // latestRead() already suspends the flag for its pull-recomputes; this
284
- // covers creation-time computes and flushes that run inside the window.
285
- const A = latestReadActive;
286
- latestReadActive = false;
287
- // A memo computes under its OWN lane posture, never the puller's (A31,
288
- // #3442): its value is one shared slot every reader sees, so a pull from a
289
- // lane-carrying reader (a probe effect on its companion lane pulling a sync
290
- // memo) must not run it with that lane's read carve-outs — under a lane, a
291
- // pending node on no lane serves its committed value instead of throwing,
292
- // and the memo then published a stale "settled" value, dropped its
293
- // pending status, and stopped holding its transaction. The branches below
294
- // re-establish the posture the memo itself owns (OPT-dirty, or adopted
295
- // through its deps). Effects keep the ambient lane: their runs are the
296
- // lane's own view.
297
- if (!t) currentOptimisticLane = null;
298
- // Lane posture lives with the engine: OPTIMISTIC_DIRTY is only ever set by
299
- // engine-driven paths, and _optimisticNodes is only pushed by
300
- // _optimisticWrite, so the hook is installed whenever either gate holds.
301
- // (Resolved at the top of this pass, ahead of the parking site.)
302
- if (u) currentOptimisticLane = u;
303
- const C = t && t !== EFFECT_USER;
304
- const p = stale;
305
- if (C) stale = true;
306
- // An effect recorded for this transaction's commit replay (it once read a
307
- // node the transaction held and showed the committed value) and now
308
- // recomputing UNDER the transaction sees its staged view: the value this
309
- // run produces is applied by the commit itself, and the stale recording
310
- // would publish the frame a second time. Drop it; the reads below re-record
311
- // if they are served the committed view again (a lane's committed read).
312
- if (t && activeTransition !== null && activeTransition.In.size) activeTransition.In.delete(e);
313
210
  try {
314
- if (!false && e.C & CONFIG_SYNC) {
315
- N = e.he(N);
316
- if (e.o !== null) e.o.Ce = null;
317
- e.ve = false;
211
+ if (!false && e.u & CONFIG_SYNC) {
212
+ I = e.re(I);
213
+ if (e.m !== null) e.m.De = null;
214
+ e._e = false;
318
215
  } else {
319
- // Snapshot `_inFlight` so we can detect whether `_fn` self-registered an async
320
- // subscription (e.g. `createProjection` calls `handleAsync` from inside its body
321
- // with a setter callback). In that case, the outer `handleAsync` call below would
322
- // clobber the fresh subscription, so we skip it and let the internally-registered
323
- // iteration drive updates.
324
- const n = e.o?.Ce;
325
- const t = e.he(N);
326
- const i = typeof t === "object" && t !== null;
327
- const u = e.o?.Ce !== n;
328
- N = u || !i ? t : handleAsync(e, t);
329
- if (!u && !i) {
330
- if (e.o !== null) e.o.Ce = null;
216
+ // A projection's body self-registers its flight through handleAsync
217
+ // (with the commit as setter): its undefined return is not a sync
218
+ // answer, and the outer handleAsync must not clobber the registration.
219
+ const t = e.m?.De;
220
+ const n = e.re(I);
221
+ const E = typeof n === "object" && n !== null;
222
+ const u = e.m?.De !== t;
223
+ I = u || !E ? n : handleAsync(e, n);
224
+ if (!u && !E) {
225
+ if (e.m !== null) e.m.De = null;
331
226
  // A sync (non-object) return is the first real answer; async-shaped
332
227
  // results clear inside handleAsync at their own landing points, and a
333
- // self-registered flight (inFlightChanged — projections) clears when
334
- // its internal handleAsync lands.
335
- e.ve = false;
228
+ // self-registered flight clears when its own handleAsync lands.
229
+ e._e = false;
336
230
  }
337
231
  }
338
232
  // On a status-free node clearStatus is a guaranteed no-op: every field
339
233
  // its body gates on is either _statusFlags or lives in the cold
340
234
  // extension — no extension, no status to clear. (_x from an unrelated
341
235
  // installer just makes clearStatus a cheap re-verified no-op.)
342
- // A node born held keeps STATUS_UNINITIALIZED until its transaction
343
- // commits: it has no committed value, and read() holds its readers.
344
- if (e.h !== 0 || e.o !== null) clearStatus(e, n && stagedEntry === null);
345
- // _optimisticLane is only ever assigned by engine paths (CONFIG_HAS_LANE
346
- // is their sticky presence mark).
347
- if (e.C & CONFIG_HAS_LANE && e.o?.me) GlobalQueue.Tn(e);
348
- } catch (n) {
349
- const t = n instanceof NotReadyError;
350
- if (t && e.ve) {
236
+ if (e.G !== 0 || e.m !== null) clearStatus(e, t);
237
+ } catch (t) {
238
+ const n = t instanceof NotReadyError;
239
+ if (n && e._e) {
351
240
  // Loading window with an unready sync dependency: register for the
352
241
  // source's settle (the settlePendingSource walk runs off
353
242
  // _pendingSources + _blocked alone) but take NO read-visible pending
354
- // status, no downstream propagation, no transition, no lane
355
- // registration — the committed loading value keeps serving. If the
243
+ // status and no downstream propagation — the committed loading value
244
+ // keeps serving. If the
356
245
  // node is currently errored the error stays the answer until this
357
246
  // retry can actually run.
358
- parkLoadingWindow(e, n);
247
+ parkLoadingWindow(e, t);
359
248
  } else {
360
- // Track pending async in the lane (not the lane's source — it creates the lane
361
- // but doesn't belong to it). Set lane BEFORE notifyStatus for downstream propagation.
362
- if (t && currentOptimisticLane) GlobalQueue.Sn(e);
363
- let i = false;
364
- if (t) {
365
- ext(e).Pe = true;
366
- if (GlobalQueue.On !== null) i = GlobalQueue.On(e, f);
367
- }
368
- notifyStatus(e, t ? STATUS_PENDING : STATUS_ERROR, n, undefined, t ? e.o?.me : undefined);
249
+ if (n) ext(e).Ie = true;
250
+ notifyStatus(e, n ? STATUS_PENDING : STATUS_ERROR, t);
369
251
  // The replacement source is fully propagated now. If no new flight
370
252
  // re-owned self, retire the superseded flight and its dependent copies.
371
- if (t && c && !e.o?.Ce) settlePendingSource(e);
253
+ if (n && _ && !e.m?.De) settlePendingSource(e);
372
254
  // A re-park drops what the earlier pass carried (#3456): a source this
373
255
  // pass no longer reaches — its branch switched, or a fresh flight
374
256
  // replaced the inputs' pending with its own — stays copied onto
@@ -377,32 +259,34 @@ function recompute(e, n = false) {
377
259
  // dependent then waits forever on a flight it has no path to. The
378
260
  // re-park twin of the unchanged-value recovery sweep below; dependents
379
261
  // with another path keep the source (retryReaches).
380
- if (t && a) for (const n of a) if (n !== e && !e.o?.ue?.has(n)) settlePendingSource(e, n);
381
- if (i) GlobalQueue.k(e);
262
+ if (n && l) for (const t of l) if (t !== e && !e.m?.Se?.has(t)) settlePendingSource(e, t);
382
263
  }
383
264
  } finally {
384
- tracking = S;
385
- latestReadActive = A;
386
- if (C) stale = p;
265
+ tracking = T;
387
266
  // Consume the missed-wake latch (#3037, set by insertSubs): a dep write
388
267
  // landed beneath this pass on a link it had already validated. The wipe
389
268
  // below must not key off DIRTY/CHECK — the read-time pull protocol
390
269
  // (markNode(c) in read()) marks the running node as part of ordinary
391
270
  // bookkeeping, and those marks are correctly discarded here.
392
- T = (e.oe & REACTIVE_MISSED_WAKE) !== 0;
271
+ N = (e.R & REACTIVE_MISSED_WAKE) !== 0;
272
+ f = (e.R & REACTIVE_JOINED) !== 0;
273
+ // A verdict reader is one for as long as it probes: a pass that entered
274
+ // no window (REACTIVE_PROBED) is an ordinary derivation again.
275
+ if (!(e.R & REACTIVE_PROBED)) e.u &= ~CONFIG_VERDICT;
393
276
  // REACTIVE_DISPOSED survives too (#3621): the pass may have disposed its
394
277
  // own owner (a memo calling its root's `dispose()`, a cleanup doing so
395
278
  // #3601/#3606), and `disposeChildren` set the flag on this node
396
279
  // reentrantly. Dropped, the node read as live — `refresh()` re-ran it
397
- // and `isDisposed()` lied.
398
- e.oe = e.oe & (REACTIVE_ZOMBIE | REACTIVE_DISPOSED) | (n ? e.oe & REACTIVE_SNAPSHOT_STALE : 0);
399
- context = d;
280
+ // and `isDisposed()` lied. REACTIVE_FRAME_READ (A15 stale reader) is
281
+ // this pass's verdict for the landing; the next pass's wipe at the top
282
+ // clears it.
283
+ e.R = e.R & (REACTIVE_ZOMBIE | REACTIVE_DISPOSED | REACTIVE_FRAME_READ | REACTIVE_STAGED_READ | REACTIVE_LANE_READ | REACTIVE_SCREEN_READ | REACTIVE_PROBE_UNANSWERED) | (t ? e.R & REACTIVE_SNAPSHOT_STALE : 0);
284
+ context = r;
285
+ // A19 exc. 2: a pass that went pending on a `refresh()` re-asks the
286
+ // question already answered — quiet for the verdict; any other pending
287
+ // pass is a new question. Settled, there is nothing to classify.
288
+ if (e.m !== null) e.m.be = o && (e.G & STATUS_PENDING) !== 0;
400
289
  }
401
- // The cast re-widens: TS narrowed `stagedEntry` to `null` at the reset
402
- // above and does not invalidate that across the compute call that
403
- // `enterStagedRead` runs under. No emitted code.
404
- const R = stagedEntry;
405
- stagedEntry = E;
406
290
  // A node that died during its own pass (#3621) is dead at the end of it,
407
291
  // and the pass is void. Its owner's teardown already unlinked its deps,
408
292
  // removed it from the heap and ran its cleanups; what remains is what the
@@ -414,278 +298,185 @@ function recompute(e, n = false) {
414
298
  // so nothing is staged, committed, or propagated to subscribers, and an
415
299
  // effect's run is not enqueued (runEffect would refuse it anyway). The
416
300
  // attribution frame opened at the top is still closed.
417
- if (e.oe & REACTIVE_DISPOSED) {
301
+ if (e.R & REACTIVE_DISPOSED) {
418
302
  clearDeps(e);
419
- if (e.o !== null) e.o.Ce = null;
420
- currentOptimisticLane = O;
303
+ if (e.m !== null) e.m.De = null;
304
+ setPassLane(E);
421
305
  return;
422
306
  }
423
- if (!e.o?._) {
307
+ // The lane this pass is work of, if any: its seat (the node's, its
308
+ // creator's, or the one a lane read moved it into). A pass in a lane's
309
+ // seat that read none of the lane's world has left it: its result is the
310
+ // frame's (a derivation whose branch no longer reaches the guess). A
311
+ // guess is written, not derived — it never leaves this way.
312
+ let S = passLane;
313
+ // Listed before its staging, a pending pass included (the lane's own
314
+ // flight is the lane's); false: the pass left the lane (lanes.ts).
315
+ const c = !!e.m?.V;
316
+ if (S !== null) {
317
+ if (GlobalQueue.M(e, S, t, c)) setPassLane(S); else S = null;
318
+ }
319
+ if (!e.m?.V) {
424
320
  // INV-11 (#3330): the equality gate compares against the slot this run
425
- // publishes to. An override-covered node publishes the override; a lane
426
- // recompute (OPT-dirty) direct-commits `_value` — the lane's own reveal
427
- // schedule — so a transaction-held `_pendingValue` that already equals
428
- // the new result is not "unchanged": the screen still shows `_value`.
429
- // Only a transaction-staged run compares against `_pendingValue`.
430
- const u = l ? unwrapOverride(e.o?.Fe) : i || e._e === NOT_PENDING ? e.ce : e._e;
431
- let s = false;
321
+ // publishes to — the staged `_pendingValue` when staged; a lane node's
322
+ // lane value (a node entering the lane this pass has none yet — its
323
+ // committed value, `laneStage` having voided a frame staging).
324
+ const i = e.Ae !== NOT_PENDING ? e.Ae : e.u & CONFIG_OVERRIDE && e.m.Z !== NOT_PENDING ? e.m.Z : e.pe;
325
+ let o = false;
432
326
  try {
433
- s = !t && r || !e.xe || !e.xe(u, N);
434
- } catch (n) {
327
+ o = !n && u || !e.We || !e.We(i, I);
328
+ } catch (t) {
435
329
  // A throwing user comparator is an error of this node's computation.
436
330
  // Route it through the same status path as a compute-phase throw so
437
331
  // error boundaries contain it; otherwise it unwinds the scheduler
438
332
  // flush, bypassing every boundary and wedging the queue (#2837).
439
- notifyStatus(e, STATUS_ERROR, n);
333
+ notifyStatus(e, STATUS_ERROR, t);
440
334
  }
441
335
  // Effects use `_equals: false` (no per-effect closure). The side effects that
442
336
  // the equals closure used to perform — flagging the effect dirty and enqueueing
443
337
  // its runner — happen here instead. `!create` matches the previous `initialized`
444
338
  // gate: the explicit recompute(node, true) inside effect() does not enqueue, so
445
339
  // effect() can call its runner synchronously for the first run.
446
- if (t && s) {
447
- e.Xe = !e.o?._;
340
+ if (n && o &&
341
+ // A stale reader of a lane (REACTIVE_SCREEN_READ) that computed what it
342
+ // last applied owes no run (lanes.ts).
343
+ !(e.R & REACTIVE_SCREEN_READ && !e.Fe && Object.is(e.Ze, I)) &&
344
+ // A re-staging pass owes no run: the commit replays the effect (#3802).
345
+ e.Ae === NOT_PENDING) {
346
+ e.Fe = !e.m?.V;
448
347
  // Reuse one bound runner per effect — runEffect no-ops on a stale
449
348
  // `_modified`, so re-enqueueing the same function is harmless.
450
- if (!n) {
451
- e.T.enqueue(t, e.An ??= GlobalQueue.Cn.bind(null, e));
452
- // Contested effect (#3322). Effects don't entangle transactions (a
453
- // shared effect is not shared state), yet they have one value slot:
454
- // when this write commits under a different transaction
455
- // (`activeTransition`, null = mainline) than the one that produced the
456
- // previous value (`_valueTransition`), that view is gone. Rather than
457
- // merge the two, each commit re-derives the effect against its own
458
- // committed world (Transition._contested, re-dirtied by
459
- // finalizePureQueue ahead of the heap run). The previous owner always
460
- // needs it if still live: its commit is silent (staging already
461
- // notified) and the value it computed is gone. The new owner needs it
462
- // too, for the same reason, unless it is mainline — mainline publishes
463
- // what it computes. A previous owner that was mainline, or already
464
- // committed, left nothing to protect.
465
- let n = e.pn;
466
- if (n !== activeTransition) {
467
- e.pn = activeTransition;
468
- if (n !== null && (n = currentTransition(n)) !== activeTransition && !n.Rn) {
469
- (n.Dn ??= []).push(e);
470
- if (activeTransition !== null) (activeTransition.Dn ??= []).push(e);
471
- }
472
- }
473
- }
349
+ // Lane work's run is the lane's (released at its reveal) — a first
350
+ // pass under a lane too: `effect()` skips the synchronous first run of
351
+ // a lane's node.
352
+ if (!t || S !== null) globalQueue.enqueue(n, e.J ??= GlobalQueue.X.bind(null, e), S);
474
353
  }
475
- if (e.o?._) ; else if (s) {
476
- const u = l ? e.o?.Fe : undefined;
477
- if (n && R === null ||
478
- // Plain sync flush (no transition on either side) commits effect
479
- // values directly — the pending round-trip (queuePendingNode +
480
- // commitPendingNodes) exists to sequence transition reveals, and
481
- // paying it per effect on the plain path is pure overhead.
482
- // DIRECT_COMMIT effects (resolve/until) commit directly even under
483
- // their own held transition: their applies deliver on a microtask,
484
- // not the stashed queues, so a staged value would hand the immediate
485
- // apply stale state — see CONFIG_DIRECT_COMMIT.
486
- t && R === null && (activeTransition !== e.we || activeTransition === null || e.C & CONFIG_DIRECT_COMMIT) || i) {
487
- // Lanes stage (#3479): a lane pass on a memo publishes its speculative
488
- // result as an OVERRIDE — `_value` stays the committed truth, so a
489
- // reader off the lane (A17's committed view, #3460) sees a whole
490
- // committed frame: the source's shadow and its derivations together,
491
- // never a committed shadow beside a speculative memo. The lane's own
492
- // readers and untracked reads see the override (A17); the revert
493
- // drops it and re-derives (resolveOptimisticNodes). Effects keep the
494
- // direct commit — their `_value` is a run result the lane's queues
495
- // already sequence. Either way the lane pass drops any superseded
496
- // older hold so its queued commit can't clobber the fresh frame: a
497
- // hold staged on an earlier, lane-free pass of the SAME transaction
498
- // is superseded — left in place, the commit published the older
499
- // frame over the fresh one (#3377). A reversion pass (OPT-dirty with
500
- // no lane — the override dropped) commits directly: it IS the truth.
501
- if (i && !t && currentOptimisticLane !== null) GlobalQueue.Me(e, N, currentOptimisticLane); else e.ce = N;
502
- if (i) e._e = NOT_PENDING;
354
+ // Lanes. A written guess's own pass from the frame: its source
355
+ // recomputed it — the truth (A18: "the source is whatever recomputes the
356
+ // node"). It stages under the lane's parent whether or not it changed (a
357
+ // confirm is a landing too — the lane's end commits it) and notifies
358
+ // only a correction: an equal truth re-runs nothing (lanes.ts). (As the
359
+ // lane's own work the lane judged it — `laneStage`.)
360
+ if (!t && S === null && e.u & CONFIG_GUESS && GlobalQueue.Qe(e, I, c)) ; else if (c) ; else if (o) {
361
+ // L2: a first pass is born held — staged, committed with the
362
+ // transaction, its effect's first run the landing's (A29; `effect()`
363
+ // skips the synchronous first run on a staged value) — when the flush
364
+ // has joined a transaction and either the pass read a held node (it
365
+ // derives from that world — the join merged the node's transaction
366
+ // into the flush's), or — a verdict lane's mount, mainline — read a
367
+ // staging of this flush (the same world before the seam parks it; the
368
+ // mount is not shown ahead of it: #3851), or a pass created it (ruling
369
+ // A: a held pass's children are the transaction's). Any other mount
370
+ // that read a staging does not join by being new (2026-10-07): it
371
+ // publishes and re-derives if the flush parks. A node created outside any pass
372
+ // that read only the committed world (root setup, a mount, an effect
373
+ // callback) is nobody's frame and publishes directly, as does a first
374
+ // pass that runs before anything joins: the pass's input, not a verdict
375
+ // after it. An effect still carrying an uncommitted staged value
376
+ // re-stages: the commit applies the latest pass, not the born-held one.
377
+ if (S !== null) {
378
+ // Lane work: the lane's value — into the slot while the lane has not
379
+ // revealed (its reveal shows it), as its staging once it has (the
380
+ // next reveal promotes it; the screen keeps the revealed value). An
381
+ // effect's value slot is private: the run the lane holds is what
382
+ // shows it — unless the effect was born held, whose first run is the
383
+ // commit's (A29): it re-stages, as below.
384
+ if (n && e.Ae === NOT_PENDING) e.pe = I; else if (n || S.ve) e.Ae = I; else e.m.Z = I;
385
+ } else if (t ? !((flushTransaction !== null || passTx !== null) && (f || E && e.R & REACTIVE_STAGED_READ || (creatorPass(r)?.R ?? 0) & REACTIVE_JOINED)) : n && e.Ae === NOT_PENDING) {
386
+ // A first pass publishes directly. So does an effect: its value slot
387
+ // is private (only its own run reads it), and the staging round-trip
388
+ // (queuePendingNode + commitPendingNodes) paid per effect on the
389
+ // plain path is pure overhead.
390
+ // NOTE (stage-3, 2026-08-21): a quiet-world MEMO direct-commit was
391
+ // attempted here and REVERTED — memo staging is load-bearing beyond
392
+ // transitions: mid-batch pulls (read-triggered recomputes before
393
+ // sources commit) must see the fresh value while PLAIN reads stay
394
+ // committed until flush (#3009 purity). The pending round-trip is
395
+ // that separation; it cannot be skipped on any path a pull can reach.
396
+ e.pe = I;
503
397
  } else {
504
- e._e = N;
505
- if (R !== null) {
506
- // Born held: the pass ran from mainline and derived from this
507
- // transaction's staged world (enterStagedRead). Its value is the
508
- // transaction's — staged into it directly, stamped, and committed
509
- // with it; mainline's batch never sees it. A born-held effect
510
- // skips its synchronous first run (effect()) and is replayed by
511
- // the commit like a stale reader that showed the committed frame.
512
- // (A re-pass under a fresh boundary — the in-flush form — is
513
- // already the transaction's: restaged, not re-queued.)
514
- if (e.we !== R) {
515
- e.we = R;
516
- R.Gn.push(e);
517
- }
518
- if (t) R.In.add(e);
519
- // Under a boundary that has not revealed, a held first value is
520
- // something not ready under it (#3540): the boundary collects this
521
- // node as a source and shows its fallback; the source stays
522
- // collected while born held (CollectionQueue._checkSources) and
523
- // is released by the commit that initializes it. A boundary that
524
- // already shows content is not told — it holds like any reader.
525
- if (underFreshLoadingBoundary(e)) e.T.notify(e, STATUS_PENDING, STATUS_PENDING, new NotReadyError(e));
398
+ e.Ae = I;
399
+ // Born held: in the transaction from birth, so a read of it this
400
+ // tick is a read of its world (the mount-during-a-hold case), not
401
+ // only after the seam parks it.
402
+ if (t) {
403
+ holdNode(e, flushTransaction ?? passTx);
404
+ // Born into the future: no committed value until the landing
405
+ // (`commitPendingNode` initializes it) — every reader of it
406
+ // derives from the future (`read`), an untracked one throws
407
+ // (A19 exc. 1).
408
+ e.G |= STATUS_UNINITIALIZED;
526
409
  }
527
- // A window landing that gets held re-opens the window until the hold
528
- // commits — the verdict's held-value branch is window-gated (#2990).
529
- if (_) e.ve = true;
530
- // A staged sync recompute is a write path like setSignal/asyncWrite,
531
- // so sync derivations of held sources stay visible to isPending()/latest()
532
- // (#2831). Both companion writes are transition-scoped (optimistic) and
533
- // auto-revert/re-derive at commit. Not gated on an active transition:
534
- // a plain flush can still become a hold after this recompute — an
535
- // async memo downstream pends and the batch is adopted into a
536
- // transaction (scheduler.enterTransition) — and nothing re-derives
537
- // the companion at adoption, so a memo held that way read
538
- // isPending() false while its held source read true (#3413).
539
- if (e.C & CONFIG_HAS_COMPANIONS && GlobalQueue.Ve !== null) GlobalQueue.Ve(e, N);
540
410
  }
541
411
  // insertSubs only walks _subs (no scheduling of its own), so a
542
412
  // subscriber-less node has nothing to notify.
543
- if (e.u !== null && (!l || i || e.o?.Fe !== u)) insertSubs(e, i || l);
544
- // A18 supersession, sync twin of asyncWrite's override branch (#3331):
545
- // this pass published truth that differs from the override (the gate
546
- // compared against it) into the transaction-held slot. Whether the
547
- // source is this node's own async or an upstream node it derives from
548
- // synchronously makes no difference — "the source recomputed". The
549
- // override stays displayed until the commit; the graph moves to the
550
- // staged truth now (plain channel, lane demoted). Ordering: "a new
551
- // value from the source" postdates the override — an override written
552
- // in this same tick (optimisticWrite stamps `_overrideTime`) is the
553
- // newer intent over whatever this pass derives from the batch's staged
554
- // inputs, and is not superseded by it.
555
- else if (l && !i && e.o.hn !== clock) GlobalQueue.ke(e, N);
556
- } else if (l) {
557
- // Unchanged value (equals the override) recomputed while the override
558
- // is active: _value may still be stale, so hold the authoritative value
559
- // for commit on its own transition's schedule — invisibly (A17/A18).
560
- if (e._e === NOT_PENDING) queuePendingNode(e);
561
- e._e = N;
562
- if (_) e.ve = true;
563
- // see the held branch above (#2990)
564
- // A confirmation after a supersession restores the override as the
565
- // graph's value and notifies; a plain confirmation wakes only an
566
- // authoritative-view reader (until()'s predicate, refresh()'s waiter)
567
- // that observed this node past its override — "authoritative arrival
568
- // equal to the override" is exactly the acknowledgment it waits for;
569
- // A17 silence holds for every ordinary subscriber. Both live in the
570
- // engine's supersedeOverride.
571
- GlobalQueue.ke(e, N);
572
- } else if (e.rn != I) {
573
- for (let n = e.u; n !== null; n = n.Ae) {
574
- insertIntoHeapHeight(n.ge, queueFor(n.ge));
413
+ if (e.t !== null) {
414
+ insertSubs(e);
415
+ // Lane work re-staged: the lane's members re-derive as its work.
416
+ if (S !== null) laneDirty(e, S);
575
417
  }
418
+ } else if (e.Le != a) {
419
+ for (let t = e.t; t !== null; t = t.l) insertIntoHeapHeight(t.o, dirtyQueue);
576
420
  }
577
421
  // Silent recovery: errored → unchanged value fires no notification, but
578
422
  // dependents still holding the propagated error consumed their dirty flag
579
423
  // in an errored run and may sit on stale commits (#2949). Changed-value
580
424
  // recoveries ride insertSubs above; a comparator throw re-errored the node
581
425
  // (el._x?._error re-set), so this only runs on a genuinely clean recovery.
582
- if (!s && !e.o?._) {
583
- if (o !== undefined) settleErroredDependents(e, o);
426
+ if (!o && !e.m?.V) {
427
+ if (s !== undefined) settleErroredDependents(e, s);
584
428
  // Self-registration (this node's own superseded flight) is the #3181
585
429
  // sweep's business below — retiring it here too would walk twice.
586
- if (a) for (const n of a) if (n !== e) settlePendingSource(e, n);
430
+ if (l) for (const t of l) if (t !== e) settlePendingSource(e, t);
587
431
  }
588
432
  // #3181: a synchronous settle supersedes the old landing callback, so
589
433
  // recompute owns its pending-source sweep. An uninitialized node without
590
434
  // a replacement source still has no truth to reveal and must stay parked.
591
- if (c && !(e.h & (STATUS_PENDING | STATUS_UNINITIALIZED))) {
592
- settlePendingSource(e);
593
- // The superseded flight will not enter its waiting transactions at
594
- // landing. Recheck them now so an unchanged value cannot leave their
595
- // writes parked after the last pending source has settled.
596
- wakeParked();
597
- }
435
+ if (_ && !(e.G & (STATUS_PENDING | STATUS_UNINITIALIZED))) settlePendingSource(e);
598
436
  }
599
- // A REPORTER whose pass stopped reading a source it reported on (a gate
600
- // closed) stops counting for the transaction waiting on it (A15 / #3426:
601
- // the hold lasts while a live reporter observes the flight). Nothing else
602
- // re-judges a parked transaction (see wokenTransitions; the disposal
603
- // (#3372) and boundary (#3375) twins of this site), so the writes it held
604
- // stayed staged for as long as the flight stayed up — forever, for one
605
- // that never lands (fuzzer #3446 P1, spec O3). The event is "this pass
606
- // dropped a dep" — deps past `_depsTail` (trimmed below, or kept by A30
607
- // for a staged pass), or a pass that read nothing — not "recovered from
608
- // pending": a reporter registered by the stale-reader carve-out
609
- // (heldFromStale, an INITIALIZED source refetching) displays the committed
610
- // value and is never pending (fuzzer case 79). Every parked transaction,
611
- // not the reporter's stamp: the transaction waiting on it registered it
612
- // without stamping it. One idle pass per parked transaction; done ones
613
- // return at re-entry. Effects only — reporters register from render-effect
614
- // notification (INV-3).
615
- // (`_depsTail` was reset at the top of the pass; TS keeps that narrowing.)
616
- const D = e.Nn;
617
- if (t && (s && !(e.h & STATUS_PENDING) || (D === null ? e.Ie !== null : D.Ne !== null))) wakeParked();
618
- // Dependencies are the committed frame's until it is replaced (A30, #3410; the
619
- // deps twin of the held children above): a pass that staged its value
620
- // leaves the previous pass's tail linked for `commitPendingNode` to trim,
621
- // so a write to a dependency the committed value still derives from
622
- // reaches this node — and joins its hold if the stage is transaction-held
623
- // by then (a plain flush decides nothing here: the transaction that holds
624
- // the pass may open later in the same flush). A pass that published
625
- // directly (a first pass, a lane's own reveal) trims now. An errored pass
626
- // (a throw, NotReady included, or a comparator throw above) keeps its full
437
+ // A first pass that went pending where the born-held arm would have held
438
+ // its value (it read a held node, or a verdict lane's mount read a staging,
439
+ // #3851) is born into that transaction without holding it: the hold never
440
+ // waits for a first load (the direction rule), but the answer lands into it
441
+ // while it is live (A29, #3800).
442
+ if (t && S === null && (f || E && e.R & REACTIVE_STAGED_READ) && e.G & STATUS_PENDING) ext(e).Re = flushTransaction ?? passTx;
443
+ // Dependencies are the committed frame's until it is replaced (A30, #3410):
444
+ // a pass that staged its value leaves the previous pass's tail linked for
445
+ // `commitPendingNode` to trim, so a write to a dependency the committed
446
+ // value still derives from reaches this node until the commit. A pass that
447
+ // published directly, or changed nothing, trims now. An errored pass (a
448
+ // throw, NotReady included, or a comparator throw above) keeps its full
627
449
  // list as before — `_depsTail` marks where it stopped — and the commit
628
450
  // skips it by the same `_error`. An effect's frame is the run its value is
629
- // applied by, not the value slot (#3438): a direct-committed pass that
630
- // still owes a run (`_modified`) has not replaced what the last run
631
- // published — the same flush may stash that run into a transaction it
632
- // opens later — so its tail waits for `runEffect` to trim once the run
633
- // applies. A pass that changed nothing replaced nothing either (#3469): the
634
- // same flush may park with its inputs held, and the committed frame still
635
- // derives from the tail — its trim waits on the flush's verdict (heldTrims).
636
- // A tracked effect's pass IS its run (it bypasses the heap and runs after
637
- // the commit): the frame is replaced, trim now.
638
- if (!e.o?._ && e._e === NOT_PENDING && !(t && e.Xe)) {
639
- if (n || i || t === EFFECT_TRACKED) trimStaleDeps(e); else if (e.Nn?.Ne ?? e.Ie) heldTrims.push(e);
640
- }
641
- currentOptimisticLane = O;
642
- // A parked LANE frame is not a hold (#3662): its drain is the effect's own
643
- // run, not a commit — the node is neither queued nor stamped for it, and
644
- // the release below (for transaction zombies) leaves it parked.
645
- const G = (e.C & CONFIG_LANE_FRAME) !== 0;
646
- const h = e._e !== NOT_PENDING || !G && e.o !== null && (e.o._n !== null || e.o.fn !== null) || (e.h & (STATUS_PENDING | STATUS_UNINITIALIZED)) !== 0;
647
- // Override-covered holds (hasOverride) always queue: their commit belongs
648
- // to their own transition's schedule (A18 re-rule) and is unobservable
649
- // under the override (A17). Revert no longer commits anything, so an
650
- // unqueued covered hold would leak (INV-7) once the revert clears
651
- // _transition.
652
-
653
- // While a pass's result waits on a commit, its children (and `_disposal`)
654
- // wait with it, and a re-run may tear them down immediately
655
- // (CONFIG_HELD_CHILDREN, #3404). One exception: a transaction-owned effect
656
- // recomputed mainline (contested, #3322) published its value directly — a
657
- // `_pendingValue` left from an earlier held pass is that transaction's,
658
- // not this one's — so this pass's children are the frame's, and any
659
- // zombies deferred at the top are superseded on that same frame. Its
660
- // commit rides the transaction, not this flush: release them here rather
661
- // than let two generations render at once. A LANE pass is the same case
662
- // (#3662): it direct-commits ahead of its transaction, so its children are
663
- // the frame's too. Left flagged for an OLDER frame's zombies, the stamped
664
- // transaction's same-flush re-run below disposed the lane's freshly built
665
- // children (an insert's inner effect, its run still queued in the lane)
666
- // and held their replacements for a commit that never came.
667
- let P = h && (!n || R !== null || (e.h & STATUS_PENDING) !== 0);
668
- if (P && (!e.we || l)) queuePendingNode(e); else if (P && (activeTransition === null || i) && !(e.h & (STATUS_PENDING | STATUS_UNINITIALIZED))) {
669
- P = false;
670
- if (!G) disposeChildren(e, false, true);
451
+ // applied by, not the value slot (#3438): a pass that still owes a run
452
+ // (`_modified`) has not replaced what the last run published, so its tail
453
+ // waits for `runEffect` to trim once the run applies. A pass that changed
454
+ // nothing replaced nothing either (#3469): it cannot know at its tail
455
+ // whether the flush that ran it will park with its inputs held, so the
456
+ // trim waits on the flush's verdict (`heldTrim`: trimmed at the commit,
457
+ // kept at a park — one spurious recompute at most). A creation pass and a
458
+ // tracked effect trim now: their frames are replaceable like a direct
459
+ // commit, and a tracked effect's spurious run would be user-visible.
460
+ if (!e.m?.V && e.Ae === NOT_PENDING && !(n && e.Fe)) {
461
+ if (t || n === EFFECT_TRACKED) trimStaleDeps(e); else heldTrim(e);
671
462
  }
672
- if (P) e.C |= CONFIG_HELD_CHILDREN; else e.C &= ~CONFIG_HELD_CHILDREN;
673
- // (A born-held pass IS the transaction's staged view — nothing to refresh.)
674
- if (e.we && t && activeTransition !== e.we && R === null) {
675
- // The re-run refreshes the transaction's STAGED view (_pendingValue); the
676
- // value this pass published in _value belongs to the run that just
677
- // finished. Keep that ownership, or the effect phase parks a
678
- // mainline-computed value with the transaction (#3412).
679
- const n = e.pn;
680
- runInTransition(e.we, () => recompute(e));
681
- e.pn = n;
463
+ // A staged value, a parked frame (L2: the commit retires it), or status the
464
+ // commit sweep must settle (a pending or uninitialized pass), queues the
465
+ // node for this flush's commit. A first pass queues only when pending or
466
+ // born held: otherwise its value published directly. A queued pass's
467
+ // children are uncommitted (CONFIG_STAGED) until that commit.
468
+ if (e.Ae !== NOT_PENDING || e.m !== null && (e.m.Me !== null || e.m.Be !== null) || (e.G & (STATUS_PENDING | STATUS_UNINITIALIZED)) !== 0 && (!t || (e.G & STATUS_PENDING) !== 0)) {
469
+ e.u |= CONFIG_STAGED;
470
+ // Lane work is the lane's to reveal (its seam), not this flush's commit.
471
+ if (S === null) queuePendingNode(e);
682
472
  }
473
+ setPassLane(E);
683
474
  // Missed-wake reschedule (see the finally above): values this pass read
684
475
  // before the nested commit are stale, so run again now that the heap will
685
476
  // accept the node. Equality gates stop same-value landings from cascading,
686
477
  // and a re-run only latches again if another nested commit changes a dep
687
478
  // beneath it — convergent unless deps genuinely keep changing.
688
- if (T) {
479
+ if (N) {
689
480
  enqueueSub(e);
690
481
  schedule();
691
482
  }
@@ -698,38 +489,38 @@ function updateIfNecessary(e) {
698
489
  // (#3037); readers meanwhile serve the values the pass has so far.
699
490
  // Never recompute a DISPOSED node either: recompute rewrites _flags and
700
491
  // would resurrect it (#2983) — readers serve its last value.
701
- if (e.oe & (REACTIVE_RECOMPUTING_DEPS | REACTIVE_DISPOSED)) return;
702
- if (e.oe & REACTIVE_CHECK) {
703
- for (let n = e.Ie; n; n = n.Ne) {
704
- const t = n.Oe;
705
- const i = t.De || t;
706
- if (i.he) {
707
- updateIfNecessary(i);
492
+ if (e.R & (REACTIVE_RECOMPUTING_DEPS | REACTIVE_DISPOSED)) return;
493
+ if (e.R & REACTIVE_CHECK) {
494
+ for (let t = e._; t; t = t.p) {
495
+ const n = t.I;
496
+ if (n.re) {
497
+ updateIfNecessary(n);
708
498
  }
709
- if (e.oe & REACTIVE_DIRTY) {
499
+ if (e.R & REACTIVE_DIRTY) {
710
500
  break;
711
501
  }
712
502
  }
713
503
  }
714
- if (e.oe & (REACTIVE_DIRTY | REACTIVE_OPTIMISTIC_DIRTY) || e.o?._ && e.be < clock && !e.o?.Ce) {
504
+ if (e.R & REACTIVE_DIRTY || e.m?.V && e.Ne < clock && !e.m?.De) {
715
505
  recompute(e);
716
506
  }
717
507
  // The guard above refused an already-disposed node; the recompute it just
718
508
  // ran may have disposed it (#3621) — carry the flag, or it comes back alive.
719
- // The manual-write mask is state, not scheduling (#3612): it says the
720
- // node's staging is a PROPOSAL, and only the commit (or a later-tick
721
- // refresh, #3026) lifts it — a pull that recomputed nothing must not, or
722
- // an isPending()/latest() probe decided whether a later write to a held
723
- // node was a second proposal or the derivation's `prev`.
724
- e.oe = e.oe & (REACTIVE_SNAPSHOT_STALE | REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT | REACTIVE_ZOMBIE | REACTIVE_DISPOSED | REACTIVE_MANUAL_WRITE);
509
+ // The manual-write mark is state, not scheduling (#3612, A34 rule B): it
510
+ // says the node's staging is a PROPOSAL, lifted by a pass that re-derives
511
+ // or by the commit — a pull that recomputed nothing must not. Nor may it
512
+ // erase the last pass's verdicts for the landing (a stale reader's
513
+ // REACTIVE_FRAME_READ — a verdict reader pulled by a sibling before the
514
+ // landing lost its re-derivation; the lane reads likewise).
515
+ e.R = e.R & (REACTIVE_SNAPSHOT_STALE | REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT | REACTIVE_ZOMBIE | REACTIVE_DISPOSED | REACTIVE_MANUAL_WRITE | REACTIVE_FRAME_READ | REACTIVE_STAGED_READ | REACTIVE_LANE_READ | REACTIVE_SCREEN_READ | REACTIVE_PROBE_UNANSWERED);
725
516
  }
726
517
 
727
- function computed(e, n) {
728
- const t = n?.transparent ?? false;
518
+ function computed(e, t) {
519
+ const n = t?.transparent ?? false;
729
520
  // `in` (not `!== undefined`): an explicit `loadingValue: undefined` on a
730
521
  // `T | undefined` node is a real commit #0. The typeof guard tolerates
731
522
  // non-object option values that older call shapes force through `as any`.
732
- const i = n !== null && typeof n === "object" && "loadingValue" in n;
523
+ const E = t !== null && typeof t === "object" && "loadingValue" in t;
733
524
  // Two literals, one per tier, selected at build time (the observe flag is
734
525
  // a literal after replacement; the untaken branch is dead code). The observe
735
526
  // literal is the prod literal plus its `_name` slot — a slot in the
@@ -739,43 +530,40 @@ function computed(e, n) {
739
530
  // two in sync — the dist artifact test pins observe's key set to prod's
740
531
  // plus `_name`.
741
532
  const u = {
742
- id: inheritId(n, t, context),
743
- C: (t ? CONFIG_TRANSPARENT : 0) | (n?.ownedWrite ? CONFIG_OWNED_WRITE : 0) | (!context || n?.lazy ? CONFIG_AUTO_DISPOSE : 0) | (n?.sync ? CONFIG_SYNC : 0) | (n?.H ? CONFIG_NO_SNAPSHOT : 0) | (snapshotCaptureActive && ownerInSnapshotScope(context) ? CONFIG_IN_SNAPSHOT_SCOPE : 0),
744
- xe: n?.equals ?? isEqual,
745
- qe: null,
746
- T: context?.T ?? globalQueue,
747
- Je: context?.Je ?? defaultContext,
748
- En: 0,
749
- he: e,
750
- ce: i ? n.loadingValue : undefined,
751
- rn: 0,
752
- Pn: undefined,
753
- Fn: null,
754
- Ie: null,
755
- Nn: null,
533
+ id: inheritId(t, n, context),
534
+ u: (n ? CONFIG_TRANSPARENT : 0) | (t?.ownedWrite ? CONFIG_OWNED_WRITE : 0) | (!context || t?.lazy ? CONFIG_AUTO_DISPOSE : 0) | (t?.sync ? CONFIG_SYNC : 0) | (t?.ie ? CONFIG_NO_SNAPSHOT : 0) | (t?.we ?? 0) | (snapshotCaptureActive && ownerInSnapshotScope(context) ? CONFIG_IN_SNAPSHOT_SCOPE : 0),
535
+ We: t?.equals ?? isEqual,
536
+ Pe: null,
537
+ U: context?.U ?? defaultContext,
756
538
  Ye: 0,
757
- u: null,
758
- mn: null,
539
+ re: e,
540
+ pe: E ? t.loadingValue : undefined,
541
+ Le: 0,
542
+ je: undefined,
543
+ Ke: null,
544
+ _: null,
545
+ S: null,
546
+ Ge: 0,
547
+ t: null,
548
+ qe: null,
759
549
  _parent: context,
760
- un: null,
761
- gn: null,
762
- tn: null,
763
- oe: n?.lazy ? REACTIVE_LAZY : REACTIVE_NONE,
550
+ me: null,
551
+ Je: null,
552
+ ge: null,
553
+ R: t?.lazy ? REACTIVE_LAZY : REACTIVE_NONE,
764
554
  // A loadingValue node is born committed: commit #0 is already in _value.
765
- h: i ? 0 : STATUS_UNINITIALIZED,
766
- be: clock,
767
- _e: NOT_PENDING,
768
- we: null,
769
- vn: -1,
770
- ve: i,
771
- // Cold machinery (async/transition/optimistic/verdict slots) lives one
772
- // hop away in the lazily-allocated extension — the core literal MUST
555
+ G: E ? 0 : STATUS_UNINITIALIZED,
556
+ Ne: clock,
557
+ Ae: NOT_PENDING,
558
+ ze: -1,
559
+ _e: E,
560
+ // Cold machinery (async slots) lives one hop away in the lazily-allocated extension — the core literal MUST
773
561
  // stay under V8's in-object boundary (§12: past ~39 fields every
774
562
  // allocation spills to a backing store and creation cost ~4x's).
775
- o: null
563
+ m: null
776
564
  };
777
- if (n?.unobserved) ext(u).Hn = n.unobserved;
778
- setupComputedNode(u, n);
565
+ if (t?.unobserved) ext(u).Xe = t.unobserved;
566
+ setupComputedNode(u, t);
779
567
  return u;
780
568
  }
781
569
 
@@ -783,269 +571,274 @@ function computed(e, n) {
783
571
  * computeds — `_x` access stays monomorphic). Installers write through
784
572
  * this; hot paths read `el._x?._field` gated by the _config presence bits.
785
573
  * Never call ext() just to store a field's default. */ function ext(e) {
786
- return e.o ??= {
787
- Fe: undefined,
788
- Ln: undefined,
789
- hn: 0,
790
- bn: NOT_PENDING,
791
- Vn: 0,
792
- me: undefined,
793
- Ze: undefined,
794
- He: undefined,
795
- kn: undefined,
796
- t: 0,
797
- Ce: null,
798
- ye: null,
799
- _: undefined,
800
- Pe: undefined,
801
- ue: undefined,
802
- S: undefined,
803
- Le: false,
804
- i: null,
805
- Hn: undefined,
806
- sn: undefined,
807
- fn: null,
808
- _n: null,
809
- Un: undefined
574
+ return e.m ??= {
575
+ De: null,
576
+ Te: null,
577
+ V: undefined,
578
+ Ie: undefined,
579
+ Se: undefined,
580
+ Xe: undefined,
581
+ xe: undefined,
582
+ Me: null,
583
+ Be: null,
584
+ ke: null,
585
+ Re: null,
586
+ be: false,
587
+ $e: NOT_PENDING,
588
+ et: -1,
589
+ Oe: 0,
590
+ Z: NOT_PENDING,
591
+ T: 0
810
592
  };
811
593
  }
812
594
 
595
+ /** A tracked read of a held node (the reader derives from its transaction's
596
+ * world): the reading pass is marked as having read it (born-held decision
597
+ * in `recompute`), and the flush joins the node's transaction — unless the
598
+ * reader is a render effect. A render effect is the frame, not a derivation
599
+ * (rule 3): in that transaction's own flush, or born into it (uninitialized,
600
+ * A29), it reads the staged value and holds nothing of its own; otherwise it
601
+ * reads the committed value instead (`frameRead`). A node born into the
602
+ * future has no committed value: every reader joins it. A first pass is
603
+ * something not ready under a loading boundary that has not shown content:
604
+ * the boundary collects it and shows its fallback, and the pass is the
605
+ * boundary's, not the tick's (A29's boundary exemption, #3540). */ function joinPass(e, t) {
606
+ e.R |= REACTIVE_JOINED;
607
+ if (t.G & STATUS_UNINITIALIZED || e.i !== EFFECT_RENDER) joinPassTx(txOf(t), GlobalQueue.ce?.(e));
608
+ }
609
+
610
+ /** A15's stale reader (shared-hole and reveal corollaries): a render effect
611
+ * reading a node held by a transaction that is not the flush's. It is served
612
+ * the committed value — a pending one's too — publishes mainline, and is
613
+ * re-derived after that transaction's landing (`_reruns`,
614
+ * REACTIVE_FRAME_READ) so the frame catches up with it once it is the
615
+ * committed world. Not a frame born into that transaction (held and never
616
+ * committed — created by one of its held passes, A29): that one reads its
617
+ * transaction's values and keeps staging. Not of a flight whose inputs are
618
+ * already visible (CONFIG_INPUTS_PUBLISHED, #3305): its committed value
619
+ * would tear against them, so the reveal observes the flight instead. Once
620
+ * per pass.
621
+ *
622
+ * Lane work is a stale reader too (maintainer, 2026-10-01: a lane sees the
623
+ * screen plus its own guesses). A held write is held because showing it
624
+ * would tear against the rest of its frame; a lane revealing a derivation
625
+ * of it would show it anyway, beside inputs still committed elsewhere on
626
+ * the page. The guess is the one value the user opted into predicting. So
627
+ * a lane pass reading a transaction's held node — its parent's or any
628
+ * other's — derives from the committed value and is re-derived at that
629
+ * landing. The case read-through was built for — a corrected guess whose
630
+ * downstream async must refetch with the truth at once, while another of
631
+ * the parent's flights is still up — needs none of this: the correction
632
+ * dissolves the lane, and the refetching pass is the parent's own, reading
633
+ * the truth as a member (`joinPass`). */ function frameRead(e, t) {
634
+ // Frame readers: a render effect, a verdict reader (CONFIG_VERDICT — it
635
+ // reads the screen like one: `[isPending(x), x()]` never pairs the fresh
636
+ // value with pending, A10, because the reader never sees the fresh value),
637
+ // and lane work (a lane sees the screen plus its own guesses). Not a
638
+ // mount's memo (2026-10-02, considered and reverted): a memo is not a
639
+ // leaf — the transaction's own later passes read it — so a mainline mount's
640
+ // derivations carry the future (A29, born held); only its direct bindings
641
+ // read the screen. Lane work with no committed value yet reads a flight
642
+ // as a mount's memo does: it enters, and the boundary it mounts catches
643
+ // the pending (#3540).
644
+ const n = e.u & CONFIG_VERDICT;
645
+ if ((passLane === null || e.G & STATUS_UNINITIALIZED && t.G & STATUS_PENDING) && !n && (e.i !== EFFECT_RENDER || t.u & CONFIG_INPUTS_PUBLISHED)) return false;
646
+ const E = txOf(t);
647
+ // Lane work and verdict readers are never the transaction's pass, whichever
648
+ // flush runs it: a node T holds re-enters T when it re-runs (`recompute`'s
649
+ // head), and the pass may then read a guess and become the lane's.
650
+ if (E === flushTransaction && passLane === null && !n || e.G & STATUS_UNINITIALIZED && e.u & CONFIG_HELD && txOf(e) === E) return false;
651
+ staleReader(e, E);
652
+ return true;
653
+ }
654
+
655
+ /** The computed whose pass a creation under `owner` belongs to (a root's is
656
+ * its nearest computed ancestor's), or null outside every pass. */ function creatorPass(e) {
657
+ return e !== null && e.Et ? e.ut : e;
658
+ }
659
+
660
+ /** L2 — park the previous pass's frame for this node's commit: the children
661
+ * (already allocated — nothing new) and the `_disposal` list move to the
662
+ * extension, keep reacting from the heap, and die when the commit publishes
663
+ * the frame that replaces them (`commitPendingNode`) or when the owner does. */ function parkChildren(e) {
664
+ markDisposal(e);
665
+ const t = ext(e);
666
+ t.Be = e.Pe;
667
+ t.Me = e.ge;
668
+ e.Pe = null;
669
+ e.ge = null;
670
+ e.Ye = 0;
671
+ }
672
+
813
673
  /**
814
674
  * Build an Effect node with all effect-specific fields baked into a single object literal,
815
675
  * so V8 sees the full hidden class shape at construction time. Effects always run in lazy
816
676
  * mode (recompute is called explicitly by `effect()`), so we hardcode the lazy bits and skip
817
677
  * the auto-dispose CONFIG bit (effect() previously cleared it post-construction).
818
- */ function createEffectNode(e, n, t, i, u) {
819
- const l = u?.transparent ?? false;
678
+ */ function createEffectNode(e, t, n, E, u) {
679
+ const s = u?.transparent ?? false;
820
680
  // Prod and observe boilerplates — see computed() for why the observe tier
821
681
  // gets its `_name` as a literal slot rather than a write after the fact.
822
682
  // The default label is the node kind (tracked effects relabel their computed
823
683
  // in trackedEffect); the wrappers in signals.ts no longer spread a name into
824
684
  // the options to get it.
825
- const r = {
826
- id: inheritId(u, l, context),
827
- C: (l ? CONFIG_TRANSPARENT : 0) | (u?.ownedWrite ? CONFIG_OWNED_WRITE : 0) | (u?.sync ? CONFIG_SYNC : 0) | (u?.yn ?? 0) | (snapshotCaptureActive && ownerInSnapshotScope(context) ? CONFIG_IN_SNAPSHOT_SCOPE : 0),
828
- xe: false,
829
- qe: null,
830
- T: context?.T ?? globalQueue,
831
- Je: context?.Je ?? defaultContext,
832
- En: 0,
833
- he: e,
834
- ce: undefined,
835
- rn: 0,
836
- Pn: undefined,
837
- Fn: null,
838
- Ie: null,
839
- Nn: null,
685
+ const i = {
686
+ id: inheritId(u, s, context),
687
+ u: (s ? CONFIG_TRANSPARENT : 0) | (u?.ownedWrite ? CONFIG_OWNED_WRITE : 0) | (u?.sync ? CONFIG_SYNC : 0) | (u?.we ?? 0) | (snapshotCaptureActive && ownerInSnapshotScope(context) ? CONFIG_IN_SNAPSHOT_SCOPE : 0),
688
+ We: false,
689
+ Pe: null,
690
+ U: context?.U ?? defaultContext,
840
691
  Ye: 0,
841
- u: null,
842
- mn: null,
692
+ re: e,
693
+ pe: undefined,
694
+ Le: 0,
695
+ je: undefined,
696
+ Ke: null,
697
+ _: null,
698
+ S: null,
699
+ Ge: 0,
700
+ t: null,
701
+ qe: null,
843
702
  _parent: context,
844
- un: null,
845
- gn: null,
846
- tn: null,
847
- oe: REACTIVE_LAZY,
848
- h: STATUS_UNINITIALIZED,
849
- be: clock,
850
- _e: NOT_PENDING,
851
- we: null,
852
- vn: -1,
853
- ve: false,
854
- Xe: false,
855
- xn: undefined,
856
- Qn: n,
857
- Mn: t,
858
- wn: undefined,
859
- je: i,
860
- pn: null,
861
- o: null
703
+ me: null,
704
+ Je: null,
705
+ ge: null,
706
+ R: REACTIVE_LAZY,
707
+ G: STATUS_UNINITIALIZED,
708
+ Ne: clock,
709
+ Ae: NOT_PENDING,
710
+ ze: -1,
711
+ _e: false,
712
+ Fe: false,
713
+ Ze: undefined,
714
+ st: t,
715
+ it: n,
716
+ lt: undefined,
717
+ i: E,
718
+ m: null
862
719
  };
863
720
  // Effects dispatch status through the SHARED notifier (statusNotifierOf,
864
721
  // keyed off _type) — storing it per node forced a full NodeExtension
865
722
  // allocation on EVERY effect at creation (an alloc + 19 field stores,
866
723
  // +23% effect creation, caught by the creation benches). Only genuinely
867
724
  // per-node channels (boundaries) live on _x.
868
- if (u?.unobserved) ext(r).Hn = u.unobserved;
869
- setupComputedNode(r, lazyOptions);
870
- return r;
725
+ if (u?.unobserved) ext(i).Xe = u.unobserved;
726
+ setupComputedNode(i, lazyOptions);
727
+ return i;
871
728
  }
872
729
 
873
730
  /**
874
731
  * The shared status notifier for effect nodes, installed once by effect.ts
875
732
  * at module evaluation (`this`-dispatched — one function serves every
876
- * effect, so nodes never store it). Boundary computeds keep their own
877
- * per-node channel on `_x._notifyStatus`, which takes precedence.
733
+ * effect, so nodes never store it). CARVE 4: the boundaries' per-node
734
+ * channel (`_x._notifyStatus`) went with them; effects are the only
735
+ * display consumers.
878
736
  */ let effectStatusNotify = null;
879
737
 
880
738
  function setEffectStatusNotify(e) {
881
739
  effectStatusNotify = e;
882
740
  }
883
741
 
884
- /** Resolve a node's status notifier: an own `_x` channel (boundaries) wins;
885
- * effect nodes (`_type` — EFFECT_PURE is 0, and only effect literals carry
886
- * the field) fall back to the shared notifier. Presence doubles as the
887
- * "display consumer" membership test in the status walks, exactly as the
888
- * per-node field did when every effect carried one. */ function statusNotifierOf(e) {
889
- const n = e.o?.S;
890
- if (n !== undefined) return n;
891
- return e.je ? effectStatusNotify ?? undefined : undefined;
742
+ /** Resolve a node's status notifier: effect nodes (`_type` — EFFECT_PURE is
743
+ * 0, and only effect literals carry the field) get the shared notifier.
744
+ * Presence doubles as the "display consumer" membership test in the status
745
+ * walks, exactly as the per-node field did when every effect carried one. */ function statusNotifierOf(e) {
746
+ return e.i ? effectStatusNotify ?? undefined : undefined;
892
747
  }
893
748
 
894
749
  const lazyOptions = {
895
750
  lazy: true
896
751
  };
897
752
 
898
- function setupComputedNode(e, n) {
899
- e.Fn = e;
900
- const t = context?.Wn ? context.qn : context;
753
+ function setupComputedNode(e, t) {
754
+ e.Ke = e;
755
+ const n = context?.Et ? context.ut : context;
901
756
  if (context) linkChild(context, e);
902
- if (t) e.rn = t.rn + 1;
903
- if (GlobalQueue.Zn !== null) GlobalQueue.Zn(e);
904
- !n?.lazy && recompute(e, true);
905
- if (snapshotCaptureActive && !n?.lazy) {
906
- if (!(e.h & STATUS_PENDING) && !(e.C & CONFIG_NO_SNAPSHOT)) {
907
- ext(e).sn = e.ce === undefined ? NO_SNAPSHOT : e.ce;
908
- e.C |= CONFIG_HAS_SNAPSHOT;
757
+ if (n) e.Le = n.Le + 1;
758
+ GlobalQueue._t?.(e);
759
+ !t?.lazy && recompute(e, true);
760
+ if (snapshotCaptureActive && !t?.lazy) {
761
+ if (!(e.G & STATUS_PENDING) && !(e.u & CONFIG_NO_SNAPSHOT)) {
762
+ ext(e).xe = e.pe === undefined ? NO_SNAPSHOT : e.pe;
763
+ e.u |= CONFIG_HAS_SNAPSHOT;
909
764
  snapshotSources.add(e);
910
765
  }
911
766
  }
912
767
  }
913
768
 
914
- function signal(e, n, t = null) {
769
+ function signal(e, t) {
915
770
  // Prod and observe boilerplates — see computed(). The observe literal adds
916
771
  // `_name` and `_owner` (the creating owner, stamped by registerGraph for
917
772
  // createSignal nodes so ownerPath can locate signal subjects; null here,
918
773
  // and staying null on internal signals — one shape either way).
919
- const i = {
920
- xe: n?.equals ?? isEqual,
921
- C: (n?.ownedWrite ? CONFIG_OWNED_WRITE : 0) | (n?.H ? CONFIG_NO_SNAPSHOT : 0),
922
- ce: e,
923
- u: null,
924
- mn: null,
925
- be: clock,
926
- De: t,
927
- Ue: t?.o?.i || null,
928
- Yn: null,
929
- _e: NOT_PENDING,
774
+ const n = {
775
+ We: t?.equals ?? isEqual,
776
+ u: (t?.ownedWrite ? CONFIG_OWNED_WRITE : 0) | (t?.ie ? CONFIG_NO_SNAPSHOT : 0),
777
+ pe: e,
778
+ t: null,
779
+ qe: null,
780
+ Ne: clock,
781
+ Ae: NOT_PENDING,
930
782
  // Signal-literal diet (§12e): NO _time/_fn/_statusFlags slots. Stores
931
783
  // materialize one signal per touched leaf, so signal bytes are store
932
784
  // bytes. _time is write-only on signals (every read site is computed-
933
785
  // typed error-retry gating); _fn/_statusFlags read falsy-identically as
934
786
  // missing properties on the shared paths (undefined masks to 0).
935
- we: null,
936
- vn: -1,
937
- o: null
787
+ ze: -1,
788
+ m: null
938
789
  };
939
- if (n?.unobserved) ext(i).Hn = n.unobserved;
940
- if (t) linkFirewallChild(t, i);
941
- if (snapshotCaptureActive && !(i.C & CONFIG_NO_SNAPSHOT) && !((t?.h ?? 0) & STATUS_PENDING)) {
942
- ext(i).sn = e === undefined ? NO_SNAPSHOT : e;
943
- i.C |= CONFIG_HAS_SNAPSHOT;
944
- snapshotSources.add(i);
790
+ if (t?.unobserved) ext(n).Xe = t.unobserved;
791
+ if (snapshotCaptureActive && !(n.u & CONFIG_NO_SNAPSHOT)) {
792
+ ext(n).xe = e === undefined ? NO_SNAPSHOT : e;
793
+ n.u |= CONFIG_HAS_SNAPSHOT;
794
+ snapshotSources.add(n);
945
795
  }
946
- return i;
947
- }
948
-
949
- // ---------------------------------------------------------------------------
950
- // SLOT SIGNALS (store leaves) — the create-floor diet. Store mounts
951
- // materialize one signal per touched leaf (~13 × rows on dbmon), so per-node
952
- // allocations are mount bytes: the generic path costs an options object, an
953
- // equals closure, an unobserved closure, a NodeExtension to hold it, and
954
- // three post-construction expandos (acc/px/pxv → hidden-class transitions).
955
- // slotSignal bakes everything into ONE literal: `_host`/`_key` backrefs
956
- // replace the closures (equals is a method call — `this` is the node; the
957
- // unobserved sweep dispatches CONFIG_SLOT_NODE to one shared hook), and the
958
- // store's wrap-cache fields are pre-shaped.
959
- /** The shared slot-node unobserved handler — a live binding read directly by
960
- * the sweep sites (no wrapper frame, no null check: a CONFIG_SLOT_NODE node
961
- * existing implies the store module loaded and registered the hook). */ let slotUnobservedHook;
962
-
963
- /** Install the shared slot-node unobserved handler (store module, once). */ function setSlotUnobserved(e) {
964
- slotUnobservedHook = e;
796
+ return n;
965
797
  }
966
798
 
967
- /** Push a new node onto its firewall's child chain (the literal already
968
- * points `_nextChild` at the old head). Doubly linked so a released leaf
969
- * unlinks in O(1) — the chain is walked per mark of the projection and
970
- * would otherwise grow by one node per leaf ever read (#3351). */ function linkFirewallChild(e, n) {
971
- const t = n.Ue;
972
- if (t !== null) t.Yn = n;
973
- ext(e).i = n;
974
- e.C |= CONFIG_FW_CHILDREN;
799
+ function isEqual(e, t) {
800
+ return e === t;
975
801
  }
976
802
 
977
- /** Release a firewall child the store no longer addresses (unobserved sweep
978
- * dropped it from its target's cache): unlink it from the chain so the
979
- * projection stops retaining it and its last value. The node keeps its own
980
- * `_nextChild` so a walk that is mid-chain on it still terminates. It also
981
- * leaves `_companionChildren` (#3503): the companions themselves are
982
- * permanent on the node, but the node is unreachable through the store, so
983
- * the set would only retain it and its last value. */ function unlinkFirewallChild(e) {
984
- const n = e;
985
- const t = n.De;
986
- if (!t) return;
987
- const i = n.Yn;
988
- const u = n.Ue;
989
- if (i !== null) i.Ue = u; else if (t.o.i === n) t.o.i = u;
990
- if (u !== null) u.Yn = i;
991
- n.Yn = null;
992
- // #3503: the companion set is the last projection-side reference to a
993
- // released leaf; leaving it there kept the leaf and its last value alive
994
- // for the projection's lifetime after every latest()/isPending() reader
995
- // was disposed.
996
- t.o.Un?.delete(n);
997
- }
998
-
999
- function slotSignal(e, n, t, i, u, l = null) {
1000
- // Prod and observe boilerplates — see computed(). The store relabels the
1001
- // observe slot (`store.<key>`) when the attribution engine is installed.
1002
- const r = {
1003
- xe: n,
1004
- C: CONFIG_OWNED_WRITE | CONFIG_SLOT_NODE,
1005
- ce: e,
1006
- u: null,
1007
- mn: null,
1008
- be: clock,
1009
- De: l,
1010
- Ue: l?.o?.i || null,
1011
- Yn: null,
1012
- _e: NOT_PENDING,
1013
- we: null,
1014
- vn: -1,
1015
- o: null,
1016
- // Slot backrefs: what the equals/unobserved closures used to capture.
1017
- Bn: t,
1018
- Kn: i,
1019
- // Store read-path caches, pre-shaped (were post-construction expandos).
803
+ /** A store slot node (CONFIG_SLOT_NODE): the whole node in ONE literal — the
804
+ * target and key as back-refs in place of closures (`equals` is a method
805
+ * call, `this` the node; the unobserved sweep dispatches to one shared hook,
806
+ * graph.ts), the store's wrap cache (`px`/`pxv`: the proxy last served for
807
+ * this key and the raw it wrapped — one pointer compare replaces a WeakMap
808
+ * lookup per read) and the accessor verdict (`acc`) pre-shaped. No options
809
+ * object, no NodeExtension, no post-construction expandos. `ownedWrite` is
810
+ * baked in: the setter carries the owned-scope guard; node-level writes are
811
+ * the store's notification machinery. The observe literal adds the label
812
+ * slot (the store relabels it `store.<key>` when the engine is installed). */ function slotSignal(e, t, n, E, u) {
813
+ const s = {
814
+ We: t,
815
+ u: CONFIG_OWNED_WRITE | CONFIG_SLOT_NODE,
816
+ pe: e,
817
+ t: null,
818
+ qe: null,
819
+ Ne: clock,
820
+ Ae: NOT_PENDING,
821
+ ze: -1,
822
+ m: null,
823
+ ot: n,
824
+ rt: E,
1020
825
  acc: u,
1021
826
  px: undefined,
1022
827
  pxv: undefined
1023
828
  };
1024
- if (l) linkFirewallChild(l, r);
1025
- if (snapshotCaptureActive && !((l?.h ?? 0) & STATUS_PENDING)) {
1026
- ext(r).sn = e === undefined ? NO_SNAPSHOT : e;
1027
- r.C |= CONFIG_HAS_SNAPSHOT;
1028
- snapshotSources.add(r);
1029
- }
1030
- return r;
829
+ return s;
1031
830
  }
1032
831
 
1033
- function optimisticSignal(e, n) {
1034
- const t = signal(e, n);
1035
- ext(t).Fe = NOT_PENDING;
1036
- t.C |= CONFIG_OPTIMISTIC;
1037
- return t;
1038
- }
1039
-
1040
- function optimisticComputed(e, n) {
1041
- const t = computed(e, n);
1042
- ext(t).Fe = NOT_PENDING;
1043
- t.C |= CONFIG_OPTIMISTIC;
1044
- return t;
1045
- }
832
+ /**
833
+ * When set to a component name string, any reactive read that is not inside a nested tracking
834
+ * scope will log a dev-mode warning. Managed automatically by `untrack(fn, strictReadLabel)`.
835
+ */
836
+ /** The verdict windows' read (verdict.ts), installed while a `latest` or
837
+ * `isPending` window is open and null otherwise: `read` dispatches to it
838
+ * then, and a program that never imports them never has one. */ let verdict = null;
1046
839
 
1047
- function isEqual(e, n) {
1048
- return e === n;
840
+ function setVerdict(e) {
841
+ verdict = e;
1049
842
  }
1050
843
 
1051
844
  /**
@@ -1069,15 +862,15 @@ function isEqual(e, n) {
1069
862
  * }
1070
863
  * );
1071
864
  * ```
1072
- */ function untrack(e, n) {
1073
- if (GlobalQueue.jn === null && !tracking && true) return e();
1074
- const t = tracking;
865
+ */ function untrack(e, t) {
866
+ if (GlobalQueue.It === null && !tracking && true) return e();
867
+ const n = tracking;
1075
868
  tracking = false;
1076
869
  try {
1077
- if (GlobalQueue.jn !== null) return GlobalQueue.jn(e);
870
+ if (GlobalQueue.It) return GlobalQueue.It(e);
1078
871
  return e();
1079
872
  } finally {
1080
- tracking = t;
873
+ tracking = n;
1081
874
  }
1082
875
  }
1083
876
 
@@ -1093,630 +886,327 @@ function isEqual(e, n) {
1093
886
  * born-held tree would otherwise pull the mounting pass into the hold).
1094
887
  */ let spectating = false;
1095
888
 
1096
- /**
1097
- * Evaluates `fn` untracked, recording nothing on the current `context`: no
1098
- * untracked-pending re-run link, no transaction entry. For bookkeeping reads
1099
- * made on behalf of no node — see `spectating`.
1100
- */ function spectate(e) {
1101
- const n = spectating;
1102
- spectating = true;
1103
- try {
1104
- return untrack(e);
1105
- } finally {
1106
- spectating = n;
1107
- }
1108
- }
1109
-
1110
889
  /**
1111
890
  * Bring a computed to a readable state: lazy/disposed nodes are (re)computed;
1112
- * an isPending() probe (`refresh`) additionally pulls the node fully up to
1113
- * date so its status flags reflect the current graph.
1114
- */ function prepareComputed(e, n) {
1115
- if (e.oe & REACTIVE_LAZY) {
1116
- e.oe &= ~REACTIVE_LAZY;
891
+ * `refresh` additionally pulls the node fully up to date so its status flags
892
+ * reflect the current graph.
893
+ */ function prepareComputed(e, t) {
894
+ if (e.R & REACTIVE_LAZY) {
895
+ e.R &= ~REACTIVE_LAZY;
1117
896
  recompute(e, true);
1118
- } else if (e.oe & REACTIVE_DISPOSED) {
897
+ } else if (e.R & REACTIVE_DISPOSED) {
1119
898
  // Two disposal lifecycles share the flag (#3024). Observation-lifecycle
1120
899
  // nodes (CONFIG_AUTO_DISPOSE) are dormant — torn down by unobserved()
1121
900
  // when the last subscriber left — and reads reawaken them; that is the
1122
901
  // pay-for-use contract. Owner-lifecycle nodes are dead: recomputing would
1123
902
  // re-run user code in a torn-down tree (and discard manual writes on
1124
903
  // derived-writable signals), so reads return the last committed value.
1125
- if (e.C & CONFIG_AUTO_DISPOSE) {
1126
- const n = e._parent;
1127
- if (n !== null) {
904
+ if (e.u & CONFIG_AUTO_DISPOSE) {
905
+ const t = e._parent;
906
+ if (t !== null) {
1128
907
  // A dormant node was off the chain when its owner died, so the strip
1129
908
  // in disposeChildren missed it: freeze here instead (#3024).
1130
- if (n.oe & REACTIVE_DISPOSED) {
1131
- e.C &= ~CONFIG_AUTO_DISPOSE;
909
+ if (t.R & REACTIVE_DISPOSED) {
910
+ e.u &= ~CONFIG_AUTO_DISPOSE;
1132
911
  return;
1133
912
  }
1134
- // A zombie never left its chain: settleAutodispose releases without
1135
- // the !ZOMBIE check its siblings have, so this guard is load-bearing.
1136
- if (!(e.oe & REACTIVE_ZOMBIE)) linkChild(n, e);
913
+ // A zombie never left its chain (the parked frame is drained whole,
914
+ // and its members skip the splice): relinking would put it on the
915
+ // live chain too.
916
+ if (!(e.R & REACTIVE_ZOMBIE)) linkChild(t, e);
1137
917
  }
1138
918
  recompute(e, true);
1139
919
  }
1140
- } else if (n) {
1141
- updateIfNecessary(e);
1142
- }
920
+ } else ;
1143
921
  }
1144
922
 
923
+ // CARVE 3: until()'s authoritative-view wakeup (notifyAuthoritativeObservers /
924
+ // installAuthoritativeRead), the stale-of-foreign clause (heldFromStale,
925
+ // recordStaleReplay, ownsHold) and the transaction entry on a staged read
926
+ // (enterStagedRead, stagedEntry / born held, underFreshLoadingBoundary) went
927
+ // with the transactions.
1145
928
  /**
1146
- * Sentinel returned by readNodeFast when the plain-signal fast path does not
1147
- * apply and the caller must fall back to the full read().
1148
- */ const READ_SLOW = Symbol("read-slow");
1149
-
1150
- /**
1151
- * read()'s plain-signal fast path as a standalone entry for hot callers
1152
- * (store traps). Safe to substitute for read() only because the bail
1153
- * conditions mirror read()'s prelude and fast-path guard exactly: the
1154
- * latestRead and pendingCheck windows run side-effectful hooks before the
1155
- * fast path, `_fn` nodes need prepareComputed, and firewall / override /
1156
- * snapshot / transition / lane / dev-strictRead state all take the full
1157
- * resolution. Anything slow returns READ_SLOW; the caller then calls read().
1158
- */
1159
- /**
1160
- * Wake only authoritative-view readers (until() predicates) subscribed to `el`.
1161
- * The A17-silent ack paths — an authoritative arrival equal to the active
1162
- * override — use this so the predicate re-evaluates without re-firing
1163
- * ordinary subscribers whose visible (override) value did not change.
1164
- * Pay-for-use: reached through GlobalQueue._notifyAuthoritativeObservers,
1165
- * installed at first until() call — apps that never use until() shake it.
1166
- */ function notifyAuthoritativeObservers(e) {
1167
- for (let n = e.u; n !== null; n = n.Ae) {
1168
- const e = n.ge;
1169
- if (!(e.C & CONFIG_AUTHORITATIVE_READ)) continue;
1170
- // Missed-wake latch (#3037), same contract as insertSubs: the reader may
1171
- // itself have pulled this recompute (updateIfNecessary from its own
1172
- // read), and the heap refuses RECOMPUTING nodes — latch so recompute's
1173
- // tail reschedules it with the staged value visible.
1174
- if (e.oe & REACTIVE_RECOMPUTING_DEPS && n.Be === e.Ye && n !== e.Nn) e.oe |= REACTIVE_MISSED_WAKE;
1175
- enqueueSub(e);
1176
- }
1177
- schedule();
1178
- }
1179
-
1180
- /** Installs the authoritative-reader wakeup hook. Idempotent; called by every
1181
- * creator of a CONFIG_AUTHORITATIVE_READ computation — until() and refresh() —
1182
- * before its first read (same late-binding contract as the optimistic engine;
1183
- * the gating bit is only ever set by such a read, so the `!` call sites are
1184
- * safe once every setter installs, #3303). */ function installAuthoritativeRead() {
1185
- if (GlobalQueue.zn === null) GlobalQueue.zn = notifyAuthoritativeObservers;
1186
- }
1187
-
1188
- /**
1189
- * Stale-reader term of the value selections below: a render effect reading a
1190
- * node some OTHER live transaction has staged sees the committed value. The
1191
- * commit is silent — the staging walk was the notification — so a reader
1192
- * that linked AFTER that walk (an effect created during the hold, a store
1193
- * key first read under it) would show the old value past the reveal: record
1194
- * it for the transaction's commit replay (the `_gatedSubs` contract lanes
1195
- * already use). An effect the transaction itself computed re-derives at its
1196
- * commit on its own (parked run, or the contested re-derive, #3322) and is
1197
- * not recorded — replaying it too would publish the frame twice.
1198
- *
1199
- * Flight twin (the pending-branch carve-out): the reader is served the
1200
- * node's committed, pre-flight value and now observes that flight — A15:
1201
- * async work observed by a reader settles as one unit with the writes that
1202
- * asked it — so it joins the transaction's reporters for the node. The
1203
- * reporter the transaction recorded when the flight started may be gone (a
1204
- * keyed remount disposed it, #3374); a completion check that found no live
1205
- * reporter committed the writes ahead of the answer, tearing the new
1206
- * reader's frame (`Count: 1` beside `Details: 0`). Joins an entry the
1207
- * transaction already holds; a flight nobody had observed yet has none (the
1208
- * reader is its first observer — a conditional that just revealed it, #3458)
1209
- * and is notified up the reader's own queue chain under that transaction,
1210
- * the one sanctioned registration site (INV-3): a collecting boundary above
1211
- * the reader consumes it as it would any pending, an unboundaried reader
1212
- * opens the entry — and the transaction, judged complete on its other
1213
- * flights, revealed the inputs beside the reader's pre-flight value
1214
- * otherwise (`Count: 1 | A: 1` beside `B: 0`). A staged signal or a settled
1215
- * node registers nothing. Every reporter dies with its reader
1216
- * (reporterBlocksSource: the read linked it as a dep). The node's own entry
1217
- * is the only one that can matter: a chain's intermediate memo is re-pulled
1218
- * by the read (updateIfNecessary's retry) and enters the transaction, so the
1219
- * reader holds through the normal path; a node with its own flight that is
1220
- * also pending on an upstream re-ask blocks through that flight until it
1221
- * lands, and its landing re-runs the reader into the normal path.
1222
- */
1223
- /** The replay half of the stale-of-foreign clause (A15 / A26): a stale reader
1224
- * served the committed value because `txn` holds what it read re-runs at
1225
- * txn's commit, when the value it was denied becomes the frame — unless its
1226
- * own last value already came from that transaction. One registration for
1227
- * the node path (heldFromStale) and the store's backing paths, which have
1228
- * no node to carry the hold (heldFromReader, the adoption hold view). */ function recordStaleReplay(e, n) {
1229
- const t = n.pn;
1230
- if (t == null || currentTransition(t) !== e) e.In.add(n);
1231
- }
1232
-
1233
- /**
1234
- * The ownership relation (DESIGN-CONSOLIDATION §6, ruled 2026-09-17): is
1235
- * `hold` part of the running pass's world? A plain reader's world is the
1236
- * transaction it runs under, through merges. A lane reader's world is its
1237
- * lane AND the transition that owns the lane — the one asymmetry between a
1238
- * lane and a separate transaction (a lane sees what lands from its parent as
1239
- * its own; a separate transaction would wait for the parent to settle) —
1240
- * see `ownsLane` in lanes.ts, built on this. One relation for the
1241
- * stale-of-foreign clause (heldFromStale), the lane arm (readsHeldCommitted)
1242
- * and the store's backing holds (foreignHold); `serve` has no lane arm of
1243
- * its own, the lane's extra visibility lives here.
1244
- */ function ownsHold(e) {
1245
- return activeTransition !== null && currentTransition(e) === currentTransition(activeTransition);
1246
- }
1247
-
1248
- function heldFromStale(e, n) {
1249
- const t = e.we;
1250
- if (t === null || ownsHold(t)) return false;
1251
- const i = currentTransition(t);
1252
- recordStaleReplay(i, n);
1253
- const u = i.le.get(e);
1254
- if (u) u.add(n); else if (e.h & STATUS_PENDING) runInTransition(i, () => n.T.notify(n, STATUS_PENDING, STATUS_PENDING, e.o._));
1255
- return true;
1256
- }
1257
-
1258
- /**
1259
- * A tracked computation about to be served a live transaction's staged value
1260
- * derives from that transaction's world, so it enters the transaction and
1261
- * this pass's result is held with it (A29, #3408). The write side (`setSignal`)
1262
- * and a stamped node's recompute already enter; a reader that only now
1263
- * starts reading the held node — a conditional memo whose branch flipped —
1264
- * was the gap: it published a value derived from the staged world into the
1265
- * mainline frame. Not for a probe (`isPending(() => x())` observes, it does
1266
- * not derive) and a no-op for the ambient batch (`_transition` null) or the
1267
- * transaction already active.
1268
- */
1269
- /** The transaction a pass running OUTSIDE a flush was served a staged value
1270
- * from (A29, creation-time form). Inside a flush the pass enters through
1271
- * initTransition; outside one — a memo or effect created from mainline code
1272
- * while a hold is live — entering would leave `activeTransition` and the
1273
- * batch pointed at the transaction for the rest of the synchronous block,
1274
- * so an unrelated write made after the mount was held with someone else's
1275
- * action. The entry is the pass's alone: recompute stages the node into the
1276
- * transaction (born held) and mainline is never touched.
1277
- *
1278
- * A pass under a FRESH loading boundary takes this path inside a flush too
1279
- * (#3540). Born held is right for a plain memo or effect: published, its
1280
- * value would tear the frame. A boundary that has not revealed yet is the
1281
- * exception by definition — its job is to catch what is not ready under it
1282
- * rather than let it hold: the pass is staged into the transaction as
1283
- * above, and the boundary is told (recompute's born-held arm notifies it
1284
- * with a `NotReadyError` sourced at the node) so it shows its fallback now
1285
- * and reveals the staged result at the commit.
1286
- * Entering instead adopted the whole flush into the hold — a `Show` that
1287
- * flipped mainline to mount a `Loading` over a held value waited for the
1288
- * hold with it. A boundary that already shows content keeps the entering
1289
- * path: it has content to keep, and holds like any reader. */ let stagedEntry = null;
1290
-
1291
- /** Is `el` routed to a loading boundary that still shows its fallback — the
1292
- * nearest pending-collecting queue up its chain is uninitialized? (Measured
1293
- * 2026-09-18: relocating the walk behind a `GlobalQueue` slot installed by
1294
- * boundaries.ts saved ~8 B on the core floor and cost boundary-using apps
1295
- * 50–70 B — the indirection's tokens outweigh the walk. Kept inline.) */ function underFreshLoadingBoundary(e) {
1296
- for (let n = e.T; n !== null; n = n._parent) if (n.te & STATUS_PENDING) return !n.q;
1297
- return false;
1298
- }
1299
-
1300
- function enterStagedRead(e, n = e.we) {
1301
- if (!n || n === activeTransition || pendingCheckActive) return;
1302
- // A companion (the latest() shadow, the isPending() verdict signal) is the
1303
- // engine's mirror of the flushed world — reading it, or being it, is an
1304
- // observation, not a derivation from the hold: latest(x) never enters x's
1305
- // transaction, and the shadow's own pass never enters either (it would
1306
- // flip activeTransition under the reader that pulled it). (`el` is null for
1307
- // a store backing served under a hold — no node, the transaction is the
1308
- // fold's.)
1309
- if (e?.o?.kn || context?.o?.kn) return;
1310
- // A bookkeeping read (`spectate`) is nobody's derivation: it compares or
1311
- // probes, and enters nothing — the boundary priming read of a born-held
1312
- // tree must not enter the creator's pass into the hold (#3540).
1313
- if (spectating) return;
1314
- // Verdict machinery (GlobalQueue._verdictPull: companion creation and the
1315
- // latest()/isPending() pulls — the latest() shadow is created before it is
1316
- // marked optimistic, so the bit alone cannot tell) and optimistic nodes
1317
- // (own lane posture, A31) read staged truth by design; they keep the
1318
- // entering path.
1319
- // (`context` is non-null here: every caller selected a value for a reader.)
1320
- const t = context;
1321
- const i = activeTransition === null && !globalQueue.Jn;
1322
- // Verdict pulls are observations, not derivations: a latest() /
1323
- // isPending() call from mainline must never enter a transaction (it
1324
- // would capture the rest of the caller's synchronous block).
1325
- if (i && GlobalQueue.Xn) return;
1326
- if (t.oe & REACTIVE_RECOMPUTING_DEPS && !(t.C & CONFIG_OPTIMISTIC) && (stagedEntry === null || stagedEntry === n) && (i || !GlobalQueue.Xn && underFreshLoadingBoundary(t))) {
1327
- stagedEntry = n;
1328
- return;
1329
- }
1330
- globalQueue.initTransition(n);
1331
- }
1332
-
1333
- /**
1334
- * Rule 1 (value selection), the full arm: does this reader see a STAGED
1335
- * node's COMMITTED value? One implementation of the rule the fast paths
1336
- * (readNodeFast, read's fast block) carry as their trivial ternary and that
1337
- * every slow site — read's tail, the store's backing selection, the lane and
1338
- * verdict arms — used to restate by hand (docs/DESIGN-CONSOLIDATION.md, move 3b). In order:
929
+ * Rule 1 (value selection): does this reader see a STAGED node's COMMITTED
930
+ * value? One implementation of the rule the fast paths (read's fast block)
931
+ * carry as their trivial ternary. In order:
1339
932
  * - no reader at all (an untracked read) — the committed frame;
1340
- * - a reader under an optimistic lane the engine says reads committed
1341
- * (laneReadsCommitted: another lane's hold, #3460);
1342
933
  * - nothing staged;
1343
934
  * - a children-forbidden reader (createTrackedEffect / onSettled: the frame,
1344
- * never the graph — A32);
1345
- * - a stale reader (render effect) of a FOREIGN transaction's staged write —
1346
- * committed, no entanglement (heldFromStale registers the replay; a node
1347
- * born held has no committed frame to fall back to, `noCommitted`);
1348
- * - HELD truth (#3164, CONFIG_HELD_TRUTH) read by a LANE pass: staged
1349
- * confirming truth — fold-staged onto an armed family, or entangle-stolen
1350
- * by an awaited until() — is masked from lane passes only, owning
1351
- * transaction or not. A lane applies its frame display-ahead at the park,
1352
- * so a lane pass served the truth would paint the confirmation beside the
1353
- * optimism it confirms (`saving=true` beside the saved row — the #3164
1354
- * tear); it keeps committed and is re-run by the reveal's post-revert
1355
- * wake. Every other deriving reader falls through to A29 below: the truth
1356
- * is a staged value like any other, and the pass that derives from it is
1357
- * held with it — including the retaining transaction's own passes, which
1358
- * a superseded override already hands the truth (#3568: masking them
1359
- * composed the landed `length` with rows still masked to committed).
1360
- * latest() and authoritative readers (until()'s predicate) tunnel
1361
- * through — the tunnel that keeps the hold deadlock-free.
1362
- * False means the reader derives from the staged value and enters its
1363
- * transaction (enterStagedRead, A29).
1364
- */ function readerSeesCommitted(e, n, t, i) {
1365
- return !!(!n || currentOptimisticLane !== null && GlobalQueue.$n(e, t, n) || e._e === NOT_PENDING || n.C & CONFIG_CHILDREN_FORBIDDEN || stale && !i && heldFromStale(e, n) || e.C & CONFIG_HELD_TRUTH && currentOptimisticLane !== null && !latestReadActive && !(n.C & CONFIG_AUTHORITATIVE_READ));
935
+ * never the graph — A32).
936
+ * False means the reader derives from the staged value.
937
+ */ function readerSeesCommitted(e, t) {
938
+ return !!(!t || e.Ae === NOT_PENDING || t.u & CONFIG_CHILDREN_FORBIDDEN);
1366
939
  }
1367
940
 
1368
- /** A28 — set when a node is staged (queuePendingNode) or a held node rewritten
1369
- * (stashHeldRewrite) OUTSIDE a flush; cleared when the next flush begins. The
1370
- * read sites test this one module boolean instead of `globalQueue._running`:
1371
- * inside a flush it is false and the A28 arm costs nothing; outside, only a
1372
- * tick with unflushed writes pays the staged-node check. */ let unflushedStaged = false;
941
+ /** A28 — set when a node is staged (queuePendingNode) OUTSIDE a flush;
942
+ * cleared when the next flush begins. The read sites test this one module
943
+ * boolean instead of `globalQueue._running`: inside a flush it is false and
944
+ * the A28 arm costs nothing; outside, only a tick with unflushed writes pays
945
+ * the staged-node check. */ let unflushedStaged = false;
1373
946
 
1374
947
  function markUnflushedStaged() {
1375
948
  unflushedStaged = true;
1376
949
  }
1377
950
 
1378
- /** A28 — a write becomes visible at flush. Outside a flush, a node holding an
1379
- * AMBIENT staged value (no transaction stamp) was written since the last
1380
- * flush: ambient staging commits at flush end, so nothing else leaves a node
1381
- * in this state; a stamped value is the flushed held world, which A28 says
1382
- * latest() serves. Inside a flush the rule does not apply (A28 (4): promoted
1383
- * within the round). Structural — no marker on the write path. */ function unflushed(e) {
1384
- return unflushedValue(e) !== NOT_PENDING;
951
+ /** A28 — a write becomes visible at flush. Outside a flush, a node holding a
952
+ * staged value was written since the last flush: staging commits at flush
953
+ * end, so nothing else leaves a node in this state. Inside a flush the rule
954
+ * does not apply (A28 (4): promoted within the round). The value an
955
+ * unflushed node serves is its committed value, or NOT_PENDING when nothing
956
+ * is unflushed. Exempt: promoted writes (A28 (4): a write issued inside a
957
+ * recompute is promoted at that recompute's end — boundary and loading
958
+ * machinery, signals declared for in-computation writes). */ function unflushedValue(e) {
959
+ if (globalQueue.ee || e.Ae === NOT_PENDING || e.u & CONFIG_PROMOTED) return NOT_PENDING;
960
+ // A held node (L2) carries a staged value between flushes too, but it was
961
+ // flushed — and parked. Not an unflushed write — unless rewritten since:
962
+ // then the flushed staging is what the world sees until the next flush.
963
+ if (e.u & CONFIG_HELD) return e.m.et === clock ? e.m.$e : NOT_PENDING;
964
+ return e.pe;
1385
965
  }
1386
966
 
1387
- /** The value an unflushed node serves — the committed value for an ambient
1388
- * write, the flushed staged value for a rewrite of a held node — or
1389
- * NOT_PENDING when nothing is unflushed. Exempt: owned-write nodes (A28 (4):
1390
- * a write issued inside a recompute is promoted at that recompute's end —
1391
- * boundary and loading machinery, until()'s internals, signals declared for
1392
- * in-computation writes) and engine companions (the isPending() verdict
1393
- * signal, the latest() shadow: the system's own writes, made at the source's
1394
- * write to mirror it, installing eagerly — A28, A8). */ function unflushedValue(e, n = e.ce) {
1395
- if (globalQueue.Jn || e._e === NOT_PENDING || e.C & CONFIG_PROMOTED || e.o?.kn) return NOT_PENDING;
1396
- // Ambient, or adopted by a transaction before any flush carried the staging
1397
- // (CONFIG_ADOPTED_UNFLUSHED): nothing flushed is staged — the committed
1398
- // value answers (the caller's notion of committed: a store node's backing).
1399
- // A held node: unflushed only if rewritten since the last flush (stash).
1400
- if (e.we === null || e.C & CONFIG_ADOPTED_UNFLUSHED) return n;
1401
- return e.o === null ? NOT_PENDING : e.o.bn;
967
+ /** A28: a held node rewritten outside a flush keeps the staging the last
968
+ * flush left (`_flushed`) until the flush that carries the rewrite — the
969
+ * stash is stamped with the clock, which that flush advances. */ function stashFlushed(e) {
970
+ const t = e.m;
971
+ if (t.et !== clock) {
972
+ t.$e = e.Ae;
973
+ t.et = clock;
974
+ unflushedStaged = true;
975
+ }
1402
976
  }
1403
977
 
1404
- /** Held nodes rewritten since the last flush (setSignal); the flush clears
1405
- * their stash — from then on latest() answers with the rewrite. */ const unflushedRewrites = [];
1406
-
1407
978
  /** Nodes written inside a creation-time recompute (CONFIG_PROMOTED). */ const promotedWrites = [];
1408
979
 
1409
- /** A28 (5): an optimistic write becomes the ACTIVE override at the flush that
1410
- * carries it. `_overrideTime` is stamped with `clock` at the write and `clock`
1411
- * advances after every flush, so "this tick, outside a flush" is unflushed. */ function unflushedOverride(e) {
1412
- // Companions are optimistic signals written by the engine (see unflushed).
1413
- return !globalQueue.Jn && e.o?.hn === clock && !e.o?.kn;
1414
- }
1415
-
1416
- /** Active optimistic override on an armed node (an armed slot idles at
1417
- * NOT_PENDING; undefined = unarmed plain node). The writer's own channels —
1418
- * the draft, `in`/keys inside the setter — compose on this regardless of
1419
- * flush state. */ function hasActiveOverride(e) {
1420
- const n = e.o;
1421
- return n !== null && n.Fe !== undefined && n.Fe !== NOT_PENDING;
1422
- }
1423
-
1424
- /** The override a READER sees: installed, and carried by a flush (A28 (5) —
1425
- * an optimistic write is a write; until its flush no reader sees it). One
1426
- * implementation for read()'s override arm, the verdict channels
1427
- * (latestRead, computePendingState) and the store's selection
1428
- * (docs/DESIGN-CONSOLIDATION.md, move 3b). */ function visibleOverride(e) {
1429
- return hasActiveOverride(e) && !unflushedOverride(e);
1430
- }
1431
-
1432
980
  /** A derivation served the committed value because of an unflushed write
1433
981
  * (A28) must run again in the flush that carries it — the late-linker case
1434
982
  * (#3337's reason to defer the walk): it linked after the write walked. */ function markLateLinker(e) {
1435
983
  // The pass's own tail re-enqueues on this latch (recompute's finally) —
1436
984
  // a direct enqueue here would be wiped by the pass's flag reset.
1437
- e.oe |= REACTIVE_MISSED_WAKE;
985
+ e.R |= REACTIVE_MISSED_WAKE;
1438
986
  return true;
1439
987
  }
1440
988
 
1441
- /** Companion-bearing nodes written outside a flush (setSignal); the flush
1442
- * that carries their writes re-syncs their companions (A28). */ const unflushedCompanions = [];
1443
-
1444
989
  function resyncUnflushedCompanions() {
1445
990
  unflushedStaged = false;
1446
- // Length-guarded: the common flush has nothing here, and must allocate nothing.
1447
991
  // Length-guarded: the common flush has nothing here and allocates nothing.
1448
- if (unflushedRewrites.length !== 0) {
1449
- for (const e of unflushedRewrites) e.o.bn = NOT_PENDING;
1450
- unflushedRewrites.length = 0;
1451
- }
1452
- if (promotedWrites.length !== 0) {
1453
- for (const e of promotedWrites) e.C &= ~CONFIG_PROMOTED;
992
+ if (promotedWrites.length !== 0) {
993
+ for (const e of promotedWrites) e.u &= ~CONFIG_PROMOTED;
1454
994
  promotedWrites.length = 0;
1455
995
  }
1456
- if (unflushedCompanions.length !== 0) {
1457
- for (const e of unflushedCompanions) GlobalQueue.Ve(e, e._e !== NOT_PENDING ? e._e : e.ce);
1458
- unflushedCompanions.length = 0;
1459
- }
1460
996
  }
1461
997
 
1462
- function readNodeFast(e) {
1463
- if (latestReadActive || pendingCheckActive || e.he || e.De || e.o?.Fe !== undefined || e.o?.sn !== undefined || activeTransition !== null || currentOptimisticLane !== null || snapshotCaptureActive ||
1464
- // A28: a staged node read outside a flush may serve its committed value;
1465
- // that arm lives on the slow path so this body stays inlinable.
1466
- unflushedStaged && e._e !== NOT_PENDING || false) return READ_SLOW;
1467
- let n = context;
1468
- if (n?.Wn) n = n.qn;
1469
- if (n && tracking) link(e, n);
1470
- // Children-forbidden readers (createTrackedEffect / onSettled callbacks) get
1471
- // committed visibility: like the effect half of createEffect and event
1472
- // handlers, effect-phase code never observes its own unsettled write — the
1473
- // write lands in the same flush's continuation (#3006).
1474
- // A stale reader (render effect) recomputing with no transaction active is
1475
- // mainline: a write staged by a live transaction (`_transition` stamped —
1476
- // ambient staging never is) stays masked until that transaction's reveal,
1477
- // the same rule the slow path applies (#3322). Without it a zombie
1478
- // recompute, or a commit-time re-derive of a contested effect, published
1479
- // another transaction's uncommitted value.
1480
- return !n || e._e === NOT_PENDING || n.C & CONFIG_CHILDREN_FORBIDDEN || stale && heldFromStale(e, n) ? e.ce : (enterStagedRead(e),
1481
- e._e);
998
+ /** A tracked read's pull of a computed: bring it current when the flush has
999
+ * reached its height (or the reader is a fresh-pull waiter), and sit the
1000
+ * reader above it. */ function pullComputed(e, t) {
1001
+ if (e.Le >= dirtyQueue.He) {
1002
+ markNode(t);
1003
+ markHeap(dirtyQueue);
1004
+ updateIfNecessary(e);
1005
+ }
1006
+ // Fresh-pull readers (awaitable refresh's waiter) recompute a dirty
1007
+ // source inline even when the height gate defers to the flush: the
1008
+ // waiter must park on the re-ask's window (or serve its sync answer),
1009
+ // never read the PRE-re-ask value as settled. Self-guarded: a clean
1010
+ // node no-ops and updateIfNecessary refuses disposed nodes (#2983) —
1011
+ // a dead target serves its last value, which is already quiescent.
1012
+ else if (t.u & CONFIG_FRESH_READ) updateIfNecessary(e);
1013
+ const n = e.Le;
1014
+ // parent check is shallow, might need to be recursive
1015
+ if (n >= t.Le && e._parent !== t) t.Le = n + 1;
1482
1016
  }
1483
1017
 
1484
1018
  function read(e) {
1485
- // Handle latest() mode: read from _latestValueComputed
1486
- // Checked before isPending so that isPending(() => latest(x)) checks
1487
- // the _pendingSignal of _latestValueComputed (async in flight) rather
1488
- // than the original node (which stays "pending" while held in a transition).
1489
- if (latestReadActive) return GlobalQueue.et(e);
1490
- let n = context;
1491
- if (n?.Wn) n = n.qn;
1492
- const t = e;
1493
- const i = e.De;
1494
- const u = i || e;
1495
- // Handle isPending() mode: collect pending state while preserving normal read semantics.
1496
- // Probe mode is suspended while preparing the node so nested reads during a
1497
- // recompute don't collect into the probe.
1498
- if (pendingCheckActive) {
1499
- GlobalQueue.nt(e, n, u, i);
1500
- } else if (typeof t.he === "function") {
1501
- prepareComputed(e, false);
1502
- }
1503
- if (!t.he && u === e && e.o?.Fe === undefined && e.o?.sn === undefined && activeTransition === null && currentOptimisticLane === null && !snapshotCaptureActive && (!unflushedStaged || e._e === NOT_PENDING) && // A28, see readNodeFast
1019
+ let t = context;
1020
+ if (t?.Et) t = t.ut;
1021
+ const n = e;
1022
+ // CARVE 1: `owner` was `el._firewall || el` — a store leaf's status,
1023
+ // height and error were read off its projection computed. (Typed loosely
1024
+ // as the `||` expression was: a signal's `_statusFlags`/`_height` read as
1025
+ // undefined and mask to 0 on every site below.)
1026
+ const E = e;
1027
+ if (typeof n.re === "function") prepareComputed(e);
1028
+ // The verdict windows (`latest`, `isPending`; verdict.ts): one cold path,
1029
+ // off this one, present only while a window is open.
1030
+ if (verdict !== null) return verdict(e, t);
1031
+ if (!n.re && e.m?.xe === undefined && !snapshotCaptureActive && (!unflushedStaged || e.Ae === NOT_PENDING) && // A28, see readNodeFast
1032
+ !(e.u & CONFIG_OVERRIDE) && // lanes: the slow path's one arm
1504
1033
  true) {
1505
- if (n && tracking) link(e, n);
1506
- // Committed visibility for children-forbidden readers and for stale
1507
- // readers of a foreign transaction's staged write — see readNodeFast.
1508
- return !n || e._e === NOT_PENDING || n.C & CONFIG_CHILDREN_FORBIDDEN || stale && heldFromStale(e, n) ? e.ce : (enterStagedRead(e),
1509
- e._e);
1510
- }
1511
- if (n && tracking) {
1512
- link(e, n, pendingCheckActive);
1513
- if (u.he) {
1514
- const t = queueFor(e);
1515
- if (u.rn >= t.ln) {
1516
- markNode(n);
1517
- markHeap(t);
1518
- updateIfNecessary(u);
1519
- }
1520
- // Fresh-pull readers (awaitable refresh's waiter) recompute a dirty
1521
- // source inline even when the height gate defers to the flush: the
1522
- // waiter must park on the re-ask's window (or serve its sync answer),
1523
- // never read the PRE-re-ask value as settled. Self-guarded: a clean
1524
- // node no-ops and updateIfNecessary refuses disposed nodes (#2983) —
1525
- // a dead target serves its last value, which is already quiescent.
1526
- else if (n.C & CONFIG_FRESH_READ) updateIfNecessary(u);
1527
- const i = u.rn;
1528
- // parent check is shallow, might need to be recursive
1529
- if (i >= n.rn && e._parent !== n) {
1530
- n.rn = i + 1;
1034
+ if (t) {
1035
+ if (tracking) link(e, t);
1036
+ // L2: a pass that reads something already in the future joins it —
1037
+ // the one mechanism behind "a write that reaches the future joins
1038
+ // it". Tracked or not (`untrack` is about dependencies, not about
1039
+ // which world a pass derives from — posture-store-parity S4/S5): a
1040
+ // derivation of a held write published mainline would tear. Frame
1041
+ // readers (children-forbidden, A32) see committed below and stay
1042
+ // out; a render effect outside a parking flush sees committed and
1043
+ // stays out too (rule 3, `frameRead`). The pass remembers it read the
1044
+ // future (REACTIVE_JOINED): a first pass that did is born held (A29),
1045
+ // wherever it was created. Lane work sees the screen (`frameRead`).
1046
+ if (e.u & CONFIG_HELD && !(t.u & CONFIG_CHILDREN_FORBIDDEN)) {
1047
+ if (frameRead(t, e)) return e.pe;
1048
+ joinPass(t, e);
1531
1049
  }
1532
1050
  }
1051
+ // Committed visibility for untracked and children-forbidden readers.
1052
+ if (!t || e.Ae === NOT_PENDING || t.u & CONFIG_CHILDREN_FORBIDDEN) return e.pe;
1053
+ // (A plain signal is never uninitialized — the carve-out is `serve`'s.)
1054
+ if (t.u & CONFIG_VERDICT && stagedScreen(t)) return e.pe;
1055
+ stagedRead(t);
1056
+ return e.Ae;
1057
+ }
1058
+ // Rule 3: this read serves the committed value to a render effect outside a
1059
+ // parking flush (decided after the pull below — a pull can join).
1060
+ let u = false;
1061
+ if (t) {
1062
+ if (tracking) {
1063
+ link(e, t);
1064
+ if (E.re) pullComputed(E, t);
1065
+ }
1066
+ // L2, as in the fast block above (tracked or not). A node born into the
1067
+ // future (uninitialized) has no committed value: every reader derives
1068
+ // from the future there, a render effect included (A29: a stale reader
1069
+ // of it cannot fall back to the committed frame and enters instead).
1070
+ if (e.u & CONFIG_HELD && !(e.u & CONFIG_OVERRIDE) && !(t.u & CONFIG_CHILDREN_FORBIDDEN)) {
1071
+ if (E.G & STATUS_UNINITIALIZED || !frameRead(t, e)) joinPass(t, e); else u = true;
1072
+ }
1073
+ }
1074
+ // Lanes: a lane's node (after the pull — the node is current). NOT_PENDING
1075
+ // falls through: lane work's read of a pending member throws like any.
1076
+ if (e.u & CONFIG_OVERRIDE) {
1077
+ const n = GlobalQueue.Nt(t, e);
1078
+ if (n !== NOT_PENDING) return n;
1079
+ }
1080
+ // A stale reader of a held flight (rule 3, A15's reveal corollary) is served
1081
+ // the committed value — coherent with the frame, whose inputs are the
1082
+ // committed ones too — and does not go pending on it. So is lane work
1083
+ // reading a flight that is not the lane's own (the parent's, or
1084
+ // mainline's): a lane breaks out of its parent's hold and waits only on
1085
+ // what derives from the guess (A31: "under a lane, a pending node on no
1086
+ // lane serves its committed value").
1087
+ // A verdict reader likewise (CONFIG_VERDICT): a frame reader sees the
1088
+ // screen, and for a flight the screen is the committed value — a render
1089
+ // effect keeps its DOM by throwing, a memo has no DOM and is handed the
1090
+ // value. `[isPending(x), x()]` reads `[true, stale]` in either order (A10)
1091
+ // — unless the flight committed beneath inputs already on screen
1092
+ // (`observeFlight`).
1093
+ if (E.G & STATUS_PENDING && !u && !(e.u & CONFIG_OVERRIDE) && !(E.G & STATUS_UNINITIALIZED)) {
1094
+ // A reader with no committed value yet sees the flight pending: a
1095
+ // boundary a lane mounts shows its fallback (A29's boundary exemption).
1096
+ if (passLane !== null && !(t?.G & STATUS_UNINITIALIZED)) u = true; else if (t !== null && t.u & CONFIG_VERDICT) u = GlobalQueue.ft(t, E);
1533
1097
  }
1534
- if (u.h & STATUS_PENDING) {
1535
- // A reader landing on a pending node throws — the reveal that discovered
1536
- // the flight holds on it (A15: observed async settles as one unit) — with
1537
- // one carve-out: a stale (render) reader of a node pending in some OTHER
1538
- // transaction keeps showing the node's committed value, no entanglement
1539
- // (parallel transactions; the reader is recorded for that transaction's
1540
- // commit replay, `heldFromStale`). The carve-out is sound only while the
1541
- // committed value is coherent with the visible frame, i.e. while the
1542
- // flight's inputs are themselves unpublished: the stamp alone does not
1543
- // say so (it is pending-node bookkeeping), so it is refused when the
1544
- // inputs are on screen — committed by a batch that left the flight in
1545
- // the air (CONFIG_INPUTS_PUBLISHED, #3305) or revealed through a lane
1546
- // (optimistic / latest, #3334) — and the reader holds instead. An
1547
- // UNINITIALIZED node has no committed value to show and holds too
1548
- // (firewall-backed store reads always did; plain memos since the #3043
1549
- // port): falling through served `undefined` as if settled and stranded
1550
- // the reader outside both transactions, so it never re-ran.
1551
- if (n && !(stale && !(u.h & STATUS_UNINITIALIZED) && !(u.C & CONFIG_INPUTS_PUBLISHED) && !(u.C & CONFIG_HAS_LANE && GlobalQueue.tt(u)) && heldFromStale(u, n))) {
1552
- // Per-lane suspension lives with the engine (a non-null lane implies it
1553
- // is installed): under a lane, only same-lane pending async without an
1554
- // active override throws — plus uninitialized sources regardless of
1555
- // lane (#3276); that check rides laneSuspends so floor bundles don't
1556
- // pay for it.
1557
- if (currentOptimisticLane === null || GlobalQueue.it(u)) {
1098
+ if (E.G & STATUS_PENDING && !u) {
1099
+ // A reader landing on a pending node throws; an untracked read of an
1100
+ // UNINITIALIZED node has no committed value to serve and throws too. A
1101
+ // children-forbidden reader (createTrackedEffect / onSettled) sees the
1102
+ // frame, not the graph (A32): the committed value, and the NotReady only
1103
+ // where there is none (uninitialized).
1104
+ if (t) {
1105
+ if (!(t.u & CONFIG_CHILDREN_FORBIDDEN) || E.G & STATUS_UNINITIALIZED) {
1558
1106
  // An untracked read of a pending node still re-runs its reader when
1559
1107
  // the node settles — unless nobody is reading (`spectating`, #3528)
1560
1108
  // or the reader is the node itself.
1561
- if (!tracking && !spectating && e !== n) link(e, n);
1562
- throw u.o?._;
1109
+ if (!tracking && !spectating && e !== t) link(e, t);
1110
+ throw E.m?.V;
1563
1111
  }
1564
- } else if (!n && u.h & STATUS_UNINITIALIZED &&
1565
- // An armed DERIVED override shields the uninitialized state from a
1566
- // read with no reader identity (#3648 follow-up, A18 (d)): a memo
1567
- // whose first landing rode its lane (asyncWrite's lane branch →
1568
- // `laneOverride`) has no `_value` — the flag stays set until the lane's
1569
- // commit promotes the override — yet the override IS the displayed
1570
- // value of a pending node (A18 (c), the screen keeps it until the
1571
- // commit), exactly as an initialized node re-deriving under its override
1572
- // displays it. "Uninitialized must suspend" (#3276, A19 exception 1) was
1573
- // written for a node with NOTHING to show; this node has the override.
1574
- // The arm fires in the body-end window: the source override superseded
1575
- // (A18 body-end, #3427), the memo re-deriving on the plain channel and
1576
- // held, its own slot still armed. Fall through to serve()'s override
1577
- // arm. Readers WITH identity are untouched: a tracked lane reader keeps
1578
- // the override (A17), an off-lane one suspends (#3651, `overrideRead`).
1579
- !(hasActiveOverride(e) && e.C & CONFIG_DERIVED_OVERRIDE)) {
1580
- throw u.o?._;
1112
+ } else if (E.G & STATUS_UNINITIALIZED) {
1113
+ throw E.m?.V;
1581
1114
  }
1582
1115
  }
1583
- // `owner` is the computed itself, or the firewall behind a store node —
1584
- // firewall-backed reads follow the same rules (memo parity, #2897 ruling):
1585
- // an errored derive throws for every late reader instead of silently
1586
- // serving node values (the seed, or last-good data after a failed refetch).
1587
- if (u.he && u.h & STATUS_ERROR) {
1116
+ // An errored derive throws for every late reader instead of silently
1117
+ // serving node values (memo parity, #2897 ruling).
1118
+ if (E.re && E.G & STATUS_ERROR) {
1588
1119
  // Only a genuine reactive re-read may retry an errored async source:
1589
1120
  // - tracking: owned/tracked scope only (never events / `untrack` / effect side-effect phase)
1590
- // - !pendingCheckActive: an `isPending` probe observes the error, never refetches
1591
1121
  // - owner._time < clock: only on a later cycle than the one the error was found
1592
- if (tracking && !pendingCheckActive && u.be < clock) {
1593
- recompute(u);
1122
+ if (tracking && E.Ne < clock) {
1123
+ recompute(E);
1594
1124
  return read(e);
1595
- } else throw u.o?._;
1125
+ } else throw E.m?.V;
1596
1126
  }
1597
- if (snapshotCaptureActive && n && n.C & CONFIG_IN_SNAPSHOT_SCOPE) {
1598
- const t = e.o?.sn;
1599
- if (t !== undefined) {
1600
- const i = t === NO_SNAPSHOT ? undefined : t;
1601
- const u = e._e !== NOT_PENDING ? e._e : e.ce;
1602
- if (u !== i) n.oe |= REACTIVE_SNAPSHOT_STALE;
1603
- return i;
1127
+ if (snapshotCaptureActive && t && t.u & CONFIG_IN_SNAPSHOT_SCOPE) {
1128
+ const n = e.m?.xe;
1129
+ if (n !== undefined) {
1130
+ const E = n === NO_SNAPSHOT ? undefined : n;
1131
+ const u = e.Ae !== NOT_PENDING ? e.Ae : e.pe;
1132
+ if (u !== E) t.R |= REACTIVE_SNAPSHOT_STALE;
1133
+ return E;
1604
1134
  }
1605
1135
  }
1606
- const l = serve(e, n, u, e.ce);
1607
- if (!n && u === e && typeof t.he === "function" && e.C & CONFIG_AUTO_DISPOSE && !(u.h & STATUS_PENDING) && !e.u &&
1608
- // An untracked read served a visible override returned before this
1609
- // sweep registration when the arm was inline; keep that.
1610
- !visibleOverride(e)) {
1136
+ if (u) return e.pe;
1137
+ const s = serve(e, t);
1138
+ if (!t && typeof n.re === "function" && e.u & CONFIG_AUTO_DISPOSE && !(E.G & STATUS_PENDING) && !e.t) {
1611
1139
  // Deferred, not inline (#3078): an inline unobserved() here made untracked
1612
1140
  // reads destructive — dispose on this read, full revival recompute on the
1613
1141
  // next — so consecutive reads could answer differently with no write in
1614
- // between (the revival samples the ambient transition/lane context).
1142
+ // between.
1615
1143
  // The sweep at flush finalization re-validates and reclaims; schedule()
1616
1144
  // guarantees that flush happens even if nothing else is queued.
1617
1145
  dormantNodes.add(e);
1618
1146
  schedule();
1619
1147
  }
1620
- return l;
1148
+ return s;
1621
1149
  }
1622
1150
 
1623
1151
  /**
1624
1152
  * Rule 1, the one slow implementation (DESIGN-CONSOLIDATION move 3b, step
1625
1153
  * 6c): the value a reader `c` (null = untracked, no pass) is served from
1626
- * `el`, whose committed value is `committed` — the node's own `_value` for
1627
- * a signal or memo, the BACKING for a store property node (single-home rule,
1628
- * O6: committed truth lives in the backing and a node's `_value` is never
1629
- * served for one). Called by read()'s slow tail and by the store's untracked
1630
- * node path (nodeValue); the fast paths (readNodeFast, read's fast block)
1631
- * keep their trivial ternary by design (perf, see the doc). Arms, in order:
1632
- * - the override (A17), routed through the engine for a tracked reader under
1633
- * a lane or a supersession (A18), an authoritative reader marked instead;
1634
- * - the lane entanglement gate (committed, recorded for replay);
1635
- * - a node born held has nothing for an untracked reader (A19 exception 1);
1154
+ * `el`. Called by read()'s slow tail; the fast path (read's fast block) keeps
1155
+ * its trivial ternary by design (perf, see the doc). Arms, in order:
1156
+ * - a node born staged has nothing for an untracked reader (A19 exception 1);
1636
1157
  * - an unflushed write serves committed and re-runs the reader in the
1637
1158
  * carrying flush (A28);
1638
- * - readerSeesCommitted, else the staged value and the transaction (A29).
1639
- */ function serve(e, n, t, i) {
1640
- if (hasActiveOverride(e)) {
1641
- // A17: the override IS the value for every reader — except an authoritative
1642
- // reader (until()'s predicate carries CONFIG_AUTHORITATIVE_READ): it must
1643
- // observe independently-arriving truth, and serving it the caller's own
1644
- // tentative write would trivially satisfy the predicate. The bit is checked
1645
- // on the reading computation itself, so a shared computed the predicate
1646
- // pulls recomputes as ITSELF (context = the memo, no bit) under the normal
1647
- // view. Fall through to normal value selection (staged `_pendingValue` is
1648
- // authoritative — optimism never lives there); the sticky mark makes the
1649
- // A17-silent "landing equals override" paths notify this node's subs so
1650
- // the reader re-runs when truth arrives.
1651
- // A28 (5): an optimistic write written this tick, outside a flush, is not
1652
- // yet the active override — fall through to the normal selection (the
1653
- // authoritative mark below still applies: until() must wake on landing).
1654
- if (!(n && n.C & CONFIG_AUTHORITATIVE_READ) && !unflushedOverride(e)) {
1655
- // A tracked read of an override is the engine's selection (a lane or a
1656
- // supersession implies the engine): a render effect OFF the override's
1657
- // held lane sees the committed value (#3460, lanes mirror transitions);
1658
- // a node whose own source answered with a DIFFERENT value hands a
1659
- // tracked reader the staged truth (A18 supersession, #3331). Untracked
1660
- // reads display the override.
1661
- if (n && e.C & (CONFIG_HAS_LANE | CONFIG_OVERRIDE_SUPERSEDED)) return GlobalQueue.ut(e, n);
1662
- return unwrapOverride(e.o?.Fe);
1663
- }
1664
- e.C |= CONFIG_AUTHORITATIVE_OBSERVED;
1665
- }
1666
- // Entanglement gate: a reader recomputing under an optimistic lane that reads
1667
- // a pending mid-transition write sees the committed value. Projection-store
1668
- // manual writes use the firewall's manual-write flag to opt into this path.
1669
- // Async drivers are not under an optimistic lane and so bypass this, reading
1670
- // _pendingValue for correct fetching. The sub is recorded for replay at commit
1671
- // so it re-runs with the new committed view. (Gate details live with the
1672
- // engine — a non-null lane implies it is installed.)
1673
- if (currentOptimisticLane !== null && activeTransition !== null && n !== null && GlobalQueue.lt(e, t, n)) {
1674
- return i;
1675
- }
1676
- // In optimistic lane context, return _value for optimistic/lane-assigned signals
1677
- // and for regular signals in stale mode (render effects). Non-stale readers (user
1678
- // effects) see _pendingValue so that latest() and direct reads stay consistent.
1679
- // (The lane-context clause lives with the engine.) Children-forbidden readers
1680
- // (createTrackedEffect / onSettled callbacks) get committed visibility — see
1681
- // readNodeFast (#3006).
1682
- // A node born held (recompute) has a staged value and no committed one: a
1683
- // stale reader cannot fall back to the committed frame, so it takes the
1684
- // staged value and enters like a tracked reader (A29); an untracked reader
1685
- // has nothing to serve and holds (A19 exception 1) — a bookkeeping read
1686
- // (`spectate`) likewise: it derives nothing, so it cannot enter, and a
1687
- // held-only value is simply not ready to it.
1688
- const u = e._e !== NOT_PENDING && (e.h & STATUS_UNINITIALIZED) !== 0;
1689
- if (u && (!n || spectating)) throw new NotReadyError(null);
1690
- const l = n && unflushedStaged ? unflushedValue(e, i) : NOT_PENDING;
1691
- if (l !== NOT_PENDING) {
1692
- markLateLinker(n);
1693
- if (pendingCheckActive) GlobalQueue.rt(e, l);
1694
- return l;
1159
+ * - readerSeesCommitted, else the staged value.
1160
+ */ function serve(e, t) {
1161
+ // A node born staged (recompute) has a staged value and no committed one:
1162
+ // an untracked reader has nothing to serve and holds (A19 exception 1) — a
1163
+ // bookkeeping read (`spectate`) likewise, and a children-forbidden reader
1164
+ // (A32: the frame, which has nothing here).
1165
+ if (e.Ae !== NOT_PENDING && e.G & STATUS_UNINITIALIZED && (!t || spectating || t.u & CONFIG_CHILDREN_FORBIDDEN)) throw new NotReadyError(null);
1166
+ const n = t && unflushedStaged ? unflushedValue(e) : NOT_PENDING;
1167
+ if (n !== NOT_PENDING) {
1168
+ markLateLinker(t);
1169
+ return n;
1695
1170
  }
1696
- const r = readerSeesCommitted(e, n, t, u) ? i : (enterStagedRead(e), e._e);
1697
- // Record that this isPending() probe observed the fresh pending value, so
1698
- // the probe doesn't pair "pending" with the new value (#2831).
1699
- if (pendingCheckActive) GlobalQueue.rt(e, r);
1700
- return r;
1171
+ if (readerSeesCommitted(e, t)) return e.pe;
1172
+ if (t.u & CONFIG_VERDICT && !(e.G & STATUS_UNINITIALIZED) && stagedScreen(t)) return e.pe;
1173
+ stagedRead(t, e);
1174
+ return e.Ae;
1701
1175
  }
1702
1176
 
1703
- /** A28 — a rewrite of a HELD node outside a flush keeps the staged value the
1704
- * last flush left, for latest()/verdicts, until the next flush carries it
1705
- * (stash, cleared at that flush). Cold: only stamped nodes reach here. */ function stashHeldRewrite(e) {
1706
- if (globalQueue.Jn) return;
1707
- const n = ext(e);
1708
- if (n.bn === NOT_PENDING) {
1709
- n.bn = e._e;
1710
- unflushedRewrites.push(e);
1711
- unflushedStaged = true;
1712
- }
1177
+ /** A pass read a staging of this flush: it derives from what the flush may
1178
+ * yet hold (REACTIVE_STAGED_READ — the seam decides). Lane work too (plan sec. 28, a
1179
+ * lane sees the screen plus its own guesses): the staging is the screen if
1180
+ * the frame commits — one pass, the common case — and a held write if it
1181
+ * parks, which the seam repairs (`stagedReaders`): the pass re-derives on
1182
+ * the committed world and its lane's runs wait that round, so the held
1183
+ * write never shows through the lane. A verdict lane's work likewise: the
1184
+ * lane holds verdicts, not the frame's other stagings (#3851) — except a
1185
+ * verdict reader, which answered for itself (the lane seam, lanes.ts). Not
1186
+ * a read of a node born staged: it has no committed value to re-derive on,
1187
+ * and a re-run would read the same staging and re-queue every round. */ function stagedRead(e, t) {
1188
+ e.R |= REACTIVE_STAGED_READ;
1189
+ if (passLane !== null && !(t?.G & STATUS_UNINITIALIZED)) stagedReaders.push(e);
1190
+ }
1191
+
1192
+ /** A10 for a staged node: a verdict reader (the pass entered a window) that
1193
+ * also reads a frame's proposal plainly sees the screen — `[latest(q), q()]`
1194
+ * is `[b, a]` — once the frame has a transaction, and re-derives when it
1195
+ * lands: at this very seam if nothing holds it (the stale run is void,
1196
+ * #3322 — one run, on the committed world), or with the hold. Before any
1197
+ * transaction the answer is the seam's and the reader watches it
1198
+ * (verdict.ts). A node born into the future has no screen: its staging is
1199
+ * its only value (A29). */ function stagedScreen(e) {
1200
+ if (flushTransaction === null) return false;
1201
+ staleReader(e, flushTransaction);
1202
+ return true;
1713
1203
  }
1714
1204
 
1715
1205
  /** A28 (4) — written inside a recompute that runs OUTSIDE a flush (a
1716
1206
  * creation-time compute): promoted at that pass's end, visible to the rest of
1717
1207
  * the block. Cold: only contextual writes reach here. */ function notePromotedWrite(e) {
1718
- if (globalQueue.Jn || e.C & CONFIG_PROMOTED) return;
1719
- e.C |= CONFIG_PROMOTED;
1208
+ if (globalQueue.ee || e.u & CONFIG_PROMOTED) return;
1209
+ e.u |= CONFIG_PROMOTED;
1720
1210
  promotedWrites.push(e);
1721
1211
  }
1722
1212
 
@@ -1726,52 +1216,29 @@ function read(e) {
1726
1216
  * async landing (asyncWrite), and a value arriving from async during the pass
1727
1217
  * REVEALS — the creation-time arm skips pending computeds for the same
1728
1218
  * reason. Firewall leaves belong to a projection whose compute is the tree's
1729
- * own work, captured (or deliberately not) at creation. */ function captureWriteSnapshot(e, n) {
1730
- if (e.C & CONFIG_NO_SNAPSHOT || e.he !== undefined || e.De || e.o?.sn !== undefined) return;
1731
- ext(e).sn = n === undefined ? NO_SNAPSHOT : n;
1732
- e.C |= CONFIG_HAS_SNAPSHOT;
1219
+ * own work, captured (or deliberately not) at creation. */ function captureWriteSnapshot(e, t) {
1220
+ if (e.u & CONFIG_NO_SNAPSHOT || e.re !== undefined || e.m?.xe !== undefined) return;
1221
+ ext(e).xe = t === undefined ? NO_SNAPSHOT : t;
1222
+ e.u |= CONFIG_HAS_SNAPSHOT;
1733
1223
  snapshotSources.add(e);
1734
1224
  }
1735
1225
 
1736
- function setSignal(e, n) {
1737
- // A write to a held node is a second proposal on a contested node (A34, #3494):
1738
- // the writer's tick reveals with the hold, the same value or another. Inside
1739
- // a flush the round enters now; from mainline the entry waits for the next
1740
- // flush's start (batchJoins) — entering here left activeTransition set for
1741
- // the rest of the caller's block, so a memo created after the write became
1742
- // the transaction's instead of mainline's (A28, A29). Before the equality
1743
- // gate below: repeating the held value proposes it too — and that repeat
1744
- // leaves through the gate, so the join schedules its own flush here; left
1745
- // for the next flush to find, it adopted an unrelated tick (#3519 review).
1746
- // A held DERIVATION is not a proposal (A34 amendment, #3612): the user
1747
- // setters of derived nodes (setMemo, the derived store's setter) classify
1748
- // the write before it reaches here — see heldDerivation — and re-derive
1749
- // under the hold instead of masking; the join stands either way.
1750
- if (e.we && activeTransition !== e.we) {
1751
- if (globalQueue.Jn) globalQueue.initTransition(e.we); else {
1752
- batchJoins.push(e.we);
1753
- // dupes: a bare return in initTransition
1754
- schedule();
1755
- }
1756
- }
1757
- // The optimistic write path lives with the engine: only optimisticSignal /
1758
- // optimisticComputed callers and optimistic store nodes carry an
1759
- // _overrideValue slot (flagged by CONFIG_OPTIMISTIC — a masked read of the
1760
- // always-present config instead of a missing-property probe), and every
1761
- // module that installs one installs the engine first.
1762
- if (e.C & CONFIG_OPTIMISTIC) {
1763
- if (!projectionWriteActive) return GlobalQueue.ot(e, n);
1764
- // An authoritative store landing on an override-covered node: the store
1765
- // twin of asyncWrite's override branch, decided by the engine (#3331).
1766
- const t = e.o?.Fe;
1767
- if (t !== undefined && t !== NOT_PENDING) return GlobalQueue.st(e, n);
1768
- }
1769
- const t = e._e === NOT_PENDING ? e.ce : e._e;
1770
- if (typeof n === "function") n = n(t);
1226
+ function setSignal(e, t) {
1227
+ const n = e.Ae === NOT_PENDING ? e.pe : e.Ae;
1228
+ if (typeof t === "function") t = t(n);
1229
+ // Lanes: a write landing on a guess is its truth (A18 — an async guess's
1230
+ // own landing), judged against the guess; one landing on a lane's
1231
+ // derivation (its flight) is the lane's staging (lanes.ts).
1232
+ if (e.u & CONFIG_OVERRIDE) return GlobalQueue.Tt(e, t);
1233
+ // L2 (T4) / A34 (1): a write to a node whose staged state is held is a
1234
+ // second proposal for the slot — the same value again or another — and
1235
+ // the two cannot finish at different times: the writer's tick joins the
1236
+ // hold, before the equality gate.
1237
+ if (e.u & CONFIG_HELD) joinFuture(txOf(e));
1771
1238
  // Uninitialized check first: the first commit has no previous value, so the
1772
1239
  // user comparator must not run against `undefined` (matches recompute).
1773
- const i = !!(e.h & STATUS_UNINITIALIZED) || !e.xe || !e.xe(t, n);
1774
- if (!i) return n;
1240
+ const E = !!(e.G & STATUS_UNINITIALIZED) || !e.We || !e.We(n, t);
1241
+ if (!E) return t;
1775
1242
  // A write during hydration's snapshot capture to a source that has no
1776
1243
  // snapshot — created BEFORE capture began (module-level state: an identity
1777
1244
  // minted from onSettled in the pass, a preference read from storage) —
@@ -1781,94 +1248,58 @@ function setSignal(e, n) {
1781
1248
  // pass whose DOM writes are skipped, and a component rendered later in the
1782
1249
  // pass reads a value the server never had. Store leaves written here are
1783
1250
  // plain signals and qualify the same way.
1784
- if (snapshotCaptureActive) captureWriteSnapshot(e, t);
1785
- const u = e._e !== NOT_PENDING;
1251
+ if (snapshotCaptureActive) captureWriteSnapshot(e, n);
1252
+ const u = e.Ae !== NOT_PENDING;
1786
1253
  if (!u) queuePendingNode(e);
1787
- // A28 arms, gated on the loads the write already pays for (a plain ambient
1788
- // rewrite outside a flush — the write-loop shape — costs `_transition` and
1789
- // `context` here and nothing else; the arms themselves are cold helpers so
1790
- // setSignal stays within every setter's inlining budget, ~300 B bytecode).
1791
- else if (e.we !== null) stashHeldRewrite(e);
1792
- e._e = n;
1254
+ // A28: a held node rewritten outside a flush keeps its flushed staging
1255
+ // for every reader until the flush that carries the rewrite.
1256
+ else if (e.u & CONFIG_HELD && !globalQueue.ee) stashFlushed(e);
1257
+ e.Ae = t;
1793
1258
  if (context !== null) notePromotedWrite(e);
1794
- // syncCompanions only pokes _pendingSignal/_latestValueComputed — with
1795
- // neither companion present the call is a guaranteed no-op (companions are
1796
- // only ever created, never removed, and creating one installs the hook and
1797
- // sets CONFIG_HAS_COMPANIONS — one masked read replaces two optional-field
1798
- // probes on every write).
1799
- if (e.C & CONFIG_HAS_COMPANIONS && GlobalQueue.Ve !== null) {
1800
- GlobalQueue.Ve(e, n);
1801
- // A28 (2): the verdict computed here is the PRE-flush one (an unflushed
1802
- // write is not pending); the flush that carries the write re-syncs so
1803
- // the companions mirror the flushed world. Only companion nodes pay.
1804
- if (!globalQueue.Jn) unflushedCompanions.push(e);
1805
- }
1806
1259
  // _time is a computed-only slot (§12e): writing it on a signal would fork
1807
1260
  // the lean shape. Every read site is computed-typed.
1808
- if (e.he !== undefined) e.be = clock;
1261
+ if (e.re !== undefined) e.Ne = clock;
1809
1262
  // Staged-rewrite fast path (§12d): a re-write to a node whose subscribers
1810
1263
  // were already walked — and where nothing has recomputed or linked since
1811
1264
  // (epoch) — re-stages the value and stops. The walk is idempotent (subs
1812
- // marked, heap entries flag-guarded, effects queued once); lane and reask
1813
- // contexts change what a walk MEANS, so they always walk.
1814
- if (u && e.vn === notifyEpoch && currentOptimisticLane === null && !reaskArmed) return n;
1265
+ // marked, heap entries flag-guarded, effects queued once).
1266
+ if (u && e.ze === notifyEpoch) return t;
1815
1267
  insertSubs(e);
1816
1268
  schedule();
1817
- return n;
1269
+ return t;
1818
1270
  }
1819
1271
 
1820
1272
  /**
1821
- * Suppresses automatic recomputation of `el` until the scheduler drains. Used
1822
- * when a manual write should win over dependency changes queued in the same
1823
- * tick. The MANUAL_WRITE flag is cleared by the pending-node drain; projection
1824
- * computeds don't commit values, but they still need the same end-of-tick
1825
- * cleanup point.
1826
- */ function suppressComputedRecompute(e) {
1827
- deleteFromHeap(e, queueFor(e));
1828
- if (!(e.oe & REACTIVE_MANUAL_WRITE) && e._e === NOT_PENDING) {
1829
- queuePendingNode(e);
1273
+ * User-facing setter for the memo form of `createSignal(fn)`. A write applies
1274
+ * first, then derivations re-run (A34 as amended 2026-10-01, rule B; core
1275
+ * R31): the write stages like any other, and a source change — in this flush
1276
+ * or a later one, under a hold or on mainline — re-derives with the staged
1277
+ * write as `prev`. The write never refuses the re-run (the frame-scoped mask
1278
+ * of #3733/#3740 and #2692's "write wins the tick" before it are gone; call
1279
+ * order inside a flush was never observable) and on its own never causes one.
1280
+ * REACTIVE_MANUAL_WRITE only marks the staging as a user proposal — the A34
1281
+ * (1)/(3) discriminator — until a pass re-derives it or the commit lands it.
1282
+ */ function setMemo(e, t) {
1283
+ // A34 (3), #3612: is `el`'s staging a derivation another transaction holds
1284
+ // — held, not a manual proposal, and the writer not that transaction
1285
+ // (mainline, or a flush joined elsewhere)? A held pass result is nobody's
1286
+ // proposal: a setter reaching it composes on the committed frame it was
1287
+ // written against and becomes `prev` for the hold's re-derivation, instead
1288
+ // of replacing it. A write made under the hold carries the mark and keeps
1289
+ // (1)'s last-write-wins. Only the user setter asks; an async landing
1290
+ // writing a held node is the transaction's own work.
1291
+ const n = e.u & CONFIG_HELD && !(e.R & REACTIVE_MANUAL_WRITE) && txOf(e) !== flushTransaction;
1292
+ // The writer read the committed frame; its updater composes on it.
1293
+ if (n && typeof t === "function") t = t(e.pe);
1294
+ const E = setSignal(e, t);
1295
+ if (n) {
1296
+ // The one write that re-runs: the staging it replaced was derived from
1297
+ // inputs the writer never saw, so the hold re-derives over the write.
1298
+ e.R = e.R & ~REACTIVE_CHECK | REACTIVE_DIRTY;
1299
+ insertIntoHeap(e, dirtyQueue);
1830
1300
  schedule();
1831
- }
1832
- e.oe = e.oe & -4 | REACTIVE_MANUAL_WRITE;
1833
- e.ct = clock;
1834
- }
1835
-
1836
- /** A34 amendment (#3612) — is `el`'s staging a DERIVATION another transaction
1837
- * holds: stamped by a transaction that is not the writer's, and not a manual
1838
- * proposal (the mask, on the node or — a store leaf — its firewall)? #2692's
1839
- * "manual write wins" is a rule for one synchronous frame; across a hold the
1840
- * held pass result is nobody's proposal, and a user setter reaching it
1841
- * composes on the committed frame it was written against and becomes `prev`
1842
- * for the transaction's re-derivation (rederiveHeld) instead of replacing it.
1843
- * Writes made under the holding transaction masked the node and keep
1844
- * A34(1)'s last-write-wins. Only the user setters ask; an async landing or a
1845
- * companion writing a stamped node is the transaction's own work. */ function heldDerivation(e) {
1846
- return e.we !== null && activeTransition !== e.we && !((e.De || e).oe & REACTIVE_MANUAL_WRITE);
1847
- }
1848
-
1849
- /** The held-derivation write's second half: the node re-derives under its
1850
- * hold with the written staging as the pass's `prev`. Nothing is masked. The
1851
- * write took the A34 join (setSignal), which scheduled the flush that drains
1852
- * this; recompute re-enters the stamp. */ function rederiveHeld(e) {
1853
- e.oe |= REACTIVE_DIRTY;
1854
- // over CHECK: the heap visit recomputes, not re-checks
1855
- enqueueSub(e);
1856
- }
1857
-
1858
- /**
1859
- * User-facing setter for the memo form of `createSignal(fn)`. Behaves like
1860
- * `setSignal`, but also cancels any pending recompute of the memo so the
1861
- * manual value wins over a value that would otherwise be produced by an
1862
- * upstream change in the same tick. Across a hold the write is not a
1863
- * proposal: a memo another transaction holds as a pass result composes on the
1864
- * committed value and re-derives under the hold with the write as `prev`
1865
- * (A34 amendment, #3612; heldDerivation).
1866
- */ function setMemo(e, n) {
1867
- const t = heldDerivation(e);
1868
- if (t && typeof n === "function") n = n(e.ce);
1869
- const i = setSignal(e, n);
1870
- t ? rederiveHeld(e) : suppressComputedRecompute(e);
1871
- return i;
1301
+ } else if (e.Ae !== NOT_PENDING) e.R |= REACTIVE_MANUAL_WRITE;
1302
+ return E;
1872
1303
  }
1873
1304
 
1874
1305
  /**
@@ -1889,27 +1320,23 @@ function setSignal(e, n) {
1889
1320
  * setTimeout(() => runWithOwner(owner, fn), ms);
1890
1321
  * }
1891
1322
  * ```
1892
- */ function runWithOwner(e, n) {
1893
- const t = context;
1894
- const i = tracking;
1323
+ */ function runWithOwner(e, t) {
1324
+ const n = context;
1325
+ const E = tracking;
1895
1326
  context = e;
1896
1327
  tracking = false;
1897
1328
  try {
1898
- return n();
1329
+ return t();
1899
1330
  } finally {
1900
- context = t;
1901
- tracking = i;
1331
+ context = n;
1332
+ tracking = E;
1902
1333
  }
1903
1334
  }
1904
1335
 
1905
- function staleValues(e, n = true) {
1906
- const t = stale;
1907
- stale = n;
1336
+ function staleValues(e, t = true) {
1908
1337
  try {
1909
1338
  return e();
1910
- } finally {
1911
- stale = t;
1912
- }
1339
+ } finally {}
1913
1340
  }
1914
1341
 
1915
1342
  /**
@@ -1917,42 +1344,19 @@ function staleValues(e, n = true) {
1917
1344
  * it validates the target, marks through here, then builds the quiescence
1918
1345
  * promise on the resolve()/until() effect machinery). Flags the node's next
1919
1346
  * recompute as a quiet re-ask and schedules it; no-ops for non-derived or
1920
- * disposed targets and for same-tick manual writes.
1347
+ * disposed targets.
1921
1348
  */ function markRefresh(e) {
1922
- if (typeof e.he === "function" && !(e.oe & REACTIVE_DISPOSED)) {
1923
- if (e.oe & REACTIVE_MANUAL_WRITE) {
1924
- // A manual write in the CURRENT tick wins over the refresh (#2692).
1925
- // A mask stamped in an earlier tick only survives because a
1926
- // transaction (action) is holding the pending drain open; there the
1927
- // refresh is a later, explicit re-ask and lifts the mask — otherwise
1928
- // any setStore early in an action silently swallows every refresh()
1929
- // for the rest of the transaction (#3026).
1930
- if (e.ct === clock) return;
1931
- e.oe &= ~REACTIVE_MANUAL_WRITE;
1932
- // The lift falls through to the re-ask classification below. The held
1933
- // write's value change already rides the transaction; the refetch it
1934
- // asks for is the same question with unchanged inputs. Skipping the
1935
- // mark here classified that refetch as a NEW question, which pends
1936
- // every leaf (3.1) — an action doing setStore + yield + refresh(store)
1937
- // lit up every sibling row, and affects() could not narrow it (a mark
1938
- // only turns pending on). Same-question motion stays silent (3.4);
1939
- // the written slot and any declared mark carry the pending instead.
1940
- }
1941
- // A refresh with no value-change dirt already queued is a re-ask of the
1942
- // same question: mark it so the recompute classifies any resulting
1943
- // pending window as quiet (not pending). If the node is already dirty
1944
- // from a real input change, the question changed — don't mark.
1945
- // REACTIVE_IN_HEAP counts as dirt: insertSubs schedules subscribers by
1946
- // heap insertion alone (no DIRTY/CHECK flag), so a same-batch value
1947
- // change followed by refresh() must not be laundered into a quiet re-ask.
1948
- if (!(e.oe & (REACTIVE_DIRTY | REACTIVE_CHECK | REACTIVE_IN_HEAP))) {
1949
- e.oe |= REACTIVE_REASK;
1950
- armReaskClear();
1951
- }
1952
- e.oe = e.oe & ~REACTIVE_CHECK | REACTIVE_DIRTY;
1953
- insertIntoHeap(e, queueFor(e));
1349
+ if (typeof e.re === "function" && !(e.R & REACTIVE_DISPOSED)) {
1350
+ // A manual write never refuses the re-run (A34 rule B): a refresh in the
1351
+ // write's own frame re-asks with the write as `prev`, like any source
1352
+ // change (#3026 generalized).
1353
+ // The re-ask of an answered question (A19 exc. 2): the next pass, going
1354
+ // pending, classifies its flight quiet for the verdict. Not when an
1355
+ // input already changed this tick — that pass asks a new question.
1356
+ e.R = e.R & ~REACTIVE_CHECK | REACTIVE_DIRTY | (e.R & (REACTIVE_DIRTY | REACTIVE_CHECK | REACTIVE_IN_HEAP) ? 0 : REACTIVE_REASK);
1357
+ insertIntoHeap(e, dirtyQueue);
1954
1358
  schedule();
1955
1359
  }
1956
1360
  }
1957
1361
 
1958
- export { READ_SLOW, clearSnapshots, computed, context, createEffectNode, currentOptimisticLane, effectStatusNotify, enterStagedRead, ext, hasActiveOverride, heldDerivation, installAuthoritativeRead, isEqual, latestReadActive, markLateLinker, markRefresh, markSnapshotScope, markUnflushedStaged, notifyAuthoritativeObservers, notifyOnLane, optimisticComputed, optimisticSignal, ownsHold, pendingCheckActive, prepareComputed, read, readNodeFast, readerSeesCommitted, recompute, recordStaleReplay, rederiveHeld, releaseSnapshotScope, resyncUnflushedCompanions, runWithOwner, serve, setContextInternal, setEffectStatusNotify, setLatestReadActive, setMemo, setPendingCheckActive, setSignal, setSlotUnobserved, setSnapshotCapture, signal, slotSignal, slotUnobservedHook, snapshotCaptureActive, snapshotSources, spectate, spectating, stale, staleValues, statusNotifierOf, suppressComputedRecompute, tracking, unflushed, unflushedCompanions, unflushedOverride, unflushedStaged, unflushedValue, unlinkFirewallChild, untrack, visibleOverride };
1362
+ export { clearSnapshots, computed, context, createEffectNode, effectStatusNotify, ext, isEqual, markLateLinker, markRefresh, markSnapshotScope, markUnflushedStaged, notePromotedWrite, prepareComputed, pullComputed, read, readerSeesCommitted, recompute, releaseSnapshotScope, resyncUnflushedCompanions, runWithOwner, serve, setEffectStatusNotify, setMemo, setSignal, setSnapshotCapture, setVerdict, signal, slotSignal, snapshotCaptureActive, snapshotSources, spectating, stagedRead, stagedScreen, staleValues, stashFlushed, statusNotifierOf, tracking, unflushedStaged, unflushedValue, untrack, verdict };