OpenHands icon indicating copy to clipboard operation
OpenHands copied to clipboard

Reuse one runtime container / no separate runtime containers per conversation

Open Ricent82 opened this issue 8 months ago • 8 comments

What problem or use case are you trying to solve?

I'm using OpenHands in the default Docker setup, except that I map the workspace to a project folder on my host machine. I noticed that it seems to create an entirely new runtime container every time I start a new conversation. Can this be avoided? Can it just reuse the existing runtime container if one is already present, and only create a new one if really needed?

The benefit of having a runtime container is clear, but in many cases having an entirely separate one for each session seems like quite overkill - causing it to take longer to start a new conversation, more system overhead, more storage, more cleanup required.

Thanks in advance

Ricent82 avatar Apr 26 '25 22:04 Ricent82

I have the same question. I think run_controller intends to support passing a runtime but actually main does not use it. I am also using the cli.py and that one doesn't seem to support passing an existing runtime.

rbrugaro avatar May 01 '25 18:05 rbrugaro

@enyst does passing the -n param to the CLI only keep the conversation? Or does it use the same runtime?

mamoodi avatar May 01 '25 19:05 mamoodi

Related to my issue https://github.com/All-Hands-AI/OpenHands/issues/7914 - it's very cumbersome to have to keep manually cleaning up all the countless runtime containers it creates & leaves on the system. Reusing the same one would implicitly solve this lack of cleanup (for those willing to reuse)

JGKle avatar May 02 '25 04:05 JGKle

The -n parameter is only for the conversation, not runtime, indeed. Edited to add: Also, it works for headless, but not for CLI. This PR makes it work for CLI.

We've been trying to set up a persistent container in the past, but it hasn't worked well from what I recall. 😥

enyst avatar May 13 '25 02:05 enyst

This would also be my highest wish list item. Every time starting a new conversation it takes quite a while "waiting for client to become ready...". If instead it just started one single runtime, and kept that persistent for all conversations, I believe this would be much faster to start each conversation, like with Claude Code

Kansai53 avatar May 16 '25 00:05 Kansai53

@Kansai53 Sorry I ask, does Claude Code work in a docker container by default? I thought it didn't have any... 🤔

enyst avatar May 16 '25 11:05 enyst

Right, Claude Code doesn't use a container. I'm just saying that if OpenHands started a single runtime container that it reused for every conversation, then it wouldn't have to take so long to start each and every new conversation. It could start new conversations quickly, like Claude Code does. Because once the first container is started, that's the only one it needs - it doesnt need to start new ones over and over

Kansai53 avatar May 16 '25 14:05 Kansai53

The -n parameter is only for the conversation, not runtime, indeed. Edited to add: Also, it works for headless, but not for CLI. This PR makes it work for CLI.

We've been trying to set up a persistent container in the past, but it hasn't worked well from what I recall. 😥

The -n option in headless mode restarts an exited runtime container when same session name is provided. Below is the relevant code: https://github.com/All-Hands-AI/OpenHands/blob/e69d6b3ef15452dfe7b7c5f602f6517131472094/openhands/runtime/impl/docker/docker_runtime.py#L145 https://github.com/All-Hands-AI/OpenHands/blob/e69d6b3ef15452dfe7b7c5f602f6517131472094/openhands/runtime/impl/docker/docker_runtime.py#L392

rbrugaro avatar May 19 '25 18:05 rbrugaro

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jun 20 '25 02:06 github-actions[bot]

Not stale

JGKle avatar Jun 20 '25 02:06 JGKle

Thank you, @rbrugaro ! @metal450 does it work for your in headless mode - and now it should be the same with the CLI?

enyst avatar Jul 07 '25 14:07 enyst

I'm only using the standard docker/web UI, can confirm when it hits there :)

JGKle avatar Jul 08 '25 00:07 JGKle

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Aug 07 '25 02:08 github-actions[bot]

This issue is stale because it has been open for 40 days with no activity. Remove the stale label or leave a comment, otherwise it will be closed in 10 days.

github-actions[bot] avatar Sep 17 '25 02:09 github-actions[bot]

This issue was automatically closed due to 50 days of inactivity. We do this to help keep the issues somewhat manageable and focus on active issues.

github-actions[bot] avatar Oct 04 '25 02:10 github-actions[bot]