Skip to content

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

Log Rust follow-up execution start

Magnus Müller2e638697e105
diff --git a/RUST_AGENT_INTEGRATION_FEATURES.md b/RUST_AGENT_INTEGRATION_FEATURES.md
index 31ece56ad..6d349e3fd 100644
--- a/RUST_AGENT_INTEGRATION_FEATURES.md
+++ b/RUST_AGENT_INTEGRATION_FEATURES.md
@@ -906,10 +906,15 @@ Terminal core branch: `magnus/browser-use-rust-main-integration` at terminal mai
- Run-delegated follow-ups preserve the normal callback order: step-start hook, terminal execution, new-step callback, step-end hook, done callback.
- Proof: `test_rust_agent_run_follow_up_invokes_on_step_end`.
+179. Rust Agent run-delegated follow-up main-loop logging parity
+ - Browser Use-style `Agent.add_new_task(...); Agent.run(...)` follow-ups now log the main execution-loop start line before invoking the Rust terminal follow-up command.
+ - The log includes the follow-up run's resolved max-step budget, matching the run-start debug metadata emitted by normal terminal-backed runs.
+ - Proof: `test_rust_agent_run_follow_up_logs_main_execution_start`.
+
## 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` (150 tests)
+- `uv run pytest -q tests/ci/test_rust_agent.py` (151 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 056a0ce12..fa3933361 100644
--- a/browser_use/rust/service.py
+++ b/browser_use/rust/service.py
@@ -2991,6 +2991,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
return self.history
if self.state.follow_up_task and self.terminal_session_id:
self.state.follow_up_task = False
+ self._log_main_execution_start(max_steps)
return await self._follow_up_terminal(
self.task,
max_steps=max_steps,
diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.py
index 1a99cef16..179097cfc 100644
--- a/tests/ci/test_rust_agent.py
+++ b/tests/ci/test_rust_agent.py
@@ -3207,6 +3207,62 @@ async def test_rust_agent_run_logs_main_execution_start(monkeypatch):
assert logger.errors == []
+async def test_rust_agent_run_follow_up_logs_main_execution_start(monkeypatch):
+ from browser_use.rust import Agent
+
+ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')
+ process_calls = []
+ load_count = 0
+
+ class RecordingLogger:
+ def __init__(self):
+ self.infos = []
+ self.debugs = []
+ self.errors = []
+
+ def info(self, message, *args, **kwargs):
+ self.infos.append(message)
+
+ def debug(self, message, *args, **kwargs):
+ self.debugs.append(message)
+
+ def error(self, message, *args, **kwargs):
+ self.errors.append(message)
+
+ logger = RecordingLogger()
+ monkeypatch.setattr(Agent, 'logger', property(lambda self: logger))
+ agent = Agent(task='Log follow-up execution start.', llm=type('LLM', (), {'model': 'gpt-test'})())
+
+ async def fake_run_process(argv, timeout_seconds=None):
+ process_calls.append(argv)
+ if len(process_calls) == 1:
+ return 0, 'Session: 12345678-1234-1234-1234-123456789abc\n', ''
+ if len(process_calls) == 2:
+ assert argv[-3] == 'followup'
+ assert 'Starting main execution loop with max 5 steps...' in logger.debugs
+ return 0, '', ''
+
+ async def fake_load_events():
+ nonlocal load_count
+ load_count += 1
+ return [{'event_type': 'session.done', 'payload': {'result': f'logged follow-up execution {load_count}'}}]
+
+ agent._run_process = fake_run_process
+ agent._load_events = fake_load_events
+
+ history = await agent.run(max_steps=4)
+
+ assert history.final_result() == 'logged follow-up execution 1'
+ logger.debugs.clear()
+ agent.add_new_task('Continue and log follow-up execution start.')
+
+ history = await agent.run(max_steps=5)
+
+ assert history.final_result() == 'logged follow-up execution 2'
+ assert len(process_calls) == 3
+ assert logger.errors == []
+
+
async def test_rust_agent_run_registers_browser_use_signal_handler(monkeypatch):
import asyncio