← Back to PRs

#15301: Feat/gemini overflow and tags

by divisonofficer open 2026-02-13 07:48 View on GitHub →
agents stale size: M
## Overview This PR improves the robustness of Google Gemini (Cloud Code Assist) integration by addressing two main issues: inaccurate error mapping for large contexts and strict output format requirements. ## Key Changes Cloud Code Assist 400 Error Mapping: Previously, the Cloud Code Assist API would sometimes return a generic 400: Request contains an invalid argument error when the session payload became too large, instead of a specific overflow error. Added logic to treat this specific 400 error as a context overflow when the current session exceeds 200k tokens. This ensures that the system's built-in overflow-compaction is correctly triggered, maintaining session continuity. Relaxed Gemini Tag Enforcement: Disabled mandatory ` tag enforcement by default for both google-gemini-cli and google-generative-ai` providers. This provides more flexibility in handling model responses while keeping reasoning capabilities intact. ## Technical Details Modified src/agents/pi-embedded-runner/run.ts to include the isLikelyCloudCodeInvalidArgumentOverflow check. Updated resolveEnforceFinalTag in src/auto-reply/reply/agent-runner-utils.ts to exclude Gemini providers from default enforcement. Added comprehensive unit tests in run.overflow-compaction.test.ts and agent-runner-utils.test.ts to cover large-context edge cases and default tag behavior. ## Testing Status [x] Unit tests passed. [x] Regression tests for overflow compaction verified. [x] Linting and formatting applied (oxlint, oxfmt). <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR improves Gemini/Cloud Code Assist robustness in two areas: - **Overflow compaction triggering:** adds detection in the embedded runner to treat Cloud Code Assist’s generic `400 invalid argument` as a context overflow when the configured context window is already very large, so the existing auto-compaction loop can run. - **Final-tag enforcement:** adjusts `resolveEnforceFinalTag` so Gemini providers (`google-gemini-cli`, `google-generative-ai`) no longer force final-tag formatting by default, while still honoring explicit `run.enforceFinalTag` and keeping enforcement for other reasoning-tag providers. - **Transcript/tool-call sanitization & embeddings auto-selection:** updates transcript policy to sanitize tool call IDs for OpenAI providers, updates session-history sanitization tests accordingly, and changes embeddings “auto” provider selection to prefer local embeddings. Main merge blockers called out below focus on behavior changes that either contradict existing mode semantics (images-only sanitization) or can impose unexpected heavy local initialization in auto embeddings selection. <h3>Confidence Score: 3/5</h3> - This PR is close, but has a couple behavior changes that should be corrected before merging. - Core changes around Cloud Code Assist overflow mapping and Gemini final-tag enforcement look coherent and are covered by unit tests, but two changes likely alter semantics unintentionally: (1) tool-call ID sanitization now runs even in images-only sanitization mode, and (2) embeddings auto-selection always attempts local initialization first, which can add heavy overhead or fail in environments without the optional dependency/configuration. - src/agents/pi-embedded-helpers/images.ts, src/memory/embeddings.ts <sub>Last reviewed commit: a40afc7</sub> <!-- greptile_other_comments_section --> <sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub> <!-- /greptile_comment -->

Most Similar PRs