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(gemini): bound pending tool data in translated streams - #9067
Use the shared translator budget while assembling tool calls for Gemini streaming responses on the Chat bridge. Each call can retain up to 2 MiB of arguments, and all pending tool data shares a 32 MiB allowance per turn. Release the buffer when the calls are emitted, when a reader cancels, or when the upstream stream ends in error. Names and arguments split across chunks preserve their UTF-8 byte count, including split surrogate pairs.
Verification
Windows, Bun 1.4.4. bun test tests/responses/responses-gemini-codec.test.ts tests/server/server-native-final-log.test.ts passed all 28 tests (91 assertions). The tests use small injected limits and in-memory streams, including cancellation and upstream failure.
bun check --no-script --noEmit checked 2,691 files. bun scripts/structure-ssot.ts, bun scripts/privacy-scan.ts, and git diff --check passed.
Independently reviewed stream termination, byte accounting, and existing SSE and JSON-array framing. Checked that merging this change and fix(gemini): honor provider routing on native generation #9066 in either order produces the same Git tree. Local tests focused on the affected codec and server path. The full local suite was not run.
Checklist
Limited the change to tool data retained by the Gemini streaming bridge and its regression tests.
Updated the operator reference and Gemini data-plane contract.
Reviewed release of retained data on all terminal paths and preservation of ordinary response content. Maintainer review is requested.
Summary by CodeRabbit
New Features
Gemini streaming responses now enforce a 2 MiB argument limit per tool call and a 32 MiB limit for retained tool data per turn. Exceeding either limit ends the stream with an error.
Streamed tool data is released when calls are emitted or when the stream fails or is canceled.
Reviewing files that changed from the base of the PR and between ddc386e and 0509cd3.
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
Gemini streaming tool calls now use translator budgets for retained arguments and tool fields. The codec releases tool state after emission, failure, or cancellation. Documentation and tests cover the limits, UTF-8 fragment accounting, and cleanup outcomes.
The codec charges retained tool fields and UTF-8 fragments against per-call and per-turn budgets. It adjusts charges when signatures change and disposes of tool state after emission. Tests cover budget limits, split Unicode fragments, emitted calls, and disposal. The documentation describes the limits and release behavior.
The native stream setup passes a callback to dispose of Gemini tool state. Tests verify budget release and final-log outcomes on cancellation and upstream read failure.
Gemini streaming tool calls now use bounded buffers: 2 MiB of arguments per call and 32 MiB of pending tool data per turn. The buffers are released on emission, cancellation, or upstream failure. No concrete merge-blocking risk was identified, and tests cover the limits, UTF-8 fragment accounting, and cleanup outcomes.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "fix(gemini): bound pending tool data in translated streams" matches the main change. The PR adds a shared TranslatorBudget to the Gemini stream state, caps per-call arguments at 2 MiB and p…
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: Title check
Explanation
The title "fix(gemini): bound pending tool data in translated streams" matches the main change. The PR adds a shared TranslatorBudget to the Gemini stream state, caps per-call arguments at 2 MiB and pending tool data at 32 MiB per turn, and releases buffers on emission, cancellation, or upstream error. The changed files (src/protocols/codecs/gemini.ts, src/server/gemini-inbound.ts, the docs, and the tests) all support this. The title is specific and concise, and it follows a conventional-commit style.
Finishing Touches
Generate unit tests (beta)
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; 4 remain after this review.
PR checks passing on that head: enforce / enforce-target, ci, test changed, hygiene / hygiene, docs site build, npm-global ubuntu-latest, api usage, gates, enforce / resolve-pr, label / label, docker smoke, Catalog async contracts (ubuntu-latest), storage policy, structure gate, changes, select windows runner, validate-source. Skipped jobs are not counted as passing.
Relaxed gate: (a) 5 commits behind origin/dev 927c3f3 (limit 10): PASS. (b) git merge-tree --write-tree 927c3f30509cd3: clean. (c) dev commits since merge-base 8961476 touch none of this PR's files: yes; shared-class files dev touched: scripts/test-layout/layout-server-inbound.json tests/fixtures/test-layout-expected.json ; shared-class files this PR touches: none (guards below decide when both sides touch a class). (d) temporary local merge 19ccece073d2db2faef96f36a9ec238ab76f61f5: bun run typecheck exit 0; bun test --timeout 60000 [focused: tests/responses/responses-gemini-codec.test.ts tests/server/server-native-final-log.test.ts] [guards: tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/ci-workflows/file-size-ratchet.test.ts tests/ci-workflows/skill-ocx.test.ts]: 81 pass 0 fail exit 0; bun run structure:check exit 0: PASS.
Independent review (gpt-6.1-terra): APPROVE, no findings. Focused Gemini codec, native final-log and inbound tests pass; a byte-limit assertion rejects oversized arguments here and is accepted by dev's codec.
scripts/ci/assert-mergeable-review.sh --maintainer-integration 9067: OK.
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.
Summary
Use the shared translator budget while assembling tool calls for Gemini streaming responses on the Chat bridge. Each call can retain up to 2 MiB of arguments, and all pending tool data shares a 32 MiB allowance per turn. Release the buffer when the calls are emitted, when a reader cancels, or when the upstream stream ends in error. Names and arguments split across chunks preserve their UTF-8 byte count, including split surrogate pairs.
Verification
bun test tests/responses/responses-gemini-codec.test.ts tests/server/server-native-final-log.test.tspassed all 28 tests (91 assertions). The tests use small injected limits and in-memory streams, including cancellation and upstream failure.bun check --no-script --noEmitchecked 2,691 files.bun scripts/structure-ssot.ts,bun scripts/privacy-scan.ts, andgit diff --checkpassed.Checklist
Summary by CodeRabbit