Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Send C-c to stop background process when stop button is clicked #6846

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

neubig
Copy link
Contributor

@neubig neubig commented Feb 20, 2025

When the stop button is clicked, it only changes the agent state but does not actually stop the running process. This causes the process to continue running in the background, preventing new commands from being executed.

This fix modifies the AgentController to send a C-c command to stop any running process when transitioning to the STOPPED state. This ensures that background processes are properly terminated when the stop button is clicked.

Changes:

  • Removed the _source field from CmdRunAction as it is not the right approach
  • Uses EventSource.USER properly when adding events to the event stream

Added tests:

  • test_bash_session_stop_behavior: Shows the issue with background processes
  • test_bash_session_stop_command: Shows that C-c properly stops processes
  • test_agent_controller_stop: Verifies the fix works correctly

Fixes #6848


To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:bb9a07b-nikolaik   --name openhands-app-bb9a07b   docker.all-hands.dev/all-hands-ai/openhands:bb9a07b

When the stop button is clicked, it only changes the agent state but doesn't
actually stop the running process. This causes the process to continue running
in the background, preventing new commands from being executed.

This fix modifies the AgentController to send a C-c command to stop any running
process when transitioning to the STOPPED state. This ensures that background
processes are properly terminated when the stop button is clicked.

Added tests:
- test_bash_session_stop_behavior: Shows the issue with background processes
- test_bash_session_stop_command: Shows that C-c properly stops processes
- test_agent_controller_stop: Verifies the fix works correctly
@neubig neubig changed the title add failing test for stopping bash session fix: Send C-c to stop background process when stop button is clicked Feb 20, 2025
When the stop button is clicked, it sends a C-c command to stop any running
process. This command needs to be marked as a user action to avoid requiring
tool call metadata when the agent processes it.

- Added _source parameter to CmdRunAction to set source at creation time
- Set source='user' when creating C-c command
- Added tests to verify agent can process C-c command without error
- Use _ to indicate intentionally unused variables
- Add comments explaining why we don't use the message results
# Send C-c as a user action to avoid tool call metadata requirement
stop_action = CmdRunAction(command='C-c', is_input=True)
# Add as a user event to avoid tool call metadata requirement
self.event_stream.add_event(stop_action, EventSource.USER)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we need to do this, what do you think about doing it in the method just above, _reset at line 430? 🤔

@neubig neubig self-assigned this Feb 22, 2025
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.

[Bug]: Stop button does not terminate background process
4 participants