Skip to content

Commit 59ed7fd

Browse files
ryansolidClaude via Cursor
andcommitted
fix(signals): store follows signal — A28 at the backing, an override survives its key becoming unobserved (S6, S7)
Ruling 2026-09-17: store rules follow signal rules. The two divergences the 7-reader posture matrix recorded in #3520 are closed. S6 — A28 at the backing. Core read() serves an unflushed node's committed value and re-runs the reader in the carrying flush (unflushedValue / markLateLinker); the store's backing selection served the pending backing to every owner-context reader at once. A derivation created inside a foreign action that adopted a mainline setStore published the unflushed 1 where the signal published 0. Now: ensurePB stamps the target with clock when the draft opens outside a flush from outside any owner (the A28 (4) promoted-write exemption, core's notePromotedWrite twin); pendingBackingVisible serves committed for a stamped-this-tick backing and marks the reader late linker; nodeValue gains core's unflushedValue arm; getNode gains a third born kind — a node born in the unflushed window stages the pending backing's value as core's ambient staging does (stageUnflushedKey: queuePendingNode, and CONFIG_ADOPTED_UNFLUSHED under a transaction body), so the carrying flush commits the write through the node. deep()/snapshot() keep their documented speculative-peek contract. S7 — the slot hook released a property node the moment its last subscriber left, with the optimistic override on it (overrides live on nodes over a clone the setter discards): s.n read 0 while the action was live. A node carrying an override or a staged write now defers its release to the flush that resolves it (deferSlotRelease feeds the previously unfed transientStoreNodes sweep, whose checks were already exactly these). Pins: posture-store-parity S6 (three shapes, with the commit follow-through) and S7 (override visible; node released at settle) flip from recorded divergences to parity pins. Matrix: every paired signal/store state is now row-for-row identical (5 pairs x 37 rows, 0 differences). Gate: suite green; oracles identical; solid/web unchanged from next; +0 B minified core, +457 B minified store; two brotli caps ratcheted. Co-authored-by: Claude via Cursor <[email protected]>
1 parent e30fcc7 commit 59ed7fd

7 files changed

Lines changed: 198 additions & 47 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+
Store visibility follows the signal rules in two more places. A store write made outside a flush (and outside any owner) is no longer visible to computations until the flush that carries it, as a signal write is not (A28) — a memo created inside an action that adopted such a write published the pending value where the same memo over a signal published the committed one. And an optimistic store override now survives its key becoming unobserved: the property node was released with the override on it the moment its last reader left, so `s.n` read the committed value while the action was still live; the release now waits for the flush that resolves the override.

‎packages/signals/docs/DESIGN-CONSOLIDATION.md‎

Lines changed: 12 additions & 12 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
7272
| A25 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:241` | verdict.ts×1 | uninitialized-visibility.test.ts×3 visibility-oracle-store.states.ts×7 visibility-oracle-store.test.ts×1 | [ruled 2026-07-16] A derived store's seed is a draft, never an observable value — (**ruled 2026-07-16**, #2897) **A derived store's seed is a draft, never an observable value.** The seed exists for th… |
7373
| A26 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:67` | core.ts×1 scheduler.ts×1 | action-await-contract.test.ts×2 posture-store-parity.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… |
75-
| A28 | ruled, mechanism landed | `docs/SPEC-ASYNC-SEMANTICS.md:51` | constants.ts×2 core.ts×19 optimistic.ts×1 scheduler.ts×3 types.ts×1 verdict.ts×6 optimistic.ts×3 | createOptimistic.test.ts×5 latest-held-till-flush.test.ts×1 optimistic-store-layer-scope.test.ts×1 posture-store-parity.test.ts×4 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… |
75+
| A28 | ruled, mechanism landed | `docs/SPEC-ASYNC-SEMANTICS.md:51` | constants.ts×2 core.ts×19 optimistic.ts×1 scheduler.ts×3 types.ts×1 verdict.ts×6 optimistic.ts×3 store.ts×5 | createOptimistic.test.ts×5 latest-held-till-flush.test.ts×1 optimistic-store-layer-scope.test.ts×1 posture-store-parity.test.ts×6 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… |
7676
| A29 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:75` | action.ts×1 core.ts×6 effect.ts×1 optimistic.ts×1 signals.ts×1 store.ts×3 | body-end-supersession-visibility.test.ts×1 born-held.test.ts×3 direct-commit-readers-posture.test.ts×1 held-conditional-memo.test.ts×1 held-frame-dependencies.test.ts×2 latest-held-till-flush.test.ts×2 posture-store-parity.test.ts×4 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 … |
7777
| A30 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:207` | async.ts×1 attribution.ts×1 core.ts×2 effect.ts×1 scheduler.ts×4 | 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 posture-born-held-and-observation.test.ts×1 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 … |

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,19 @@ export let _hitUnhandledAsync = false;
122122
// pending render effect — N async siblings at mount used to produce N copies.
123123
let _reportedUnhandledAsync = false;
124124

