Skip to content

Commit 885b99b

Browse files
ryansolidclaude
andauthored
fix(signals): a second guess shows beside the first action's re-ask (#4629, memo) (#4637)
* fix(signals): seat a held pending reader of a re-guess in the lane from its first read (#4629) A body-end correction re-homes an overlay memo into its action's hold, pending on the action's refresh. A second action's guess into the same slot opened a new lane, but the overlay's re-run started as the hold's work and threw on the pending list before reaching the guess read that would have moved it into the lane. Readers the lane's parent holds pending are now listed in the lane before the pass, so lane work reads the parent's flight as the screen (D-26, D-37) in either read order (D-28). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE * test(signals): #4629 frame (4) now passes in both shapes With #4633 (projection) and this fix (memo), the second guess shows at once beside the screen's issues (D-26): the it.fails rows become plain rows and the D-26 known-deviation note becomes a fixed note. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE * fix(signals): seat the held re-ask reader at every lane node's change (#4629) The seating loop ran only over the guessed node's direct subscribers, so a held pending pass reading the guess through a derived memo (byId) was still thrown back into the hold at frame (4). Moved into laneDirty, which runs at the guess and at each lane node's change (core and store), so the pass is seated whatever depth it reads the guess at (D-26, D-37, D-28). Smaller than the direct-only loop. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0117BoWNSSgtemsSYsaX2hXE --------- Co-authored-by: Claude <[email protected]>
1 parent 4235019 commit 885b99b

5 files changed

Lines changed: 209 additions & 8 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+
A second action's guess into an optimistic slot now shows at once while the first action's `refresh()` of a list the overlay also reads is still in flight, whatever order the overlay reads the two in, and whether it reads the guess directly or through a memo derived from it (#4629).

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ What is rendered from a display-ahead read reveals together with it: an async me
216216

217217
A held display-ahead world ("a lane") is a hold seen from the outside. A render effect _off_ it that reads what it is revealing — mounted mid-hold, or re-run by an unrelated sync write — shows the committed value (what is on screen), publishes now, entangles nothing, and re-derives at the release: `Late: 0` at the mount, `Details: 1 | Late: 1 | Value: 1` at the release. `latest()` is not special here: a `createOptimistic` source behaves the same. A reader whose removal is staged in a live hold is still on screen and keeps holding the lane while visible; `latest()` read in such a branch peers through to the proposal. A direct leaf reading a lane's derivation shows the lane's revealed value and re-derives at the reveal (control and content never disagree); a derivation between (a memo, a boundary's tree) carries the future and is born held with its mount (D-2). The same holds for a render effect that reads an optimistic value before its lane is judged: if the lane holds on a derivation's flight, the effect shows the committed value and `latest()` of the guess shows the guess beside it, whether the two reads share one render effect or not — `1 x1 / 5`, then `5 x5 / 5` at the landing (#4284). **Inside the lane, "sees the parent's landings" is about computing, not showing (clarified 2026-10-28):** a lane derivation that reads a value the parent holds joins that hold (D-1) — it computes now, so async downstream of it starts without waiting for the commit, and its result shows at the commit as the hold's work. What lane work _displays_ is the screen plus the lane's own values: its guesses, or what its `latest()` reads asked for. A plain read in lane work of a node the parent holds and the lane does not show ahead is the screen's value, in a verdict lane as in an optimistic one (F-6: "a plain read beside it is a read"); `[s(), L()]` with `L = createMemo(() => latest(s))` shows `v:0 l:1`, as the inline `[s(), latest(s)]` does. A15 #3460's sentence is the computing half.
218218

219-
**Collapses:** [A15](./SPEC-ASYNC-SEMANTICS.md#a15-transition-entanglement-is-graph-driven-lanes-settle-as-one-reveal) lanes corollary (#3460, #3463, #3479, #3662, #3698), #3444, the fuzzer-finding F8 ruling (2026-10-05, #3806), the adopted-staging ruling. **Status:** standing; fuzzer finding F5b ("a stale reader of a held re-guess shows the revealed guess") pinned `it.fails`. Grouping: `tests/lane-render-effect-grouping-4284.test.ts`. Known deviation (#4629, 2026-11-02): a second action's guess into a slot whose earlier action's `refresh()` is in flight waits for that re-ask to land instead of showing now beside the screen's value of the re-asked node (the plain read in lane work above); pinned `it.fails` in `tests/projection-second-guess-4629.test.ts`.
219+
**Collapses:** [A15](./SPEC-ASYNC-SEMANTICS.md#a15-transition-entanglement-is-graph-driven-lanes-settle-as-one-reveal) lanes corollary (#3460, #3463, #3479, #3662, #3698), #3444, the fuzzer-finding F8 ruling (2026-10-05, #3806), the adopted-staging ruling. **Status:** standing; fuzzer finding F5b ("a stale reader of a held re-guess shows the revealed guess") pinned `it.fails`. Grouping: `tests/lane-render-effect-grouping-4284.test.ts`. Fixed 2026-11-02 (#4629, #4633, #4637): a second action's guess into a slot whose earlier action's `refresh()` is in flight shows now, beside the screen's value of the re-asked node (the plain read in lane work above), whatever order the pass reads them in (D-28); `tests/projection-second-guess-4629.test.ts`, `tests/optimistic-second-guess-reask-4629.test.ts`.
220220

221221
### D-27. A verdict reader's mount is a mainline mount
222222

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,8 +1426,25 @@ export function insertSubs(node: Signal<any> | Computed<any>): void {
14261426
* `laneRead` re-derives it on the screen if that lane holds (`entered`). */
14271427
export function laneDirty(node: Signal<any> | Computed<any>, l: Transaction): void {
14281428
for (let s = node._subs; s !== null; s = s._nextSub) {
1429-
const c = s._sub,
1430-
t = c._x?._transaction;
1429+
const c = s._sub;
1430+
let t = c._x?._transaction;
1431+
// A reader the parent holds pending on its re-ask (a correction's
1432+
// re-derivation waiting on a refresh) re-derives from the guess as the
1433+
// lane's work, seated there before its pass: lane work reads the
1434+
// parent's flight as the screen (D-26, D-37), whether it reads the
1435+
// flight before the guess or after (D-28), and whether it reads the
1436+
// guess itself or a derivation of it — this walk runs at every lane
1437+
// node's change. Seated at the guess read, the earlier read threw the
1438+
// pass back into the hold (#4629).
1439+
if (
1440+
t &&
1441+
l._parent &&
1442+
!(c as any)._type &&
1443+
(c._config & (CONFIG_HELD | CONFIG_OVERRIDE)) === CONFIG_HELD &&
1444+
(c._statusFlags & (STATUS_PENDING | STATUS_UNINITIALIZED)) === STATUS_PENDING &&
1445+
resolveTx(t) === resolveTx(l._parent)
1446+
)
1447+
list(c, (t = l));
14311448
if ((c as any)._type === EFFECT_RENDER && node._config & CONFIG_VERDICT)
14321449
((c._config |= CONFIG_VERDICT), (c._flags &= ~REACTIVE_LANE_DIRTY));
14331450
if (t?._lane ? sameLane(t, l) : (c as any)._type) c._flags |= REACTIVE_LANE_DIRTY;
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/**
2+
* #4629 (the memo half): an async list `issues`, a `createOptimistic` log of
3+
* assignments overlaid on it by a memo. Action 1 is accepted and its
4+
* `refresh(issues)` is in flight when action 2 guesses into the same log.
5+
*
6+
* `issues` is not derived from the guess, so F-6's lane hold does not apply:
7+
* what lane work displays is the screen plus the lane's own values, and a
8+
* plain read in lane work of a node the parent holds is the screen's value
9+
* (D-26, clarified 2026-10-28). Action 1's re-ask is a `refresh()`, which
10+
* re-asks the same question and holds nothing new (D-34, D-31). The two
11+
* guesses share the log slot, so they entangle (D-33): the log reverts only
12+
* when the last of them settles, and a rejected second action reverts only
13+
* its own guess.
14+
*/
15+
import { describe, expect, it } from "vitest";
16+
import {
17+
action,
18+
createMemo,
19+
createOptimistic,
20+
createRenderEffect,
21+
createRoot,
22+
createSignal,
23+
flush,
24+
mapArray,
25+
refresh
26+
} from "../src/index.js";
27+
28+
type Row = { id: number; a: string };
29+
30+
const tick = async () => {
31+
for (let i = 0; i < 4; i++) {
32+
await new Promise(r => setTimeout(r, 0));
33+
flush();
34+
}
35+
};
36+
37+
type Read = "issuesFirst" | "guessFirst" | "viaMemo" | "viaMemoFirst";
38+
39+
function run(read: Read = "issuesFirst") {
40+
const asks: { key: string; res: (v: any) => void; rej: (e: any) => void }[] = [];
41+
const ask = (key: string) => new Promise<any>((res, rej) => asks.push({ key, res, rej }));
42+
const settle = async (key: string, v: any, fail = false) => {
43+
const i = asks.findIndex(a => a.key === key);
44+
const a = asks.splice(i, 1)[0];
45+
fail ? a.rej(v) : a.res(v);
46+
await tick();
47+
};
48+
const server: Row[] = [
49+
{ id: 3, a: "-" },
50+
{ id: 4, a: "dana" }
51+
];
52+
let screen = "";
53+
let assign!: (id: number) => any;
54+
createRoot(() => {
55+
const issues = createMemo<Row[]>(() => ask("issues"));
56+
const [truth] = createSignal<Row[]>(() => []);
57+
const [assigning, guess] = createOptimistic<Row[]>(() => truth());
58+
// The guess read straight, or through a memo derived from it (the held
59+
// pass is then a grandchild of the guessed node).
60+
const byId = createMemo(() => {
61+
const m: Record<number, string> = {};
62+
for (const x of assigning()) m[x.id] = x.a;
63+
return m;
64+
});
65+
const guessed = () => {
66+
if (read === "viaMemo" || read === "viaMemoFirst") return byId();
67+
const m: Record<number, string> = {};
68+
for (const x of assigning()) m[x.id] = x.a;
69+
return m;
70+
};
71+
const overlay = createMemo(() => {
72+
const first = read === "guessFirst" || read === "viaMemoFirst" ? guessed() : undefined;
73+
return issues().map(i => {
74+
const a = (first ?? guessed())[i.id];
75+
return a ? { ...i, a } : i;
76+
});
77+
});
78+
const rows = mapArray(overlay, (r: Row) => () => `[#${r.id} ${r.a}]`);
79+
createRenderEffect(
80+
() =>
81+
rows()
82+
.map(f => f())
83+
.join(""),
84+
v => void (screen = v)
85+
);
86+
assign = action(function* (id: number) {
87+
guess(xs => [...xs, { id, a: "guest" }]);
88+
try {
89+
yield ask(`assign:${id}`);
90+
} catch {
91+
return;
92+
}
93+
refresh(issues);
94+
});
95+
});
96+
return {
97+
get screen() {
98+
return screen;
99+
},
100+
settle,
101+
server,
102+
assign: (id: number) => assign(id),
103+
snap: () => server.map(x => ({ ...x }))
104+
};
105+
}
106+
107+
async function toSecondGuess(read?: Read) {
108+
const t = run(read);
109+
flush();
110+
await tick();
111+
await t.settle("issues", t.snap());
112+
expect(t.screen).toBe("[#3 -][#4 dana]");
113+
t.assign(3);
114+
await tick();
115+
expect(t.screen).toBe("[#3 guest][#4 dana]");
116+
t.server[0].a = "guest";
117+
await t.settle("assign:3", {});
118+
// action 1's refresh(issues) is in flight
119+
expect(t.screen).toBe("[#3 guest][#4 dana]");
120+
t.assign(4);
121+
await tick();
122+
return t;
123+
}
124+
125+
describe("#4629: a second guess into a log beside the first action's re-ask (memo)", () => {
126+
it("the guess shows at once, beside the screen's issues (D-26), and stays", async () => {
127+
const t = await toSecondGuess();
128+
// (4)
129+
expect(t.screen).toBe("[#3 guest][#4 guest]");
130+
await t.settle("issues", t.snap());
131+
// (5) action 1's re-ask lands; action 2's guess still stands
132+
expect(t.screen).toBe("[#3 guest][#4 guest]");
133+
t.server[1].a = "guest";
134+
await t.settle("assign:4", {});
135+
await t.settle("issues", t.snap());
136+
// (6) both actions settled on the truth
137+
expect(t.screen).toBe("[#3 guest][#4 guest]");
138+
});
139+
140+
// D-28: whether a read throws is the read's own — not the order of the
141+
// reads around it. Reading the log before `issues` showed the guess at
142+
// once already.
143+
it("either read order, read straight or through a memo: the guess shows at once", async () => {
144+
for (const read of ["issuesFirst", "guessFirst", "viaMemo", "viaMemoFirst"] as const) {
145+
const t = await toSecondGuess(read);
146+
expect(t.screen, read).toBe("[#3 guest][#4 guest]");
147+
await t.settle("issues", t.snap());
148+
expect(t.screen, read).toBe("[#3 guest][#4 guest]");
149+
}
150+
});
151+
152+
it("through a memo, a rejected second action reverts its row", async () => {
153+
const t = await toSecondGuess("viaMemo");
154+
expect(t.screen).toBe("[#3 guest][#4 guest]");
155+
await t.settle("issues", t.snap());
156+
await t.settle("assign:4", new Error("no"), true);
157+
expect(t.screen).toBe("[#3 guest][#4 dana]");
158+
});
159+
160+
it("a rejected second action reverts its row", async () => {
161+
const t = await toSecondGuess();
162+
expect(t.screen).toBe("[#3 guest][#4 guest]");
163+
await t.settle("issues", t.snap());
164+
expect(t.screen).toBe("[#3 guest][#4 guest]");
165+
await t.settle("assign:4", new Error("no"), true);
166+
expect(t.screen).toBe("[#3 guest][#4 dana]");
167+
});
168+
169+
// D-33: the two guesses share the log slot, so the slot reverts only when
170+
// the last of the two actions settles — action 1 is out until its re-ask
171+
// lands (D-35: a plain load the action asked for is still in flight).
172+
it("a second action rejected before action 1's re-ask lands reverts with it", async () => {
173+
const t = await toSecondGuess();
174+
expect(t.screen).toBe("[#3 guest][#4 guest]");
175+
await t.settle("assign:4", new Error("no"), true);
176+
expect(t.screen).toBe("[#3 guest][#4 guest]");
177+
await t.settle("issues", t.snap());
178+
expect(t.screen).toBe("[#3 guest][#4 dana]");
179+
});
180+
});

‎packages/signals/tests/projection-second-guess-4629.test.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
* `issues` is not derived from the guess, so F-6's lane hold does not apply:
99
* a plain read in lane work of a node the parent holds is the screen's value
1010
* (D-26, clarified 2026-10-28), and the lane displays the screen plus its own
11-
* guesses — `[#4 guest]` now, in both shapes. Today both shapes hold the
12-
* guess until action 1's re-ask lands (`[#4 dana]`): a known deviation,
13-
* pinned `it.fails` below.
11+
* guesses — `[#4 guest]` now, in both shapes. (Before #4637 both shapes held
12+
* the guess until action 1's re-ask landed: the overlay's pass threw on its
13+
* first, pending read before it reached the guess, D-28.)
1414
*
1515
* (5) Through the projection the guess never showed before the server's
1616
* answer: the derive's pass that ran as the landing's (the frame's) work and
@@ -137,8 +137,7 @@ describe("#4629: a second guess into a log while the first action's refresh is i
137137
expect([f5, f6]).toEqual(["[#3 guest][#4 guest]", "[#3 guest][#4 guest]"]);
138138
});
139139

140-
// Known deviation (D-26): the guess waits on action 1's re-ask.
141-
it.fails(`${name}: the guess shows at once, beside the screen's issues (D-26)`, async () => {
140+
it(`${name}: the guess shows at once, beside the screen's issues (D-26)`, async () => {
142141
expect(await frames(proj)).toEqual([
143142
"[#3 guest][#4 guest]",
144143
"[#3 guest][#4 guest]",

0 commit comments

Comments
 (0)