Skip to content

Commit 9789498

Browse files
committed
fix(signals): an async memo with no verdict window of its own takes no verdict role
#4397 review: with two verdict sources (`m1 = ask(1 + m0() + m0b())` over `m0 = ask(1 + latest(s) + s())` and `m0b = ask(10 * (latest(t) + t()))`), the grouped `[isPending(m1), m1()]` reader asked `m1:5` a second time on stale inputs after both sources landed. m1 lost CONFIG_VERDICT when its first source went pending, but a pass that threw NotReady at that source's read picked it back up (F-6, `read`). The settle walk then re-ran m1 as a verdict reader, and the committed values a hold had moved past were served to it (A10). The demotion is now per pass, in `recompute`. An async memo (new CONFIG_ASYNC: its last answering pass registered a flight) whose pass opened no isPending/latest window of its own (REACTIVE_WINDOW) does not become a verdict reader by reading a verdict memo. It waits on its sources like any derivation (F-9), reads them plainly (D-25), and asks each question once. The side-effecting clear in `propagateStatus` is gone, since that path no longer sees such a memo as a verdict reader. Pinned: two verdict memos into one async memo, grouped and split, with no question asked twice and equal final screens. A `test.fails` pin records that the grouped shape still skips the t lane's m1:15/m1:16 asks that split makes: whether a later write merges into an open transaction or opens its own lane depends on grouping (#4398). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent 1d6b8b7 commit 9789498

6 files changed

Lines changed: 112 additions & 26 deletions

File tree

‎.changeset/verdict-memo-flight-no-reask.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@solidjs/signals": patch
33
---
44

