Exit llm chat cleanly on Ctrl+D#1457
Open
ATOM00blue wants to merge 1 commit into
Open
Conversation
Pressing Ctrl+D (EOF) at the chat prompt let click.prompt's Abort propagate, printing "Aborted!" and exiting with a non-zero status. Catch the Abort and break out of the loop so EOF ends the session cleanly, matching the Python REPL and other interactive tools. Refs simonw#1214
There was a problem hiding this comment.
Pull request overview
This PR fixes llm chat so pressing Ctrl+D (EOF) exits the chat loop cleanly (status 0) instead of bubbling up to Click’s top-level abort handler that prints Aborted! and exits non-zero.
Changes:
- Catch
click.exceptions.Abortaround theclick.prompt(...)call in the chat loop and exit the loop cleanly. - Add a regression test that simulates EOF by patching
click.promptto raiseclick.Abortand asserting exit code 0 with noAborted!output.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
llm/cli.py |
Wraps the interactive prompt read to treat click.exceptions.Abort as a clean exit from llm chat. |
tests/test_chat.py |
Adds a test covering EOF/Abort behavior to prevent regression and verify clean exit semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Fixes #1214
Pressing Ctrl+D (EOF) at the
llm chatprompt currently printsAborted!and exits with a non-zero status, instead of exiting cleanly the way most interactive REPLs (Python, etc.) do:Root cause
The chat loop reads input with
click.prompt(...). On EOF,click.promptcatches the underlyingEOFErrorand re-raises it asclick.exceptions.Abort. Nothing in the loop handles that, so it bubbles up to Click's top level, which printsAborted!and exits with status 1.Fix
Wrap the
click.promptcall in the loop and treat anAbortas a clean exit:Testing
Added
test_chat_eof_exits_cleanly, which patchesclick.promptto raiseclick.Abort(the same thing a real terminal EOF produces) and asserts the command exits with status 0 and never printsAborted!. The test fails onmainand passes with this change. The rest oftests/test_chat.pystill passes.