You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(server): let mergeAsyncIterables release the last buffered value - #7932
mergeAsyncIterables, used by JSONL streaming (httpBatchStreamLink, streamed responses), keeps the last value it yielded alive until the next one arrives. While the generator awaits, V8 keeps the loop body's last const alive, so a large final chunk stays reachable as long as the stream is idle.
What
The buffer entry is held in a let outside the loop and cleared once the consumer has taken the value. Behaviour is otherwise unchanged.
Stack
Each PR is based on the one below it, so its diff shows only its own commits. Merge from the bottom up.
Regression check: mergeAsyncIterables.test.ts "lets go of the last yielded value while it waits for the next" fails on main (expected false to be true: a 50 MB value is still reachable after gc()) and passes with this change.
AI model
Claude Opus 5.5
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.
Summary by CodeRabbit
Bug Fixes
Improved memory handling in merged streams so consumed buffer data can be released while the iterator waits for another value.
Errors encountered during iteration continue to be propagated, and waiting iterators can resume with subsequent values.
Reviewing files that changed from the base of the PR and between a9f89a6 and 7e80272.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
The merge loop now clears a yielded item reference after the consumer resumes and throws buffered errors before accessing yielded values. A new test checks that a large yielded array can be collected while the merged iterator waits for another value.
Changes: Merge reference cleanup
Layer / File(s)
Summary
Handle and release buffered items packages/server/src/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.ts, packages/server/src/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.test.ts
The merge loop checks buffered errors before yielding, pulls the source iterator after resumption, and clears the item reference. A test checks collection of a large yielded array while the merged iterator waits.
The change releases the previously yielded reference while awaiting another value and adds regression coverage. No merge-blocking issue remains established.
Pre-merge checks: 5
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the main change: allowing mergeAsyncIterables to release the last buffered value.
Docstring Coverage
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
While the merged generator waits for the next value, V8 keeps the const
destructured from the last buffer entry alive, and with it the last value
yielded. Hold the entry in a let outside the loop and clear it after use.
Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: alexander <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
Holding the buffer entry in a let and clearing it after use lets the last yielded value be collected while the stream waits. Regression test fails on main, passes here. CI green.
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.
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
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.
Why
mergeAsyncIterables, used by JSONL streaming (httpBatchStreamLink, streamed responses), keeps the last value it yielded alive until the next one arrives. While the generator awaits, V8 keeps the loop body's lastconstalive, so a large final chunk stays reachable as long as the stream is idle.What
letoutside the loop and cleared once the consumer has taken the value. Behaviour is otherwise unchanged.Stack
Each PR is based on the one below it, so its diff shows only its own commits. Merge from the bottom up.
mergeAsyncIterableslets go of its last value, based onmainLinks
None
Alternatives considered
None
Testing
mergeAsyncIterables.test.ts"lets go of the last yielded value while it waits for the next" fails onmain(expected false to be true: a 50 MB value is still reachable aftergc()) and passes with this change.AI model
Claude Opus 5.5
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit