Skip to content

Commit 20c115c

Browse files
ryansolidclaude
andauthored
fix(signals): a derived store's readers settle with its derive, not by a re-run (#4493)
* fix(signals): a derived store's derive re-runs when a source it pends on settles `createStore(fn)` over an async memo. The derive went pending on the memo's flight by propagation (`familyStatus` -> `wakeFamily`), and the store's readers were parked on the derive itself. When the flight then settled without the derive re-running (a rejection staged in its transaction, or a re-ask that returned to the committed question), the settle walk retired the memo from the derive but never reached the readers parked on it: `isPending` stayed true forever (F-9), and the staged rejection's transaction never landed, so the error never showed (F-12, D-41). The wake now marks the derive blocked, as a pass that threw is, so the settle re-runs it and its commit settles the family. Found by the async-gen rerun on rc.20 (pair E3, rows #1 and #9). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): record the derived-store settle fix's sizes over next @ 7135a77 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): a derived store's readers settle with its derive, not by a re-run The derive pending by propagation (familyStatus -> wakeFamily) was marked blocked so its source's settle re-ran it. For an async derive that re-run is a new flight: when the source's rejection was staged, the walk in stageError re-ran the derive in the same flush, ahead of the commit that publishes the error to it. The new flight woke the family again, so a reader beside isPending showed a second pending frame before the error (#4463's error-once test, D-41). The settle walk now settles the family instead (familyStatus with no status -> settleFamily) when it retires a derive's pending without a pass to re-run, as a memo's readers settle through its dependents (F-9, A9). The error still reaches the derive at the commit (F-12, D-41), and the re-ask that nets to the committed question ends isPending (F-9). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): record the derived-store settle fix's sizes over next @ d0fc285 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): settle a derive's family only in a store build On next @ 643a7a7 the ungated `else (node as any).fam?.st()` laid out +20 B brotli on hello world (9,993 B, over its 9.98 KB cap) from -3 B minified. A derive's family exists only when the store module is loaded, which is what sets `storeParkHook`, so the arm is gated on it and folds away in store-free bundles: every one is 0 B vs next, hello world included (9,973 B). The settle walk's `_blocked` clear is back to next's form. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 --------- Co-authored-by: Claude <[email protected]>
1 parent 4ae408f commit 20c115c

6 files changed

Lines changed: 165 additions & 2 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+
`createStore(fn)`: a derive that went pending on a source and was settled without re-running (a staged rejection, or a re-ask that returned to the committed question) settles its readers with it, as a memo's would: `isPending` ends and a refetch's rejection reaches them.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
5353
| A6 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:361` | boundaries.ts×2 | derived-write-then-derivation-3733.test.ts×1 enforceLoadingBoundary.test.ts×1 | [ruled] `ASYNC_OUTSIDE_LOADING_BOUNDARY` is warn-only — `ASYNC_OUTSIDE_LOADING_BOUNDARY` is a warn-only diagnostic; an `Errored` above must not swallow it and must not show its fallback for a pending. |
5454
| A7 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:167` | seat.ts×1 truth.ts×1 verdict.ts×1 | fuzz-findings-l2.test.ts×1 latest-uninitialized-over-latest-4362.test.ts×2 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:175` | — | 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… |
56-
| A9 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:183` | 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… |
56+
| A9 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:183` | async.ts×1 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… |
5757
| A10 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:191` | async.ts×1 core.ts×3 lanes.ts×1 scheduler.ts×1 seat.ts×1 verdict.ts×3 | boundary-not-born-held-3540.test.ts×1 createMemo.test.ts×1 error-staged-recovery.test.ts×1 fuzz-findings-l2.test.ts×1 ispending-memo-unstamped-hold-3457.test.ts×2 latest-isPending-consistency.test.ts×3 latest-uninitialized-over-latest-4362.test.ts×1 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:199` | — | 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… |

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ import {
4949
freshHook,
5050
holdWorkHook,
5151
guessing,
52-
laneStageHook
52+
laneStageHook,
53+
storeParkHook
5354
} from "./scheduler.js";
5455
import type { Computed, Link, Owner } from "./types.js";
5556

@@ -377,6 +378,11 @@ export function settlePendingSource(el: Computed<any>, source: Computed<any> = e
377378
enqueueSub(node);
378379
scheduled = true;
379380
}
381+
// A derived store's derive pending by propagation (its pass not re-run):
382+
// its readers wait on the derive itself, not on this source, so they
383+
// settle with it, as a memo's would through its dependents (F-9, A9).
384+
// Only a store build has one (`storeParkHook`).
385+
else if (storeParkHook) (node as any).fam?.st();
380386
if (node._x !== null) node._x._blocked = false;
381387
// Fully settled with nobody watching: release candidate (#2934). Checked
382388
// again at release time — deferred so unobserved() can't unlink subs

‎packages/signals/src/store/projection.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ function settleFamily(fam: StoreFamily): void {
214214
* pass's own throw. */
215215
function familyStatus(this: StoreFamily, status: number, error?: unknown): void {
216216
if (status & STATUS_PENDING) wakeFamily(this);
217+
// No status: the source's settle walk retired the derive's pending, its
218+
// pass not re-run (core `settlePendingSource`) — the readers waiting on the
219+
// derive settle with it (F-9). A re-run would ask again: an async derive's
220+
// new flight is a second wait, and would run ahead of a staged rejection's
221+
// publish, which reaches the derive at the commit (F-12, D-41).
222+
else if (!status) settleFamily(this);
217223
// The error rides along: a reader the derive's own pass already handed it
218224
// (a sync derive re-run in the same flush) is not handed it again.
219225
else if (status & STATUS_ERROR) errorFamily(this, error);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { expect, it } from "vitest";
2+
import {
3+
createErrorBoundary,
4+
createLoadingBoundary,
5+
createMemo,
6+
createRenderEffect,
7+
createRoot,
8+
createSignal,
9+
createStore,
10+
flush
11+
} from "../src/index.js";
12+
13+
// A derived store over an async memo (`d.v = m()`) reads like the memo
14+
// (async-gen E3). The derive went pending on the memo's flight, and the
15+
// flight settled without the derive re-running: the settle retired the memo
16+
// from the derive, and now settles the store's readers with it, as a memo's
17+
// readers settle through its dependents — not by re-running the derive,
18+
// whose new flight would be a second wait (F-9; #4463's error-once test)
19+
// (F-12: a rejection staged in the transaction lands; its isPending twin,
20+
// F-9, is pinned in web's async-gen store-derive-settle-e3.spec.ts).
21+
const micro = () => Promise.resolve();
22+
const drain = async () => {
23+
for (let i = 0; i < 4; i++) {
24+
for (let j = 0; j < 6; j++) await micro();
25+
flush();
26+
await new Promise(r => setTimeout(r, 0));
27+
}
28+
flush();
29+
};
30+
31+
function app(
32+
kind: "memo" | "store",
33+
init: number,
34+
poison: number | null,
35+
leaf: (v: () => any) => string
36+
) {
37+
const flights: (() => void)[] = [];
38+
const [s, setS] = createSignal(init);
39+
let screen = "";
40+
const dispose = createRoot(d => {
41+
const m = createMemo(() => {
42+
const v = s() + 1;
43+
return new Promise<number>((res, rej) =>
44+
flights.push(() => (v % 4 === poison ? rej(new Error(`m0:${v}`)) : res(v)))
45+
);
46+
});
47+
let view: () => any = m;
48+
if (kind === "store") {
49+
const [st] = createStore<{ v?: number }>(d => {
50+
d.v = m();
51+
}, {});
52+
view = () => st.v;
53+
}
54+
const b = createErrorBoundary(
55+
() =>
56+
createLoadingBoundary(
57+
() => createMemo(() => leaf(view)),
58+
() => "[L]"
59+
),
60+
() => "[E]"
61+
);
62+
createRenderEffect(
63+
() => {
64+
const r: any = b();
65+
return typeof r === "function" ? r() : r;
66+
},
67+
v => {
68+
screen = String(v);
69+
}
70+
);
71+
return d;
72+
});
73+
flush();
74+
const settleAll = async () => {
75+
await drain();
76+
while (flights.length) {
77+
flights.shift()!();
78+
await drain();
79+
}
80+
};
81+
return { flights, setS, settleAll, screen: () => screen, dispose };
82+
}
83+
84+
for (const kind of ["memo", "store"] as const) {
85+
it(`${kind}: a refetch's rejection, asked in the first answer's flush, shows the error`, async () => {
86+
const a = app(kind, 2, 1, v => `v${v()}`);
87+
a.flights.shift()!();
88+
await micro();
89+
a.setS(0);
90+
await a.settleAll();
91+
expect(a.screen()).toBe("[E]");
92+
a.dispose();
93+
});
94+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
// async-gen rerun on rc.20, E3 (a derived store `createStore(d => { d.v = m() })`
5+
// reads like `m`): two liveness failures with one cause. The derive went
6+
// pending on m0's flight; the flight then settled (a rejection staged in its
7+
// transaction, or a re-ask that returned to the committed question) without
8+
// the derive re-running. The settle retired m0 from the derive, but the
9+
// store's readers wait on the derive itself (projection.ts `wakeFamily`), and
10+
// nothing retired that: `isPending` stayed true forever (F-9), and the staged
11+
// rejection's transaction never landed, so the error never showed (F-12). The
12+
// settle walk now settles the family with the derive (core
13+
// `settlePendingSource` -> projection.ts `familyStatus`), as a memo's
14+
// readers settle through its dependents.
15+
import { expect, test } from "vitest";
16+
import { runScenario } from "./run.js";
17+
18+
const cases: Record<string, any> = {
19+
// [s0=2 m0=async(s0)] <span fx[m0()]>isPending(m0)</span> :: S5 m A(s0=0) s0=2
20+
"isPending settles when the re-ask nets to the committed question": {
21+
signals: [2],
22+
memos: [{ async: true, deps: [{ src: { k: "s", i: 0 }, how: "plain" }], poison: null }],
23+
tree: {
24+
t: "leaf",
25+
text: [{ how: "pending", src: { k: "m", i: 0 } }],
26+
attrs: [{ how: "plain", src: { k: "m", i: 0 } }],
27+
grouped: true
28+
},
29+
steps: [
30+
{ t: "settle", pick: 5 },
31+
{ t: "micro" },
32+
{ t: "action", s: 0, v: 0 },
33+
{ t: "write", s: 0, v: 2 }
34+
]
35+
},
36+
// [s0=2 s1=2 m0=async(s1 !%4=1)] <span>m0()</span> :: S4 m s1=0
37+
"a refetch's rejection reaches the store's readers": {
38+
signals: [2, 2],
39+
memos: [{ async: true, deps: [{ src: { k: "s", i: 1 }, how: "plain" }], poison: 1 }],
40+
tree: { t: "leaf", text: [{ how: "plain", src: { k: "m", i: 0 } }], attrs: [], grouped: true },
41+
steps: [{ t: "settle", pick: 4 }, { t: "micro" }, { t: "write", s: 1, v: 0 }]
42+
}
43+
};
44+
45+
for (const [name, sc] of Object.entries(cases))
46+
test(`E3: ${name}`, async () => {
47+
const memo = await runScenario(sc, {});
48+
const store = await runScenario(sc, { store: true });
49+
expect(store.screens).toEqual(memo.screens);
50+
expect(store.final).toBe(memo.final);
51+
expect(store.findings).toEqual([]);
52+
});

0 commit comments

Comments
 (0)