Skip to content

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

scope down: drop #4484 step_interval fix, keep AX tree fix only

Saurav Panda3a2b93cd05f5
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index ab6ed5cc1..5b427dedf 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -1354,7 +1354,8 @@ class Agent(Generic[Context, AgentStructuredOutput]):
if last_history_item.metadata:
previous_end_time = last_history_item.metadata.step_end_time
- step_interval = max(0, self.step_start_time - previous_end_time)
+ previous_start_time = last_history_item.metadata.step_start_time
+ step_interval = max(0, previous_end_time - previous_start_time)
metadata = StepMetadata(
step_number=self.state.n_steps,
step_start_time=self.step_start_time,
diff --git a/browser_use/dom/service.py b/browser_use/dom/service.py
index 760e55c53..69002ce25 100644
--- a/browser_use/dom/service.py
+++ b/browser_use/dom/service.py
@@ -363,13 +363,10 @@ class DomService:
)
ax_tree_requests.append(ax_tree_request)
- # Wait for all requests to complete. Use return_exceptions=True so a single
- # detached frame (TOCTOU race with ad/widget iframes between Page.getFrameTree
- # and Accessibility.getFullAXTree) doesn't discard AX data from every other
- # frame, including the main document. See #4778.
+ # return_exceptions=True so a single frame detaching mid-request (e.g. ad iframes)
+ # doesn't discard AX data from every other frame, including the main document.
ax_trees = await asyncio.gather(*ax_tree_requests, return_exceptions=True)
- # Merge all AX nodes into a single array, skipping frames that failed.
merged_nodes: list[AXNode] = []
for frame_id, ax_tree in zip(all_frame_ids, ax_trees):
if isinstance(ax_tree, BaseException):
diff --git a/tests/ci/test_history_wait_time.py b/tests/ci/test_history_wait_time.py
index 63169cf2e..8479e9b29 100644
--- a/tests/ci/test_history_wait_time.py
+++ b/tests/ci/test_history_wait_time.py
@@ -21,26 +21,20 @@ def test_step_metadata_step_interval_optional():
def test_step_interval_calculation():
- """step_interval is the gap between steps, not the previous step's duration.
-
- Regression test for #4484: _finalize() previously computed
- (previous_end - previous_start) which is duration. The correct value is
- (current_start - previous_end) — the idle time between steps, including
- LLM decision time (see rerun_history at agent/service.py).
- """
- # Previous step ran from 100.0 to 102.5 (duration: 2.5s)
+ """Test step_interval calculation logic (uses previous step's duration)"""
+ # Previous step (Step 1): runs from 100.0 to 102.5 (duration: 2.5s)
+ previous_start = 100.0
previous_end = 102.5
- # Current step starts at 105.0 — a 2.5s gap (LLM thinking, IO, etc.)
- current_start = 105.0
+ previous_duration = previous_end - previous_start
- calculated_step_interval = max(0, current_start - previous_end)
+ # Current step (Step 2): should have step_interval = previous step's duration
+ # This tells the rerun system "wait 2.5s before executing Step 2"
+ expected_step_interval = previous_duration
+ calculated_step_interval = max(0, previous_end - previous_start)
+ assert abs(calculated_step_interval - expected_step_interval) < 0.001 # Float comparison
assert calculated_step_interval == 2.5
- # Clamp behavior: if clocks went backwards or timestamps overlap, clamp to 0
- calculated_step_interval = max(0, 100.0 - 102.5)
- assert calculated_step_interval == 0
-
def test_step_metadata_serialization_with_step_interval():
"""Test that step_interval is included in metadata serialization"""