π OpenHands: AI-Driven Development
add few seconds to properly receive timeout error from client
Xingyao Wangdd2cb4399a65
diff --git a/openhands/runtime/client/runtime.py b/openhands/runtime/client/runtime.pyindex 32b002f3ea..8c714fbedc 100644--- a/openhands/runtime/client/runtime.py+++ b/openhands/runtime/client/runtime.py@@ -418,7 +418,8 @@ class EventStreamRuntime(Runtime):response = self.session.post(f'{self.api_url}/execute_action',json={'action': event_to_dict(action)},- timeout=action.timeout,+ # wait a few more seconds to get the timeout error from client side+ timeout=action.timeout + 5,)if response.status_code == 200:output = response.json()diff --git a/openhands/runtime/remote/runtime.py b/openhands/runtime/remote/runtime.pyindex 8d8dbd52c3..67281c6fd9 100644--- a/openhands/runtime/remote/runtime.py+++ b/openhands/runtime/remote/runtime.py@@ -36,13 +36,13 @@ from openhands.events.serialization.action import ACTION_TYPE_TO_CLASSfrom openhands.runtime.builder.remote import RemoteRuntimeBuilderfrom openhands.runtime.plugins import PluginRequirementfrom openhands.runtime.runtime import Runtime-from openhands.utils.tenacity_stop import stop_if_should_exitfrom openhands.runtime.utils.request import (DEFAULT_RETRY_EXCEPTIONS,is_404_error,send_request,)from openhands.runtime.utils.runtime_build import build_runtime_image+from openhands.utils.tenacity_stop import stop_if_should_exitclass RemoteRuntime(Runtime):@@ -260,7 +260,8 @@ class RemoteRuntime(Runtime):'POST',f'{self.runtime_url}/execute_action',json=request_body,- timeout=action.timeout,+ # wait a few more seconds to get the timeout error from client side+ timeout=action.timeout + 5,retry_exceptions=list(filter(lambda e: e != TimeoutError, DEFAULT_RETRY_EXCEPTIONS)),diff --git a/tests/runtime/test_bash.py b/tests/runtime/test_bash.pyindex c28957888d..1c21a2e946 100644--- a/tests/runtime/test_bash.py+++ b/tests/runtime/test_bash.py@@ -57,6 +57,31 @@ def test_bash_command_pexcept(temp_dir, box_class, run_as_openhands):_close_test_runtime(runtime)+def test_bash_timeout_and_keyboard_interrupt(temp_dir, box_class, run_as_openhands):+ runtime = _load_runtime(temp_dir, box_class, run_as_openhands)+ try:+ action = CmdRunAction(command='python -c "import time; time.sleep(10)"')+ action.timeout = 1+ obs = runtime.run_action(action)+ logger.info(obs, extra={'msg_type': 'OBSERVATION'})+ assert isinstance(obs, CmdOutputObservation)+ assert (+ '[Command timed out after 1 seconds. SIGINT was sent to interrupt it.]'+ in obs.content+ )+ assert 'KeyboardInterrupt' in obs.content++ # follow up command should not be affected+ action = CmdRunAction(command='ls')+ action.timeout = 1+ obs = runtime.run_action(action)+ assert isinstance(obs, CmdOutputObservation)+ assert obs.exit_code == 0+ logger.info(obs, extra={'msg_type': 'OBSERVATION'})+ finally:+ _close_test_runtime(runtime)++def test_multiline_commands(temp_dir, box_class):runtime = _load_runtime(temp_dir, box_class)try: