Skip to content

fix(gemini): bound pending tool data in translated streams - #9067

Merged
lidge-jun merged 3 commits into
lidge-jun:devfrom
luvs01:codex/gemini-stream-tool-budget
Nov 25, 2026
Merged

lidge-jun merged 3 commits into
lidge-jun:devfrom
luvs01:codex/gemini-stream-tool-budget

Conversation

@luvs01

@luvs01 luvs01 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • 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.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 23, 2026
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

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.

Changes: Gemini streaming tool budgets

Layer / File(s) Summary
Budgeted tool-call assembly
src/protocols/codecs/gemini.ts, tests/responses/responses-gemini-codec.test.ts, docs-site/src/content/docs/reference/proxy-formats.md, structure/data-planes/gemini-inbound.md
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.
Native stream cleanup
src/server/gemini-inbound.ts, tests/server/server-native-final-log.test.ts
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.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: andrew05060414

Merge Risk: Minimal · previous review 74d43

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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9e0e298 and 74d4330.

Files selected for processing: 6

  • docs-site/src/content/docs/reference/proxy-formats.md
  • src/protocols/codecs/gemini.ts
  • src/server/gemini-inbound.ts
  • structure/data-planes/gemini-inbound.md
  • tests/responses/responses-gemini-codec.test.ts
  • tests/server/server-native-final-log.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer integration into dev (MAINTAINERS.md, maintainer-integration path), under the coordinator's relaxed behind-dev gate.

  • Exact head: 0509cd37cc54708019c648048608cdba0e5d99d5.
  • 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 927c3f3 0509cd3: 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.

@lidge-jun
lidge-jun merged commit 846ebcd into lidge-jun:dev Nov 25, 2026
49 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants