Skip to content

Conversation

@tofarr
Copy link
Collaborator

@tofarr tofarr commented Dec 5, 2025

Summary of PR

This PR modifies the _wait_for_sandbox_start method in the LiveStatusAppConversationService class to query for existing running sandboxes before starting a new one. When no specific sandbox_id is provided, the system now:

  1. First searches for running sandboxes belonging to the current user
  2. Reuses an existing running sandbox if found
  3. Only starts a new sandbox if no running sandbox is available

Key Changes:

  • Added _find_running_sandbox_for_user() method: Searches through all sandboxes with pagination, filtering for running sandboxes owned by the current user
  • Modified _wait_for_sandbox_start() method: Now queries for existing sandboxes before creating new ones
  • Added comprehensive tests: Three new test cases covering successful finding, not found scenarios, and error handling
  • Maintained backward compatibility: Preserves existing behavior when a specific sandbox_id is provided

Technical Details:

  • Uses proper pagination to search through all available sandboxes
  • Filters by both sandbox status (RUNNING) and user ownership
  • Includes robust error handling with logging
  • Returns the first matching sandbox found for optimal performance

Change Type

  • New feature
  • Refactor

Checklist

  • I have read and reviewed the code and I understand what the code is doing.
  • I have tested the code to the best of my ability and ensured it works as expected.

Fixes

This addresses the issue mentioned in the original request where the system would always start a new sandbox instead of reusing existing running ones, leading to inefficient resource utilization.

Release Notes

  • Include this change in the Release Notes.

Improved sandbox resource utilization: The system now reuses existing running sandboxes for users before starting new ones, reducing resource consumption and improving conversation startup times.

@tofarr can click here to continue refining the PR


To run this PR locally, use the following command:

GUI with Docker:

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.openhands.dev/openhands/runtime:8a7a455-nikolaik   --name openhands-app-8a7a455   docker.openhands.dev/openhands/openhands:8a7a455

- Add _find_running_sandbox_for_user() method to search for existing running sandboxes
- Modify _wait_for_sandbox_start() to query for running sandboxes first when no sandbox_id is specified
- Only start new sandbox if no running sandbox is found for the current user
- Add comprehensive tests for the new functionality
- Maintain backward compatibility when sandbox_id is provided

This improves resource utilization and reduces startup times for conversations.
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server/app_conversation
  live_status_app_conversation_service.py 442-443, 470, 484-492
Project Total  

This report was generated by python-coverage-comment-action

@openhands-ai
Copy link

openhands-ai bot commented Dec 5, 2025

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • Docker

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #11922 at branch `reuse-running-sandboxes`

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

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.

3 participants