Skip to content

Commit f8ec4dc

Browse files
committed
fix(signals): two latest() readers under one async memo ask each question once
- A latest() reader whose frame lands at the seam that would re-derive it in the verdict lane keeps its flight: the pass was the landing's (it asked the frame question twice in one flush). The check moves from core's `_update` into lanes.ts `laneSeams`. - Verdict-lane work that read a staging re-derives on the committed world only while the transaction holding the staging stays parked: judged on the flush's transaction, not the lane's parent, and not when the pass's own render effect is all that keeps it parked (`heldBy`). The re-derive asked a question already asked and showed it over inputs the landing replaced. - The landing's adopt of a parked frame flight is a lane hook (`laneAdoptHook`): scheduler.ts no longer imports `adoptFlight`. - #4398's grouped/split pin passes here: grouped and split ask the same questions with latest()'s pass the frame's. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent 4bac383 commit f8ec4dc

6 files changed

Lines changed: 269 additions & 40 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/signals": patch
3+
---
4+
5+
Two `latest()` async readers under one async memo, with the second input written while the first one's flush is parked, ask each question once. A `latest()` reader whose frame lands at the seam no longer re-derives in the verdict lane, so its frame question isn't asked a second time. A verdict-lane pass that read a staging re-derives only while the transaction holding that staging stays parked, judged on that transaction rather than the lane's parent and not counting the pass's own render effect. Before, the memo asked a question twice and could show a value derived from the input's old answer next to its new one.

