refactor: Make agent mode interruptions more robust#516
Merged
Conversation
added 9 commits
May 15, 2026 11:42
Co-authored-by: cecli (openai/gemini_cli_local/gemini-2.5-pro)
Co-authored-by: cecli (openai/gemini_cli_local/gemini-2.5-pro)
Co-authored-by: cecli (openai/gemini_cli_local/gemini-2.5-pro)
Co-authored-by: cecli (openai/gemini_cli_local/gemini-2.5-pro)
Co-authored-by: cecli (openai/gemini_cli_local/gemini-2.5-pro)
Co-authored-by: cecli (openai/gemini_cli_local/gemini-2.5-pro)
Co-authored-by: cecli (openai/gemini_cli_local/gemini-2.5-pro)
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes agent mode interruptions more robust by ensuring that long-running operations (linting, command execution, streaming responses, and LLM completion calls) can be properly interrupted via the existing
interrupt_eventmechanism.Changes
Core Interruption Infrastructure
cecli/helpers/coroutines.py: Addedinterruptible_async_generator()- a utility that wraps async generators to make them interruptible via anasyncio.Event, enabling cancellation of streaming LLM responses mid-generation.Linting (
cecli/linter.py)Linter.lint(),Linter.run_cmd(),Linter.py_lint(), andLinter.flake8_lint()allasyncso they can be interrupted.interrupt_eventparameter and usesrun_cmd_asyncinstead of blockingsubprocess.run()calls.None(graceful handling) instead of crashing.Command Execution (
cecli/run_cmd.py)run_cmd_async()- an async version ofrun_cmdthat usesasyncio.create_subprocess_shelland monitors aninterrupt_eventto terminate processes early when interrupted.Agent Coder (
cecli/coders/agent_coder.py)coroutines.interruptible()to allow interruption.coroutines.interruptible()instead of a blockingasyncio.sleep().Base Coder (
cecli/coders/base_coder.py)show_send_output_stream()method now wraps the async generator withinterruptible_async_generator(), allowing Ctrl+C to interrupt streaming LLM responses mid-generation.coroutines.interruptible()to allow interruption duringformat_messages().lint_edited()is now async and handlesasyncio.CancelledErrorgracefully.run_cmd_async()instead ofasyncio.to_thread(run_cmd, ...)for interruptible command execution.Run Command (
cecli/commands/run.py)asyncio.to_thread(run_cmd, ...)torun_cmd_async()for interruptible execution.Models (
cecli/models.py)litellm.acompletion) now usecoroutines.interruptible()to allow interruption during API calls.Testing