Skip to content

feat: implement Ctrl+C pause/interrupt flow and update SDK hash#548

Draft
malhotra5 wants to merge 5 commits intomainfrom
feat/ctrl-c-pause-interrupt
Draft

feat: implement Ctrl+C pause/interrupt flow and update SDK hash#548
malhotra5 wants to merge 5 commits intomainfrom
feat/ctrl-c-pause-interrupt

Conversation

@malhotra5
Copy link
Collaborator

@malhotra5 malhotra5 commented Feb 25, 2026

Summary

This PR implements two changes:

  1. Updates pyproject.toml to use the new SDK hash (b9780a1f570da8157fa9bcdb2b0c723d6ed7f003) for openhands-sdk, openhands-tools, and openhands-workspace
  2. Implements progressive Ctrl+C behavior using the new conversation.interrupt() API

Changes

SDK Update

  • Updated pyproject.toml to use git sources for openhands packages with revision b9780a1f570da8157fa9bcdb2b0c723d6ed7f003
  • Updated agent-client-protocol version constraint from >=0.7.0,<0.8.0 to >=0.8.1 to match SDK requirements

Ctrl+C Progressive Stopping

Implemented a new progressive stopping behavior when Ctrl+C is pressed:

State Action
Agent running, first Ctrl+C conversation.pause() - graceful pause, waits for current step
Agent still running, second Ctrl+C conversation.interrupt() - immediate cancellation of LLM calls
Agent not running Normal quit flow

Key code changes:

  • Added InterruptConversation message class in conversation_manager.py
  • Added interrupt() method in ConversationRunner that calls conversation.interrupt()
  • Added _pause_attempted flag in OpenHandsApp to track pause state
  • Changed Ctrl+C binding from action_request_quit to new action_stop_or_quit
  • Reset _pause_attempted flag when conversation finishes

Note: Ctrl+Q and Ctrl+D still trigger immediate quit flow.

Testing

  • make lint
  • make test (TUI tests) ✅ - 558 tests passed

Fixes #547

Verification Commands Run

make lint
uv run pytest tests/tui/ -m "not integration" --ignore=tests/snapshots -v -x

🚀 Try this PR

uvx --python 3.12 git+https://github.com/OpenHands/OpenHands-CLI.git@feat/ctrl-c-pause-interrupt

- Update pyproject.toml to use SDK hash b9780a1f570da8157fa9bcdb2b0c723d6ed7f003
- Update agent-client-protocol version constraint to >=0.8.1
- Add InterruptConversation message and handler
- Add interrupt() method to ConversationRunner
- Implement progressive Ctrl+C behavior:
  - First Ctrl+C while running: pause
  - Second Ctrl+C while still running: interrupt
  - Ctrl+C when not running: quit
- Reset pause tracking when conversation finishes

Co-authored-by: openhands <openhands@all-hands.dev>
When agent is not running, Ctrl+C now shows a notification:
'Agent is already stopped. Use /exit or Ctrl+Q to quit.'

This prevents accidental app termination and guides users to the
proper quit methods.

Co-authored-by: openhands <openhands@all-hands.dev>
- Change interrupt() to be synchronous and fire-and-forget
- Add _interrupt_in_progress flag to prevent duplicate interrupt messages
- SDK's interrupt() is thread-safe, no need to await

This fixes the issue where rapidly pressing Ctrl+C would queue up
multiple interrupt requests, causing delayed notifications.

Co-authored-by: openhands <openhands@all-hands.dev>
Instead of posting InterruptConversation message through Textual's
message queue, call conversation.interrupt() directly from the
action handler. This matches the pattern in the SDK example where
signal handlers call interrupt() directly for immediate response.

The SDK's interrupt() is thread-safe and designed for direct calls.

Co-authored-by: openhands <openhands@all-hands.dev>
Remove the two-step pause→interrupt flow. Now Ctrl+C immediately
interrupts the agent on first press, which is the expected behavior.

- Removed _pause_attempted flag (no longer needed)
- Ctrl+C now directly calls conversation.interrupt()

Co-authored-by: openhands <openhands@all-hands.dev>
@jpshackelford
Copy link
Contributor

jpshackelford commented Mar 6, 2026

Question: Is this PR now blocking SDK fixes for CLI (because of sdk #2133?

We're trying to test SDK PR OpenHands/software-agent-sdk#2334 (terminal escape filter fix) with the CLI, but it fails because the SDK PR is based on post-breaking-change main (after OpenHands/software-agent-sdk#2133).

See test PR: #572

Questions:

  1. Is this PR blocking the release/testing of other SDK fixes intended for CLI use?
  2. What's needed to get this PR to pass CI and merge?
  3. Should SDK PRs intended for CLI testing be rebased onto v1.11.5 until this PR merges?

The CI failures on this PR appear to be similar type-checking and import issues that need to be resolved for compatibility with the new SDK API.

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.

Immediately terminate agent step on ctrl + c

3 participants