Skip to content

Commit 64fedc7

Browse files
ryansolidclaude
andauthored
fix(signals): a reader mounted mid-flight reads a derived store like its memo (#4491) (#4500)
* fix(signals): a reader mounted mid-flight reads a derived store like its memo (#4491) `createStore(d => { d.v = m1() })` over an async memo whose input reads `latest()` has a derive that is a verdict reader through what it reads (D-25 / F-6). At a re-ask it is served `m1`'s committed value and settles over it, so its leaves read as final: a reader that mounted mid-flight showed the old question's answer before the new one (in the mounting flush once #4479 skips the unread derive, at the landing before it), where a reader of `m1()` is held (F-2). D-30: a derived store reads like its memo. `pullFamily`: a tracked reader of a settled verdict-reader derive with no window of its own reads the flights among the derive's deps, as the memo's reader would, so it is held; the derive is that hold's work until it answers. `runProjectionComputed`: a derive whose pending is on its leaves' readers (`fam.woke`) reads plainly, as a pending node's pass does (#3884), so its landing is the answer the held reader shows. Store-only: no frozen floor moves. The #4479 review's probe forms (key read, Object.keys, JSON) are pinned against the memo form: mounted mid-flight with and without a plain write beside the flight, on screen at the re-ask, and mounted after the landing. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): gate #4491 on the verdict engine; the derive's posture is never written outside its pass Review of a78d91a: a verdict reader exists only with the verdict engine, so both halves of the fix now sit behind `observeFlightHook`. Store bundles without isPending/latest fold them away (createStore, compiled CSR and compiled hydrating at +0 B vs next), so the cap raises recorded for createStore and compiled CSR are dropped. The pull no longer clears the derive's CONFIG_VERDICT. That clear was sticky: when the flight's landing equalled the screen, the derive did not re-run and stayed a non-verdict reader into its next flight. The read now marks the family (`fam.w`), the derive's next pass consumes the mark and reads plainly, and a read that finds no flight up clears it. The posture stays the passes' own (core `recompute`). New tests: after the held mount, a later flight runs as for a store read from the start and as the memo form, after a changed landing and after an equal one. The equal-landing case fails on a78d91a (verdict=false after the landing). 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 ef0aadd commit 64fedc7

7 files changed

Lines changed: 301 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+
A reader of a derived store that mounts while the derive's input is in flight is held until it answers, as a reader of the async memo is, instead of showing the previous answer first: `createStore(d => { d.v = m1() })` over a memo that reads `latest()`, read mid-flight, no longer shows the old question's value before the new one (#4491).

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Effect-phase code that runs after the frame is decided reads the frame as it sta
252252

253253
**From:** F-9, F-1. **Scenarios:** S-36, S-37.
254254

255-
Pending is per node — per store key: a held write to a plain store pends exactly the touched keys; a derived store's leaves report the derive's new-question refetch like any async memo, in both forms, and a quiet re-ask (`refresh(store)`) is quiet on them too. A derived store's landing resumes the frame that asked it: when a consumer of its leaves goes async, the landed leaves are held with that frame and read stale and pending until it reveals (signal parity); an untouched sibling key is final. A derived store's seed is a draft for the derive, never an observable value: until the first resolution (first yield for a generator) every outside read — tracked, untracked, `in`, enumeration — throws `NotReadyError` (DEV in a component body: `PENDING_ASYNC_UNTRACKED_READ`); write-path reads see it. A seedless derived store (`createStore(fn)` with a derive that takes no draft) starts from an empty record, the same unobservable draft. `loadingValue` / `seedLoadingValue` promote a first value to commit #0: reads serve it, no boundary trips, no hold starts or extends, `isPending` is `false` on every axis until the first real landing — a hydration invariant (the server always answers `false`) — after which the node is an ordinary memo.
255+
Pending is per node — per store key: a held write to a plain store pends exactly the touched keys; a derived store's leaves report the derive's new-question refetch like any async memo, in both forms, and a quiet re-ask (`refresh(store)`) is quiet on them too. So do the leaves of a derive that is a verdict reader only through what it reads (D-25) and was served a flight's committed value: a tracked reader of them reads the flight as the memo's reader would — one that mounts mid-flight is held (F-2) and shows the flight's answer, never the old question's — and the derive computes that landing plainly, as the hold's work (D-25) (#4491, `tests/unread-derive-midflight-mount-4491.test.ts`). A derived store's landing resumes the frame that asked it: when a consumer of its leaves goes async, the landed leaves are held with that frame and read stale and pending until it reveals (signal parity); an untouched sibling key is final. A derived store's seed is a draft for the derive, never an observable value: until the first resolution (first yield for a generator) every outside read — tracked, untracked, `in`, enumeration — throws `NotReadyError` (DEV in a component body: `PENDING_ASYNC_UNTRACKED_READ`); write-path reads see it. A seedless derived store (`createStore(fn)` with a derive that takes no draft) starts from an empty record, the same unobservable draft. `loadingValue` / `seedLoadingValue` promote a first value to commit #0: reads serve it, no boundary trips, no hold starts or extends, `isPending` is `false` on every axis until the first real landing — a hydration invariant (the server always answers `false`) — after which the node is an ordinary memo.
256256

257257
**Collapses:** [A9](./SPEC-ASYNC-SEMANTICS.md#a9-store-leaves-behind-a-firewall-report-the-firewalls-new-question-refetch), [A22](./SPEC-ASYNC-SEMANTICS.md#a22-pending-is-per-node-store-wide-only-for-the-firewalls-own-work) (amended 2026-10-03), [A25](./SPEC-ASYNC-SEMANTICS.md#a25-a-derived-stores-seed-is-a-draft-never-an-observable-value), [A27](./SPEC-ASYNC-SEMANTICS.md#a27-the-commit-0-loading-window-is-loading-class-and-verdict-quiet), the L2 stores ruling (statement 7), OS-R30–R36, PJ-R23/R30/R31. **Status:** standing; one adoption shape pinned `it.fails` (`adoption-unchanged-key-read-3706.test.ts`, a row first read after the adoption).
258258

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
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 … |
6161
| A14 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:215` | — | spec-async-semantics.test.ts×1 | [ruled, amended in place 2026-07-06 (promoted from B2)] Companion nodes get child lanes that do not merge with the owner — (was B2) `isPending`/`latest` companion nodes get child lanes that do not mer… |
62-
| A15 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:251` | async.ts×2 constants.ts×1 core.ts×4 lanes.ts×6 scheduler.ts×16 seat.ts×1 verdict.ts×4 | async-chain-supersession.test.ts×1 boundary-output-frame-reader.test.ts×1 create-deferred-3710.test.ts×2 first-observer-stale-reader.test.ts×1 fuzz-findings-l2.test.ts×17 held-restore.test.ts×1 hold-recovers-landing-reruns-4469.test.ts×1 l2-contract.test.ts×7 l2-fuzz-existing-rules.test.ts×2 lane-contract.test.ts×1 lane-hold-on-observation.test.ts×1 lane-outside-view.test.ts×1 lane-pass-stamped-effect-3662.test.ts×1 latest-memo-inline-parity.test.ts×1 latest-uninitialized-over-latest-4362.test.ts×1 loading-fallback-in-flush-3540.test.ts×4 mount-over-foreign-hold-3761.test.ts×2 overlapping-flights.test.ts×3 posture-born-held-and-observation.test.ts×4 posture-store-parity.test.ts×2 reveal-carve-out.test.ts×2 shared-effect-no-entangle.test.ts×1 show-stale-child-in-action-4137.test.ts×2 spec-async-semantics.test.ts×2 stale-read-uninitialized-cross-transition.test.ts×1 superseded-source-blocks-3462.test.ts×2 tick-scoped-pass-transaction.test.ts×1 treeshake.test.ts×4 verdict-memo-flight-no-reask.test.ts×1 visibility-oracle-store.states.ts×6 visibility-oracle.states.ts×7 visibility-oracle.test.ts×1 write-proposals-3494.test.ts×1 | [ruled, amended in place 2026-07-06 (promoted from B3)] Transition entanglement is graph-driven; lanes settle as one reveal — (was B3) Transition entanglement is graph-driven: writes whose async work … |
62+
| A15 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:251` | async.ts×2 constants.ts×1 core.ts×4 lanes.ts×6 scheduler.ts×16 seat.ts×1 verdict.ts×4 store.ts×1 | async-chain-supersession.test.ts×1 boundary-output-frame-reader.test.ts×1 create-deferred-3710.test.ts×2 first-observer-stale-reader.test.ts×1 fuzz-findings-l2.test.ts×17 held-restore.test.ts×1 hold-recovers-landing-reruns-4469.test.ts×1 l2-contract.test.ts×7 l2-fuzz-existing-rules.test.ts×2 lane-contract.test.ts×1 lane-hold-on-observation.test.ts×1 lane-outside-view.test.ts×1 lane-pass-stamped-effect-3662.test.ts×1 latest-memo-inline-parity.test.ts×1 latest-uninitialized-over-latest-4362.test.ts×1 loading-fallback-in-flush-3540.test.ts×4 mount-over-foreign-hold-3761.test.ts×2 overlapping-flights.test.ts×3 posture-born-held-and-observation.test.ts×4 posture-store-parity.test.ts×2 reveal-carve-out.test.ts×2 shared-effect-no-entangle.test.ts×1 show-stale-child-in-action-4137.test.ts×2 spec-async-semantics.test.ts×2 stale-read-uninitialized-cross-transition.test.ts×1 superseded-source-blocks-3462.test.ts×2 tick-scoped-pass-transaction.test.ts×1 treeshake.test.ts×4 unread-derive-midflight-mount-4491.test.ts×1 verdict-memo-flight-no-reask.test.ts×1 visibility-oracle-store.states.ts×6 visibility-oracle.states.ts×7 visibility-oracle.test.ts×1 write-proposals-3494.test.ts×1 | [ruled, amended in place 2026-07-06 (promoted from B3)] Transition entanglement is graph-driven; lanes settle as one reveal — (was B3) Transition entanglement is graph-driven: writes whose async work … |
6363
| A16 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:223` | scheduler.ts×1 | latest-uninitialized-over-latest-4362.test.ts×2 spec-async-semantics.test.ts×1 strict-read-pending-store.test.ts×2 uninitialized-visibility.test.ts×1 visibility-oracle-store.states.ts×2 visibility-oracle.states.ts×2 visibility-oracle.test.ts×1 | [ruled, amended in place 2026-07-06 (promoted from B5)] `isPending` never throws in untracked contexts — (was B5) `isPending` never throws in untracked contexts — thunks that throw real errors or read… |
6464
| A17 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:71` | async.ts×3 constants.ts×1 lanes.ts×7 scheduler.ts×2 seat.ts×1 verdict.ts×1 map.ts×1 optimistic.ts×1 store.ts×3 | create-deferred-3710.test.ts×1 fuzz-findings-l2.test.ts×6 lane-uninitialized-landing-3648.test.ts×5 optimistic-over-held-row-3796.test.ts×1 optimistic-read-lane-not-transaction-3698.test.ts×2 optimistic-undefined-override.test.ts×1 posture-store-parity.test.ts×1 refresh-await.test.ts×1 reveal-gating-contract.test.ts×3 spec-async-semantics.test.ts×10 createOptimisticStore.test.ts×2 kanban-a17-fixture.test.ts×3 optimistic-list-mutation-matrix.test.ts×1 optimistic-maparray-index-frame-f1.test.ts×1 optimistic-untracked-reads-f3-f5.test.ts×1 signal-store-twins-qd.test.ts×1 treeshake.test.ts×1 until.test.ts×1 visibility-oracle-store.states.ts×24 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×20 visibility-oracle.test.ts×1 | [ruled, amended in place 2026-07-06 (promoted from C4)] An active override is the displayed value until its transaction commits, and the graph's value until its own source answers — **Statement (curre… |
6565
| A18 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:81` | action.ts×1 async.ts×2 core.ts×3 lanes.ts×8 scheduler.ts×2 types.ts×1 verdict.ts×1 map.ts×1 optimistic.ts×1 projection.ts×1 | body-end-supersession-visibility.test.ts×4 createOptimistic.test.ts×3 l2-fuzz-existing-rules.test.ts×2 lane-contract.test.ts×1 lane-frame-deferred-run-3662.test.ts×1 lane-outside-view.test.ts×1 lane-uninitialized-landing-3648.test.ts×5 optimistic-move-duplicate-3548.test.ts×2 optimistic-read-lane-not-transaction-3698.test.ts×4 posture-store-parity.test.ts×5 spec-async-semantics.test.ts×5 flight-owned-transaction.test.ts×1 lane-authority-twins.test.ts×1 optimistic-list-mutation-matrix.test.ts×1 optimistic-untracked-reads-f3-f5.test.ts×1 signal-store-twins-qd.test.ts×1 unchanged-presence-no-hold-3743.test.ts×2 superseded-before-first-commit.test.ts×4 visibility-oracle-store.states.ts×8 visibility-oracle-store.test.ts×1 visibility-oracle.states.ts×19 visibility-oracle.test.ts×1 | [ruled, amended in place 2026-07-07 (promoted from B4)] An override lives exactly as long as its own transaction; a newer truth from the source supersedes it in the graph immediately, on screen at com… |

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import { attrHooks } from "../core/attribution-hooks.js";
2020
import {
2121
CONFIG_AUTO_DISPOSE,
22+
CONFIG_VERDICT,
2223
STATUS_ERROR,
2324
STATUS_PENDING,
2425
STATUS_UNINITIALIZED
@@ -34,7 +35,13 @@ import {
3435
} from "../core/async.js";
3536
import { enqueueSub } from "../core/heap.js";
3637
import { getOwner, isDisposed } from "../core/owner.js";
37-
import { insertSubs, question, schedule, setQuestion } from "../core/scheduler.js";
38+
import {
39+
insertSubs,
40+
observeFlightHook,
41+
question,
42+
schedule,
43+
setQuestion
44+
} from "../core/scheduler.js";
3845
import type { Computed, Signal } from "../core/types.js";
3946
import type { Refreshable } from "../core/index.js";
4047
import { optHooks } from "./hooks.js";
@@ -239,6 +246,18 @@ export function runProjectionComputed<T extends object>(
239246
const target: StoreTarget = (wrappedStore as any)[$TARGET];
240247
const fam = target.fam!;
241248
const run = (fam.run = (fam.run || 0) + 1);
249+
// A verdict reader's pass that is the hold's work reads plainly, as a
250+
// pending node's is (core `recompute`, #3884, D-25), so the landing it
251+
// computes is the one a reader held on it shows, not the screen a frame
252+
// reader is served (#4491; D-30, F-2): its pending is on its leaves'
253+
// readers (`wakeFamily`) with no landing to settle them yet — the settle
254+
// walk clears the derive's own pending before the landing re-runs it — or
255+
// a reader of the leaves reads a flight it was served the committed value
256+
// of (`fam.w`, store.ts `pullFamily`; this pass consumes the mark). For
257+
// this pass only: its reads set the posture again at its end, and a window
258+
// in it re-stamps it (`markVerdictReader`). Only the verdict engine makes
259+
// a verdict reader (`observeFlightHook`).
260+
if (observeFlightHook && (fam.woke || fam.w)) ((fam.w = 0), (owner._config &= ~CONFIG_VERDICT));
242261
let result: void | T | Promise<void | T> | AsyncIterable<void | T>;
243262
// Open loading window (seedLoadingValue): the observable store IS commit #0
244263
// for the whole first flight — the derive works a detached shadow of the

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import {
9595
joinPassTx,
9696
list,
9797
laneStageHook,
98+
observeFlightHook,
9899
passLane,
99100
queuePendingNode,
100101
schedule,
@@ -1871,7 +1872,38 @@ function pullFamily(target: StoreTarget): void {
18711872
// (optimistic.ts `stands`, #4336).
18721873
if (verdict === null && fw._statusFlags & STATUS_PENDING && optHooks?.stands(target)) return;
18731874
readNode(fw);
1874-
} else untrack(() => readNode(fw));
1875+
} else {
1876+
untrack(() => readNode(fw));
1877+
// #4491: a derive that is a verdict reader only through what it reads (a
1878+
// verdict memo's value, D-25 / F-6; no window of its own) is served the
1879+
// committed value of a flight it reads (`observeFlight`, A15's stale
1880+
// reader) and settles over it: its leaves are the screen, not the
1881+
// flight's answer. A derived store reads like its memo (D-30): a tracked
1882+
// reader of the leaves reads that flight as the memo's reader would, so
1883+
// one that mounts mid-flight consumes unanswered async and is held (F-2)
1884+
// instead of shown the old question's answer. The derive is that hold's
1885+
// work until it answers (D-25): the read marks its next pass, which reads
1886+
// plainly (`fam.w`, projection.ts), so the landing it computes is the one
1887+
// the held reader shows. The mark is all it writes — the derive's posture
1888+
// stays its passes' own (core `recompute`) — and a read that finds no
1889+
// flight up clears it: a landing equal to the screen re-runs nothing, and
1890+
// the mark does not outlive the flight. Only the verdict engine makes a
1891+
// verdict reader (`observeFlightHook`: without it the branch folds away).
1892+
// (The window flag is REACTIVE_WINDOW, spelled from EFFECT_RENDER: an
1893+
// import of it keeps a dead copy in bundles without the store.)
1894+
if (
1895+
observeFlightHook &&
1896+
fw._config & CONFIG_VERDICT &&
1897+
!(fw._flags & (EFFECT_RENDER << 21)) &&
1898+
tracking
1899+
) {
1900+
const fam = target.fam!;
1901+
fam.w = 0;
1902+
for (let l = fw._deps; l; l = l._nextDep)
1903+
if ((l._dep as Computed<any>)._statusFlags & STATUS_PENDING)
1904+
((fam.w = 1), readNode(l._dep));
1905+
}
1906+
}
18751907
}
18761908

18771909
/** A projection's writes are its derive's: a staging made while the derive

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export interface StoreFamily {
4949
* landing has settled them yet: the next commit walks the family
5050
* (`settleFamily`). A sync commit with no wake behind it walks nothing. */
5151
woke?: boolean;
52+
/** A tracked reader of the leaves reads a flight the derive was served
53+
* the committed value of (store.ts `pullFamily`, #4491): the derive's next
54+
* pass reads plainly (projection.ts). */
55+
w?: number;
5256
}
5357

5458
/** One setter's written keys; `u` is the batch's earlier setters' (the

0 commit comments

Comments
 (0)