π OpenHands: AI-Driven Development
refactor(action_execution_client): rename function and add property (#7913)
Xingyao Wangf1f7dca009b5
diff --git a/openhands/runtime/impl/action_execution/action_execution_client.py b/openhands/runtime/impl/action_execution/action_execution_client.pyindex e4694ee83e..8e2f121980 100644--- a/openhands/runtime/impl/action_execution/action_execution_client.py+++ b/openhands/runtime/impl/action_execution/action_execution_client.py@@ -94,9 +94,13 @@ class ActionExecutionClient(Runtime):git_provider_tokens,)- @abstractmethod- def _get_action_execution_server_host(self) -> str:- pass+ @property+ def action_execution_server_url(self) -> str:+ raise NotImplementedError("Action execution server URL is not implemented")++ @property+ def runtime_initialized(self) -> bool:+ return self._runtime_initialized@retry(retry=retry_if_exception(_is_retryable_error),@@ -127,7 +131,7 @@ class ActionExecutionClient(Runtime):def check_if_alive(self) -> None:response = self._send_action_server_request('GET',- f'{self._get_action_execution_server_host()}/alive',+ f'{self.action_execution_server_url}/alive',timeout=5,)assert response.is_closed@@ -145,7 +149,7 @@ class ActionExecutionClient(Runtime):response = self._send_action_server_request('POST',- f'{self._get_action_execution_server_host()}/list_files',+ f'{self.action_execution_server_url}/list_files',json=data,timeout=10,)@@ -163,7 +167,7 @@ class ActionExecutionClient(Runtime):params = {'path': path}with self.session.stream('GET',- f'{self._get_action_execution_server_host()}/download_files',+ f'{self.action_execution_server_url}/download_files',params=params,timeout=30,) as response:@@ -207,7 +211,7 @@ class ActionExecutionClient(Runtime):response = self._send_action_server_request('POST',- f'{self._get_action_execution_server_host()}/upload_file',+ f'{self.action_execution_server_url}/upload_file',files=upload_data,params=params,timeout=300,@@ -224,12 +228,12 @@ class ActionExecutionClient(Runtime):)def get_vscode_token(self) -> str:- if self.vscode_enabled and self._runtime_initialized:+ if self.vscode_enabled and self.runtime_initialized:if self._vscode_token is not None: # cached valuereturn self._vscode_tokenresponse = self._send_action_server_request('GET',- f'{self._get_action_execution_server_host()}/vscode/connection_token',+ f'{self.action_execution_server_url}/vscode/connection_token',timeout=10,)response_json = response.json()@@ -288,7 +292,7 @@ class ActionExecutionClient(Runtime):}response = self._send_action_server_request('POST',- f'{self._get_action_execution_server_host()}/execute_action',+ f'{self.action_execution_server_url}/execute_action',json=execution_action_body,# wait a few more seconds to get the timeout error from client sidetimeout=action.timeout + 5,diff --git a/openhands/runtime/impl/daytona/daytona_runtime.py b/openhands/runtime/impl/daytona/daytona_runtime.pyindex 3199975c9c..0c89bb6da7 100644--- a/openhands/runtime/impl/daytona/daytona_runtime.py+++ b/openhands/runtime/impl/daytona/daytona_runtime.py@@ -127,7 +127,8 @@ class DaytonaRuntime(ActionExecutionClient):]return f'https://{port}-{self.workspace.id}.{node_domain}'- def _get_action_execution_server_host(self) -> str:+ @property+ def action_execution_server_url(self) -> str:return self.api_urldef _start_action_execution_server(self) -> None:diff --git a/openhands/runtime/impl/docker/docker_runtime.py b/openhands/runtime/impl/docker/docker_runtime.pyindex 9fe7946e07..aa71637106 100644--- a/openhands/runtime/impl/docker/docker_runtime.py+++ b/openhands/runtime/impl/docker/docker_runtime.py@@ -86,7 +86,6 @@ class DockerRuntime(ActionExecutionClient):)self.config = config- self._runtime_initialized: bool = Falseself.status_callback = status_callbackself._host_port = -1@@ -133,7 +132,8 @@ class DockerRuntime(ActionExecutionClient):f'Installing extra user-provided dependencies in the runtime image: {self.config.sandbox.runtime_extra_deps}',)- def _get_action_execution_server_host(self):+ @property+ def action_execution_server_url(self):return self.api_urlasync def connect(self):diff --git a/openhands/runtime/impl/local/local_runtime.py b/openhands/runtime/impl/local/local_runtime.pyindex 33e924d336..05eafaec8e 100644--- a/openhands/runtime/impl/local/local_runtime.py+++ b/openhands/runtime/impl/local/local_runtime.py@@ -174,7 +174,8 @@ class LocalRuntime(ActionExecutionClient):headless_mode,)- def _get_action_execution_server_host(self):+ @property+ def action_execution_server_url(self):return self.api_urlasync def connect(self):@@ -292,7 +293,7 @@ class LocalRuntime(ActionExecutionClient):async def execute_action(self, action: Action) -> Observation:"""Execute an action by sending it to the server."""- if not self._runtime_initialized:+ if not self.runtime_initialized:raise AgentRuntimeDisconnectedError('Runtime not initialized')if self.server_process is None or self.server_process.poll() is not None:diff --git a/openhands/runtime/impl/modal/modal_runtime.py b/openhands/runtime/impl/modal/modal_runtime.pyindex d3d0143d86..9bbff143df 100644--- a/openhands/runtime/impl/modal/modal_runtime.py+++ b/openhands/runtime/impl/modal/modal_runtime.py@@ -146,7 +146,8 @@ class ModalRuntime(ActionExecutionClient):self.send_status_message(' ')self._runtime_initialized = True- def _get_action_execution_server_host(self):+ @property+ def action_execution_server_url(self):return self.api_url@tenacity.retry(diff --git a/openhands/runtime/impl/remote/remote_runtime.py b/openhands/runtime/impl/remote/remote_runtime.pyindex 610351c7b4..f85f8166df 100644--- a/openhands/runtime/impl/remote/remote_runtime.py+++ b/openhands/runtime/impl/remote/remote_runtime.py@@ -93,7 +93,8 @@ class RemoteRuntime(ActionExecutionClient):message = f'[runtime session_id={self.sid} runtime_id={self.runtime_id or "unknown"}] {message}'getattr(logger, level)(message, stacklevel=2)- def _get_action_execution_server_host(self):+ @property+ def action_execution_server_url(self):return self.runtime_urlasync def connect(self):diff --git a/openhands/runtime/impl/runloop/runloop_runtime.py b/openhands/runtime/impl/runloop/runloop_runtime.pyindex 1bdcb6f739..104d747668 100644--- a/openhands/runtime/impl/runloop/runloop_runtime.py+++ b/openhands/runtime/impl/runloop/runloop_runtime.py@@ -56,7 +56,8 @@ class RunloopRuntime(ActionExecutionClient):# Buffer for container logsself._vscode_url: str | None = None- def _get_action_execution_server_host(self):+ @property+ def action_execution_server_url(self):return self.api_url@tenacity.retry(