-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Feat: Stop runtimes rather than delete them #6403
Merged
+121
−28
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
10185e1
Restarting containers
tofarr f5b6e34
WIP
tofarr 007b43d
Stopping runtimes rather than deleting them
tofarr b316c0e
Fix for delete
tofarr 35f7c24
Merge branch 'main' into feat-stop-runtimes
tofarr 28be124
Always stop all runtime containers on exit
tofarr 0287b0e
Removed comment
tofarr 6a9acbe
Add unit tests for DockerRuntime container cleanup behavior
openhands-agent 2027bae
Lint fixes
tofarr 9172ca8
Merge branch 'main' into feat-stop-runtimes
tofarr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import docker | ||
|
||
|
||
def remove_all_containers(prefix: str): | ||
def stop_all_containers(prefix: str): | ||
docker_client = docker.from_env() | ||
|
||
try: | ||
containers = docker_client.containers.list(all=True) | ||
for container in containers: | ||
try: | ||
if container.name.startswith(prefix): | ||
container.remove(force=True) | ||
container.stop() | ||
except docker.errors.APIError: | ||
pass | ||
except docker.errors.NotFound: | ||
pass | ||
except docker.errors.NotFound: # yes, this can happen! | ||
pass | ||
finally: | ||
docker_client.close() |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
from openhands.core.logger import openhands_logger as logger | ||
from openhands.events.stream import EventStreamSubscriber | ||
from openhands.runtime import get_runtime_cls | ||
from openhands.server.auth import get_user_id | ||
from openhands.server.routes.settings import ConversationStoreImpl, SettingsStoreImpl | ||
from openhands.server.session.conversation_init_data import ConversationInitData | ||
|
@@ -227,6 +228,8 @@ async def delete_conversation( | |
is_running = await session_manager.is_agent_loop_running(conversation_id) | ||
if is_running: | ||
await session_manager.close_session(conversation_id) | ||
runtime_cls = get_runtime_cls(config.runtime) | ||
await runtime_cls.delete(conversation_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explicitly allow the runtime to run delete logic here. |
||
await conversation_store.delete_metadata(conversation_id) | ||
return True | ||
|
||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to change this logic because the existing logic did not work for stopped containers.