Repository navigation
fix(ssr): let prerender outlast a reader that rethrows a settled thenable - #1409
Merged
Merged
Conversation
…able A resource reader can keep throwing a thenable that has already settled while its own state waits for a later task, such as a timer or an I/O callback. Buffered SSR retried on microtasks, so it spent all 50 passes before that task could run and failed with a message that blamed use(). runBuffered now recognizes a stalled wave: every registration is a resource-thrown thenable this render has already seen settle. Stalled waves do not spend the pass budget. After the thenables notify again, the retry waits on a timer that doubles from 1ms to 100ms, and the stall fails with a new error (332) once it lasts timeoutMs. A narrower stalled wave means a reader finished, so the rest get a fresh deadline. Width only shrinks, so a reader that cycles between settled thenables stays bounded. Stalls are recognized by identity only. Probing whether a thenable was settled when thrown also caught a new Promise.resolve() per attempt, but it made every level of a cached thrown-resource waterfall look stalled, slowing that case from 138us to 8.8ms per render. When a pass limit is reached on a wave made only of thrown thenables, buffered (333) and streamed boundary (334) errors now name thrown thenables instead of use(). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…son-309a17 Keep both retry-pacing bullets in differences-from-react.md, client (#1400) first. Point section 13's "SSR is unchanged" limit at the buffered server rule in section 9. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
September 29, 2026 17:31
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
prerendernow finishes when a resource reader keeps rethrowing a thenable that has already settled while its own state waits for a later task, such as a timer or an I/O callback. Before this change, buffered SSR retried on microtasks. It spent all 50 passes before that task could run, then failed with a message that blameduse().'|throw#') that this render has already seen settle.runBufferedchecks this before settling, inisStalledWave.timeoutMs(default 10s;0disables it).use().Why this design
React is not the reference here. In React 19.2.7, Fizz's
pingTaskschedules retries withsetImmediateonly once a streaming request is open. For all ofprerender, and during a stream's first task, it pings on a microtask. In a probe, React'sprerenderre-rendered 200,000 times and never let a 0ms timer fire. This change deliberately does better than React; the docs record the divergence.Identity only. My first version also counted a native promise that was already settled when thrown as stalled. That covered a reader throwing a new
Promise.resolve()on every attempt. But it made every level of a cached thrown-resource waterfall look stalled too, and a micro-benchmark went from 138µs to 8.8ms per render. Identity cannot misread that pattern, and it matches the client rule in #1400. A reader that throws a new settled promise on every attempt still hits the pass limit, now with error 333; this is documented as a limit.Streaming is not changed here. It already yields one macrotask per wave, but each wave still counts toward the 50 consecutive passes, so a 20ms lag fails there. A follow-up session is working on streamed stalls on top of this diff.
Changes
packages/octane/src/runtime.server.ts:isThrownKey,isThrownWave, andisStalledWave;settleSuspendedrecords settled thrown thenables inresolved.settledThrows. Also the stall accounting and backoff inrunBuffered, and error-code selection for 47/333 and 48/334.packages/octane/error-codes/codes.json, plus the regeneratederror-codes.server.generated.tsand CLI data.packages/octane/audit/SUSPENSE_DIVERGENCE.md: section 9 describes the server behavior, React's behavior, and the limits. Section 13's "SSR is unchanged" limit now points to section 9.docs/differences-from-react.mdanddocs/ssr.md(timeoutMs), plus a changeset.Validation
packages/octane/tests/ssr-suspense.test.ts, in both theoctaneandoctane-prodprojects.use()control that keeps the old message.main, the fulloctane,octane-prod, andcliprojects gave 24,796 of 24,797 passed. The one failure was ahydration/independent-parent.test.tsload flake; it uses synchronousrenderToString, never reaches this code, and passes when re-run alone.main, the SSR, streaming, static, hydration, suspense, actions, react-compat SSR, and production-error-bundle suites gave 3,563 of 3,564 passed at load average 35–47. The failure was the same flake, which passed 2 of 2 alone.pnpm error-codes:check,pnpm sync, andpnpm format:files:checkon all changed files.pnpm typecheck:fileson the changed source is clean. The test file's four existing errors (a.tsrximport and olderreplayThenablefixtures) are outside this diff.pnpm format:check,pnpm typecheck, andpnpm test: not run locally; CI covers them.Performance (
ssr-throughput):waterfall-d1/d2/d4,nested-d4,deopt-fast, andcontrol-flowwere within −1.0% to +0.4%, with no consistent winner and byte-identical bodies.use()control) moved between −1.5% and +2.6% across processes, so there's no consistent change.Risk / follow-ups
renderToPipeableStreamandrenderToReadableStream) are in progress in a separate change built on this one.use()when a resource-thrown thenable never settles. I left it unchanged.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 buffered SSR suspense retry logic and failure modes; behavior shifts for resource readers that lag behind settled promises, though scope is server-only with extensive new tests.
Overview
Buffered
prerenderno longer burns the 50-pass suspense budget when a resource reader keeps throwing the same already-settled thenable until a timer or I/O callback updates its state. The server tracks settled resource throws inresolved.settledThrows, treats an all-|throw#wave as stalled viaisStalledWave, and after settle waits on a 1ms→100ms backoff timer instead of microtask spins. Stalled retries do not increment the pass counter; unrecoverable stalls fail with new error 332 aftertimeoutMs(also documented forprerender).When pass limits hit on waves made only of thrown thenables, buffered (333) and streaming-boundary (334) errors now blame resource throws outside
use()instead of genericuse()messages. Docs/changeset record the React divergence;ssr-suspense.test.tsadds coverage for pacing, deadlines, waterfalls, abort, and the new diagnostics.Reviewed by Cursor Bugbot for commit f8ab94a. Bugbot is set up for automated code reviews on this repo. Configure here.