From 1a9971b1bfb4bc275b2c16b16dbf4e687a7ef131 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 29 Jan 2025 17:30:18 -0500 Subject: [PATCH] misc: make RemoteRuntime API timeout configurable (#6518) Co-authored-by: Robert Brennan --- evaluation/benchmarks/swe_bench/run_infer.py | 1 + openhands/core/config/sandbox_config.py | 2 ++ openhands/runtime/impl/remote/remote_runtime.py | 1 + tests/unit/test_iteration_limit.py | 3 ++- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/evaluation/benchmarks/swe_bench/run_infer.py b/evaluation/benchmarks/swe_bench/run_infer.py index 959576ffcd..e1a1764f21 100644 --- a/evaluation/benchmarks/swe_bench/run_infer.py +++ b/evaluation/benchmarks/swe_bench/run_infer.py @@ -139,6 +139,7 @@ def get_config( remote_runtime_api_url=os.environ.get('SANDBOX_REMOTE_RUNTIME_API_URL'), keep_runtime_alive=False, remote_runtime_init_timeout=3600, + remote_runtime_api_timeout=120, remote_runtime_resource_factor=get_instance_resource_factor( dataset_name=metadata.dataset, instance_id=instance['instance_id'], diff --git a/openhands/core/config/sandbox_config.py b/openhands/core/config/sandbox_config.py index bd3d81f559..55ff384e0c 100644 --- a/openhands/core/config/sandbox_config.py +++ b/openhands/core/config/sandbox_config.py @@ -14,6 +14,7 @@ class SandboxConfig(BaseModel): user_id: The user ID for the sandbox. timeout: The timeout for the default sandbox action execution. remote_runtime_init_timeout: The timeout for the remote runtime to start. + remote_runtime_api_timeout: The timeout for the remote runtime API requests. enable_auto_lint: Whether to enable auto-lint. use_host_network: Whether to use the host network. initialize_plugins: Whether to initialize plugins. @@ -49,6 +50,7 @@ class SandboxConfig(BaseModel): user_id: int = Field(default=os.getuid() if hasattr(os, 'getuid') else 1000) timeout: int = Field(default=120) remote_runtime_init_timeout: int = Field(default=180) + remote_runtime_api_timeout: int = Field(default=10) enable_auto_lint: bool = Field( default=False # once enabled, OpenHands would lint files after editing ) diff --git a/openhands/runtime/impl/remote/remote_runtime.py b/openhands/runtime/impl/remote/remote_runtime.py index 57d8e8def8..ca72bb86b3 100644 --- a/openhands/runtime/impl/remote/remote_runtime.py +++ b/openhands/runtime/impl/remote/remote_runtime.py @@ -381,6 +381,7 @@ class RemoteRuntime(ActionExecutionClient): def _send_runtime_api_request(self, method, url, **kwargs): try: + kwargs['timeout'] = self.config.sandbox.remote_runtime_api_timeout return send_request(self.session, method, url, **kwargs) except requests.Timeout: self.log( diff --git a/tests/unit/test_iteration_limit.py b/tests/unit/test_iteration_limit.py index 4520231a0d..29108387e7 100644 --- a/tests/unit/test_iteration_limit.py +++ b/tests/unit/test_iteration_limit.py @@ -7,6 +7,7 @@ from openhands.core.schema import AgentState from openhands.events import EventStream from openhands.events.action import MessageAction from openhands.events.event import EventSource +from openhands.llm.metrics import Metrics class DummyAgent: @@ -15,7 +16,7 @@ class DummyAgent: self.llm = type( 'DummyLLM', (), - {'metrics': type('DummyMetrics', (), {'merge': lambda x: None})()}, + {'metrics': Metrics()}, )() def reset(self):