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
Reserve bounded Rust follow-up timeouts
Magnus Müller19bfb125a9d1
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex c7d46db5e..670e87d02 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -3385,7 +3385,14 @@ class Agent(Generic[Context, AgentStructuredOutput]):await self._finalize_run_cleanup()return self.history- async def follow_up(self, task: str, max_steps: int | None = None) -> AgentHistoryList[AgentStructuredOutput]:+ async def follow_up(+ self,+ task: str,+ max_steps: int | None = None,+ *,+ step_timeout: int | None = None,+ enqueue_timeout: int | None = None,+ ) -> AgentHistoryList[AgentStructuredOutput]:if not self.terminal_session_id:raise RustAgentError('No active Rust session. Call run() before follow_up().')resolved_max_steps = max_steps if max_steps is not None else self.kwargs.get('max_steps', 100)@@ -3393,7 +3400,13 @@ class Agent(Generic[Context, AgentStructuredOutput]):self.state.follow_up_task = Falseself._register_run_signal_handler(resolved_max_steps)try:- return await self._follow_up_terminal(self.task, max_steps=max_steps, resolved_max_steps=resolved_max_steps)+ return await self._follow_up_terminal(+ self.task,+ max_steps=max_steps,+ resolved_max_steps=resolved_max_steps,+ step_timeout=step_timeout,+ enqueue_timeout=enqueue_timeout,+ )except asyncio.CancelledError:await self._finalize_exceptional_run(max_steps=resolved_max_steps, agent_run_error='CancelledError')raise@@ -3413,14 +3426,18 @@ class Agent(Generic[Context, AgentStructuredOutput]):resolved_max_steps: int,initialize_lifecycle: bool = True,on_step_end: AgentHookFunc | None = None,+ step_timeout: int | None = None,+ enqueue_timeout: int | None = None,) -> AgentHistoryList[AgentStructuredOutput]:if initialize_lifecycle:self._initialize_run_lifecycle_state()started = time.time()binary = find_browser_use_terminal_binary()+ run_timeout = self.settings.step_timeout if step_timeout is None else step_timeout+ followup_timeout = run_timeout if enqueue_timeout is None else enqueue_timeoutreturncode, stdout_text, stderr_text = await self._run_process([binary, *self._state_dir_args(), 'followup', self.terminal_session_id, task],- timeout_seconds=self.settings.step_timeout,+ timeout_seconds=followup_timeout,)self.last_stdout = stdout_textself.last_stderr = stderr_text@@ -3428,7 +3445,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):raise RustAgentError(stderr_text or stdout_text)returncode, run_stdout_text, run_stderr_text = await self._run_process(self._run_existing_argv(resolved_max_steps),- timeout_seconds=self.settings.step_timeout,+ timeout_seconds=run_timeout,)self.last_stdout = '\n'.join(part for part in (stdout_text.strip(), run_stdout_text.strip()) if part)self.last_stderr = '\n'.join(part for part in (stderr_text.strip(), run_stderr_text.strip()) if part)diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 22a960260..757a46482 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -4931,6 +4931,43 @@ async def test_rust_agent_direct_follow_up_updates_task_state_and_transcript(tmpassert follow_up_snapshot['stderr'] == 'followup stderr\nrerun stderr'+async def test_rust_agent_follow_up_allows_timeout_overrides(monkeypatch):+ from browser_use.rust import Agent++ monkeypatch.setenv('BROWSER_USE_TERMINAL_BINARY', '/tmp/browser-use-terminal')+ agent = Agent(task='Summarize current evidence.', llm=type('LLM', (), {'model': 'gpt-test'})())+ agent.terminal_session_id = '12345678-1234-1234-1234-123456789abc'+ process_calls = []++ async def fake_run_process(argv, timeout_seconds=None):+ process_calls.append((argv, timeout_seconds))+ return 0, 'ok\n', ''++ async def fake_load_events():+ return [{'event_type': 'session.done', 'payload': {'result': 'finalized answer'}}]++ agent._run_process = fake_run_process+ agent._load_events = fake_load_events++ history = await agent.follow_up(+ 'Return the final answer from gathered evidence.',+ max_steps=2,+ step_timeout=45,+ enqueue_timeout=10,+ )++ assert history.final_result() == 'finalized answer'+ assert len(process_calls) == 2+ assert process_calls[0][0][-3:] == [+ 'followup',+ '12345678-1234-1234-1234-123456789abc',+ 'Return the final answer from gathered evidence.',+ ]+ assert process_calls[0][1] == 10+ assert 'max_turns=2' in process_calls[1][0]+ assert process_calls[1][1] == 45++async def test_rust_agent_run_logs_browser_use_lifecycle_dispatch(monkeypatch):from browser_use.rust import Agent