Add interrupt callbacks for terminal tool termination#2209
Draft
malhotra5 wants to merge 1 commit intofeature/conversation-interruptfrom
Draft
Add interrupt callbacks for terminal tool termination#2209malhotra5 wants to merge 1 commit intofeature/conversation-interruptfrom
malhotra5 wants to merge 1 commit intofeature/conversation-interruptfrom
Conversation
- Add _interrupt_callbacks list to LocalConversation with register/unregister methods - Invoke all registered callbacks when conversation.interrupt() is called - Add request_interrupt() method to TerminalSession that sets flag and sends Ctrl+C - Add interrupt check in TerminalSession execute loop to return early when interrupted - Register interrupt callback in TerminalExecutor.__call__ to terminate terminal commands - Add tests for interrupt callback registration and terminal session interruption Co-authored-by: openhands <openhands@all-hands.dev>
Contributor
Coverage Report •
|
||||||||||||||||||||||||||||||||||||||||
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 adds an interrupt callback mechanism that allows
conversation.interrupt()to immediately terminate in-flight terminal commands.Changes
LocalConversation
_interrupt_callbacks: listattribute to store registered callbacksregister_interrupt_callback(callback)method to register callbacksunregister_interrupt_callback(callback)method to remove callbacksinterrupt()to invoke all registered callbacks before changing statusTerminalSession
_interrupt_requested: boolflag to track interrupt requestsrequest_interrupt()method that sets the flag and sends Ctrl+C to the terminal_handle_interrupted_command()method to create appropriate observation for interrupted commandsexecute()to reset interrupt flag at start and check it in the polling loopTerminalExecutor
__call__()to register an interrupt callback when conversation is availableself.session.request_interrupt()finallyblock to ensure cleanupHow it works
When
conversation.interrupt()is called while a terminal command is running:session.request_interrupt()Design Decisions
The
register_interrupt_callbackandunregister_interrupt_callbackmethods are only onLocalConversation, not onBaseConversationas abstract methods because:Tests
Added tests for: