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 session interruptions

Magnus Müller80f5ea9a5bac
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index d21bebd48..aaed3c485 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -729,10 +729,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- This preserves current-main browser/Python tool results that return structured payloads instead of transcripts, so Browser Use `action_history()` and `ActionResult` surfaces do not show `None` for successful actions.
- Proof: `test_rust_history_reconstructs_terminal_structured_tool_output_results`.
+144. Rust terminal session-interrupted reconstruction
+ - Terminal `session.interrupted` events are now reconstructed as Browser Use history errors instead of falling through to the generic missing-result fallback.
+ - This preserves interrupted subagent/session lifecycle outcomes on Python-visible `errors()`, `is_done()`, and final `ActionResult.error` surfaces.
+ - Proof: `test_rust_history_surfaces_terminal_session_interrupted_message`.
+
## 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` (115 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (116 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 e4772bd41..5a7458592 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -929,6 +929,12 @@ def _failure_from_events(events: list[dict[str, Any]]) -> str | None:
if isinstance(reason, str) and reason.strip():
return f'Rust terminal session was cancelled: {reason.strip()}'
return 'Rust terminal session was cancelled.'
+ if event_type == 'session.interrupted':
+ payload = _event_payload(event)
+ reason = payload.get('reason') or payload.get('message') or payload.get('error')
+ if isinstance(reason, str) and reason.strip():
+ return f'Rust terminal session was interrupted: {reason.strip()}'
+ return 'Rust terminal session was interrupted.'
if event_type in ('agent.failed', 'agent.cancelled'):
payload = _event_payload(event)
inner_payload = payload.get('payload')
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 80e868083..f5e65b935 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -3677,6 +3677,27 @@ def test_rust_history_surfaces_terminal_cancellation_and_tool_abort_messages():
assert aborted.action_results()[-1].error == 'browser aborted: aborted by user'
+def test_rust_history_surfaces_terminal_session_interrupted_message():
+ from browser_use.rust.service import _history_from_events
+
+ history = _history_from_events(
+ [
+ {'event_type': 'model.turn.request', 'payload': {'model': 'gpt-test'}},
+ {'event_type': 'session.interrupted', 'payload': {'reason': 'interrupted by send_input'}},
+ ],
+ model='gpt-test',
+ started=1.0,
+ finished=2.0,
+ output_model_schema=None,
+ process_error=None,
+ )
+
+ assert history.final_result() is None
+ assert history.is_done() is False
+ assert history.errors() == ['Rust terminal session was interrupted: interrupted by send_input']
+ assert history.action_results()[-1].error == 'Rust terminal session was interrupted: interrupted by send_input'
+
+
def test_real_v8_smoke_selects_case_by_index_and_task_id(tmp_path):
module = _load_real_v8_smoke_module()
dataset = tmp_path / 'real_v8.json'