Gemini CLI PR fixes bug where pressing Esc didn't stop the agent from running more tools
jesussamuel-byte · ghdev · 2026-10-22
A community PR (#29868) on google-gemini/gemini-cli fixes a cancellation bug:
- Problem: in interactive mode, pressing Escape to cancel while a continuation stream runs after a tool batch (e.g. right after SearchText finishes) prints "Request cancelled." but the CLI keeps executing subsequent model turns and tool calls (Shell git status, git worktree list).
- Root cause: processGeminiStreamEvents() only broke out of the switch on UserCancelled without returning a cancelled status; and the cancelled continuation stream (isContinuation === true, no visible text) was mistaken for an empty model response, triggering auto-nudge — which created a new AbortController, reset the cancellation flag, and sent another nudge prompt, effectively resurrecting the agent.
- Fix: return StreamProcessingStatus.UserCancelled immediately on UserCancelled or signal.aborted || turnCancelledRef.current; prevent auto-nudging after terminal stream events; check cancellation state across async boundaries in submitQuery and handleCompletedTools.
A instructive cancellation-semantics case for anyone building agent loops / streaming control.
More from coding & agent
- Claude Code Pushes Urgent Security Update Across All Installations — umeshonai · 2026-10-23
- Claude cut a 2.6-hour video export to 20 minutes — but only after being told to rebuild the server — byhewar · 2026-10-23
- 3 flight-booking rules my AI agent checks that I'd never do by hand — Efistoffeles · 2026-10-23
- OpenJet claims Qwen3.8-27B coding runs 1.9x faster than llama.cpp on one RTX 3090 — JeremyCMorgan · 2026-10-23
- Building an autonomous SEO agent in Hermes with three skills: programmatic pages, Keywords Everywhere, DataForSEO — EXM7777 · 2026-10-23
- Building a sports betting AI agent with onchain execution and human approval by default: architecture and lessons — Dry-Comfortable-2678 · 2026-10-23