Gemini CLI PR fixes session context poisoning and infinite loops from interrupted agentic turns
dylanyunlon · ghdev · 2026-09-18
A P2 PR in google-gemini/gemini-cli exposes a subtle agent engineering pitfall: when the agentic loop is interrupted (SIGINT, timeout, aborted tool call), the CLI injects a synthetic turn reading [The previous response was interrupted before it completed.]. Gemini later parrots this string back as an expected completion pattern, poisoning session history and blocking tool execution until reset.
The fix applies defense in depth:
- A new interruptionSanitizer.ts detects the placeholder and replaces it with benign text ("Continuing.");
- Source-level fix in closeUnansweredToolResponseTurn() injects the benign text instead;
- extractCuratedHistory() sanitizes before history hits the API, catching residue from old sessions;
- nextSpeakerChecker short-circuits on interruption turns, returning {nextspeaker: 'model'} without an LLM call;
- Compression and history-scrubbing pipelines sanitize too, plus an E2E test with a mock Gemini server.
Key takeaway for agent builders: any synthetic text injected into chat history can be learned and echoed by the model.
More from coding & agent
- Anthropic's Head of Product Drops a 28-Minute Masterclass on Agents in Production — ifioknkem · 2026-09-20
- Teknium: Jev can't compact context well — Hermes summarizes 95% of it away — Teknium · 2026-09-20
- HarnessRouter: routing agent harnesses instead of models, a fresh infra idea — daniel_mac8 · 2026-09-20
- MCP tool naming: short generic verbs vs explicit prefixes for LLM tool selection — skvark · 2026-09-20
- GameToMac launched 10 days ago and already runs AoE IV, CS2 and Diablo IV on Apple Silicon — nickbaumann_ · 2026-09-20
- DialKit 2.0 ships: open-source real-time UI tuning tool with prompts for coding agents — LinusEkenstam · 2026-09-20