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
Reconstruct Rust terminal command waiting results
Magnus Müller832181c39e0f
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex 956bf42bd..a5d24a780 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -764,10 +764,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai- 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`.+151. Rust terminal command-waiting reconstruction+ - Terminal `command.waiting` events now reconstruct live unified-exec process results when no generic textual `tool.output` is present.+ - This preserves current-main long-running command state on Python-visible `ActionResult.extracted_content`, `long_term_memory`, and `action_history()` instead of falling back to synthetic tool-completion text.+ - Proof: `test_rust_history_reconstructs_terminal_command_waiting_result`.+## 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` (122 tests)+- `uv run pytest -q tests/ci/test_rust_agent.py` (123 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 2e6b96718..e110d53a8 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -1003,6 +1003,33 @@ def _exec_command_end_failure_message(payload: dict[str, Any]) -> str | None:return f'{tool_name} failed: {detail}'+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):+ return f'Process running with session ID {session_id}'+ return 'Process running'+++def _command_waiting_payload(payload: dict[str, Any], previous_payload: dict[str, Any] | None) -> dict[str, Any]:+ waiting_text = _command_waiting_text(payload)+ previous_text = _tool_result_text(previous_payload) if previous_payload is not None else None+ if previous_text and waiting_text not in previous_text:+ waiting_text = f'{previous_text}\n\n{waiting_text}'+ next_payload = dict(payload)+ next_payload['text'] = waiting_text+ return next_payload+++_TEXTUAL_TOOL_RESULT_EVENTS = (+ 'tool.output',+ 'tool.output_delta',+ 'command.waiting',+ 'exec_command.end',+ 'tool.finished',+ 'model.response.input_item',+)++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:@@ -1137,6 +1164,7 @@ def _tool_results_by_call_id(events: list[dict[str, Any]]) -> dict[str, tuple[stif event_type not in ('tool.output','tool.output_delta',+ 'command.waiting','exec_command.end','tool.failed','tool.aborted',@@ -1168,6 +1196,17 @@ def _tool_results_by_call_id(events: list[dict[str, Any]]) -> dict[str, tuple[stmerged_payload['text'] = f'{previous_text if isinstance(previous_text, str) else ""}{delta_text}'results[key] = (event_type, merged_payload)continue+ if event_type == 'command.waiting':+ if previous is not None and previous[0] in (+ 'tool.output',+ 'tool.failed',+ 'tool.aborted',+ 'exec_command.end',+ 'model.response.input_item',+ ):+ continue+ results[key] = (event_type, _command_waiting_payload(payload, previous[1] if previous is not None else None))+ continueif event_type == 'exec_command.end' and previous is not None and previous[0] in ('tool.output','tool.failed',@@ -1190,6 +1229,7 @@ def _unkeyed_tool_results(events: list[dict[str, Any]]) -> list[tuple[str, dict[if event_type not in ('tool.output','tool.output_delta',+ 'command.waiting','exec_command.end','tool.failed','tool.aborted',@@ -1240,6 +1280,25 @@ def _unkeyed_tool_results(events: list[dict[str, Any]]) -> list[tuple[str, dict[if previous_delta_index is not None and payload.get('stream') is not True:results[previous_delta_index] = (event_type, payload)continue+ elif event_type == 'command.waiting':+ name = payload.get('name')+ previous_result_index = next(+ (+ index+ for index in range(len(results) - 1, -1, -1)+ if isinstance(name, str)+ and name+ and results[index][1].get('name') == name+ ),+ None,+ )+ if previous_result_index is not None:+ previous_event_type, previous_payload = results[previous_result_index]+ if previous_event_type in ('tool.output', 'tool.failed', 'tool.aborted', 'exec_command.end', 'model.response.input_item'):+ continue+ results[previous_result_index] = (event_type, _command_waiting_payload(payload, previous_payload))+ continue+ payload = _command_waiting_payload(payload, None)elif event_type == 'exec_command.end':if not _tool_result_text(payload):continue@@ -1551,12 +1610,8 @@ def _action_results_from_tool_calls(action_results.append(ActionResult(error=error,- extracted_content=text- if event_type in ('tool.output', 'tool.output_delta', 'exec_command.end', 'tool.finished', 'model.response.input_item')- else None,- long_term_memory=text- if event_type in ('tool.output', 'tool.output_delta', 'exec_command.end', 'tool.finished', 'model.response.input_item')- else None,+ extracted_content=text if event_type in _TEXTUAL_TOOL_RESULT_EVENTS else None,+ long_term_memory=text if event_type in _TEXTUAL_TOOL_RESULT_EVENTS else None,))diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 1d9d9affd..0804e550f 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -751,6 +751,59 @@ def test_rust_history_surfaces_terminal_exec_command_end_failure():assert history.action_results()[-1].error == error+def test_rust_history_reconstructs_terminal_command_waiting_result():+ from browser_use.rust.service import _history_from_events++ history = _history_from_events(+ [+ {+ 'type': 'tool.started',+ 'payload': {+ 'name': 'exec_command',+ 'tool_call_id': 'call-exec',+ 'arguments': {'cmd': 'sleep 60 && echo done', 'yield_time_ms': 250},+ },+ },+ {+ 'type': 'tool.output_delta',+ 'payload': {+ 'name': 'exec_command',+ 'tool_call_id': 'call-exec',+ 'process_id': '1000',+ 'session_id': 1000,+ 'stream': 'stdout',+ 'text': 'started\n',+ },+ },+ {+ 'type': 'command.waiting',+ 'payload': {+ 'name': 'exec_command',+ 'tool_call_id': 'call-exec',+ 'process_id': '1000',+ 'session_id': 1000,+ },+ },+ {'event_type': 'session.done', 'payload': {'result': 'command is still running'}},+ ],+ model='gpt-test',+ started=1.0,+ finished=2.0,+ output_model_schema=None,+ process_error=None,+ )++ first_result = history.action_results()[0]+ waiting_result = 'started\n\nProcess running with session ID 1000'++ assert history.action_names() == ['exec_command', 'done']+ assert first_result.extracted_content == waiting_result+ assert first_result.long_term_memory == waiting_result+ assert first_result.error is None+ assert history.action_history()[0][0]['result'] == waiting_result+ assert history.final_result() == 'command is still running'++def test_rust_history_reconstructs_terminal_unkeyed_tool_results():from browser_use.rust.service import _history_from_events