fix: cancel current command/stream on Ctrl+C instead of exiting - #89
Draft
aryansk wants to merge 1 commit into
Draft
fix: cancel current command/stream on Ctrl+C instead of exiting#89aryansk wants to merge 1 commit into
aryansk wants to merge 1 commit into
Conversation
execute_bash now catches KeyboardInterrupt from subprocess.run and returns "Command execution cancelled by user."; the streaming loop stops on interrupt and keeps the partial reply so the session and history survive; tool calls interrupted mid-run cancel cleanly. A Ctrl+C at the prompt still exits with the goodbye screen. Closes shauryagangrade#51.
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.
Problem
Pressing Ctrl+C while the assistant is streaming a reply, or while a bash
command is running, terminates the entire GCode session and prints the
goodbye screen. Any messages since the last save are lost — the turn in
progress is never persisted. Closes #51.
Change
Three interrupt-handling fixes:
execute_bash(gcode/tools.py): catchesKeyboardInterruptfromsubprocess.runand returnsCommand execution cancelled by user.instead of letting it kill the REPL. Applies both to the prompt phase
(already handled) and the running-command phase (new).
gcode/agent.py_stream): a Ctrl+C during streamingstops the stream, keeps whatever was accumulated so far as the turn's
assistant message (with no half-formed tool calls), and persists it —
the session stays alive and history is saved.
gcode/agent.py_run_tool): a Ctrl+C during any toolcall returns
Command execution cancelled by user.to the model insteadof propagating.
A Ctrl+C (or Ctrl+D) at the prompt still exits with the goodbye screen,
unchanged.
Why this approach
Minimal, targeted changes: the interrupt is caught at the two async
boundaries where it can arrive mid-work (streaming and subprocess), and the
tool-call boundary is hardened so a cancelled tool result is recorded in
history like any other tool result. No changes to the prompt loop or exit
paths.
Testing
New tests cover: partial reply retained on mid-stream interrupt, empty
reply when interrupted before any chunk, and a tool that raises
KeyboardInterrupt returning the cancelled result.
Documentation and release impact
Review notes
tool calls the model had begun to emit (they are half-formed), but keeps
the text.