Skip to content

fix(cli): handle ctrl+c and ctrl+d gracefully in interactive mode - #8273

Open
amitdevx wants to merge 1 commit into
google:mainfrom
amitdevx:main
Open

amitdevx wants to merge 1 commit into
google:mainfrom
amitdevx:main

Conversation

@amitdevx

Copy link
Copy Markdown

cli.py (interactive mode) pressing ctrl+c or ctrl+d would spit out raw python traceback rather than gracefully exiting

and while the agent was busy formulating its reply, hitting ctrl+c killed the entire CLI rather than canceling the turn and returning to prompt

the changes made by this PR address:

  • keyboard interrupt and eof error when getting user input so it gracefully exists
  • keyboard interrupt during the model's generation process to cancel the turn and resume prompt
  • keyboard interrupt during HITL function calls and session saving prompts
  • exit code 130 for sigint during single query execution
  • telemetry invoke exit code handling so ctrl+c is not counted as an unhandled crash

unit tests were added for ctrl+c and ctrl+d cases

Issue:
in interactive mode (cli.py), using ctrl+c or ctrl+d gives raw python traceback instead of quitting properly. in addition, while an agent is responding, use of ctrl+c
quits the whole process and doesn’t allow for the cancellation of the current turn but goes back to the prompt. in single query mode, ctrl+c quits without quitting
with exit code 130.

Solution:

  • catch keyboardinterrupt and eoferror when getting user input to gracefully exit
  • catch keyboardinterrupt when generating the turn to interrupt the response
  • catch keyboardinterrupt and eoferror when prompted for hitl function calls and saving the session
  • exit with status 130 on sigint in single query mode
  • change telemetry invoke handler so that keyboardinterrupt doesn’t cause an unhandled exception log
(RuntimeError, EOFError, KeyboardInterrupt)

…tive mode

Catch KeyboardInterrupt and EOFError in interactive CLI prompts and active generation turns to prevent unhandled traceback dumps and ensure clean exit.
@google-cla

google-cla Bot commented Nov 20, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@amitdevx

Copy link
Copy Markdown
Author

hi, this PR fixes ctrl+c and ctrl+d handling in adk run interactive mode so it exits cleanly without traceback dumps and lets users cancel a running turn safely. added tests as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants