Skip to content

Commit

Permalink
feat: misc bash improvements, set max value for action-exec timeout, …
Browse files Browse the repository at this point in the history
…retry on requests.ConnectionError (#6175)
  • Loading branch information
xingyaoww authored Jan 10, 2025
1 parent 828d169 commit f31ccad
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
7 changes: 7 additions & 0 deletions openhands/events/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ def timeout(self) -> int | None:
@timeout.setter
def timeout(self, value: int | None) -> None:
self._timeout = value
if value is not None and value > 600:
from openhands.core.logger import openhands_logger as logger

logger.warning(
'Timeout greater than 600 seconds may not be supported by '
'the runtime. Consider setting a lower timeout.'
)

# Check if .blocking is an attribute of the event
if hasattr(self, 'blocking'):
Expand Down
12 changes: 0 additions & 12 deletions openhands/runtime/utils/bash.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,18 +486,6 @@ def execute(self, action: CmdRunAction) -> CmdOutputObservation | ErrorObservati
last_change_time = start_time
last_pane_output = self._get_pane_content()

_ps1_matches = CmdOutputMetadata.matches_ps1_metadata(last_pane_output)
assert len(_ps1_matches) >= 1, (
'Expected at least one PS1 metadata block BEFORE the execution of a command, '
f'but got {len(_ps1_matches)} PS1 metadata blocks:\n---\n{last_pane_output!r}\n---'
)
if len(_ps1_matches) > 1:
logger.warning(
'Found multiple PS1 metadata blocks BEFORE the execution of a command. '
'Only the last one will be used.'
)
_ps1_matches = [_ps1_matches[-1]]

if command != '':
# convert command to raw string
command = escape_bash_special_chars(command)
Expand Down
4 changes: 2 additions & 2 deletions openhands/runtime/utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ def __str__(self) -> str:
return s


def is_rate_limit_error(exception):
def is_retryable_error(exception):
return (
isinstance(exception, requests.HTTPError)
and exception.response.status_code == 429
)


@retry(
retry=retry_if_exception(is_rate_limit_error),
retry=retry_if_exception(is_retryable_error),
stop=stop_after_attempt(3) | stop_if_should_exit(),
wait=wait_exponential(multiplier=1, min=4, max=60),
)
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ reportlab = "*"
[tool.coverage.run]
concurrency = ["gevent"]


[tool.poetry.group.runtime.dependencies]
jupyterlab = "*"
notebook = "*"
Expand Down Expand Up @@ -129,6 +130,7 @@ ignore = ["D1"]
[tool.ruff.lint.pydocstyle]
convention = "google"


[tool.poetry.group.evaluation.dependencies]
streamlit = "*"
whatthepatch = "*"
Expand Down

0 comments on commit f31ccad

Please sign in to comment.