Skip to content

fix(tools): report the wait duration that actually elapsed - #6040

Open
jimpablo wants to merge 1 commit into
browser-use:mainfrom
jimpablo:fix/wait-reports-actual-duration
Open

jimpablo wants to merge 1 commit into
browser-use:mainfrom
jimpablo:fix/wait-reports-actual-duration

Conversation

@jimpablo

@jimpablo jimpablo commented Oct 11, 2026 •

Copy link
Copy Markdown

Fixes #5362.

wait capped at 30s and also subtracted 1s, then wrote the requested duration into long_term_memory. A request for 1s slept 0s. A request for 120s slept 30s and told the model "Waited for 120 seconds". Later steps plan from that text.

The action now sleeps min(max(seconds, 0), 30) and reports that number. If the request was over 30s, the message says it was capped. The tool description mentions the 30s limit.

There is no page to screenshot. The thing the model sees is the log line and long_term_memory. Same three requests, previous formula on the left of each pair, this branch on the right. 1s and 5s are real sleeps. 120s stubs asyncio.sleep so the run does not sit for 30s; the string still comes from wait.

previous main
  request   1s   slept  0s   told model: Waited for 1 seconds
  request   5s   slept  4s   told model: Waited for 5 seconds
  request 120s   slept 30s   told model: Waited for 120 seconds

this branch
INFO    [browser_use.tools.service] 🕒 Waited for 1 second
INFO    [browser_use.tools.service] 🕒 Waited for 5 seconds
INFO    [browser_use.tools.service] 🕒 Waited for 30 seconds (requested 120, capped at 30)
  request   1s   slept  1s   told model: Waited for 1 second   (1.00s wall)
  request   5s   slept  5s   told model: Waited for 5 seconds   (5.00s wall)
  request 120s   slept 30s   told model: Waited for 30 seconds (requested 120, capped at 30)

The existing test_wait_action was asserting the old seconds - 1 timing, so those bounds are updated. test_wait_reports_the_sleep_it_actually_did stubs asyncio.sleep and checks the 1s and 120s cases without waiting 30s.

Locally: ruff check and ruff format --check on the two files, then

uv run pytest tests/ci/test_tools.py::TestToolsIntegration::test_wait_action tests/ci/test_tools.py::TestToolsIntegration::test_wait_reports_the_sleep_it_actually_did -o addopts='-sv --tb=short'

2 passed.


Summary by cubic

Fixes #5362 by making the wait tool report the time it actually slept instead of the time it was asked to wait.

The action previously slept min(seconds - 1, 30) and recorded the requested duration in long_term_memory — a 1s request slept 0s, and a 120s request slept 30s while telling the model "Waited for 120 seconds". Later steps plan from that text, so the model now sees misinformation.

The action now sleeps min(max(seconds, 0), 30) and reports that number. When the request exceeds 30s the response says it was capped, and the tool description mentions the limit.

Tests

  • Updated test_wait_action timing bounds to match real sleep durations.
  • Added test_wait_reports_the_sleep_it_actually_did, which stubs asyncio.sleep to verify the 1s and 120s cases without waiting 30s.

Written for commit e04377c. Summary will update on new commits.

View guided diff

wait slept min(seconds - 1, 30) but told the model it had waited the
requested number of seconds. A 1s wait slept nothing, and a 120s wait
slept 30s while recording "Waited for 120 seconds".

Report the real sleep, keep the 30s cap, and mention the cap when it applies.

Fixes browser-use#5362
@CLAassistant

CLAassistant commented Oct 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tests/ci/test_tools.py">

<violation number="1" location="tests/ci/test_tools.py:165">
P3: These elapsed-time checks use `time.time()`, which can jump when the system clock is adjusted and spuriously fail; measure the duration with `time.monotonic()` instead.</violation>

<violation number="2" location="tests/ci/test_tools.py:189">
P3: This test stubs the global `asyncio.sleep` with `monkeypatch`, which breaks the repo's binding 'never mock anything' testing rule (CLAUDE.md). The only other sleeps in this file are real. Consider asserting the reported text with a real short wait, or checking the cap logic without a stub. The stub also replaces `asyncio.sleep` for every caller during the test.</violation>
</file>

Reply to a comment to ask cubic a question or push back. It learns from your replies.
Click Fix with cubic on a comment, or reply @cubic-dev-ai fix this, and cubic writes the fix.

View guided diff | Re-trigger cubic

Comment thread tests/ci/test_tools.py
async def record_sleep(delay: float):
slept.append(delay)

monkeypatch.setattr(asyncio, 'sleep', record_sleep)

@cubic-dev-ai cubic-dev-ai Bot Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This test stubs the global asyncio.sleep with monkeypatch, which breaks the repo's binding 'never mock anything' testing rule (CLAUDE.md). The only other sleeps in this file are real. Consider asserting the reported text with a real short wait, or checking the cap logic without a stub. The stub also replaces asyncio.sleep for every caller during the test.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At tests/ci/test_tools.py, line 189:

<comment>This test stubs the global `asyncio.sleep` with `monkeypatch`, which breaks the repo's binding 'never mock anything' testing rule (CLAUDE.md). The only other sleeps in this file are real. Consider asserting the reported text with a real short wait, or checking the cap logic without a stub. The stub also replaces `asyncio.sleep` for every caller during the test.</comment>

<file context>
@@ -176,12 +174,31 @@ async def test_wait_action(self, tools, browser_session):
+		async def record_sleep(delay: float):
+			slept.append(delay)
+
+		monkeypatch.setattr(asyncio, 'sleep', record_sleep)
+		wait = tools.registry.registry.actions['wait']
+
</file context>
Fix with cubic

Comment thread tests/ci/test_tools.py
assert end_time - start_time <= 2.5 # We wait 3-1 seconds for LLM call
assert result.extracted_content == 'Waited for 3 seconds'
assert result.long_term_memory == result.extracted_content
assert 2.6 <= end_time - start_time <= 4.5

@cubic-dev-ai cubic-dev-ai Bot Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: These elapsed-time checks use time.time(), which can jump when the system clock is adjusted and spuriously fail; measure the duration with time.monotonic() instead.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At tests/ci/test_tools.py, line 165:

<comment>These elapsed-time checks use `time.time()`, which can jump when the system clock is adjusted and spuriously fail; measure the duration with `time.monotonic()` instead.</comment>

<file context>
@@ -158,13 +158,11 @@ async def test_wait_action(self, tools, browser_session):
-		assert end_time - start_time <= 2.5  # We wait 3-1 seconds for LLM call
+		assert result.extracted_content == 'Waited for 3 seconds'
+		assert result.long_term_memory == result.extracted_content
+		assert 2.6 <= end_time - start_time <= 4.5
 
 		# longer wait
</file context>
Fix with cubic

@github-actions

Copy link
Copy Markdown

👋 This PR has been automatically marked as stale because it hasn't had activity for 45 days.

To keep this PR open:

  • Rebase against the latest main branch
  • Address any review feedback or merge conflicts
  • Add a comment explaining the current status
  • Add the work-in-progress label if you're still actively working on this

This will be automatically closed in 14 days if no further activity occurs.

Thanks for contributing to browser-use! 🤖

@github-actions github-actions Bot added the stale label Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: wait action reports a duration it did not actually wait (30s cap and -1 adjustment invisible to the LLM)

2 participants