‎packages/signals/docs/RULES-INDEX.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
146146
| CS-R2a | live | `docs/INTERNALS-STORE-STATE.md:107` | — | — | Corollary R2a (Ryan, 2026-08-17): **take no responsibility for mutation |
147147
| CS-R3 | live | `docs/rules-mining/core-store.md:18` | — | — | A store proxy ingested into another store (deep or shallow) is re-wrapped in the ingesting store's own proxy family — never identity-passed, never raw-marked.** |
148148
| CS-R4 | live | `docs/rules-mining/core-store.md:22` | — | — | Write isolation across a store chain: writing through the last store in a derived chain is visible only there; upstream stores and base objects untouched (shallow or deep middle).** |
149-
| CS-R5 | live | `docs/rules-mining/core-store.md:26` | — | verdict-memo-flight-no-reask.test.ts×3 visibility-oracle-store.states.ts×4 visibility-oracle.states.ts×4 | Upstream writes propagate downstream through the chain without re-running structural machinery.** |
149+
| CS-R5 | live | `docs/rules-mining/core-store.md:26` | — | latest-two-readers-one-ask-4393.test.ts×1 verdict-memo-flight-no-reask.test.ts×5 visibility-oracle-store.states.ts×4 visibility-oracle.states.ts×4 | Upstream writes propagate downstream through the chain without re-running structural machinery.** |
150150
| CS-R6 | live | `docs/rules-mining/core-store.md:30` | — | — | No store write path ever mutates a user-provided source object.** Aligned with 2026-08-16b. |
151151
| CS-R7 | live | `docs/rules-mining/core-store.md:34` | — | — | Circular references wrap without infinite recursion; cycle consistent through proxy (`state.b.a === state.a`).** |
152152
| CS-R8 | live | `docs/rules-mining/core-store.md:38` | — | — | `snapshot` returns fully unwrapped values (no proxy anywhere, `$TARGET` undefined), incl. frozen objects/arrays; reflects committed written values incl. writes over inherited prototype props.** |
@@ -208,7 +208,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
208208
| OL-R2 | superseded | `docs/rules-mining/optimistic-lanes.md:15` | — | — | ~~An optimistic write is synchronously visible to direct reads before any flush — inside the action body, outside it, and outside any reactive context.~~ **Superseded 2026-09-10 by A28(5)** (SPEC-ASYN… |
209209
| OL-R3 | live | `docs/rules-mining/optimistic-lanes.md:19` | — | — | The setter's updater receives the current _visible_ (optimistic-if-overridden) value, never the committed value; a plain setter on the underlying source during a transition composes on the transition'… |
210210
| OL-R4 | live | `docs/rules-mining/optimistic-lanes.md:23` | — | — | Multiple optimistic writes before settle compose sequentially (each updater sees the prior override; last write wins). |
211-
| OL-R5 | live | `docs/rules-mining/optimistic-lanes.md:27` | async.ts×1 lanes.ts×1 scheduler.ts×1 types.ts×1 | — | An optimistic write **outside any action** reverts at the next flush; subscribers observe the optimistic value and then the reverted value within that single flush (effect log `[1, 2, 1]` after one `f… |
211+
| OL-R5 | live | `docs/rules-mining/optimistic-lanes.md:27` | async.ts×1 lanes.ts×2 scheduler.ts×2 types.ts×1 | — | An optimistic write **outside any action** reverts at the next flush; subscribers observe the optimistic value and then the reverted value within that single flush (effect log `[1, 2, 1]` after one `f… |
212212
| OL-R6 | live | `docs/rules-mining/optimistic-lanes.md:32` | — | — | An optimistic write inside an `action` holds for the entire action window and reverts when the action's transition completes; each intermediate write during a multi-yield action is observable in order… |
213213
| OL-R7 | live | `docs/rules-mining/optimistic-lanes.md:36` | — | — | Computed-form `createOptimistic(fn)` with no overrides is a transparent passthrough of its (possibly async) source: promise resolutions, re-fired promises, and async-iterable yields all propagate; ove… |
214214
| OL-R8 | live | `docs/rules-mining/optimistic-lanes.md:40` | — | — | Reset-on-settle targets the source's **newly computed value at settle time**, not the pre-write value: a wrong optimistic guess is auto-corrected to the real result; a correct guess settles silently (… |

‎packages/signals/src/core/lanes.ts‎

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import {
6161
import { attrHooks } from "./attribution-hooks.js";
6262
import { ext, stagedRead, tracking } from "./core.js";
6363
import { NotReadyError, type StatusError } from "./error.js";
64-
import { isThenable } from "./async.js";
64+
import { adoptFlight, isThenable } from "./async.js";
6565
import { laneValueOf } from "./truth.js";
6666
import { enqueueSub } from "./heap.js";
6767
import {
@@ -937,7 +937,22 @@ const applyGuessesAt = (parent: Transaction | null): void => {
937937
judged = lanes.length;
938938
if (pendingGuesses.length !== 0) applyGuesses(parent);
939939
};
940-
const laneSeams = (leaks: Computed<any>[] | null): void => {
940+
/** `t` is parked by `r`'s pass alone: each node keeping it is a render
941+
* effect pending on `r` only — the frame observing the lane work that read
942+
* its staging. Anything else (an open action, a lane, a flight) holds it on
943+
* its own. */
944+
function heldBy(t: Transaction, r: Computed<any>): boolean {
945+
if (t._open !== 0 || lanesBlocked(t)) return false;
946+
for (let i = 0; i < t._nodes.length; i++) {
947+
const n = t._nodes[i] as Computed<any>;
948+
if (!(n._statusFlags & STATUS_PENDING) || (n._x!._transaction !== null && txOf(n) !== t))
949+
continue;
950+
const s = n._x!._pendingSources;
951+
if ((n as any)._type !== EFFECT_RENDER || s?.size !== 1 || !s.has(r)) return false;
952+
}
953+
return true;
954+
}
955+
const laneSeams = (leaks: Computed<any>[] | null, t: Transaction | null): void => {
941956
// Passes that read a write the parked frame holds as the screen
942957
// (`stagedReaders`: lane work, a verdict reader before the verdict): they
943958
// re-derive on the committed world next round (and register as stale
@@ -952,19 +967,25 @@ const laneSeams = (leaks: Computed<any>[] | null): void => {
952967
// lane answered for itself: it re-derives at the holder's landing, not
953968
// now (one run — #3322, #3540). Other verdict-lane work re-derives only
954969
// if the frame stays parked: a transaction landing at this seam makes
955-
// what it read the screen (one run). A reader a transaction holds that
956-
// read none of its stagings (a verdict reader that probed only a
957-
// flight, held as the frame's pending observer or its staged
958-
// derivation) has nothing to re-derive: its re-run re-enters that
959-
// transaction and parks it again, every round — it runs at the
960-
// landing (#4349).
970+
// what it read the screen (one run). The frame is the transaction that
971+
// holds what it read (`t`, this flush's — not always the lane's parent:
972+
// a landing that reached a frame held elsewhere joined that one). Nor
973+
// when only this pass keeps it parked (`heldBy`): the frame lands with
974+
// the pass's answer, so what the pass read is the screen when anything
975+
// shows it — re-derived on the committed world, it would ask a question
976+
// already asked, over inputs the landing replaces. A reader a
977+
// transaction holds that read none of its stagings (a verdict reader
978+
// that probed only a flight, held as the frame's pending observer or
979+
// its staged derivation) has nothing to re-derive: its re-run
980+
// re-enters that transaction and parks it again, every round — it
981+
// runs at the landing (#4349).
961982
if (
962983
r._flags & REACTIVE_DISPOSED ||
963984
(l?._lane
964985
? l._parent?._verdict === l &&
965986
(r._config & CONFIG_VERDICT
966987
? !(r._flags & REACTIVE_PROBE_UNANSWERED)
967-
: !blocked(l._parent))
988+
: !blocked(t!) || heldBy(t!, r))
968989
: l && !(r._flags & (REACTIVE_STAGED_READ | REACTIVE_PROBE_UNANSWERED)))
969990
)
970991
continue;
@@ -978,9 +999,13 @@ const laneSeams = (leaks: Computed<any>[] | null): void => {
978999
// R5 for an async reader: its frame pass asked the frame's question
9791000
// (F-6's lane gets its own pass now). That flight is the frame's
9801001
// answer: the landing adopts it rather than asking it again (F-9: a
981-
// re-ask of the same question is no new question; `reruns`).
982-
else if (!l?._lane && r._flags & REACTIVE_PROBE_UNANSWERED && isThenable(r._x?._inFlight))
1002+
// re-ask of the same question is no new question; `reruns`). A frame
1003+
// landing at this seam has nothing to re-derive: the pass was the
1004+
// landing's, its flight the screen's answer.
1005+
else if (!l?._lane && r._flags & REACTIVE_PROBE_UNANSWERED && isThenable(r._x?._inFlight)) {
1006+
if (!blocked(t!)) continue;
9831007
r._x!._parked = r._x!._inFlight;
1008+
}
9841009
enqueueSub(r);
9851010
if (l?._lane && leaked.indexOf(l) === -1) leaked.push(l);
9861011
}
@@ -995,6 +1020,15 @@ const laneSeams = (leaks: Computed<any>[] | null): void => {
9951020
enqueueSub(r);
9961021
}
9971022
};
1023+
/** The landing's re-derive of a reader whose frame flight the seam parked
1024+
* (R5): the flight asked the question the landing would — adopted, it is
1025+
* asked once (F-9). Not over a pass already queued: that one asks anew. */
1026+
const adoptParked = (r: Computed<any>): boolean => {
1027+
const parked = r._x?._parked;
1028+
if (!parked || r._flags & (REACTIVE_DIRTY | REACTIVE_CHECK | REACTIVE_IN_HEAP)) return false;
1029+
adoptFlight(r, parked);
1030+
return true;
1031+
};
9981032
/** Render effects that read a verdict and entered a lane before its seam (#4284). */
9991033
const entered: Computed<any>[] = [];
10001034
installLaneHooks(
@@ -1006,7 +1040,8 @@ installLaneHooks(
10061040
laneSeams,
10071041
() => lanes.length !== 0 && laneCorrections(),
10081042
endLanes,
1009-
lanesBlocked
1043+
lanesBlocked,
1044+
adoptParked
10101045
);
10111046
if (__OBSERVE__)
10121047
GlobalQueue._laneGuesses = t => {

‎packages/signals/src/core/scheduler.ts‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
NOT_PENDING,
1616
CONFIG_HAS_SNAPSHOT,
1717
REACTIVE_CHECK,
18-
REACTIVE_IN_HEAP,
1918
REACTIVE_DIRTY,
2019
REACTIVE_DISPOSED,
2120
REACTIVE_FRAME_READ,
@@ -30,7 +29,7 @@ import {
3029
STATUS_UNINITIALIZED
3130
} from "./constants.js";
3231
import { attrHooks } from "./attribution-hooks.js";
33-
import { adoptFlight, notifyStatus } from "./async.js";
32+
import { notifyStatus } from "./async.js";
3433
import {
3534
dispatchingEvent,
3635
ext,
@@ -77,10 +76,14 @@ export let laneOutcomeHook:
7776
| null = null;
7877
export let laneWriteHook: (<T>(el: Signal<T> | Computed<T>, v: T) => T) | null = null;
7978
export let applyGuessesHook: ((parent: Transaction | null) => void) | null = null;
80-
export let laneSeamsHook: ((leaks: Computed<any>[] | null) => void) | null = null;
79+
export let laneSeamsHook: ((leaks: Computed<any>[] | null, t: Transaction | null) => void) | null =
80+
null;
8181
export let laneCorrectionsHook: (() => boolean) | null = null;
8282
export let endLanesHook: ((u: Transaction) => void) | null = null;
8383
export let lanesBlockedHook: ((t: Transaction) => boolean) | null = null;
84+
/** R5 (lanes.ts `laneSeams` parks a frame flight): the landing's re-derive
85+
* of a reader adopts the flight instead (true: adopted, nothing to queue). */
86+
export let laneAdoptHook: ((r: Computed<any>) => boolean) | null = null;
8487
/** A guess was written (lanes.ts `optimisticWrite`): the arms only a guess
8588
* reaches (CONFIG_GUESS) — a build without `createOptimistic` or
8689
* `createOptimisticStore` never sets it, and its bundler folds them. */
@@ -97,7 +100,8 @@ export function installLaneHooks(
97100
seams: NonNullable<typeof laneSeamsHook>,
98101
corrections: NonNullable<typeof laneCorrectionsHook>,
99102
end: NonNullable<typeof endLanesHook>,
100-
blocked: NonNullable<typeof lanesBlockedHook>
103+
blocked: NonNullable<typeof lanesBlockedHook>,
104+
adopt: NonNullable<typeof laneAdoptHook>
101105
): void {
102106
laneReadHook = read;
103107
laneStageHook = stage;
@@ -108,6 +112,7 @@ export function installLaneHooks(
108112
laneCorrectionsHook = corrections;
109113
endLanesHook = end;
110114
lanesBlockedHook = blocked;
115+
laneAdoptHook = adopt;
111116
}
112117
// Boundaries (boundaries.ts): the display consumers between an observer
113118
// and the root. `catch` — status from a frame reader, nearest boundary
@@ -1037,7 +1042,7 @@ export class GlobalQueue implements IQueue {
10371042
// world (a lane's runs wait this round).
10381043
if (laneSeamsHook) {
10391044
this._queues = lanes;
1040-
laneSeamsHook(t !== null ? stagedReaders : null);
1045+
laneSeamsHook(t !== null ? stagedReaders : null, t);
10411046
if (stagedReaders.length) stagedReaders.length = 0;
10421047
}
10431048
this._queues = [[], []];
@@ -1184,10 +1189,7 @@ export function reruns(u: Transaction): unknown {
11841189
if ((c as any)._type) (c as any)._modified = false;
11851190
// A frame flight the seam parked (lanes.ts `laneSeams`, R5) asked the
11861191
// question this landing would: adopted, it is asked once (F-9).
1187-
const parked = r._x?._parked;
1188-
if (parked && !(r._flags & (REACTIVE_DIRTY | REACTIVE_CHECK | REACTIVE_IN_HEAP)))
1189-
adoptFlight(r, parked);
1190-
else enqueueSub(r);
1192+
if (!laneAdoptHook?.(r)) enqueueSub(r);
11911193
}
11921194
}
11931195
u._reruns.length = 0;

0 commit comments

Comments
 (0)