Skip to content

Commit e0092ab

Browse files
fix(signals): a held sync write survives the pass that probes (#4544)
The branch a hold opened was still reading the signed-out session when its own pass called isPending, so a never-resolving signed-out fetch kept the hold from landing. That write now stays the staging; the probed node stays the screen. Co-authored-by: Cursor <[email protected]>
1 parent 3606fa4 commit e0092ab

8 files changed

Lines changed: 209 additions & 91 deletions

File tree

‎.changeset/fix-4544-own-probe.md‎

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 memo holding a transition's staging keeps that staging when its own pass probes, so the branch the hold opened does not wait on the signed-out world (#4544).

‎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: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… |
5656
| 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… |
57-
| 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 verdict-memo-held-branch-4544.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:191` | async.ts×1 core.ts×5 lanes.ts×1 scheduler.ts×1 seat.ts×1 verdict.ts×6 | 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 verdict-memo-held-branch-4544.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… |
6060
| A13 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:207` | — | 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/constants.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export const REACTIVE_PROBE_UNANSWERED = 1 << 19;
7373
* did not is D-25's hold work while its flight is up (verdict.ts
7474
* `holdWork`). Per pass. */
7575
export const REACTIVE_WINDOW = 1 << 21;
76+
/** #4544 — this pass already holds its transition's staging. Set once, after
77+
* the head wipe, from `holdStaging` at `recompute`'s head; `frameRead` tests
78+
* it and does not walk deps on the read. Per pass: the tail wipe clears it. */
79+
export const REACTIVE_HOLD_STAGING = 1 << 20;
7680
/** An observation-lifecycle node found unobserved by a settle (#2934) while
7781
* a pass of it was already queued — a source's landing re-enqueued the
7882
* `_blocked` reader it walks (`settlePendingSource`). The release waits for

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

Lines changed: 94 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252
REACTIVE_IN_HEAP,
5353
REACTIVE_LANE_DIRTY,
5454
REACTIVE_LANE_READ,
55+
REACTIVE_HOLD_STAGING,
5556
REACTIVE_PROBE_UNANSWERED,
5657
REACTIVE_SCREEN_READ,
5758
REACTIVE_IN_HEAP_HEIGHT,
@@ -361,6 +362,10 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
361362
bumpNotifyEpoch();
362363
const isEffect = (el as any)._type;
363364
let released: Computed<any>[] | undefined;
365+
// #4544: the head's sync-write deps, installed for the body after the flag
366+
// wipe. A probe in the body does not recompute the list.
367+
let stagedHold = false;
368+
let syncDeps: object[] | null = null;
364369
// Lanes (plan sec. 28): the seat of a pass is its node's. A node carrying a lane's
365370
// derived value runs as the lane's whoever dirtied it — a sync write, a
366371
// boundary reset, a frame rerun — so its children and its result are the
@@ -463,6 +468,13 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
463468
// A).
464469
// A boundary's structure (CONFIG_FRAME) is the frame like a render
465470
// effect: it publishes mainline outside its transaction's flush (#4283).
471+
// #4544: a verdict memo's sync writes from an earlier flush() call.
472+
// Computed even when this node was dropped from the hold — the read
473+
// still has to agree with the branch that write opened.
474+
if (observeFlightHook && el._config & CONFIG_VERDICT && !(el._config & (EFFECT_RENDER << 23))) {
475+
syncDeps = holdStagingHook?.(el) ?? null;
476+
if (syncDeps !== null && syncDeps.length !== 0) stagedHold = true;
477+
}
466478
if (el._config & CONFIG_HELD) {
467479
const tx = txOf(el);
468480
// Held by a blocked lane: the frame joins nothing — a lane never holds
@@ -475,33 +487,38 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
475487
// A verdict reader born into `tx` (`bornInto`: never committed) is the
476488
// hold's own work, whatever it asked before (D-25): it joins like any
477489
// held pass, so what it mounts is the hold's (D-13, #4467).
478-
// #4544: T's own staging stays T's work. An inherited CONFIG_VERDICT
479-
// does not drop it; an own probe (`holdStagingHook`) still does.
490+
// #4544: T's own staging stays T's work. A verdict posture does not pull
491+
// it out — inherited, or this pass's own probe (D-25: the hold's work
492+
// reads plainly; a probe does not rescue it). Computed once; the bit
493+
// below is what `frameRead` tests.
480494
if (tx._lane || el._config & CONFIG_LAGS) {
481-
} else if (
482-
!(el._config & (CONFIG_VERDICT | (EFFECT_RENDER << 23))) ||
483-
(observeFlightHook && !(el._config & (EFFECT_RENDER << 23)) && bornInto(el, tx)) ||
484-
(observeFlightHook && el._config & CONFIG_VERDICT && holdStagingHook?.(el))
485-
)
486-
joinPassTx(tx, freshHook?.(el, el._statusFlags & STATUS_UNINITIALIZED));
487-
else if (
488-
tx !== flushTransaction &&
489-
!(el._statusFlags & STATUS_UNINITIALIZED || el._config & CONFIG_HELD_FRAME)
490-
) {
491-
// Published mainline, it is not held: the frame this pass builds is
492-
// replaced on the spot (#3404) — this flush's commit retires the
493-
// committed frame the held pass had parked (`commitPendingNode`),
494-
// after the new frame's first runs, and the held pass's own
495-
// children die below (`disposeChildren`). The landing re-derives a
496-
// fresh held frame for the reveal (`_reruns`).
497-
// Not held any more, whichever frame reader it is: its readers read
498-
// the value this pass publishes — those that read the staging it
499-
// supersedes re-derive, even when it publishes the committed value
500-
// back (no change to notify them by): their held runs carry the
501-
// superseded frame, and the landing would apply them (#4378).
502-
if (el._pendingValue !== NOT_PENDING) insertSubs(el);
503-
el._pendingValue = NOT_PENDING;
504-
el._config &= ~CONFIG_HELD;
495+
} else {
496+
const staging = syncDeps;
497+
if (
498+
!(el._config & (CONFIG_VERDICT | (EFFECT_RENDER << 23))) ||
499+
(observeFlightHook && !(el._config & (EFFECT_RENDER << 23)) && bornInto(el, tx)) ||
500+
staging !== null
501+
)
502+
joinPassTx(tx, freshHook?.(el, el._statusFlags & STATUS_UNINITIALIZED));
503+
else if (
504+
tx !== flushTransaction &&
505+
!(el._statusFlags & STATUS_UNINITIALIZED || el._config & CONFIG_HELD_FRAME)
506+
) {
507+
// Published mainline, it is not held: the frame this pass builds is
508+
// replaced on the spot (#3404) — this flush's commit retires the
509+
// committed frame the held pass had parked (`commitPendingNode`),
510+
// after the new frame's first runs, and the held pass's own
511+
// children die below (`disposeChildren`). The landing re-derives a
512+
// fresh held frame for the reveal (`_reruns`).
513+
// Not held any more, whichever frame reader it is: its readers read
514+
// the value this pass publishes — those that read the staging it
515+
// supersedes re-derive, even when it publishes the committed value
516+
// back (no change to notify them by): their held runs carry the
517+
// superseded frame, and the landing would apply them (#4378).
518+
if (el._pendingValue !== NOT_PENDING) insertSubs(el);
519+
el._pendingValue = NOT_PENDING;
520+
el._config &= ~CONFIG_HELD;
521+
}
505522
}
506523
}
507524
// The previous pass's frame. If that pass is still awaiting its commit
@@ -581,6 +598,7 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
581598
// (REACTIVE_RELEASE_AFTER): the release is this pass's tail's (#4474).
582599
const releaseAfter = el._flags & REACTIVE_RELEASE_AFTER;
583600
el._flags = REACTIVE_RECOMPUTING_DEPS | (el._flags & (REACTIVE_ZOMBIE | REACTIVE_REASK));
601+
if (stagedHold) el._flags |= REACTIVE_HOLD_STAGING;
584602
el._time = clock;
585603
// The pass's previous value: its staging, else a lane node's lane value
586604
// when it has one (lanes.ts), else the committed one.
@@ -595,6 +613,16 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
595613
// L2: did this pass read the future (REACTIVE_JOINED, set by read) — or,
596614
// a lane's mount, a staging of this flush (#3851, #4166)?
597615
let joined = false;
616+
// #4544: nodes this pass probes, while it holds the transition's staging.
617+
// Nested passes save the outer list. Only a staging pass allocates one.
618+
let prevHoldProbes: object[] | null = null;
619+
let prevStagingDeps: object[] | null = null;
620+
if (stagedHold) {
621+
prevHoldProbes = holdProbes;
622+
holdProbes = null;
623+
prevStagingDeps = stagingDeps;
624+
stagingDeps = syncDeps;
625+
}
598626
let prevTracking = tracking;
599627
let prevStrictRead: string | false = false;
600628
if (__DEV__) {
@@ -699,6 +727,10 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
699727
settlePendingSource(el, source);
700728
}
701729
} finally {
730+
if (stagedHold) {
731+
holdProbes = prevHoldProbes;
732+
stagingDeps = prevStagingDeps;
733+
}
702734
tracking = prevTracking;
703735
if (laneStageHook) laneRoot = prevMount;
704736
if (__DEV__) {
@@ -1327,6 +1359,18 @@ export function joinPassAt(c: Computed<any>, t: Transaction): void {
13271359
* the parent's flights is still up — needs none of this: the correction
13281360
* dissolves the lane, and the refetching pass is the parent's own, reading
13291361
* the truth as a member (`joinPass`). */
1362+
/** Nodes the running pass probed while `REACTIVE_HOLD_STAGING` is set.
1363+
* `frameRead` serves those the screen (A10) and the pass's other held deps
1364+
* the staging. Null outside such a pass. */
1365+
let holdProbes: object[] | null = null;
1366+
/** Sync writes this pass holds. Plain reads of them see the staging; a dep
1367+
* a flight is waiting on is not in the list and stays the screen. */
1368+
let stagingDeps: object[] | null = null;
1369+
export function noteHoldProbe(el: Signal<any> | Computed<any>): void {
1370+
if (holdProbes === null) holdProbes = [el];
1371+
else holdProbes.push(el);
1372+
}
1373+
13301374
function frameRead(c: Computed<any>, el: Signal<any> | Computed<any>): boolean {
13311375
// Frame readers: a render effect, a verdict reader (CONFIG_VERDICT — it
13321376
// reads the screen like one: `[isPending(x), x()]` never pairs the fresh
@@ -1344,10 +1388,28 @@ function frameRead(c: Computed<any>, el: Signal<any> | Computed<any>): boolean {
13441388
// with no committed value to serve.
13451389
// (Verdict readers and lanes exist only with their engines installed.)
13461390
// #4544: a memo holding T's staging is not served T's committed value.
1347-
// A frame still reads the screen. The hook sits behind `observeFlightHook`
1348-
// so a build without the verdict engine folds the call away.
1391+
// The bit was set once at this pass's head. A frame still reads the
1392+
// screen. Both checks sit behind `observeFlightHook` so a build without
1393+
// the verdict engine folds them away.
13491394
const asked = observeFlightHook && c._config & CONFIG_VERDICT;
1350-
const staging = asked && holdStagingHook!(c);
1395+
// The bit is the pass. A node the pass probed still reads as the screen
1396+
// (A10): `[isPending(x), x()]` stays the committed `x`, even when another
1397+
// dep of this pass is the hold's staging.
1398+
let staging = !!(asked && c._flags & REACTIVE_HOLD_STAGING && stagingDeps !== null);
1399+
if (staging) {
1400+
staging = false;
1401+
for (let i = 0; i < stagingDeps!.length; i++)
1402+
if (stagingDeps![i] === el) {
1403+
staging = true;
1404+
break;
1405+
}
1406+
}
1407+
if (staging && holdProbes !== null)
1408+
for (let i = 0; i < holdProbes.length; i++)
1409+
if (holdProbes[i] === el) {
1410+
staging = false;
1411+
break;
1412+
}
13511413
if (staging && !(c._config & (EFFECT_RENDER << 23))) return false;
13521414
const verdict = !staging && asked;
13531415
const lane = laneStageHook && passLane !== null;
@@ -2721,6 +2783,9 @@ export function setSignal<T>(el: Signal<T> | Computed<T>, v: T | ((prev: T) => T
27212783
isSame(el, el._value, v)
27222784
? el._value
27232785
: v;
2786+
// A held node written inside this flush: the pending value is this flush's,
2787+
// not a write parked on an earlier one (#4365 vs #4544). The extension
2788+
// already exists (`CONFIG_HELD`).
27242789
// A28 arm, gated on the load the write already pays for (`context`); the
27252790
// arm itself is a cold helper so setSignal stays within every setter's
27262791
// inlining budget, ~300 B bytecode.

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,10 @@ export let holdWorkHook: ((n: Computed<any>, source: Computed<any>) => unknown)
186186
/** D-41's staged-error mark (verdict.ts `stageMark`): the settle walk's
187187
* reached node `n` carries staged error source `el`'s staging. */
188188
export let stageMarkHook: ((n: Computed<any>, el: Computed<any>) => void) | null = null;
189-
/** #4544 (verdict.ts). Null without the verdict engine. */
190-
export let holdStagingHook: ((el: Computed<any>) => boolean) | null = null;
189+
/** #4544 (verdict.ts). The pass's sync joined deps, or an empty list when it
190+
* only holds a flight's source (join, but those reads stay the screen).
191+
* Null: not this hold's staging. Null without the verdict engine. */
192+
export let holdStagingHook: ((el: Computed<any>) => object[] | null) | null = null;
191193
export function installVerdictHooks(
192194
observeFlight: NonNullable<typeof observeFlightHook>,
193195
holdWork: NonNullable<typeof holdWorkHook>,
@@ -307,6 +309,10 @@ export interface Transaction {
307309
* transaction's flush the lane's work reads its staging (core.ts
308310
* `frameRead`, #4536). Unset until then; not `_`-prefixed, as `folded`. */
309311
over?: Transaction;
312+
/** The `flush()` call that opened it. A sync write parked then is that
313+
* hold's on a later call; one parked in the call still running is the
314+
* screen (#4544, #4365). Unset name is unprefixed, as `folded`. */
315+
gen: number;
310316
/** `affects()` marks declared in it (affects.ts): released at the landing.
311317
* Not nodes — a mark holds nothing (`blocked` never sees one). */
312318
_marks: Signal<any>[] | null;
@@ -331,7 +337,8 @@ export function newTransaction(lane: boolean, parent: Transaction | null = null)
331337
_links: null,
332338
_shown: false,
333339
_held: false,
334-
_marks: null
340+
_marks: null,
341+
gen: flushGen
335342
};
336343
if (!lane) transactions.push(t);
337344
return t;
@@ -660,6 +667,9 @@ export const dirtyQueue: Heap = {
660667
};
661668

662669
export let clock = 0;
670+
/** One per draining `flush()` call. Transactions opened in that call share
671+
* it (`Transaction.gen`). */
672+
export let flushGen = 0;
663673
let scheduled = false;
664674
let halted = false;
665675
let haltNotified = false;
@@ -1613,6 +1623,7 @@ export function flush<T>(fn?: () => T): T | void {
16131623
// exactly when `flushEnd` below will. Outside every try (see the rule in
16141624
// attribution-hooks.ts).
16151625
if (__OBSERVE__ && attrHooks !== null && scheduled) attrHooks.flushStart();
1626+
if (scheduled) flushGen++;
16161627
while (scheduled) {
16171628
if (__DEV__ && ++count === 1e5) {
16181629
rethrowCleanupError(true);

0 commit comments

Comments
 (0)