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
- Butterfly traces multi-agent failures with graphs, 62.5% accuracy vs 53.8% for log prompting — JeremyCMorgan · 2026-11-04
- Free course covers the 4 hard problems of production generative media agents — Al_Grigor · 2026-11-04
- Quota reset night: Codex back to 100% while Claude shows just 10% left — rudrank · 2026-11-04
- Self-improving software is inevitable: closing the agent-observability loop — bibryam · 2026-11-04
- Building a 7-GPU 132GB VRAM local inference rig: consolidate on EPYC or split across two systems? — infectiousstupidity · 2026-11-04
- Founder of 50-person, 12-country team says he talks to AI agents more than humans — Scobleizer · 2026-11-04