Repository navigation
fix(octane): evaluate a derived$ again once the thenable it threw settles - #1779
Conversation
…tles A synchronous computation that throws a thenable is pending until it settles. Settling it resolved the node's wakeup but never invalidated the node, so every reader woken by that wait read the same clean pending state with an already-settled waiting promise. An async derived$ awaiting it with read() retried that wait on every microtask and froze the page. A redeclaration reached the same state: when the view and the cell read the same signals, sameViewResult kept the cell's pending read even though the new definition threw a different thenable, so the cell kept waiting on the replaced one (#1763). - The thrown thenable's settlement now invalidates the node still waiting on it. A thenable already seen to settle waits for a dependency instead, so a lagging computation cannot evaluate again on every microtask. - A node keeps its wakeup only while its state presents it, so an earlier thrown thenable cannot restart work that replaced it. - sameViewResult also compares the thrown thenable, and promotion hands the view's wakeup to the cell. - The wakeup holds its node only while the node waits; retirement, view retirement and candidate release drop it, so a thenable that never settles does not retain a disposed owner. Fixes #1763 Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Promotion drops settled thenable invalidation
- Propagated the view's Dirty flag into the promoted node's flags in promoteDeclarationView, so that when settleThrown invalidates the view and clears its wakeup before promotion, the node inherits the Dirty flag and re-evaluates instead of presenting a stale pending state with an already-settled waiting promise.
Or push these changes by commenting:
@cursor push 197064e3fe
Preview (197064e3fe)
diff --git a/packages/octane/src/signals/graph.ts b/packages/octane/src/signals/graph.ts
--- a/packages/octane/src/signals/graph.ts
+++ b/packages/octane/src/signals/graph.ts
@@ -1194,7 +1194,9 @@
// A view nobody read has no state to install; the cell evaluates its new definition.
const unevaluated = state === undefined;
node.flags =
- ReactiveFlags.Mutable | ReactiveFlags.Watching | (unevaluated ? ReactiveFlags.Dirty : 0);
+ ReactiveFlags.Mutable |
+ ReactiveFlags.Watching |
+ ((unevaluated ? ReactiveFlags.Dirty : 0) | (view.flags & ReactiveFlags.Dirty));
// Committed consumers learn the accepted state first. The render's own
// consumers already presented it; move them without another notification.
if ((currentChanged || retainedChanged || unevaluated) && node.subs) {You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 515bdc1. Configure here.
Benchmark report🟢 No budget breaches, no added work, and no timing changes beyond ±3%. Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)No changes across 60 measured values. Public-import reachability bundles (bytes)No changes across 105 measured values. |
A declaration view invalidated after its render, such as by the thenable it threw settling, still held the pending result of that render. Promotion committed it and left the cell clean, so the cell could present a wait that had already settled. The cell now takes the view's Dirty or Pending flags and notifies its committed consumers, so it evaluates the accepted definition instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tion-waiter-spin # Conflicts: # packages/octane/src/signals/graph.ts


Summary
Follow-up to #1775, which fixed #1763 by repairing waiter handling when a redeclared pending derived is accepted. This PR fixes the defect under that report. A synchronous
derived$whose thrown thenable settles is never evaluated again. Its readers wake, re-read the same clean pending state whosewaitingpromise has already settled, and an asyncread()spins on microtasks.That hang still happens on main with #1775 and no redeclaration at all: a derived throws P1, then P1 settles while the computation would still throw it. The issue's reproduction, minus the redeclaration step, runs out of heap on main. With this PR it passes.
What this adds on top of #1775 (
graph.ts):commitStatereleases a wakeup its new state no longer presents, so an earlier thrown thenable cannot abort async work that replaced it.#1775's promotion logic (
sameViewResult, waiter transfer, settled/invalidated retry) is kept as merged. This PR's earlier promotion changes were dropped in the merge because #1775 covers them. Docs (docs/signals.mdand the website's signals page) state the thrown-thenable contract.Validation
Against main, which includes #1775, three of this PR's tests fail and none hang:
The plain reproduction (no redeclaration) runs out of heap on main.
commitStatereleasing a wakeup it no longer presentsresolve()clearing the nodeoctane-signals: this PR'ssignals-update-depthandsignals-unifiedplus fix(octane): keep pending readers attached to accepted work #1775's five tests (signals-waiter-equivalent,signals-waiter-race-watchdog,signals-waiter-thenable,signals-pending-promotion,signals-pending-promotion-graph): 48/48 pass on the merged code.signal-local-selectors.test.ts, projectoctane(promotion and held transitions): 54/54 pass.pnpm format:files:checkandpnpm typecheck:fileson the changed sources: clean.pnpm sync: no changes.pnpm format:check,pnpm typecheck,pnpm testrepo-wide: left to CI. Prod and Strong compile modes are left to CI.Risk / follow-ups
derived$that throws a thenable now re-evaluates when the thenable settles. Before, it stayed pending: snapshot readers never updated, and async readers spun. Subscribers of such a value are now notified on settlement.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes core signal graph pending/retry semantics for thrown thenables; subscribers now update on settlement, and computations that rethrow settled thenables stay pending until a read dependency changes.
Overview
Fixes #1763: when a synchronous
derived$throws a thenable, the graph now re-runs that computation after the thenable settles and notifies subscribers, instead of leaving readers stuck on a pending value whose wait promise has already resolved.In
graph.ts, pending wakeups track the thrown thenable and the waiting node. Settlement callssettleThrown, which invalidates the node so it evaluates again. AsettledThrownweak set stops rethrowing an already-settled thenable from causing a microtask spin (asyncread()loops).commitStateonly keeps a wakeup while the new state still exposes its promise; promotion, view retirement, and transition candidate release clearwakeup.nodeso never-settling thenables do not retain disposed owners.Docs (
docs/signals.md, website) describe the thrown-thenable contract. Tests cover plain retry, redeclared definitions with switched thenables, async child readers, GC after dispose, and async work surviving replaced thrown waits.Reviewed by Cursor Bugbot for commit d0bd925. Bugbot is set up for automated code reviews on this repo. Configure here.