125-
// Store property nodes that were created solely to carry a pending write (no
126-
// subscribers at write time). Swept after each flush that commits pending
127-
// values — any still without subs get disposed via their `_unobserved` hook,
128-
// releasing the slot in the parent store's node map.
125+
// Store property nodes whose last subscriber left while they carried state
126+
// the backing cannot reconstruct — an optimistic override (overrides live on
127+
// nodes, over a clone the setter discards) or a staged write. Releasing the
128+
// slot then would drop the override: an optimistic store key read `0` the
129+
// moment its only reader gated away while the action was live (S7). Swept
130+
// after each flush — a node still without subs whose override and staging
131+
// have resolved is released through the slot hook; one that regained a
132+
// subscriber leaves the set.
129133
const transientStoreNodes = new Set<Signal<any>>();
134+
/** Slot hook's deferral: release this node when its carried state resolves. */
135+
export function deferSlotRelease(node: Signal<any>): void {
136+
transientStoreNodes.add(node);
137+
}
130138

131139
function canUseSimpleSyncFlush(queue: GlobalQueue): boolean {
132140
const batch = queue._batch;

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

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import {
2828
unwrapOverride,
2929
CONFIG_AUTHORITATIVE_READ,
3030
CONFIG_HELD_TRUTH,
31-
CONFIG_OPTIMISTIC
31+
CONFIG_OPTIMISTIC,
32+
CONFIG_ADOPTED_UNFLUSHED
3233
} from "../../core/constants.js";
3334
import {
3435
context,
@@ -41,6 +42,9 @@ import {
4142
readerSeesCommitted,
4243
recordStaleReplay,
4344
enterStagedRead,
45+
markLateLinker,
46+
unflushedStaged,
47+
unflushedValue,
4448
prepareComputed,
4549
read as readNode,
4650
READ_SLOW,
@@ -56,9 +60,12 @@ import {
5660
} from "../../core/core.js";
5761
import {
5862
activeTransition,
63+
clock,
5964
currentTransition,
65+
deferSlotRelease,
6066
globalQueue,
6167
insertSubs,
68+
queuePendingNode,
6269
type Transition
6370
} from "../../core/scheduler.js";
6471
import { devTrackHeldPending } from "../../core/invariants.js";
@@ -252,6 +259,10 @@ const slotNodeEquals = function (this: any, a: any, b: any): boolean {
252259
setSlotUnobserved((node: any): void => {
253260
// A live affects() mark keeps the node addressable (sweep parity).
254261
if (node._x?._affectsCount) return;
262+
// An active override or a staged write is state only the node holds (an
263+
// optimistic signal keeps its override whether or not anything reads it —
264+
// store parity, S7): defer the release to the flush that resolves it.
265+
if (hasActiveOverride(node) || node._pendingValue !== NOT_PENDING) return deferSlotRelease(node);
255266
const t: StoreNextTarget = node._host;
256267
const key: PropertyKey = node._key;
257268
if (t.n && t.n[key as any] === node) {
@@ -344,6 +355,21 @@ export function getNode(
344355
: (target.v as any)[key],
345356
held
346357
);
358+
// Third kind (A28 at the backing): born in the UNFLUSHED window of an
359+
// ambient fold — a setter ran outside a flush, no flush has carried it,
360+
// and the key had no node to take the write at setter exit. `current`
361+
// is the committed value (readSource served it under unflushedBacking);
362+
// stage the pending backing's value as core's ambient staging does, so
363+
// the carrying flush commits it through the node and the reader that
364+
// was served committed (and marked late linker) sees the write there.
365+
// Inside a transaction body the staging is the transaction's, adopted
366+
// before any flush (CONFIG_ADOPTED_UNFLUSHED), exactly as initTransition
367+
// marks a node that existed when the write was made.
368+
else if (target.pb !== null && unflushedBacking(target) && plainFold(target))
369+
stageUnflushedKey(
370+
created,
371+
target.del !== null && target.del.has(key) ? undefined : (target.pb as any)[key]
372+
);
347373
nodes[key] = node;
348374
target.nc++;
349375
markDescendants(target);
@@ -391,8 +417,11 @@ function liveFoldTransition(target: StoreNextTarget): Transition | null {
391417
* heldTruthMasked — neither is a plain staged write to mirror. Chained
392418
* backings serve the inner store's live value, never a node value. */
393419
function heldFoldTransition(target: StoreNextTarget): Transition | null {
394-
if (target.ch || target.fam?.opt === true || inDraft(target)) return null;
395-
return liveFoldTransition(target);
420+
return plainFold(target) ? liveFoldTransition(target) : null;
421+
}
422+
/** A backing whose staged writes a node can mirror (see heldFoldTransition). */
423+
function plainFold(target: StoreNextTarget): boolean {
424+
return !target.ch && target.fam?.opt !== true && !inDraft(target);
396425
}
397426

398427
/**
@@ -446,6 +475,17 @@ function foreignHold(txn: Transition): boolean {
446475
);
447476
}
448477

478+
function stageUnflushedKey(node: Signal<any>, nv: any): void {
479+
if (slotNodeEquals.call(node, node._value, nv)) return;
480+
node._pendingValue = nv;
481+
if (activeTransition !== null) {
482+
node._transition = activeTransition;
483+
node._config |= CONFIG_ADOPTED_UNFLUSHED;
484+
}
485+
queuePendingNode(node);
486+
if (__DEV__) devTrackHeldPending(node);
487+
}
488+
449489
function stageHeldKey(node: Signal<any>, nv: any, txn: Transition): void {
450490
if (slotNodeEquals.call(node, node._value, nv)) return;
451491
node._pendingValue = nv;
@@ -703,6 +743,11 @@ function ensurePB(target: StoreNextTarget): Record<PropertyKey, any> {
703743
pb = target.pb = null;
704744
}
705745
if (activeTransition !== null) foldBatches.set(target, activeTransition);
746+
// A28 (4) twin of core's notePromotedWrite: a write made inside a
747+
// computation (a derive, a creation-time compute) is promoted at that
748+
// pass's end and visible to the rest of the block — only an imperative
749+
// write from outside any owner is unflushed.
750+
if (!globalQueue._running && getOwner() === null) unflushedPBs.set(target, clock);
706751
if (pb === null) {
707752
// Prototype-chain overlay (#3044): plain-data non-array containers open
708753
// drafts in O(1) — own keys are the writes, reads fall through to
@@ -896,6 +941,24 @@ function queueFold(target: StoreNextTarget): void {
896941
* Refreshed on every write; resolved through currentTransition at drain
897942
* (transitions merge — same rule as heldMaskView). */
898943
const foldBatches = new WeakMap<StoreNextTarget, Transition>();
944+
/** A28 for backings — the tick (`clock`) a target's pending backing was
945+
* opened OUTSIDE a flush. `clock` advances after every flush, so "stamped
946+
* this tick, no flush running" is a write no flush has carried: readers see
947+
* the committed backing, as core read() serves an unflushed node (the node
948+
* twin is `unflushedValue`). Inside the setter the draft arm serves the
949+
* writer its own writes regardless. */
950+
const unflushedPBs = new WeakMap<StoreNextTarget, number>();
951+
function unflushedBacking(target: StoreNextTarget): boolean {
952+
return !globalQueue._running && unflushedPBs.get(target) === clock;
953+
}
954+
/** The reader served committed for an unflushed backing runs again in the
955+
* flush that carries the write (core markLateLinker — the pass linked no node
956+
* that the fold's notification would wake). */
957+
function lateLinkReader(): true {
958+
const c = readerContext();
959+
if (c !== null) markLateLinker(c);
960+
return true;
961+
}
899962

900963
/** Parked truth-staged pending backings (#3164 fold): a tentative draft that
901964
* opens while a folded landing's backing is live moves the staged container
@@ -1740,6 +1803,11 @@ function pendingBackingVisible(target: StoreNextTarget, speculative: boolean): b
17401803
((speculative || inOwnerContext()) &&
17411804
!heldTruthMasked(target) &&
17421805
!heldFromReader(target) &&
1806+
// A28: a write no flush has carried is not yet visible — committed,
1807+
// and the reader re-runs in the carrying flush. The speculative peek
1808+
// (deep()/snapshot()) keeps its documented contract of seeing
1809+
// pending writes synchronously.
1810+
!(!speculative && unflushedBacking(target) && lateLinkReader()) &&
17431811
(enterHeldBacking(target), true)) ||
17441812
// A projection's pending backing is authoritative-elect: serve it to
17451813
// context-free readers too UNLESS a transition is holding the node
@@ -1835,6 +1903,14 @@ function nodeValue(node: Signal<any>, backing: any): any {
18351903
// Authoritative-view reads (until()'s predicate) skip the override arm
18361904
// only: staged pending values are authoritative, overrides are the
18371905
// caller's optimism.
1906+
// A28 (core read()'s arm, node twin): a staged value no flush has carried
1907+
// is served as its committed value and the reader re-runs in the carrying
1908+
// flush.
1909+
const c = readerContext();
1910+
if (c !== null && unflushedStaged) {
1911+
const u = unflushedValue(node);
1912+
if (u !== NOT_PENDING) return (markLateLinker(c), u);
1913+
}
18381914
const v =
18391915
!authoritativeServe() && visibleOverride(node)
18401916
? unwrapOverride(node._x?._overrideValue)

0 commit comments

Comments
 (0)