Repository navigation
fix(octane): pace Suspense retries on an already-settled wakeable - #1400
Merged
Merged
Conversation
A retry that suspended again on a promise whose settlement had already been observed re-rendered on that promise's next microtask, forever. This happens when a resource reader throws a resolved promise before its own state catches up, or when use() reads a thenable whose status React does not recognize (router-core reports 'resolved'), which both runtimes treat as pending. Timers and network callbacks never ran, so the state that would end the suspension never arrived and the page livelocked. Every client resume subscription now goes through resumeOnSettle. A first settlement still retries on its microtask. A wakeable whose settlement was already seen still subscribes through then, so a reusable custom wakeable is not polled, and then retries after one macrotask, as React's Scheduler ping does. use() semantics are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
September 29, 2026 14:42
4 of 7 tasks
trueadm
added a commit
that referenced
this pull request
Sep 29, 2026
With #1400 on main, a universal root inside a DOM Suspense boundary is paced by both runtimes' resume subscriptions. Cover it directly: a projected root suspension, and one that holds a transition. The second fails if the urgent projection is released on the microtask, which is the only regression test for that pacing. Link the universal contract from SUSPENSE_DIVERGENCE §13. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
added a commit
that referenced
this pull request
Sep 29, 2026
…1404) * fix(universal): pace Suspense retries on an already-settled thenable A universal retry that suspended again on a thenable whose settlement had already been observed re-rendered on that thenable's next microtask, forever. This happens when a thenable's owner publishes its status on a later task, or when a reverse-region DOM child routes the same suspension back to its universal owner on every commit. Timers and native callbacks never ran, so the state that would end the suspension never arrived and the root livelocked. Boundary and hidden-Activity replays, root and transition suspensions, and routed renderer- region suspensions all looped. Every universal resume subscription now goes through resumeOnSettle, the same design as the DOM runtime. A first settlement still retries on its microtask. A thenable whose settlement was already seen still subscribes through then, so a reusable custom wakeable is not polled, and then retries after one macrotask, as React's Scheduler ping does. The urgent-projection release is paced the same way: releasing it on the microtask lets a DOM-hosted root with held transition work re-prepare, suspend on the same thenable, and loop. Universal use() also stops rewriting a thenable status it did not set. It used to replace a status React does not recognize, such as router-core's 'resolved', with its own tracking. It now leaves it alone and treats the thenable as pending, matching React's trackUsedThenable and the DOM runtime. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(universal): cover a DOM-hosted universal root pacing both runtimes With #1400 on main, a universal root inside a DOM Suspense boundary is paced by both runtimes' resume subscriptions. Cover it directly: a projected root suspension, and one that holds a transition. The second fails if the urgent projection is released on the microtask, which is the only regression test for that pacing. Link the universal contract from SUSPENSE_DIVERGENCE §13. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
7 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A Suspense retry that suspended again on a promise whose settlement Octane had already observed re-rendered on that promise's next microtask, forever. Two cases hit this: a resource reader that throws a resolved promise before its own state catches up, and
use()of a thenable whosestatusReact does not recognize, such as router-core's'resolved'. Both React and Octane treat that status as pending and leave the thenable uninstrumented. Timers and network callbacks never ran, so the state that would end the suspension never arrived, and the page livelocked at 100% CPU. React sends the same retry through a Scheduler task, so the component spins without starving the event loop. #1397 avoided this in the tanstack-router binding; this PR fixes it in core.Every client resume subscription now goes through one helper,
resumeOnSettleinruntime.ts: boundaries, transition holds, roots without a boundary, hidden Activity, passthrough pending, and initial and<Hydrate>hydration.WeakSetand checked when subscribing. The helper still subscribes throughthen, so a reusable custom wakeable waits for its next notification instead of being polled. It then retries after one macrotask (setTimeout(retry, 0)).use(): positional semantics and its handling of unrecognized statuses are unchanged.Decision: yielding a task was chosen over a retry bound. A bound either fails a legitimate component or still spins until the bound. Yielding lets the callback that ends the suspension run, matches React, and costs nothing on paths that never loop.
Docs:
packages/octane/audit/SUSPENSE_DIVERGENCE.md§13 anddocs/differences-from-react.md. Includes a patch changeset foroctane.Tests
The new test cases open their gate from a timer. Each gate also opens itself after 2,000 checks and records that it did, because the pre-fix loop would otherwise starve Vitest's own timeout.
suspense-settled-wakeable.test.ts(new):use()of a'resolved'-status thenable;initial-suspense-hydrate.test.ts: initial adoption waiting on a settled gate (both gate placements).deferred-hydration-contract.test.ts:<Hydrate>activation reading a'resolved'-status thenable.Pre-fix failures: 8 of the new cases fail on
main. Reverting just the initial-adoption subscription fails its 2 hydration cases, and reverting just the<Hydrate>activation subscription fails its case. Each plausible wrong design turns a test red:thenfor known-settled wakeables polls the reusable wakeable;Validation
pnpm format:files:checkon every changed file (not the repo-widepnpm format:check)tsgo --noEmit -p packages/octane/tsconfig.json, pluspnpm typecheck:fileson the runtime, the new test and its fixture (not the repo-widepnpm typecheck)pnpm test: not run whole locally; it runs out of memory on this machine. CI covers it.main: the fulloctaneandoctane-prodprojects, 24,617 of 24,627 passed. Most of the 10 failures were 5 s compile or import timeouts under load average ~45 from other local sessions. The HMR,behavior-rootandindependent-parentfiles passed when re-run in isolation, and the HMR test passed three times in a row. Thevolarcompile-timeout test was not re-run.main: 20 Suspense-heavy binding projects (tanstack-router/-differential/-ssr, tanstack-query/-differential, jotai/-differential/-hydration, swr/-differential, apollo-client/-differential, i18next/-differential, livestore, remix-router/-differential, tanstack-start, tanstack-db, lexical), 1,169 of 1,170 passed. The one failure was jotai's export-surface 5 s timeout, which passed in isolation.main: 56 file runs, 1,391 tests, all passed. They cover the new and changed tests plus the nearest Suspense, SSR-Suspense, hydration, portal and actions files in bothoctaneandoctane-prod, and the tanstack-router (including fix(tanstack-router): keep route matches suspended across match states #1397's match-suspension tests), livestore and i18next packages.benchmarks/bundle-size/run-minimal.mjs): +109 B raw and about +45 B gzip on client bundles that include root rendering. Server, capture-only and vanilla-binding bundles are unchanged, and every scenario stays under its budget.audit-981-coverageSuspense list (64 independently pending keyed boundaries, compared with the baseline source viaCLIENT_SOURCE_ROOT): function-entry counts are identical on all 12 operations, including settle-odd and settle-even. All 68 applicable ratio guards pass. The render path is untouched.WeakSetinsert. One boundary's suspend-and-resume costs about 125 µs in jsdom, so this is roughly 0.1%. A symbol property on the promise would be cheaper, but it writes to user-owned thenables that proxies can observe and frozen objects reject; React also tracks thrown wakeables in a WeakMap/WeakSet. Not per render.Risk / follow-ups
use()replay) reuse the same promise.act()does not drain, like the retry-reveal delay in §5. A test has to await a task insideact()to observe it.prerenderstops with "exceeded 50 suspense passes" after 51 reads, before a 0 ms timer can fire. A probe confirmed this, and the error message wrongly blamesuse().universal-core.tsresubscribes the same microtask way. It is very likely affected, but not confirmed here.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Touches core Suspense scheduling across boundaries, roots, Activity, and hydration; behavior change is intentional but widespread, with small client bundle growth and paced retries not fully drained by
act()without awaiting a task.Overview
Fixes a Suspense livelock where a retry that kept suspending on a promise Octane had already seen settle re-ran on that promise’s microtask forever, starving timers and network callbacks so the UI never recovered. Typical triggers are resource readers that throw a resolved promise before local state catches up, or
use()on thenables with unrecognizedstatusvalues (e.g. router-core’s'resolved').resumeOnSettleinruntime.tsnow backs every client Suspense resume subscription (boundaries, root holds, transition/hidden Activity, passthrough pending, initial and deferred hydration). The first settlement still schedules the retry on the settling microtask; after a wakeable is recorded in a lazyWeakSet, further retries still subscribe viathenbut yield one macrotask (setTimeout(0)) after the next notification, matching React’s scheduler pacing without polling custom wakeables.Docs add SUSPENSE_DIVERGENCE §13 and a differences-from-react note; a patch changeset ships the fix. New
suspense-settled-wakeabletests (plus hydration cases) assert timer-driven recovery and that first-time / shared-pending paths still reveal on microtasks.Reviewed by Cursor Bugbot for commit c67e7b4. Bugbot is set up for automated code reviews on this repo. Configure here.