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
Recover projected SDK final events
Magnus Müllera7c43d3caf59
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.mdindex b65569e13..af9567a23 100644--- a/RUST_AGENT_INTEGRATION_FEATURES.md+++ b/RUST_AGENT_INTEGRATION_FEATURES.md@@ -146,6 +146,11 @@ This branch keeps the Python `Agent` unchanged unless callers explicitly import`session.done` in GitHub runner progress logs therefore reconstruct thefinal answer even if the final JSON-RPC history response is empty orcompacted differently.+ - Browser-use Rust SDK notification recovery now normalizes both+ `agent.event` and `agent.projected_event` notifications into the retained+ event history. Runs whose progress logs show projected `session.done` or+ `agent.completed` events therefore no longer fall back to+ "Rust terminal session did not produce a final result."- Browser-use Rust SDK history reconstruction now prefers retained livenotifications when the final JSON-RPC response history is present but lacksa final result. Stale response-side compaction errors no longer override a@@ -225,6 +230,7 @@ This branch keeps the Python `Agent` unchanged unless callers explicitly import- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_agent_runs_through_sdk_and_reuses_session_for_followup tests/ci/test_rust_agent.py::test_rust_agent_recovers_final_result_from_sdk_notifications_after_transport_error tests/ci/test_rust_agent.py::test_rust_agent_preserves_sdk_notification_history_on_cancel -q`- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_agent_recovers_final_result_from_sdk_notifications_after_transport_error tests/ci/test_rust_agent.py::test_rust_agent_recovers_nested_sdk_notification_events tests/ci/test_rust_agent.py::test_rust_agent_prices_sdk_child_usage_events_without_overriding_parent_result -q`- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_agent_recovers_nested_sdk_notification_events tests/ci/test_rust_agent.py::test_rust_agent_prefers_notification_final_when_response_history_lacks_result tests/ci/test_rust_agent.py::test_rust_agent_uses_sdk_history_usage_when_events_do_not_include_usage tests/ci/test_rust_agent.py::test_rust_agent_prices_sdk_child_usage_events_without_overriding_parent_result -q`+- browser-use `uv run pytest tests/ci/test_rust_agent.py::test_rust_agent_recovers_final_result_from_sdk_notifications_after_transport_error tests/ci/test_rust_agent.py::test_rust_agent_recovers_nested_sdk_notification_events tests/ci/test_rust_agent.py::test_rust_agent_recovers_projected_sdk_final_events tests/ci/test_rust_agent.py::test_rust_agent_prefers_notification_final_when_response_history_lacks_result tests/ci/test_rust_agent.py::test_rust_agent_uses_sdk_history_usage_when_events_do_not_include_usage tests/ci/test_rust_agent.py::test_rust_agent_prices_sdk_child_usage_events_without_overriding_parent_result -q`- evaluations-internal `uv run python -m py_compile eval/service.py`- evaluations-internal `python -m py_compile eval/task_types.py`- evaluations-internal `PYTHONPATH=. uv run pytest tests/test_service_cli.py -q -k 'usage_aliases or trims_oversized_history_fields or rust_eval_uses_adapter_initial_navigation_default or rust_eval_preserves_explicit_direct_initial_navigation_override'`diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex 425d485d8..20054fa44 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -474,8 +474,8 @@ def _sdk_notification_summary(notification: dict[str, Any]) -> str | None:def _sdk_notification_events(sdk: Any) -> list[dict[str, Any]]:events: list[dict[str, Any]] = []seen: set[tuple[Any, Any, Any]] = set()- for notification in list(getattr(sdk, 'notifications', []) or []):- if not isinstance(notification, dict) or notification.get('method') != 'agent.event':+ for fallback_index, notification in enumerate(list(getattr(sdk, 'notifications', []) or [])):+ if not isinstance(notification, dict) or notification.get('method') not in {'agent.event', 'agent.projected_event'}:continueparams = notification.get('params')if not isinstance(params, dict):@@ -495,7 +495,18 @@ def _sdk_notification_events(sdk: Any) -> list[dict[str, Any]]:'event_type': payload.get('event_type'),'payload': payload.get('payload') if isinstance(payload.get('payload'), dict) else {},}+ elif notification.get('method') == 'agent.projected_event':+ event = {+ 'seq': event.get('seq'),+ 'id': event.get('id'),+ 'session_id': event.get('session_id'),+ 'ts_ms': event.get('ts_ms'),+ 'event_type': event.get('event_type'),+ 'payload': event.get('payload') if isinstance(event.get('payload'), dict) else {},+ }identity = (event.get('seq'), event.get('id'), event.get('event_type'))+ if identity[0] is None and identity[1] is None:+ identity = (fallback_index, notification.get('method'), event.get('event_type'))if identity in seen:continueseen.add(identity)diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 27b124555..722dabcc5 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -2774,6 +2774,61 @@ async def test_rust_agent_recovers_nested_sdk_notification_events(monkeypatch):assert [event['event_type'] for event in agent.last_events] == ['session.input', 'session.done']+async def test_rust_agent_recovers_projected_sdk_final_events(monkeypatch):+ from browser_use.rust import Agent++ class LLM:+ model = 'fake'++ class FakeSdk:+ stderr_lines = []++ def __init__(self):+ self.notifications = [+ {+ 'method': 'agent.projected_event',+ 'params': {+ 'event': {+ 'kind': 'observed',+ 'payload': {+ 'event_type': 'session.input',+ 'payload': {'text': 'task'},+ },+ }+ },+ },+ {+ 'method': 'agent.projected_event',+ 'params': {+ 'event': {+ 'kind': 'observed',+ 'payload': {+ 'event_type': 'session.done',+ 'payload': {'result': 'final from projected notification', 'success': True},+ },+ }+ },+ },+ ]++ async def call(self, method, params):+ return {'history': {'success': True, 'done': True, 'events': []}}++ fake_sdk = FakeSdk()++ async def fake_ensure_sdk_client(self):+ return fake_sdk++ monkeypatch.setattr(Agent, '_ensure_sdk_client', fake_ensure_sdk_client)++ agent = Agent(task='task', llm=LLM(), directly_open_url=False)+ history = await agent.run(max_steps=3)++ assert history.final_result() == 'final from projected notification'+ assert history.is_successful() is True+ assert [event['event_type'] for event in agent.last_events] == ['session.input', 'session.done']++async def test_rust_agent_prefers_notification_final_when_response_history_lacks_result(monkeypatch):from browser_use.rust import Agent