Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Surface Rust terminal operational failures
Magnus Müllerabac17714d15
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 84e19e246..f33e55bd7 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -779,10 +779,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai- This preserves current-main screenshot/image artifacts on the per-action Browser Use API surface while keeping final `done.files_to_display` limited to file/result attachments.- Proof: `test_rust_history_attaches_terminal_tool_images_to_actions`.+154. Rust terminal operational failure reconstruction+ - Terminal operational failure events now surface as Python-visible history errors when the session has no final result.+ - This preserves current-main browser cloud shutdown, browser cleanup, browser bridge, command write, compaction, and final-answer-not-ready failures on `history.errors()` and the final `ActionResult.error` instead of falling back to a generic missing-result error.+ - Proof: `test_rust_history_surfaces_terminal_operational_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` (125 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (126 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.pyindex e13e19b4b..2a7c88aa2 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -971,6 +971,9 @@ def _recoverable_failure_from_events(events: list[dict[str, Any]]) -> str | Noneerror = payload.get('error') or payload.get('message') or payload.get('reason')if isinstance(error, str) and error.strip():return error.strip()+ error = _terminal_operational_failure_message(event_type, payload)+ if error:+ return errorreturn None@@ -1003,6 +1006,40 @@ def _exec_command_end_failure_message(payload: dict[str, Any]) -> str | None:return f'{tool_name} failed: {detail}'+def _payload_failure_detail(payload: dict[str, Any]) -> str | None:+ for key in ('error', 'message', 'reason', 'detail', 'details'):+ value = payload.get(key)+ if isinstance(value, str) and value.strip():+ return value.strip()+ if isinstance(payload.get('errors'), list):+ errors = [str(error).strip() for error in payload['errors'] if str(error).strip()]+ if errors:+ return '; '.join(errors)+ return None+++def _terminal_operational_failure_message(event_type: str, payload: dict[str, Any]) -> str | None:+ if event_type == 'session.final_answer_not_ready_at_max_turns':+ return _payload_failure_detail(payload) or 'final answer artifact is not ready'+ if event_type == 'browser.cleanup_timed_out':+ timeout_ms = _int_value(payload.get('timeout_ms'))+ if timeout_ms:+ return f'browser cleanup timed out after {timeout_ms}ms'+ return 'browser cleanup timed out'+ labels = {+ 'browser.cloud_shutdown_failed': 'browser cloud shutdown failed',+ 'browser.cleanup_failed': 'browser cleanup failed',+ 'browser.bridge_errors': 'browser bridge failed',+ 'command.write_error': 'command write failed',+ 'session.compaction_failed': 'session compaction failed',+ }+ label = labels.get(event_type)+ if label is None:+ return None+ detail = _payload_failure_detail(payload)+ return f'{label}: {detail}' if detail else label++def _command_waiting_text(payload: dict[str, Any]) -> str:session_id = payload.get('session_id') or payload.get('process_id')if session_id is not None and str(session_id):diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 42a26306f..d34f1d220 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -3968,6 +3968,59 @@ def test_rust_history_surfaces_terminal_stream_error_message():assert history.errors() == ['provider error']+def test_rust_history_surfaces_terminal_operational_failure_events():+ from browser_use.rust.service import _history_from_events++ failed = _history_from_events(+ [+ {'event_type': 'model.turn.request', 'payload': {'model': 'gpt-test'}},+ {'event_type': 'browser.cloud_shutdown_failed', 'payload': {'error': 'cloud browser shutdown failed'}},+ ],+ model='gpt-test',+ started=1.0,+ finished=2.0,+ output_model_schema=None,+ process_error=None,+ )++ final_not_ready = _history_from_events(+ [+ {'event_type': 'model.turn.request', 'payload': {'model': 'gpt-test'}},+ {'event_type': 'session.final_answer_not_ready_at_max_turns', 'payload': {}},+ ],+ model='gpt-test',+ started=1.0,+ finished=2.0,+ output_model_schema=None,+ process_error=None,+ )++ successful_with_cleanup_warning = _history_from_events(+ [+ {'event_type': 'session.done', 'payload': {'result': 'final answer'}},+ {'event_type': 'browser.cleanup_failed', 'payload': {'error': 'cleanup panicked'}},+ ],+ 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() == ['browser cloud shutdown failed: cloud browser shutdown failed']+ assert failed.action_results()[-1].error == 'browser cloud shutdown failed: cloud browser shutdown failed'++ assert final_not_ready.final_result() is None+ assert final_not_ready.is_done() is False+ assert final_not_ready.errors() == ['final answer artifact is not ready']++ assert successful_with_cleanup_warning.final_result() == 'final answer'+ assert successful_with_cleanup_warning.is_done() is True+ assert successful_with_cleanup_warning.errors() == [None]++def test_rust_history_surfaces_terminal_tool_failure_message():from browser_use.rust.service import _history_from_events