Skip to content

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

Harden Rust Agent timeout reconstruction

Magnus Müllerecb2c55c6afe
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index ef0a09ec2..51e82255a 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -1465,6 +1465,14 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- This is a general cache-window fix for long browser/research trajectories; it does not add task-specific instructions or domain-specific behavior.
- Proof: terminal `cargo test -q -p browser-use-agent repeated_sampling_requests_emit_monotonic_turn_indices -- --nocapture`, terminal `cargo test -q -p browser-use-agent fused_driver_advertises_dispatcher_tool_specs_on_request -- --nocapture`, terminal `cargo test -q -p browser-use-agent tool_output_event_uses_structured_browser_script_fallback_text -- --nocapture`, terminal `cargo test -q -p browser-use-agent open_stream_marks_an_earlier_cache_breakpoint_for_long_histories -- --nocapture`, terminal `cargo test -q -p browser-use-agent turn_request_event_carries_full_llm_input_messages -- --nocapture`, terminal `cargo test -q -p browser-use-agent turn_request_event_carries_all_observability_messages_without_text_budget -- --nocapture`, terminal `cargo fmt --check`, terminal `git diff --check -- crates/browser-use-agent/src/session/reconstruct.rs crates/browser-use-agent/src/session/reconstruct_tests.rs crates/browser-use-agent/src/turn/sampling.rs crates/browser-use-agent/src/turn/sampling_tests.rs`, and terminal `cargo build -q -p browser-use-cli --bin browser-use-terminal`.
+279. Rust Agent eval timeout/error finalization hardening
+ - Python `browser_use.rust.Agent` history reconstruction now treats an empty or non-text latest assistant stream as absent text instead of raising `AttributeError: 'NoneType' object has no attribute 'strip'` while rebuilding a failed terminal run.
+ - The eval runner now derives dashboard `tokensUsed` from `history.usage.total_tokens` when Rust histories lack per-step Python metadata, while still sending the full structured `usage` object with cache and cost buckets.
+ - Five-task real_v8 local-platform gate `kh703qjpt46yfdkyv741pecgq58809h6` used local browser-use `48b15aaf`, terminal `9102fb2`, `BU_RUNTIME=brust`, Browser Use cloud CDP with US proxy, `--parallel-runs 5`, `--max-steps 100`, `--task-timebox-seconds 600`, Claude Sonnet 4.6 executor, and Agent SDK judge.
+ - Gate outcome: all five Browser Use cloud sessions created promptly and all five tasks saved to Convex. Scores were task 1 `0.50`, task 2 `0.85`, task 3 `0.90`, task 4 failed from the now-fixed reconstruction bug, and task 5 `0.40`; pipeline success was 4/5, saved-score mean was `0.6625`, missing-task-as-zero mean was `0.53`.
+ - Observed general risks: long trajectories were the main cost/speed issue (tasks 1 and 5 ran 428s/436s and cost `$7.33`/`$3.49`), Laminar export hit resource/deadline limits on very large traces, and one AUD vendor task reached a Cloudflare captcha despite Browser Use cloud proxy. These are not yet fixed because this gate showed them as evidence to investigate across more tasks rather than single-domain overfitting.
+ - Proof: browser-use `uv run pytest -q tests/ci/test_rust_agent.py -k 'process_failure_ignores_empty_stream_text or loads_started_session_events_after_terminal_timeout or laminar_run_summary' --disable-warnings`, browser-use `uv run python -m py_compile browser_use/rust/service.py tests/ci/test_rust_agent.py`, evaluations-internal `PYTHONPATH=. uv run pytest -q tests/test_service_cli.py -k 'uses_usage_total_tokens_when_metadata_missing or synthesizes_partial_result_on_timeout or pre_judge_checkpoint'`, evaluations-internal `PYTHONPATH=. uv run python -m py_compile eval/service.py tests/test_service_cli.py`, and dashboard query `/api/getRunResults?runId=kh703qjpt46yfdkyv741pecgq58809h6&format=only_judge`.
+
## Current Verification
- terminal `cargo test -p browser-use-agent driver_passes_populated_per_call_request_to_open_stream -- --nocapture`
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.py
index 6bbdb16e0..382a37ffe 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -1100,6 +1100,8 @@ def _last_streamed_assistant_text_from_events(events: list[dict[str, Any]]) -> s
)
candidates = events[last_request_index + 1 :] if last_request_index >= 0 else events
text = _streaming_text_from_events(candidates, ('model.delta', 'model.stream_delta', 'model.response.output_item'))
+ if not isinstance(text, str):
+ return None
text = text.strip()
return text or None
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 45863bc7c..1b5ada72f 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -7818,6 +7818,27 @@ def test_rust_history_marks_process_failure_not_done():
assert history.errors() == ['terminal failed']
+def test_rust_history_process_failure_ignores_empty_stream_text():
+ from browser_use.rust.service import _history_from_events
+
+ history = _history_from_events(
+ [
+ {'event_type': 'model.turn.request', 'payload': {'model': 'gpt-test'}},
+ {'event_type': 'model.stream_delta', 'payload': {'text': None}},
+ {'event_type': 'token_count', 'payload': {'info': {'last_token_usage': {'input_tokens': 1}}}},
+ ],
+ model='gpt-test',
+ started=1.0,
+ finished=2.0,
+ output_model_schema=None,
+ process_error='terminal failed after empty stream delta',
+ )
+
+ assert history.final_result() is None
+ assert history.is_done() is False
+ assert history.errors() == ['terminal failed after empty stream delta']
+
+
def test_rust_history_marks_missing_terminal_result_as_error():
from browser_use.rust.service import _history_from_events