Skip to content

Commit 522fdef

Browse files
Share agent terminal-status predicate across managers
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent e744c3f commit 522fdef

16 files changed

+77
-30
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ This runs lint, format checks, compile checks, tests, and package build.
7676
- Keep sync/async behavior in parity where applicable.
7777
- Prefer deterministic unit tests over network-dependent tests.
7878
- Preserve architectural guardrails with focused tests. Current guard suites include:
79+
- `tests/test_agent_terminal_status_helper_usage.py` (shared agent terminal-status helper usage enforcement),
7980
- `tests/test_architecture_marker_usage.py` (architecture marker coverage across guard modules),
8081
- `tests/test_binary_file_open_helper_usage.py` (shared binary file open helper usage enforcement),
8182
- `tests/test_browser_use_payload_helper_usage.py` (browser-use payload helper usage enforcement),
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import FrozenSet
2+
3+
AGENT_TERMINAL_STATUSES: FrozenSet[str] = frozenset(
4+
{"completed", "failed", "stopped"}
5+
)
6+
7+
8+
def is_agent_terminal_status(status: str) -> bool:
9+
return status in AGENT_TERMINAL_STATUSES

hyperbrowser/client/managers/async_manager/agents/browser_use.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional
22

33
from ....polling import wait_for_job_result_async
4+
from ...agent_status_utils import is_agent_terminal_status
45
from ...browser_use_payload_utils import build_browser_use_start_payload
56
from ...response_utils import parse_response_model
67
from ...start_job_utils import build_started_job_context
@@ -80,9 +81,7 @@ async def start_and_wait(
8081
return await wait_for_job_result_async(
8182
operation_name=operation_name,
8283
get_status=lambda: self.get_status(job_id).status,
83-
is_terminal_status=lambda status: (
84-
status in {"completed", "failed", "stopped"}
85-
),
84+
is_terminal_status=is_agent_terminal_status,
8685
fetch_result=lambda: self.get(job_id),
8786
poll_interval_seconds=poll_interval_seconds,
8887
max_wait_seconds=max_wait_seconds,

hyperbrowser/client/managers/async_manager/agents/claude_computer_use.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional
22

33
from ....polling import wait_for_job_result_async
4+
from ...agent_status_utils import is_agent_terminal_status
45
from ...response_utils import parse_response_model
56
from ...serialization_utils import serialize_model_dump_to_dict
67
from ...start_job_utils import build_started_job_context
@@ -83,9 +84,7 @@ async def start_and_wait(
8384
return await wait_for_job_result_async(
8485
operation_name=operation_name,
8586
get_status=lambda: self.get_status(job_id).status,
86-
is_terminal_status=lambda status: (
87-
status in {"completed", "failed", "stopped"}
88-
),
87+
is_terminal_status=is_agent_terminal_status,
8988
fetch_result=lambda: self.get(job_id),
9089
poll_interval_seconds=poll_interval_seconds,
9190
max_wait_seconds=max_wait_seconds,

hyperbrowser/client/managers/async_manager/agents/cua.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional
22

33
from ....polling import wait_for_job_result_async
4+
from ...agent_status_utils import is_agent_terminal_status
45
from ...response_utils import parse_response_model
56
from ...serialization_utils import serialize_model_dump_to_dict
67
from ...start_job_utils import build_started_job_context
@@ -81,9 +82,7 @@ async def start_and_wait(
8182
return await wait_for_job_result_async(
8283
operation_name=operation_name,
8384
get_status=lambda: self.get_status(job_id).status,
84-
is_terminal_status=lambda status: (
85-
status in {"completed", "failed", "stopped"}
86-
),
85+
is_terminal_status=is_agent_terminal_status,
8786
fetch_result=lambda: self.get(job_id),
8887
poll_interval_seconds=poll_interval_seconds,
8988
max_wait_seconds=max_wait_seconds,

hyperbrowser/client/managers/async_manager/agents/gemini_computer_use.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional
22

33
from ....polling import wait_for_job_result_async
4+
from ...agent_status_utils import is_agent_terminal_status
45
from ...response_utils import parse_response_model
56
from ...serialization_utils import serialize_model_dump_to_dict
67
from ...start_job_utils import build_started_job_context
@@ -83,9 +84,7 @@ async def start_and_wait(
8384
return await wait_for_job_result_async(
8485
operation_name=operation_name,
8586
get_status=lambda: self.get_status(job_id).status,
86-
is_terminal_status=lambda status: (
87-
status in {"completed", "failed", "stopped"}
88-
),
87+
is_terminal_status=is_agent_terminal_status,
8988
fetch_result=lambda: self.get(job_id),
9089
poll_interval_seconds=poll_interval_seconds,
9190
max_wait_seconds=max_wait_seconds,

hyperbrowser/client/managers/async_manager/agents/hyper_agent.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional
22

33
from ....polling import wait_for_job_result_async
4+
from ...agent_status_utils import is_agent_terminal_status
45
from ...response_utils import parse_response_model
56
from ...serialization_utils import serialize_model_dump_to_dict
67
from ...start_job_utils import build_started_job_context
@@ -83,9 +84,7 @@ async def start_and_wait(
8384
return await wait_for_job_result_async(
8485
operation_name=operation_name,
8586
get_status=lambda: self.get_status(job_id).status,
86-
is_terminal_status=lambda status: (
87-
status in {"completed", "failed", "stopped"}
88-
),
87+
is_terminal_status=is_agent_terminal_status,
8988
fetch_result=lambda: self.get(job_id),
9089
poll_interval_seconds=poll_interval_seconds,
9190
max_wait_seconds=max_wait_seconds,

hyperbrowser/client/managers/sync_manager/agents/browser_use.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional
22

33
from ....polling import wait_for_job_result
4+
from ...agent_status_utils import is_agent_terminal_status
45
from ...browser_use_payload_utils import build_browser_use_start_payload
56
from ...response_utils import parse_response_model
67
from ...start_job_utils import build_started_job_context
@@ -78,9 +79,7 @@ def start_and_wait(
7879
return wait_for_job_result(
7980
operation_name=operation_name,
8081
get_status=lambda: self.get_status(job_id).status,
81-
is_terminal_status=lambda status: (
82-
status in {"completed", "failed", "stopped"}
83-
),
82+
is_terminal_status=is_agent_terminal_status,
8483
fetch_result=lambda: self.get(job_id),
8584
poll_interval_seconds=poll_interval_seconds,
8685
max_wait_seconds=max_wait_seconds,

hyperbrowser/client/managers/sync_manager/agents/claude_computer_use.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional
22

33
from ....polling import wait_for_job_result
4+
from ...agent_status_utils import is_agent_terminal_status
45
from ...response_utils import parse_response_model
56
from ...serialization_utils import serialize_model_dump_to_dict
67
from ...start_job_utils import build_started_job_context
@@ -83,9 +84,7 @@ def start_and_wait(
8384
return wait_for_job_result(
8485
operation_name=operation_name,
8586
get_status=lambda: self.get_status(job_id).status,
86-
is_terminal_status=lambda status: (
87-
status in {"completed", "failed", "stopped"}
88-
),
87+
is_terminal_status=is_agent_terminal_status,
8988
fetch_result=lambda: self.get(job_id),
9089
poll_interval_seconds=poll_interval_seconds,
9190
max_wait_seconds=max_wait_seconds,

hyperbrowser/client/managers/sync_manager/agents/cua.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional
22

33
from ....polling import wait_for_job_result
4+
from ...agent_status_utils import is_agent_terminal_status
45
from ...response_utils import parse_response_model
56
from ...serialization_utils import serialize_model_dump_to_dict
67
from ...start_job_utils import build_started_job_context
@@ -81,9 +82,7 @@ def start_and_wait(
8182
return wait_for_job_result(
8283
operation_name=operation_name,
8384
get_status=lambda: self.get_status(job_id).status,
84-
is_terminal_status=lambda status: (
85-
status in {"completed", "failed", "stopped"}
86-
),
85+
is_terminal_status=is_agent_terminal_status,
8786
fetch_result=lambda: self.get(job_id),
8887
poll_interval_seconds=poll_interval_seconds,
8988
max_wait_seconds=max_wait_seconds,

0 commit comments

Comments
 (0)