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 exec command failures
Magnus Müller91aa90ae1b71
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex e0a2630f9..956bf42bd 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -759,10 +759,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai- This preserves current-main unified exec final stdout/stderr on Python-visible `ActionResult.extracted_content`, `long_term_memory`, and `action_history()` even if only the exec lifecycle events were recorded.- Proof: `test_rust_history_reconstructs_terminal_exec_command_end_output`.+150. Rust terminal exec-command failure reconstruction+ - Terminal `exec_command.end` events with nonzero exit codes now surface Browser Use action and history errors when no explicit `tool.failed` or `tool.aborted` event is present.+ - This preserves current-main unified exec failures on Python-visible `history.errors()` and per-action `ActionResult.error` while retaining the final command output in action memory.+ - Proof: `test_rust_history_surfaces_terminal_exec_command_end_failure`.+## 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` (121 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (122 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 3381c29df..2e6b96718 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -963,6 +963,10 @@ def _recoverable_failure_from_events(events: list[dict[str, Any]]) -> str | Noneerror = _tool_abort_message(payload)if error:return error+ if event_type == 'exec_command.end' and not _matching_tool_result_payload(events, payload, ('tool.failed', 'tool.aborted')):+ error = _exec_command_end_failure_message(payload)+ if error:+ return errorif event_type in ('model.turn.error', 'model.turn.context_overflow'):error = payload.get('error') or payload.get('message') or payload.get('reason')if isinstance(error, str) and error.strip():@@ -986,6 +990,19 @@ def _tool_abort_message(payload: dict[str, Any]) -> str | None:return f'{name} aborted: {error.strip()}' if isinstance(name, str) and name else error.strip()+def _exec_command_end_failure_message(payload: dict[str, Any]) -> str | None:+ exit_code = _int_value(payload.get('exit_code'))+ if exit_code == 0:+ return None+ name = payload.get('name')+ tool_name = name if isinstance(name, str) and name else 'exec_command'+ detail = f'exit code {exit_code}'+ text = _tool_result_text(payload)+ if text:+ detail = f'{detail}: {text}'+ return f'{tool_name} failed: {detail}'++def _tool_result_key(payload: dict[str, Any]) -> tuple[str, str] | None:call_id = payload.get('tool_call_id') or payload.get('call_id')if call_id:@@ -996,19 +1013,25 @@ def _tool_result_key(payload: dict[str, Any]) -> tuple[str, str] | None:return None-def _matching_tool_abort_payload(events: list[dict[str, Any]], payload: dict[str, Any]) -> dict[str, Any] | None:+def _matching_tool_result_payload(+ events: list[dict[str, Any]], payload: dict[str, Any], event_types: tuple[str, ...]+) -> dict[str, Any] | None:key = _tool_result_key(payload)if key is None:return Nonefor event in events:- if _event_type(event) != 'tool.aborted':+ if _event_type(event) not in event_types:continue- abort_payload = _event_payload(event)- if _tool_result_key(abort_payload) == key:- return abort_payload+ result_payload = _event_payload(event)+ if _tool_result_key(result_payload) == key:+ return result_payloadreturn None+def _matching_tool_abort_payload(events: list[dict[str, Any]], payload: dict[str, Any]) -> dict[str, Any] | None:+ return _matching_tool_result_payload(events, payload, ('tool.aborted',))++def _safe_tool_action_name(value: Any) -> str | None:if not isinstance(value, str):return None@@ -1521,6 +1544,8 @@ def _action_results_from_tool_calls(error = _tool_failure_message(payload)elif event_type == 'tool.aborted':error = _tool_abort_message(payload)+ elif event_type == 'exec_command.end':+ error = _exec_command_end_failure_message(payload)else:error = Noneaction_results.append(diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 42931bfba..1d9d9affd 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -704,6 +704,53 @@ def test_rust_history_reconstructs_terminal_exec_command_end_output():assert history.final_result() == 'final answer'+def test_rust_history_surfaces_terminal_exec_command_end_failure():+ from browser_use.rust.service import _history_from_events++ history = _history_from_events(+ [+ {'event_type': 'model.turn.request', 'payload': {'model': 'gpt-test'}},+ {+ 'type': 'tool.started',+ 'payload': {+ 'name': 'exec_command',+ 'tool_call_id': 'call-exec',+ 'arguments': {'cmd': 'exit 2'},+ },+ },+ {+ 'type': 'exec_command.end',+ 'payload': {+ 'name': 'exec_command',+ 'tool_call_id': 'call-exec',+ 'process_id': '1000',+ 'session_id': 1000,+ 'exit_code': 2,+ 'wall_time_seconds': 0.1,+ 'output': 'command failed\n',+ },+ },+ ],+ model='gpt-test',+ started=1.0,+ finished=2.0,+ output_model_schema=None,+ process_error=None,+ )++ error = 'exec_command failed: exit code 2: command failed'+ first_result = history.action_results()[0]++ assert history.final_result() is None+ assert history.is_done() is False+ assert history.errors() == [error]+ assert first_result.error == error+ assert first_result.extracted_content == 'command failed'+ assert first_result.long_term_memory == 'command failed'+ assert history.action_history()[0][0]['result'] == 'command failed'+ assert history.action_results()[-1].error == error++def test_rust_history_reconstructs_terminal_unkeyed_tool_results():from browser_use.rust.service import _history_from_events