Add pause_closed_runtimes config to pause instead of stop runtimes (#6885)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Robert Brennan 2025-02-25 13:43:51 -05:00 committed by GitHub
parent 6ba79c454b
commit ef62ccde36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -41,6 +41,7 @@ class SandboxConfig(BaseModel):
remote_runtime_api_url: str | None = Field(default='http://localhost:8000')
local_runtime_url: str = Field(default='http://localhost')
keep_runtime_alive: bool = Field(default=False)
pause_closed_runtimes: bool = Field(default=True)
rm_all_containers: bool = Field(default=False)
api_key: str | None = Field(default=None)
base_container_image: str = Field(

View File

@ -377,7 +377,22 @@ class RemoteRuntime(ActionExecutionClient):
raise AgentRuntimeNotReadyError()
def close(self):
if self.config.sandbox.keep_runtime_alive or self.attach_to_existing:
if self.attach_to_existing:
super().close()
return
if self.config.sandbox.keep_runtime_alive:
if self.config.sandbox.pause_closed_runtimes:
try:
if not self._runtime_closed:
with self._send_runtime_api_request(
'POST',
f'{self.config.sandbox.remote_runtime_api_url}/pause',
json={'runtime_id': self.runtime_id},
):
self.log('debug', 'Runtime paused.')
except Exception as e:
self.log('error', f'Unable to pause runtime: {str(e)}')
raise e
super().close()
return
try: