-
Notifications
You must be signed in to change notification settings - Fork 82
Bug: Gemini CLI bridge crashes on large MCP tool responses (64KB StreamReader limit) #1126
Description
🐛 Bug Description
Summary: The Gemini CLI bridge crashes with Separator is not found and chunk exceed the limit errors when an MCP tool returns a large response (e.g., mcp_kubernetes_events_list).
Expected Behavior: Large MCP tool responses should be processed without crashing the Gemini CLI bridge.
Actual Behavior: asyncio.StreamReader.readline() raises asyncio.LimitOverrunError because a single NDJSON line exceeds the default 64 KB buffer limit.
🔄 Steps to Reproduce
- Start a session using the Gemini CLI bridge
- Trigger a tool call that returns a large response (e.g.,
mcp_kubernetes_events_liston a busy cluster) - The bridge crashes with
Separator is not found/chunk exceed the limit
🌍 Environment
Component: Ambient Agentic Runner — Gemini CLI bridge
File: components/runners/ambient-runner/ambient_runner/bridges/gemini_cli/session.py
📋 Additional Context
Root Cause: In ambient_runner/bridges/gemini_cli/session.py, the asyncio.create_subprocess_exec() call uses Python's default StreamReader buffer limit of 64 KB. The Gemini CLI outputs NDJSON lines to stdout — when a single line exceeds 64 KB (common with large tool results), asyncio.StreamReader.readline() raises asyncio.LimitOverrunError.
Error Messages:
asyncio.LimitOverrunError: Separator is not found, and chunk exceed the limit
🔍 Possible Solution
Add limit=10 * 1024 * 1024 (10 MB) to the create_subprocess_exec() call in session.py (around line 149). One-line change:
self._process = await asyncio.create_subprocess_exec(
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
cwd=self._cwd,
env=env,
limit=10 * 1024 * 1024, # Default 64KB is too small for large MCP tool responses
)✅ Acceptance Criteria
- Bug is reproduced and root cause identified
- Fix is implemented and tested
- Regression tests added to prevent future occurrences
- Documentation updated if needed
🏷️ Labels
- Priority: high
- Complexity: trivial
- Component: backend