Skip to content

Commit

Permalink
replace set_default_timeout with set_hard_timeout blocking=false
Browse files Browse the repository at this point in the history
  • Loading branch information
xingyaoww committed Jan 15, 2025
1 parent e4e992c commit 26b7ff1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
11 changes: 2 additions & 9 deletions openhands/events/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions openhands/events/serialization/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion openhands/runtime/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 26b7ff1

Please sign in to comment.