Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Surface Rust terminal subagent failures

Magnus Müller7f67a512f688
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 5e77babfb..3d6aacbe9 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -789,10 +789,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- This matches terminal protocol result reconstruction for parent/subagent completion histories while preserving `session.done` precedence when both results exist.
- Proof: `test_rust_history_reconstructs_terminal_agent_completed_result`.
+156. Rust terminal subagent-failure reconstruction
+ - Terminal `agent.failed` and `agent.cancelled` events now surface nested subagent failure and cancellation details on Python-visible history errors.
+ - This preserves current-main child-agent failure payloads that store error text under nested `payload.failure`, plus sensible cancellation/failure fallbacks when no text is present.
+ - Proof: `test_rust_history_surfaces_terminal_subagent_failure_events`.
+
## Current Verification
- `python3 -m py_compile browser_use/agent/service.py browser_use/rust/service.py browser_use/rust/__init__.py browser_use/__init__.py tests/ci/test_rust_agent.py examples/rust_agent/basic.py examples/rust_agent/real_v8_smoke.py`
-- `uv run pytest -q tests/ci/test_rust_agent.py` (127 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (128 tests)
- `cargo build -q -p browser-use-cli` on terminal branch `magnus/browser-use-rust-main-integration`
- `cargo test -q -p browser-use-cli run_codex_session_command_accepts_task_id_and_model -- --nocapture`
- `CARGO_INCREMENTAL=0 cargo test -q -p browser-use-agent selected_remote_cdp_mode_allows_remote_cdp_connect -- --nocapture`
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.py
index 1ed360cf7..1db0ea878 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -953,9 +953,12 @@ def _failure_from_events(events: list[dict[str, Any]]) -> str | None:
inner_payload = payload.get('payload')
if not isinstance(inner_payload, dict):
inner_payload = payload
- error = inner_payload.get('error') or inner_payload.get('reason')
- if isinstance(error, str) and error.strip():
- return error.strip()
+ detail = _payload_failure_detail(inner_payload)
+ if detail:
+ return detail
+ if event_type == 'agent.cancelled':
+ return 'Subagent was cancelled.'
+ return 'Subagent failed.'
return None
@@ -1016,7 +1019,7 @@ def _exec_command_end_failure_message(payload: dict[str, Any]) -> str | None:
def _payload_failure_detail(payload: dict[str, Any]) -> str | None:
- for key in ('error', 'message', 'reason', 'detail', 'details'):
+ for key in ('error', 'failure', 'message', 'reason', 'detail', 'details'):
value = payload.get(key)
if isinstance(value, str) and value.strip():
return value.strip()
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 83138c0e5..45cd2840a 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -4068,6 +4068,63 @@ def test_rust_history_surfaces_terminal_operational_failure_events():
assert successful_with_cleanup_warning.errors() == [None]
+def test_rust_history_surfaces_terminal_subagent_failure_events():
+ from browser_use.rust.service import _history_from_events
+
+ failed = _history_from_events(
+ [
+ {
+ 'event_type': 'agent.failed',
+ 'payload': {
+ 'child_session_id': 'child-1',
+ 'status': 'failed',
+ 'payload': {
+ 'child_session_id': 'child-1',
+ 'status': 'failed',
+ 'failure': 'child task failed',
+ },
+ },
+ }
+ ],
+ model='gpt-test',
+ started=1.0,
+ finished=2.0,
+ output_model_schema=None,
+ process_error=None,
+ )
+
+ cancelled = _history_from_events(
+ [
+ {
+ 'event_type': 'agent.cancelled',
+ 'payload': {
+ 'child_session_id': 'child-2',
+ 'status': 'cancelled',
+ 'payload': {
+ 'child_session_id': 'child-2',
+ 'status': 'cancelled',
+ },
+ },
+ }
+ ],
+ model='gpt-test',
+ started=1.0,
+ finished=2.0,
+ output_model_schema=None,
+ process_error=None,
+ )
+
+ assert failed.final_result() is None
+ assert failed.is_done() is False
+ assert failed.errors() == ['child task failed']
+ assert failed.action_results()[-1].error == 'child task failed'
+
+ assert cancelled.final_result() is None
+ assert cancelled.is_done() is False
+ assert cancelled.errors() == ['Subagent was cancelled.']
+ assert cancelled.action_results()[-1].error == 'Subagent was cancelled.'
+
+
def test_rust_history_surfaces_terminal_tool_failure_message():
from browser_use.rust.service import _history_from_events