5-
An async memo that reads a memo using `latest()` or `isPending()` no longer asks the same question again when that memo re-asks. Reading such a memo makes the reader a verdict reader too (F-6), and a verdict reader is re-derived when its source goes pending. The re-derive was served the committed value that the memo had already derived from, so it repeated the request. That extra flight then held the verdict lane, and the landing ran it a third time on the same input. Now an async reader that opened no `isPending()` or `latest()` window of its own goes pending with the flight, like any other derivation, and asks once when the flight lands. Sync readers re-derive as before.
5+
An async memo that reads a memo using `latest()` or `isPending()` no longer asks the same question twice. Reading such a memo made the async memo a verdict reader too (F-6). So it was re-derived each time one of its verdict sources went pending, and it was served committed values that a hold had already moved past. Each time, it asked a question it had already answered. With two verdict sources, it could ask a stale question after both had landed. An async memo that opens no `isPending()` or `latest()` window of its own now takes no verdict role. It waits on its sources like any other derivation and asks each question once. Sync memos are unchanged.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
5454
| A7 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:165` | — | fuzz-findings-l2.test.ts×1 spec-async-semantics.test.ts×2 visibility-oracle-store.states.ts×1 visibility-oracle.states.ts×1 visibility-oracle.test.ts×1 | [ruled, amended in place] Resolved async never reads `[false, undefined]` — After an async memo resolves, `[isPending(x), latest(x)]` is `[false, resolvedValue]` — never `[false, undefined]`. **Amende… |
5555
| A8 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:173` | — | create-deferred-3710.test.ts×1 createMemo.test.ts×1 visibility-oracle-store.states.ts×1 visibility-oracle.states.ts×2 | [ruled, amended in place 2026-07-07] `isPending(() => latest(x))` follows `x`'s own async only — verdicts are per-channel — (**re-ruled 2026-07-07c** — was "tracks the transition the same as `isPendin… |
5656
| A9 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:181` | projection.ts×1 target.ts×1 | spec-async-semantics.test.ts×3 visibility-oracle-store.states.ts×4 visibility-oracle-store.test.ts×1 | [ruled, amended in place 2026-07-07] Store leaves behind a firewall report the firewall's new-question refetch — `isPending` on a store leaf behind a firewall reports the firewall's refetch like any a… |
57-
| A10 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:189` | async.ts×1 core.ts×3 verdict.ts×2 | createMemo.test.ts×1 fuzz-findings-l2.test.ts×1 ispending-memo-unstamped-hold-3457.test.ts×2 latest-isPending-consistency.test.ts×3 verdict-contract.test.ts×2 verdict-memo-flight-no-reask.test.ts×1 | [ruled] `[isPending(x), x()]` is atomic within one scope — `[isPending(x), x()]` read in one scope is atomic: a reader that observed the fresh value must not see `pending === true` for it. |
57+
| A10 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:189` | core.ts×4 verdict.ts×2 | createMemo.test.ts×1 fuzz-findings-l2.test.ts×1 ispending-memo-unstamped-hold-3457.test.ts×2 latest-isPending-consistency.test.ts×3 verdict-contract.test.ts×2 verdict-memo-flight-no-reask.test.ts×1 | [ruled] `[isPending(x), x()]` is atomic within one scope — `[isPending(x), x()]` read in one scope is atomic: a reader that observed the fresh value must not see `pending === true` for it. |
5858
| A11 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:103` | — | latest-isPending-consistency.test.ts×1 loading-fallback-in-flush-3540.test.ts×2 visibility-oracle-store.states.ts×2 visibility-oracle.states.ts×1 | [ruled] Sync derivations of held sources are visible through `latest()`/`isPending()` — Sync derivations of transition-held sources are visible through `latest()`/`isPending()` (held sync recompute is… |
5959
| A12 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:197` | — | createOptimistic.test.ts×2 spec-async-semantics.test.ts×1 | [ruled, amended in place] Resting optimistic nodes report pending like a plain memo — A resting optimistic node reports pending via exactly the causes a plain async memo does (A19) — a reverting optim… |
6060
| A13 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:205` | — | spec-async-semantics.test.ts×7 | [ruled 2026-07-06 (promoted from B1)] Resting optimistic ≡ plain async memo at every checkpoint — (was B1) A resting optimistic node (no active override) is observationally identical to a plain async … |

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
CONFIG_AUTO_DISPOSE,
3+
CONFIG_ASYNC,
34
CONFIG_REDERIVE,
45
CONFIG_GUESS,
56
CONFIG_OVERRIDE,
@@ -426,6 +427,7 @@ export function handleAsync<T>(
426427
}
427428

428429
if (!thenable && !iterator) {
430+
el._config &= ~CONFIG_ASYNC;
429431
if (el._x !== null) el._x._inFlight = null;
430432
// A sync landing is the first real answer for a loadingValue node.
431433
el._loading = false;
@@ -461,6 +463,7 @@ export function handleAsync<T>(
461463
// fired _flightTeardown. A future non-recompute registration path must
462464
// release it here before overwriting _inFlight.
463465
ext(el)._inFlight = result as PromiseLike<T> | AsyncIterable<T>;
466+
el._config |= CONFIG_ASYNC;
464467
// The question this flight answers (A18 provenance, lanes.ts): the action
465468
// whose slice asked it; mainline is always the current question.
466469
el._x!._q = question || MAINLINE_QUESTION;
@@ -990,21 +993,8 @@ export function propagateStatus(el: Computed<any>, status: number, error: any):
990993
// Inheriting the error would make a probe's reader errored. A boundary's
991994
// output (CONFIG_REDERIVE, boundaries.ts) the same: content or fallback
992995
// is its pass's call.
993-
// Not an async memo that is a verdict reader only by reading a verdict
994-
// memo (F-6, #4050: it opened no window of its own — REACTIVE_WINDOW,
995-
// whose bit >> 6 is CONFIG_VERDICT's) when that verdict memo goes
996-
// pending: re-derived, it is served the committed value it already
997-
// derived from (A10) and asks that question again. What it read ahead is
998-
// in flight, so it is pending through the flight like any derivation
999-
// (F-9) and the hold's work until the flight lands, reading plainly
1000-
// (D-25, #3884): it asks once, at the landing. A sync one re-derives as
1001-
// before — asking nothing, it stays the lane's. (`_inFlight` is its last
1002-
// pass's flight, landed or not; a sync pass clears it.)
1003996
if (
1004-
(sub._config &= ~(pendingSource && sub._x?._inFlight
1005-
? el._config & (~sub._flags >> 6) & CONFIG_VERDICT
1006-
: 0)) &
1007-
(CONFIG_REDERIVE | CONFIG_VERDICT) ||
997+
sub._config & (CONFIG_REDERIVE | CONFIG_VERDICT) ||
1008998
(status === STATUS_PENDING && link._gen !== sub._depGen)
1009999
) {
10101000
enqueueSub(sub);

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ export const REACTIVE_SCREEN_READ = 1 << 18;
6969
* the probe's answer (lanes.ts). Per pass. */
7070
export const REACTIVE_PROBE_UNANSWERED = 1 << 19;
7171
/** The pass opened a verdict window of its own (`isPending`/`latest`) — not
72-
* only read a verdict memo (F-6, core.ts `read`): a verdict memo it reads
73-
* going pending changes its answer (async.ts `propagateStatus`). Per pass,
74-
* kept until the next. CONFIG_VERDICT << 6, which the propagation relies on
75-
* (1 << 20 is lanes.ts's LEFT_SHOWN). */
72+
* only read a verdict memo (F-6, core.ts `read`). An async memo whose pass
73+
* did not takes no verdict role (core.ts `recompute`, CONFIG_ASYNC). Per
74+
* pass (1 << 20 is lanes.ts's LEFT_SHOWN). */
7675
export const REACTIVE_WINDOW = 1 << 21;
7776

7877
// Static configuration bits packed into Owner/Computed/Signal _config.
@@ -222,6 +221,12 @@ export const CONFIG_KEY_BAG = 1 << 28;
222221
* joins nothing, so two mounts under one boundary made in separate flushes
223222
* keep their holds apart (D-4, S-5 rows 1′–3′, #4283). */
224223
export const CONFIG_FRAME = 1 << 23;
224+
/** The node's last pass that answered registered a flight (`handleAsync`):
225+
* an async memo. A sync answer clears it; a pass that threw (NotReady) keeps
226+
* the last answer's. With no verdict window of its own (REACTIVE_WINDOW), it
227+
* takes no verdict role from the verdict memos it reads (core.ts
228+
* `recompute`, F-6). */
229+
export const CONFIG_ASYNC = 1 << 29;
225230

226231
export const STATUS_NONE = 0;
227232
export const STATUS_PENDING = 1 << 0;

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import {
1414
$REFRESH,
1515
CONFIG_AUTO_DISPOSE,
16+
CONFIG_ASYNC,
1617
CONFIG_CHILDREN_FORBIDDEN,
1718
CONFIG_FRESH_READ,
1819
CONFIG_GUESS,
@@ -536,6 +537,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
536537
const selfRegistered = el._x?._inFlight !== prevInFlight;
537538
value = selfRegistered || !isAsyncResult ? fnResult : handleAsync(el, fnResult);
538539
if (!selfRegistered && !isAsyncResult) {
540+
el._config &= ~CONFIG_ASYNC;
539541
if (el._x !== null) el._x._inFlight = null;
540542
// A sync (non-object) return is the first real answer; async-shaped
541543
// results clear inside handleAsync at their own landing points, and a
@@ -612,8 +614,20 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
612614
);
613615
// A verdict reader is one for as long as it probes, or reads a memo
614616
// that does (`read`): a pass that did neither (REACTIVE_PROBED, the same
615-
// bit) is an ordinary derivation again.
616-
el._config = (el._config & ~CONFIG_VERDICT) | (el._flags & REACTIVE_PROBED);
617+
// bit) is an ordinary derivation again. Not an async memo that only
618+
// read a verdict memo (F-6, #4050 — no window of its own,
619+
// REACTIVE_WINDOW): what it read ahead is the lane's, and its own async
620+
// is a derivation of it, held in that lane (F-6) — it waits on its
621+
// sources like any derivation (F-9), reading them plainly (D-25), and
622+
// asks its next question once, at their landing. A frame reader, it was
623+
// served committed values a hold had moved past (A10) and asked an
624+
// answered question again; re-derived at each verdict source going
625+
// pending, again (#4397).
626+
el._config =
627+
(el._config & ~CONFIG_VERDICT) |
628+
(el._flags &
629+
REACTIVE_PROBED &
630+
(el._config & CONFIG_ASYNC && !(el._flags & REACTIVE_WINDOW) ? 0 : CONFIG_VERDICT));
617631
// REACTIVE_DISPOSED survives too (#3621): the pass may have disposed its
618632
// own owner (a memo calling its root's `dispose()`, a cleanup doing so
619633
// #3601/#3606), and `disposeChildren` set the flag on this node
@@ -629,8 +643,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
629643
REACTIVE_STAGED_READ |
630644
REACTIVE_LANE_READ |
631645
REACTIVE_SCREEN_READ |
632-
REACTIVE_PROBE_UNANSWERED |
633-
REACTIVE_WINDOW)) |
646+
REACTIVE_PROBE_UNANSWERED)) |
634647
(create ? el._flags & REACTIVE_SNAPSHOT_STALE : 0);
635648
context = oldcontext;
636649
if (released) for (const node of released) releaseIfSettledUnobserved(node);
@@ -977,8 +990,7 @@ function updateIfNecessary(el: Computed<unknown>): void {
977990
REACTIVE_STAGED_READ |
978991
REACTIVE_LANE_READ |
979992
REACTIVE_SCREEN_READ |
980-
REACTIVE_PROBE_UNANSWERED |
981-
REACTIVE_WINDOW);
993+
REACTIVE_PROBE_UNANSWERED);
982994
}
983995

984996
export function computed<T>(fn: (prev?: T) => T | PromiseLike<T> | AsyncIterable<T>): Computed<T>;

‎packages/signals/tests/verdict-memo-flight-no-reask.test.ts‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,82 @@ for (const reader of ["m1()", "[isPending(m1), m1()]"] as const)
129129
expect(out.slice(1, -1).every(v => v.startsWith("true,"))).toBe(true);
130130
}
131131
});
132+
133+
// Two verdict memos feeding one async memo (#4397 review): `m1` over
134+
// `m0 = ask(1 + latest(s) + s())` and `m0b = ask(10 * (latest(t) + t()))`,
135+
// `setS(2)` then `setT(1)` 12ms later. An async memo that opened no window
136+
// of its own takes no verdict role (core.ts `recompute`): it waits on its
137+
// sources like any derivation (F-9), so no question is asked twice, whether
138+
// `[isPending(m1), m1()]` is read in one render effect or in two (D-25).
139+
async function twoVerdicts(grouped: boolean) {
140+
const [s, setS] = createSignal(1);
141+
const [t, setT] = createSignal(0);
142+
const asks: string[] = [];
143+
const ask = (name: string, v: number) => {
144+
asks.push(`${name}:${v}`);
145+
return sleep(10).then(() => v);
146+
};
147+
const shown = { pending: "", value: "" };
148+
createRoot(() => {
149+
const m0 = createMemo(() => ask("m0", 1 + latest(s) + s()));
150+
const m0b = createMemo(() => ask("m0b", 10 * (latest(t) + t())));
151+
const m1 = createMemo(() => ask("m1", 1 + m0() + m0b()));
152+
createLoadingBoundary(
153+
() => {
154+
if (grouped)
155+
createRenderEffect(
156+
() => [String(isPending(m1)), String(m1())],
157+
([p, v]) => void Object.assign(shown, { pending: p, value: v })
158+
);
159+
else {
160+
createRenderEffect(
161+
() => String(isPending(m1)),
162+
p => void (shown.pending = p)
163+
);
164+
createRenderEffect(
165+
() => String(m1()),
166+
v => void (shown.value = v)
167+
);
168+
}
169+
return null;
170+
},
171+
() => "L"
172+
);
173+
});
174+
flush();
175+
await settle();
176+
asks.length = 0;
177+
setS(2);
178+
await sleep(12);
179+
flush();
180+
setT(1);
181+
await settle();
182+
await settle();
183+
return { asks, shown };
184+
}
185+
186+
it("two verdict memos into one async memo: no question asked twice, grouped or split", async () => {
187+
const grouped = await twoVerdicts(true);
188+
const split = await twoVerdicts(false);
189+
for (const { asks } of [grouped, split]) expect(new Set(asks).size).toBe(asks.length);
190+
expect(grouped.shown).toEqual({ pending: "false", value: "26" });
191+
expect(split.shown).toEqual(grouped.shown);
192+
});
193+
194+
// Open question (lane merge, #4398): with the grouped reader,
195+
// `m1` is pending in the s write's transaction and the render effect reading
196+
// `isPending(m1)` beside `m1()` is held there, so the t write merges into
197+
// that transaction instead of opening its own lane — the t lane's views of
198+
// `m1` (`m1:15`, `m1:16`) are never asked. Split, the t write opens its own
199+
// lane and they are asked. Whether a later write merges into an open
200+
// transaction or opens its own lane must not depend on grouping (D-25,
201+
// D-26; F-6: `[isPending(x), x()]` in one render effect holds like `x()`
202+
// alone).
203+
it.fails(
204+
"two verdict memos into one async memo: grouped asks the t lane's questions as split does",
205+
async () => {
206+
const grouped = await twoVerdicts(true);
207+
const split = await twoVerdicts(false);
208+
expect(grouped.asks).toEqual(split.asks);
209+
}
210+
);

0 commit comments

Comments
 (0)