Skip to content

fix(octane): keep a recovered arm's streamed payload for a retry - #1759

Merged
trueadm merged 3 commits into
mainfrom
fix/unclosed-range-streamed-seeds
Oct 5, 2026
Merged

trueadm merged 3 commits into
mainfrom
fix/unclosed-range-streamed-seeds

Conversation

@trueadm

@trueadm trueadm commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This addresses the Cursor Bugbot finding on #1753 (review, "Recovery drops streamed seeds early").

When a streamed Suspense arm recovers from an unclosed range, #1753 called initial.consume?.() right away. If an enclosing attempt was then discarded, the server arm's DOM came back but its payload did not:

  • the enclosing attempt can be an outer Suspense arm's or the root's;
  • takeInitialSuspenseHydration had already deleted window.$OCTS[id] on the first take;
  • consume() deleted the only remaining copy, the initialStreamedPayloads entry.

The retry therefore hydrated the arm with no seeds and no native manifest. Instead of finding the damaged range, it suspended on the client's own use() request. Recovery and its #338 report waited for that request to settle.

Fix: the unclosed-range recovery no longer releases the payload. initialStreamedPayloads is a WeakMap keyed by the boundary's marker comment, and this path's removeRange(getNextSibling(state.start), state.end) removes that marker along with the arm:

  • If the enclosing attempt is discarded, the rollback restores the marker, so the retry finds the payload again.
  • After a commit, the detached marker releases the payload.

That is the job the map's own comment gives the weak owner: it "survives discarded nested attempts, but cannot retain a removed boundary." A deferred consume() modeled on the catch arm also fixed the bug, but it cost +61 raw bytes and broke the hydrate-root budget. Dropping the call removes 14 instead.

The finding also mentions initialSuspenseHydrations?.delete(state). That line is shared with the catch path and is unchanged. It is keyed by the TrySlot, and a discarded attempt's retry builds a new slot, which takes the payload again. Both new test cases go through that path.

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files:check passes on the three changed files.
  • pnpm typecheck: not run repo-wide. pnpm typecheck:files passes on the three changed files.
  • pnpm test: left to CI.
  • targeted tests: packages/octane/tests/hydration/unclosed-range.test.ts, --project octane: 31/31, before and after merging main (latest fb404c2).
    • Two new cases, each under the file's three builds (dev compile, prod compile, prod compile with the prod runtime). A streamed arm holds seeded use() data beside a damaged range. After the arm recovers, a later sibling suspends the attempt around it: an outer Suspense arm's attempt in one case, the root's in the other.
    • Each case asserts:
      • the discarded attempt left the server markup intact and reported nothing;
      • after the gate opens, the retry reports exactly one benchmarks: add selector-based external-store fan-out suite #338 before the client's request settles;
      • the final markup equals the undamaged server render, the button is live, and there is no uncaught error.
    • With the consume() call restored, all 6 new cases fail at the report assertion (expected [] to deeply equal [StringMatching]). The 25 existing cases pass either way.
  • pnpm sync: no generated changes.

Bundle size. Measured with run-minimal.mjs on the merge with main fb404c2. --budgets passes.

scenario main this PR Δ
hydrate-root raw / gzip 175,035 / 55,511 175,021 / 55,506 −14 / −5
deferred-hydration raw / gzip 238,545 / 75,383 238,531 / 75,380 −14 / −3

I did not ratchet the budgets down, to leave headroom for the open hydration PRs.

Changeset. None added. The #1753 changeset has not been released yet (it is pending in the Version Packages PR), and its text already describes the behavior this restores.

Risk / follow-ups

  • The fix releases the payload when the marker is garbage-collected, not at commit. Nothing retains the removed marker after the attempt returns, but this is not a synchronous release.
  • Found while writing the test, not changed here. A root retry reuses the client thenable from the discarded attempt's client render (use() batch replay). The retried hydration's useSeed then marks that thenable fulfilled with the server value before the arm fails over to the client. So with a shared promise object, the client render after recovery reads the server's value; an outer Suspense retry reads the client's. This follows from seeds writing to the thenable they are given, which is how they make later renders synchronous. The test resolves both sides to the same value so it does not depend on this.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Touches Suspense/streaming hydration recovery and payload lifetime; behavior change is narrow but in a complex hydration path with nested discard/retry.

Overview
Fixes a hydration bug where unclosed-range recovery on a streamed Suspense arm called initial.consume() too early, wiping the arm’s streamed seeds before a discarded enclosing attempt could retry.

Runtime: In the UnclosedHydrationRange path, that consume() call is removed. The arm’s payload stays in initialStreamedPayloads on the boundary marker comment removed by removeRange, so a rolled-back attempt can restore the marker and rehydrate with server data; a successful commit drops the marker and releases the payload via the weak map.

