Skip to content

Commit a2297c7

Browse files
ryansolidBrenley Dueckclaudecursoragent
committed
fix(signals): a direct-commit reader is neither entered nor born held (#3482)
`yield until(predicate)` inside an action never resolved when the predicate read the optimistic store a live stream feeds AND the confirming frame had landed before until() was called — the natural ordering for a server that broadcasts to subscribers before it answers the mutation. With a timeout, TimeoutError; without one the action hung forever. Regression from d80cd1f (#3451): a reader created mainline under a hold is born held — its synchronous first run is skipped and it is added to the transaction's _gatedSubs to replay at the commit. For a promise-delivery effect the commit IS the action's settle, which its own promise is holding open. recompute's DIRECT_COMMIT arm exists for exactly this case but is gated on `bornHeld === null`, so the born-held path pre-empted it. enterStagedRead's mainline arm now exempts CONFIG_DIRECT_COMMIT readers (resolve(), until(), awaitable refresh()'s waiter) beside the verdict-pull exemption: they read staged truth by contract — the tunnel that keeps a hold deadlock-free — and apply on their own microtask, so they neither enter the transaction nor are born held. stagedEntry never gets set for them; every downstream `bornHeld === null` holds and they take the existing direct-commit path. The predicate sees the held frame, the action settles, and the commit reveals the frame with the overlay revert. Test: tests/until-held-frame-before-call.test.ts — the issue's reproduction (frame lands while the action awaits its answer; until() reached after) and the control ordering (until() subscribed first). The first fails on next with TimeoutError, the control passes on both. Size: ~+20 B minified on a core-retained path; +20..+40 B brotli across the scenarios (−30 on observe — layout). Two app caps ratcheted 0.05 KB with notes. Tree-shake floor unchanged. Reproduction, bisect and analysis by @brenelz (#3482). Co-authored-by: Brenley Dueck <[email protected]> Co-authored-by: Claude <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent c54e4c0 commit a2297c7

5 files changed

Lines changed: 170 additions & 4 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+
`until()` (and `resolve()`, awaitable `refresh()`) no longer deadlocks an action when the confirming frame was staged before the call (#3482). Since #3451 a reader created mainline under a hold is born held: it skips its first run and is replayed at the commit. For a promise-delivery effect the commit is the action's settle — the very thing its promise holds open — so an `until()` reached after the server had already broadcast the confirming frame timed out (or hung without a timeout). A `CONFIG_DIRECT_COMMIT` reader is the tunnel through a hold by contract and applies on its own microtask; `enterStagedRead` now exempts it from entering and from being born held, the same exemption verdict pulls have. The predicate sees the held frame, the action settles, and the commit reveals frame and overlay revert together. Regression from `d80cd1f6`; `2.0.0-rc.8` is unaffected.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
7373
| A26 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:67` | scheduler.ts×1 | action-await-contract.test.ts×2 visibility-oracle-store.states.ts×1 visibility-oracle.states.ts×1 visibility-oracle.test.ts×1 | [ruled 2026-07-17] An ambient transaction window is one flush; parking is flush-driven — (**ruled 2026-07-17**, #2913; **enforcement hardened 2026-08-31**, #3141 — parking is flush-driven, and a trans… |
7474
| A27 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:233` | — | loading-value.test.ts×2 visibility-oracle.states.ts×18 visibility-oracle.test.ts×1 | [ruled 2026-08-10] The commit-#0 loading window is loading-class and verdict-quiet — (**ruled 2026-08-10**) **The commit-#0 loading window is loading-class and verdict-quiet.** A node born committed v… |
7575
| A28 | ruled, mechanism landed | `docs/SPEC-ASYNC-SEMANTICS.md:51` | constants.ts×1 core.ts×18 optimistic.ts×1 scheduler.ts×3 types.ts×1 verdict.ts×6 optimistic.ts×3 store.ts×1 | createOptimistic.test.ts×5 latest-held-till-flush.test.ts×1 optimistic-store-layer-scope.test.ts×1 posture-store-parity.test.ts×3 question-scoped-pending.test.ts×3 snapshot-derived-store-rows.test.ts×1 createOptimisticStore.test.ts×10 shallow.test.ts×1 treeshake.test.ts×2 visibility-oracle-store.states.ts×8 visibility-oracle.states.ts×8 | [ruled, mechanism landed 2026-09-15] A write becomes visible at flush — to every channel — (**ruled 2026-09-08**; supersedes the #2922 mid-tick pull) \*\*A write becomes visible at flush — to every chan… |
76-
| A29 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:75` | core.ts×5 effect.ts×1 optimistic.ts×1 | body-end-supersession-visibility.test.ts×1 born-held.test.ts×3 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 latest-held-till-flush.test.ts×2 posture-store-parity.test.ts×1 treeshake.test.ts×1 visibility-oracle-store.states.ts×3 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×5 visibility-oracle.test.ts×1 | [ruled, amended in place 2026-09-13 (#3408)] A tracked read served a live transaction's staged value enters that transaction — A tracked computation served a node's staged `_pendingValue` — a value a … |
76+
| A29 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:75` | core.ts×5 effect.ts×1 optimistic.ts×1 | body-end-supersession-visibility.test.ts×1 born-held.test.ts×3 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 latest-held-till-flush.test.ts×2 posture-store-parity.test.ts×1 treeshake.test.ts×1 until-held-frame-before-call.test.ts×1 visibility-oracle-store.states.ts×3 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×5 visibility-oracle.test.ts×1 | [ruled, amended in place 2026-09-13 (#3408)] A tracked read served a live transaction's staged value enters that transaction — A tracked computation served a node's staged `_pendingValue` — a value a … |
7777
| A30 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:207` | async.ts×1 attribution.ts×1 core.ts×1 effect.ts×1 scheduler.ts×3 | async-landing-deps-3461.test.ts×3 held-conditional-effect.test.ts×1 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 treeshake.test.ts×1 | [ruled 2026-09-13 (#3410)] A memo's dependencies are the committed frame's until the frame is replaced — A pass that _staged_ its value has not replaced the committed frame, so the committed value sti… |
7878
| A31 | live | `docs/SPEC-ASYNC-SEMANTICS.md:83` | core.ts×2 | ispending-combined-atomic-3442.test.ts×1 | [live 2026-09-14 (#3442)] A memo computes under its own lane posture, never its puller's — A memo's value is one shared slot every reader sees, so its pass runs under the lane posture the memo itself … |
7979
| A32 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:91` | — | visibility-oracle-store.states.ts×5 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×9 visibility-oracle.test.ts×1 | [ruled 2026-09-14] Children-forbidden readers see the frame, not the graph — `createTrackedEffect` and `onSettled` callbacks are effect-phase code that runs after the frame is decided. They read the f… |

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,16 @@ export function enterStagedRead(
15971597
// Verdict pulls are observations, not derivations: a latest() /
15981598
// isPending() call from mainline must never enter a transaction (it
15991599
// would capture the rest of the caller's synchronous block).
1600-
if (GlobalQueue._verdictPull) return;
1600+
// Likewise a promise-delivery effect (resolve() / until() / awaitable
1601+
// refresh()'s waiter — CONFIG_DIRECT_COMMIT): it reads staged truth by
1602+
// contract — it is the tunnel that keeps a hold deadlock-free — and
1603+
// applies on its own microtask, not the transaction's stashed queues, so
1604+
// it neither enters the transaction nor is born held. Born held, an
1605+
// until() created mainline AFTER its confirming frame was staged (the
1606+
// server broadcast before it answered the mutation) would skip its first
1607+
// run and be replayed only at the commit its own promise is holding open
1608+
// (#3482).
1609+
if (GlobalQueue._verdictPull || ctx._config & CONFIG_DIRECT_COMMIT) return;
16011610
if (
16021611
ctx._flags & REACTIVE_RECOMPUTING_DEPS &&
16031612
!(ctx._config & CONFIG_OPTIMISTIC) &&
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/**
2+
* until() created AFTER its confirming frame was staged (#3482).
3+
*
4+
* The single-primitive shape the until() docstring recommends: an optimistic
5+
* row on the store a live stream feeds, confirmed by the server's echo. When
6+
* the server broadcasts to subscribers BEFORE it answers the mutation, the
7+
* confirming frame lands while the action is still awaiting the answer and is
8+
* held under the action's optimism. The action then reaches `yield until(...)`
9+
* from mainline (after its await).
10+
*
11+
* #3451 made mainline creation under a hold born held (A29). A born-held
12+
* effect skips its synchronous first run and is replayed at the commit — but
13+
* the commit IS the action's settle, which the until() promise is holding
14+
* open. Deadlock: with a timeout, TimeoutError; without one, forever.
15+
*
16+
* Ruling: a CONFIG_DIRECT_COMMIT reader (resolve / until / awaitable
17+
* refresh's waiter) is the tunnel through a hold by contract and applies on
18+
* its own microtask, so `enterStagedRead` neither enters it nor bears it held
19+
* — the same exemption verdict pulls already have. The predicate sees the
20+
* held frame, the action settles, the commit reveals frame + overlay revert.
21+
*
22+
* Reproduction and analysis by @brenelz (#3482). Regression from d80cd1f6.
23+
*/
24+
import { expect, test } from "vitest";
25+
import {
26+
action,
27+
createOptimisticStore,
28+
createRenderEffect,
29+
createRoot,
30+
flush,
31+
TimeoutError,
32+
until
33+
} from "../src/index.js";
34+
35+
type Row = { id: string; status: "pending" | "confirmed" };
36+
type Snapshot = { rows: Row[] };
37+
38+
const settle = async (n = 3) => {
39+
for (let i = 0; i < n; i++) {
40+
await new Promise(r => setTimeout(r, 0));
41+
flush();
42+
}
43+
};
44+
45+
// A manually pumped AsyncIterable — what a live() server-function stream
46+
// materializes as on the client.
47+
function stream<T>() {
48+
const buffered: IteratorResult<T>[] = [];
49+
let waiter: ((r: IteratorResult<T>) => void) | null = null;
50+
const iterable: AsyncIterable<T> = {
51+
[Symbol.asyncIterator]: () => ({
52+
next: () =>
53+
new Promise<IteratorResult<T>>(res => {
54+
if (buffered.length) res(buffered.shift()!);
55+
else waiter = res;
56+
}),
57+
return: () => Promise.resolve({ done: true as const, value: undefined })
58+
})
59+
};
60+
return {
61+
iterable,
62+
push(value: T) {
63+
const r = { done: false as const, value };
64+
if (waiter) {
65+
const w = waiter;
66+
waiter = null;
67+
w(r);
68+
} else buffered.push(r);
69+
}
70+
};
71+
}
72+
73+
/** The optimistic-row + socket-echo shape; `frameFirst` picks the ordering. */
74+
async function reserveScenario(frameFirst: boolean) {
75+
const feed = stream<Snapshot>();
76+
let answer!: (row: Row) => void;
77+
const mutation = new Promise<Row>(res => (answer = res));
78+
const views: string[] = [];
79+
let reserve!: () => Promise<unknown>;
80+
81+
createRoot(() => {
82+
const [store, setStore] = createOptimisticStore<Snapshot>(
83+
() => feed.iterable,
84+
{ rows: [] },
85+
{ key: "id" }
86+
);
87+
reserve = action(async function* () {
88+
setStore(d => {
89+
d.rows.push({ id: "temp", status: "pending" });
90+
});
91+
const saved = await mutation;
92+
yield until(() => store.rows.some(r => r.id === saved.id), { timeout: 200 });
93+
});
94+
createRenderEffect(
95+
() => store.rows.map(r => `${r.id}:${r.status}`).join(",") || "empty",
96+
v => {
97+
views.push(v);
98+
}
99+
);
100+
});
101+
102+
feed.push({ rows: [] });
103+
await settle();
104+
expect(views.at(-1)).toBe("empty");
105+
106+
const done = reserve().then(
107+
() => "settled",
108+
e => e
109+
);
110+
await settle();
111+
expect(views.at(-1)).toBe("temp:pending");
112+
113+
const confirmed: Snapshot = { rows: [{ id: "res_1", status: "confirmed" }] };
114+
if (frameFirst) {
115+
// Server mutates and broadcasts first — the frame lands while the action
116+
// is still awaiting the mutation's answer, and is held under its optimism.
117+
feed.push(confirmed);
118+
await settle();
119+
expect(views.at(-1)).toBe("temp:pending");
120+
// Then it answers, and the action reaches its until().
121+
answer({ id: "res_1", status: "confirmed" });
122+
} else {
123+
// Control: the answer arrives first, until() subscribes, then the frame.
124+
answer({ id: "res_1", status: "confirmed" });
125+
await settle();
126+
expect(views.at(-1)).toBe("temp:pending");
127+
feed.push(confirmed);
128+
}
129+
await settle();
130+
131+
const outcome = await done;
132+
expect(outcome).not.toBeInstanceOf(TimeoutError);
133+
expect(outcome).toBe("settled");
134+
await settle();
135+
expect(views.at(-1)).toBe("res_1:confirmed");
136+
}
137+
138+
test("until() sees a confirming frame that landed on the held store before until() was called", async () => {
139+
await reserveScenario(true);
140+
});
141+
142+
test("control: until() subscribed before the confirming frame lands (unchanged)", async () => {
143+
await reserveScenario(false);
144+
});

‎scripts/size/.size-limit.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,13 @@ module.exports = [
881881
// ~+200 B; pay-for-use, the price of a boundary that can tell a monitor
882882
// what it caught. Scenarios without a boundary did not move (`render`'s
883883
// write of `onError` onto the root owner is the only prod-floor cost).
884-
limit: "19.80 KB",
884+
// until() born held (#3482, 2026-09-16): 19.80 -> 19.85 KB, measured at
885+
// 19.82 (macOS). One bit test in enterStagedRead's mainline arm — a
886+
// CONFIG_DIRECT_COMMIT reader (resolve/until/refresh waiter) is neither
887+
// entered nor born held, the exemption verdict pulls have — ~+20 B
888+
// minified, read +20..+40 brotli across the scenarios (−30 on observe):
889+
// layout. Correctness fix on the core's read path; nothing to shed.
890+
limit: "19.85 KB",
885891
modifyEsbuildConfig
886892
},
887893
{
@@ -1161,7 +1167,9 @@ module.exports = [
11611167
// ~+180 B; pay-for-use, the price of a boundary that can tell a monitor
11621168
// what it caught. Scenarios without a boundary did not move (`render`'s
11631169
// write of `onError` onto the root owner is the only prod-floor cost).
1164-
limit: "15.15 KB",
1170+
// until() born held (#3482, 2026-09-16): 15.15 -> 15.20 KB, measured at
1171+
// 15.18 (macOS). See the hydrating (no stores) note; same bit test.
1172+
limit: "15.20 KB",
11651173
modifyEsbuildConfig
11661174
},
11671175
{

0 commit comments

Comments
 (0)