feat: implement Ctrl+C pause/interrupt flow and update SDK hash#548
Draft
feat: implement Ctrl+C pause/interrupt flow and update SDK hash#548
Conversation
- 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>
3 tasks
Contributor
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:
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. |
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 implements two changes:
b9780a1f570da8157fa9bcdb2b0c723d6ed7f003) for openhands-sdk, openhands-tools, and openhands-workspaceconversation.interrupt()APIChanges
SDK Update
pyproject.tomlto use git sources for openhands packages with revisionb9780a1f570da8157fa9bcdb2b0c723d6ed7f003agent-client-protocolversion constraint from>=0.7.0,<0.8.0to>=0.8.1to match SDK requirementsCtrl+C Progressive Stopping
Implemented a new progressive stopping behavior when Ctrl+C is pressed:
conversation.pause()- graceful pause, waits for current stepconversation.interrupt()- immediate cancellation of LLM callsKey code changes:
InterruptConversationmessage class inconversation_manager.pyinterrupt()method inConversationRunnerthat callsconversation.interrupt()_pause_attemptedflag inOpenHandsAppto track pause stateaction_request_quitto newaction_stop_or_quit_pause_attemptedflag when conversation finishesNote:
Ctrl+QandCtrl+Dstill trigger immediate quit flow.Testing
make lint✅make test(TUI tests) ✅ - 558 tests passedFixes #547
Verification Commands Run
make lint uv run pytest tests/tui/ -m "not integration" --ignore=tests/snapshots -v -x🚀 Try this PR