Tests: New streamed fixtures (StreamedInSuspense, StreamedInRoot) and cases assert that after recovery is undone by a sibling suspend (outer Suspense or root), the retry still reports one recoverable #338 and does not wait on the client use() promise to find the damaged range.

Reviewed by Cursor Bugbot for commit be729c4. Bugbot is set up for automated code reviews on this repo. Configure here.

When a streamed Suspense arm recovered from an unclosed range, it released
the arm's streamed payload right away. If an enclosing Suspense arm or the
root then discarded that attempt, the rollback restored the server arm, but
the retry hydrated it without its seeds or native manifest. It waited on the
client's own requests before finding the damage.

The recovery now leaves the payload with the weak marker that owns it. A
rollback restores the marker and the retry hydrates from it again. After a
commit, the removed marker releases the payload.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 5, 2026
@trueadm
trueadm marked this pull request as ready for review October 5, 2026 11:27
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 4 value(s) increased within budget

Compares fb404c24d, the merge commit's first parent with 614d559a3 on the same runner. A byte value over its committed budget or any increase in a js-framework work counter fails this check. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 2.875 2.842 −0.0% −3.0% … ±0.0% ⚪ within noise
octane-tsrx replace 6.425 6.483 −1.5% −6.3% … +3.3% ⚪ within noise
octane-tsrx add 2.633 2.583 ±0.0% −1.9% … +0.0% ⚪ within noise
octane-tsrx update 0.121 0.123 +0.6% −1.2% … +3.4% ⚪ within noise
octane-tsrx select 0.005 0.005 −0.8% −1.6% … ±0.0% ⚪ within noise
octane-tsrx swap 0.038 0.038 −2.1% −6.3% … +1.4% ⚪ within noise
octane-tsrx remove 0.019 0.019 +1.5% −4.9% … +10.5% ⚪ within noise
octane-tsrx runlots 24.667 26.317 −0.4% −3.4% … +4.3% ⚪ within noise
octane-tsrx select_lots 0.005 0.005 ±0.0% −0.8% … +1.0% ⚪ within noise
octane-tsrx clear 45.117 43.458 −0.7% −3.3% … +1.1% ⚪ within noise
octane-jsx run 3.592 3.567 ±0.0% −2.6% … ±0.0% ⚪ within noise
octane-jsx replace 7.358 7.517 −1.4% −4.1% … +2.0% ⚪ within noise
octane-jsx add 3.383 3.392 +1.1% −0.0% … +2.9% ⚪ within noise
octane-jsx update 0.250 0.238 −0.4% −2.2% … +1.4% ⚪ within noise
octane-jsx select 0.134 0.130 −1.1% −2.0% … +0.5% ⚪ within noise
octane-jsx swap 0.226 0.227 −0.6% −2.2% … ±0.0% ⚪ within noise
octane-jsx remove 0.179 0.181 +1.3% −0.3% … +2.1% ⚪ within noise
octane-jsx runlots 30.408 32.300 +0.5% −1.7% … +4.7% ⚪ within noise
octane-jsx select_lots 1.482 1.491 +3.1% −1.1% … +4.4% ⚪ within noise
octane-jsx clear 53.733 54.283 +1.0% −2.0% … +5.8% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx bindings_js_gzip 240,982 240,970 −12 (−0.0%) 🟢
octane-tsrx bindings_js_brotli 205,086 205,148 +62 (+0.0%) 🔴
octane-tsrx bindings_app_gzip 121,729 121,717 −12 (−0.0%) 🟢
octane-tsrx bindings_app_brotli 101,728 101,790 +62 (+0.1%) 🔴
octane-tsrx full_fw_raw 571,381 571,367 −14 (−0.0%) 🟢
octane-tsrx full_fw_gzip 175,021 175,015 −6 (−0.0%) 🟢
octane-tsrx full_fw_brotli 147,640 147,802 +162 (+0.1%) 🔴
octane-jsx full_fw_raw 571,381 571,367 −14 (−0.0%) 🟢
octane-jsx full_fw_gzip 175,021 175,015 −6 (−0.0%) 🟢
octane-jsx full_fw_brotli 147,640 147,802 +162 (+0.1%) 🔴

50 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
hydrate-root raw 175,035 175,021 −14 (−0.0%) 🟢
hydrate-root gzip 55,511 55,506 −5 (−0.0%) 🟢
hydrate-root brotli 48,439 48,430 −9 (−0.0%) 🟢
deferred-hydration raw 238,545 238,531 −14 (−0.0%) 🟢
deferred-hydration gzip 75,383 75,380 −3 (−0.0%) 🟢
deferred-hydration brotli 65,115 65,068 −47 (−0.1%) 🟢

99 other measured values are unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant