Skip to content

Bug fix: Gemini CLI bridge crashes on large MCP tool responses - raise gemini cli stream buffer limit to 10 MB#1242

Open
vishsanghishetty wants to merge 2 commits intoambient-code:mainfrom
vishsanghishetty:fix/1126-gemini-cli-buffer-limit
Open

Bug fix: Gemini CLI bridge crashes on large MCP tool responses - raise gemini cli stream buffer limit to 10 MB#1242
vishsanghishetty wants to merge 2 commits intoambient-code:mainfrom
vishsanghishetty:fix/1126-gemini-cli-buffer-limit

Conversation

@vishsanghishetty
Copy link
Copy Markdown
Contributor

@vishsanghishetty vishsanghishetty commented Apr 7, 2026

Summary

Raises the asyncio.StreamReader buffer limit from the default 64 KB to 10 MB when spawning the Gemini CLI subprocess. Prevents asyncio.LimitOverrunError crashes when an MCP tool (e.g. mcp_kubernetes_events_list) returns a large NDJSON line.

Closes #1126

What changed

One-line fix in session.py — added limit=10 * 1024 * 1024 to the asyncio.create_subprocess_exec call.

How I tested

Unit testtest_stream_buffer_limit_raised mocks create_subprocess_exec and asserts the limit kwarg is 10 * 1024 * 1024.

Integration testtest_large_stdout_line_does_not_crash spawns a real subprocess that outputs 100 KB on a single line (well above the old 64 KB default) and reads it with the 10 MB limit. This would crash with ValueError: Separator is found, but chunk is longer than limit under the old default. Passes with our fix.

tests/test_gemini_session.py — 30 passed

Full E2E reproduction (triggering an actual Gemini CLI session with a large MCP tool response) requires a running ACP instance with Gemini API keys, so that's not included here. The integration test proves the mechanism at the asyncio level.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of large output streams to prevent buffer overflow errors.
  • Tests

    • Added test coverage for subprocess buffer configuration and large payload handling.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 7, 2026

Warning

Rate limit exceeded

@vishsanghishetty has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 29 minutes and 56 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 29 minutes and 56 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e2e4872d-5b08-415b-a4da-7cb4586542fe

📥 Commits

Reviewing files that changed from the base of the PR and between 49ca627 and 191c091.

📒 Files selected for processing (2)
  • components/runners/ambient-runner/ambient_runner/bridges/gemini_cli/session.py
  • components/runners/ambient-runner/tests/test_gemini_session.py
📝 Walkthrough

Walkthrough

Sets the subprocess StreamReader buffer limit to 10 MB by passing limit=10 * 1024 * 1024 to asyncio.create_subprocess_exec() in the Gemini CLI bridge to avoid asyncio.LimitOverrunError on large NDJSON stdout lines.

Changes

Cohort / File(s) Summary
Subprocess Buffer Limit Configuration
components/runners/ambient-runner/ambient_runner/bridges/gemini_cli/session.py
Added limit=10 * 1024 * 1024 argument to asyncio.create_subprocess_exec() in GeminiSessionWorker.query() to raise the StreamReader buffer limit from the 64KB default to 10MB.
Stream Buffer Limit Verification Tests
components/runners/ambient-runner/tests/test_gemini_session.py
Added TestWorkerSubprocessConfig with test_stream_buffer_limit_raised() that patches asyncio.create_subprocess_exec to assert the limit kwarg is set to 10 * 1024 * 1024, and test_large_stdout_line_does_not_crash() which runs a real subprocess emitting ~100KB to verify reading succeeds and process exits normally.
🚥 Pre-merge checks | ✅ 7 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning Title does not follow Conventional Commits format (missing type prefix and parenthetical scope). Reformat title as: 'fix(gemini-cli): raise stream buffer limit to 10 MB for large MCP tool responses'
✅ Passed checks (7 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed PR fully implements all coding requirements from issue #1126: increased buffer limit, regression tests for the fix.
Out of Scope Changes check ✅ Passed All changes directly address issue #1126—buffer limit increase and related test coverage, no extraneous modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Performance And Algorithmic Complexity ✅ Passed Bounded 10MB subprocess buffer limit prevents crashes on large payloads with no algorithmic complexity or unbounded growth introduced.
Security And Secret Handling ✅ Passed Pull request adds single-line subprocess buffer limit parameter with no secrets, proper environment variable handling, safe list-based command construction, and maintained security posture.
Kubernetes Resource Safety ✅ Passed This check is not applicable to the provided pull request. The PR exclusively modifies Python source code to increase asyncio subprocess buffer limits and add unit tests, containing no Kubernetes manifests or deployment-related files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@vishsanghishetty vishsanghishetty changed the title raise gemini cli stream buffer limit to 10 MB Bug fix: Gemini CLI bridge crashes on large MCP tool responses - raise gemini cli stream buffer limit to 10 MB Apr 7, 2026
@vishsanghishetty
Copy link
Copy Markdown
Contributor Author

@ambient-code

the default asyncio StreamReader limit of 64 KB causes crashes when
an MCP tool returns a large response (e.g. kubernetes events list).

closes ambient-code#1126

Signed-off-by: Vishali <vsanghis@redhat.com>
spawns a real subprocess that outputs 100 KB on a single line
and verifies readline() succeeds — would crash with the default
64 KB StreamReader limit.

Signed-off-by: Vishali <vsanghis@redhat.com>
@vishsanghishetty vishsanghishetty force-pushed the fix/1126-gemini-cli-buffer-limit branch from 49ca627 to 191c091 Compare April 10, 2026 19:47
@vishsanghishetty
Copy link
Copy Markdown
Contributor Author

@ambient-code

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Gemini CLI bridge crashes on large MCP tool responses (64KB StreamReader limit)

1 participant