From 26b7ff1b7365443ee102a32bd871e63e5436ebc4 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 15 Jan 2025 16:10:23 -0500 Subject: [PATCH] replace set_default_timeout with set_hard_timeout blocking=false --- openhands/events/event.py | 11 ++--------- openhands/events/serialization/action.py | 5 +---- openhands/runtime/base.py | 3 ++- .../impl/action_execution/action_execution_client.py | 3 ++- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/openhands/events/event.py b/openhands/events/event.py index b5c590f59d71..1bdece59eb75 100644 --- a/openhands/events/event.py +++ b/openhands/events/event.py @@ -64,7 +64,7 @@ def timeout(self) -> int | None: return self._timeout # type: ignore[attr-defined] return None - def set_hard_timeout(self, value: int | None) -> None: + def set_hard_timeout(self, value: int | None, blocking: bool = True) -> None: """Set the timeout for the event. NOTE, this is a hard timeout, meaning that the event will be blocked @@ -82,14 +82,7 @@ def set_hard_timeout(self, value: int | None) -> None: # Check if .blocking is an attribute of the event if hasattr(self, 'blocking'): # .blocking needs to be set to True if .timeout is set - self.blocking = True - - def set_default_timeout(self, value: int) -> None: - """Set the default timeout for the event if it is not already set. - - Setting this will NOT block the event (e.g., the soft timeout from CmdRunAction will still apply). - """ - self._timeout = value + self.blocking = blocking # optional metadata, LLM call cost of the edit @property diff --git a/openhands/events/serialization/action.py b/openhands/events/serialization/action.py index 286e26837a4b..be9990750fc6 100644 --- a/openhands/events/serialization/action.py +++ b/openhands/events/serialization/action.py @@ -75,10 +75,7 @@ def action_from_dict(action: dict) -> Action: decoded_action = action_class(**args) if 'timeout' in action: blocking = args.get('blocking', False) - if blocking: - decoded_action.set_hard_timeout(action['timeout']) - else: - decoded_action.set_default_timeout(action['timeout']) + decoded_action.set_hard_timeout(action['timeout'], blocking=blocking) # Set timestamp if it was provided if timestamp: diff --git a/openhands/runtime/base.py b/openhands/runtime/base.py index 33a05a5cd83c..94a059f06aa3 100644 --- a/openhands/runtime/base.py +++ b/openhands/runtime/base.py @@ -182,7 +182,8 @@ def on_event(self, event: Event) -> None: async def _handle_action(self, event: Action) -> None: if event.timeout is None: - event.set_default_timeout(self.config.sandbox.timeout) + # We don't block the command if this is a default timeout action + event.set_hard_timeout(self.config.sandbox.timeout, blocking=False) assert event.timeout is not None try: observation: Observation = await call_sync_from_async( diff --git a/openhands/runtime/impl/action_execution/action_execution_client.py b/openhands/runtime/impl/action_execution/action_execution_client.py index f6619f6e24d6..a2455dd2b6b8 100644 --- a/openhands/runtime/impl/action_execution/action_execution_client.py +++ b/openhands/runtime/impl/action_execution/action_execution_client.py @@ -217,7 +217,8 @@ def send_action_for_execution(self, action: Action) -> Observation: # set timeout to default if not set if action.timeout is None: - action.set_default_timeout(self.config.sandbox.timeout) + # We don't block the command if this is a default timeout action + action.set_hard_timeout(self.config.sandbox.timeout, blocking=False) with self.action_semaphore: if not action.runnable: