Skip to content

Commit a536e29

Browse files
fix: truth landings fold under retained optimism — atomic reveal at settle (#3123/#3164)
Re-ruling of the optimistic landing-consumption contract after GabbeV's union-tear report (#3164). The three interim #3123 mechanisms (equality-scoped consumption, retained-setter replay, echo mask) are removed; landings now FOLD: while any transaction retains optimism on a family, fresh truth stages into the retaining transaction (ordinary staged-setter channel, authoritative posture) and reveals atomically at its settle. Ordinary readers keep committed until the reveal (heldTruthNodes + _heldTruthMasked / optHooks.retainsOptimism, hook- dispatched so plain bundles pay only the seams); until()/latest() tunnel through, asyncWrite wakes authoritative observers under an active override (the #3164 signal deadlock), and the revert path resyncs overlaid keysets for mapArray. Consolidates the three stale unpublished changesets into one; re-pins the #2719/#3123 suites to fold semantics; adds #3164 union-tear + deadlock regression tests; bumps size budgets with attribution. Co-authored-by: Cursor <[email protected]>
1 parent 893b8f9 commit a536e29

15 files changed

Lines changed: 762 additions & 550 deletions

‎.changeset/optimistic-edit-outlives-echo.md‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎.changeset/optimistic-function-of-truth-replay.md‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎.changeset/optimistic-landing-equality-scoped-consumption.md‎

Lines changed: 0 additions & 5 deletions
This file was deleted.
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+
Truth landings under live optimism now FOLD instead of consuming (#3123, #2719, #3164). While any transaction retains optimism on a store family (or an armed signal), fresh authoritative data — continuation yields, foreign refetches, replacing landings alike — stages into the retaining transaction and reveals atomically when it settles, exactly like a signal landing under an active override. Ordinary readers keep the committed view until that reveal, so overlapping optimistic actions no longer flash each other's pending rows out, partial override coverage can no longer compose override + staged truth into a frame no timeline contains (GabbeV's union tear), and a pending add never ghosts onto the next dataset. Authoritative readers tunnel through the hold: `until()`'s predicate and `latest()` see the staged truth, and a landing staged under an active override wakes waiting authoritative observers instead of deadlocking. Key-matched rows keep their proxy identity across the fold, and the settle-time revert resyncs structural subscribers (`mapArray`) with the landed arrangement. This supersedes the interim #3123 retained-setter replay machinery, which is removed.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
CONFIG_AUTHORITATIVE_OBSERVED,
23
CONFIG_CHILD_COMPANIONS,
34
CONFIG_AUTO_DISPOSE,
45
CONFIG_SYNC,
@@ -411,6 +412,17 @@ export function handleAsync<T>(
411412
if (!hasActiveOverride(el)) {
412413
if (__DEV__ && attrHooks !== null) attrHooks.asyncEnd(el, undefined, value, true);
413414
insertSubs(el);
415+
} else if (el._config & CONFIG_AUTHORITATIVE_OBSERVED) {
416+
// A17 silence is stated over ordinary readers; an authoritative-view
417+
// reader (until()'s predicate) observed this node PAST its override
418+
// and is waiting for exactly this staged truth. Without the wake the
419+
// hold deadlocks: the landing waits on the transaction, the
420+
// transaction on the action, the action on an until() that was never
421+
// re-notified (#3164). Same selective wake as the equal-landing
422+
// branch in recompute(). Optional call: the bit implies the
423+
// optimistic engine WAS consulted, but the hook only installs with
424+
// it — a bare-core build must not crash here.
425+
GlobalQueue._notifyAuthoritativeObservers?.(el);
414426
}
415427
el._time = clock;
416428
} else if (lane) {

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,20 @@ export function read<T>(el: Signal<T> | Computed<T>): T {
12191219
GlobalQueue._laneReadsCommitted!(el, owner, c as Computed<any>)) ||
12201220
el._pendingValue === NOT_PENDING ||
12211221
c._config & CONFIG_CHILDREN_FORBIDDEN ||
1222-
(stale && el._transition && activeTransition !== el._transition)
1222+
(stale && el._transition && activeTransition !== el._transition) ||
1223+
// A17 for HELD truth on ARMED nodes (#3164 fold): fold-staged truth
1224+
// riding a live optimism-retaining transition (the hook's verdict —
1225+
// staged overrides stay visible, they ARE the optimism) is masked from
1226+
// ordinary readers — the retaining transaction's own speculative
1227+
// recomputes included: partial override coverage would otherwise
1228+
// compose override + staged truth into a state no timeline contains
1229+
// (GabbeV's union tear). The revert at settle is their notification
1230+
// point. Authoritative readers (until()'s predicate) and latest() see
1231+
// the staged truth — the tunnel that keeps the hold deadlock-free.
1232+
(el._config & CONFIG_OPTIMISTIC &&
1233+
!latestReadActive &&
1234+
!(c._config & CONFIG_AUTHORITATIVE_READ) &&
1235+
GlobalQueue._heldTruthMasked?.(el))
12231236
? el._value
12241237
: (el._pendingValue as T);
12251238
// Record that this isPending() probe observed the fresh pending value, so

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,13 @@ export class GlobalQueue extends Queue {
492492
static _notifyAuthoritativeObservers: ((el: Signal<any> | Computed<any>) => void) | null = null;
493493
static _laneAsyncSettled: ((el: Computed<any>) => void) | null = null;
494494
static _trackOptimisticStore: ((store: any) => void) | null = null;
495+
/** Held-truth mask (#3164 fold, installed by the optimistic store module):
496+
* true when a node's staged `_pendingValue` is fold-staged TRUTH riding a
497+
* live optimism-retaining transition — masked from ordinary readers (they
498+
* keep committed until the reveal). Core read()'s call site is gated by
499+
* CONFIG_OPTIMISTIC, which only optimistic modules set; the hook stays out
500+
* of the core floor (pay-for-use). */
501+
static _heldTruthMasked: ((el: Signal<any>) => boolean) | null = null;
495502
flush() {
496503
if (this._running) return;
497504
// Fast drain: nothing in flight but plain pending commits — no dirty
@@ -1125,6 +1132,27 @@ export function currentTransition(transition: Transition) {
11251132
return transition;
11261133
}
11271134

1135+
/** #3164 fold: a stamped truth is HELD (masked from ordinary readers until
1136+
* the reveal) only while its transition is live AND retaining optimism —
1137+
* overrides are what make partial-coverage composition a tear. A plain
1138+
* async transition carries no overrides, so downstream computes must see
1139+
* staged values to converge (normal speculation). Resolves merges first:
1140+
* merge unions optimistic nodes/stores into the target. */
1141+
export function transitionHoldsOptimism(transition: Transition): boolean {
1142+
const t = currentTransition(transition);
1143+
return t._done !== true && (t._optimisticNodes.length !== 0 || t._optimisticStores.size !== 0);
1144+
}
1145+
1146+
/** Nodes whose current `_pendingValue` is fold-staged TRUTH (#3164): marked
1147+
* by the optimistic module's staging sites (the only writers of truth onto
1148+
* armed nodes mid-hold). The read paths mask these from ordinary readers —
1149+
* a staged override is indistinguishable from staged truth by node state
1150+
* alone, and overrides must stay visible (they ARE the optimism), so
1151+
* membership here is the discriminator. Entries go inert once the pending
1152+
* value commits (the read arms gate on a live pending + a live retaining
1153+
* transition); no removal pass is needed. */
1154+
export const heldTruthNodes = new WeakSet<object>();
1155+
11281156
export function setActiveTransition(transition: Transition | null) {
11291157
activeTransition = transition;
11301158
}

0 commit comments

Comments
 (0)