Skip to content

Tell a search wait's timeout by its held answer - #4546

Open
yohamta0 wants to merge 4 commits into
mainfrom
fix-stagehand-search-wait-flake
Open

yohamta0 wants to merge 4 commits into
mainfrom
fix-stagehand-search-wait-flake

Conversation

@yohamta0

@yohamta0 yohamta0 commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Summary

TestStagehandSearchingWindowWaitEndsWithTimeout failed on Windows CI with "7.11s is not less than 6s". It bounded the whole replay by the search's timeout plus callTimeoutSlack, but the replay also checks the target, readies the document watch, and acts through the browser runtime. On a slow runner those round trips alone pass the bound, so the assertion measured the runner, not whether the wait ended at its timeout.

Changes

  • internal/runtime/builtin/browser/stagehand_test.go: the test asserts that the search returns while its answer is still held, which only the wait's timeout path allows. It then times the wait for the held window alone, which reads no page, so the browser's pace stays out of the bound. Its one-minute watchdog cancels the replay and waits for it before cleanup.
  • No production code changes.

Core change

The page's answer stays gated until the test releases it, so a replay that returns before the release stopped waiting at its timeout. The wait's own deadline is checked on settleDocument, while the window is still held. That check reads no page, so a slow runner can't push it over the bound. The replay's checks around the wait do read the page, and they made the old whole-replay bound flaky.

// internal/runtime/builtin/browser/stagehand_test.go, TestStagehandSearchingWindowWaitEndsWithTimeout
	select {
	case err := <-searched:
		require.NoError(t, err)
	case <-time.After(time.Minute):
		cancelSearch()
		<-searched
		require.FailNow(t, "the search waited for the answer past its timeout")
	}
	stagehand := eng.(*stagehandEngine)
	waited := time.Now()
	stagehand.settleDocument(t.Context(), waited.Add(stagehand.settleWait), waited.Add(timeout))
	assert.GreaterOrEqual(t, time.Since(waited), timeout, "the wait held for the window")
	assert.Less(t, time.Since(waited), timeout+time.Second, "the wait ended at its time")

Testing

Performance

No performance risk: a test-only change.

Out of scope

  • The test no longer bounds how late a deadline Replay hands to the wait could be. Any such bound through Replay also counts its page reads, which is what made the old check fail on a slow runner.

Agent

Claude Code, claude-opus-5-5, high

@greptile-apps

greptile-apps Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Low impact] This test-only change appears safe to merge.

Summary

Replaces a tight elapsed-time upper bound in TestStagehandSearchingWindowWaitEndsWithTimeout with a check that the search returns while its answer remains held.

  • The browser test checks when a search returns, not how long the whole click takes.

Reviews (1) · Last reviewed commit: "Tell a search wait's timeout by its held..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 619b7042-d5b1-4999-a5c4-5a75dcceae00

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The test now runs the windowed search asynchronously and checks that it returns without error while the response remains gated. It asserts that the search takes at least the configured one-second timeout.

Changes: Windowed search timeout test

Layer / File(s) Summary
Search wait assertions
internal/runtime/builtin/browser/stagehand_test.go
The test waits up to one minute for the asynchronous search to return while its response is gated. It checks for a nil error and an elapsed time of at least one second, replacing the prior upper-bound assertion.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Merge Risk: Minimal · previous review 9c9c0

This change only makes a test less sensitive to timing on slow Windows CI runners and does not alter product behavior. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Tell a search wait's timeout by its held answer" describes the main change: the test now uses the held answer to verify that the search wait ends at its timeout. It is specific to the chang…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description follows the repository template closely. It has Summary, Changes, Core change, Testing, and Performance sections, plus an Agent section. It explains the failure, the fix, and the reaso…
Full details: Title check

Explanation

The title "Tell a search wait's timeout by its held answer" describes the main change: the test now uses the held answer to verify that the search wait ends at its timeout. It is specific to the changeset, though the phrasing is somewhat unusual and not fully plain. The title is concise and on topic.

Full details: Description check

Explanation

The description follows the repository template closely. It has Summary, Changes, Core change, Testing, and Performance sections, plus an Agent section. It explains the failure, the fix, and the reason the old bound was flaky. It includes the CI failure link and local test results. Related Issues and the template checklist are not filled in. The Related Issues section is conditional, so its absence is minor. The Changes section does not show user-visible behavior before and after. That part is not applicable here because the change is test-only with no production code changes. The description is mostly complete, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 1edb2c0a-e7c3-4c74-a2fa-6b2f98333d81
Commits

Reviewing files that changed from the base of the PR and between d48aa99 and 9c9c044.

Files selected for processing: 1

  • internal/runtime/builtin/browser/stagehand_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@yohamta0 yohamta0 added the windows-ci Run the Windows tests on this pull request, without conformance and E2E label Dec 3, 2026
@yohamta0
yohamta0 force-pushed the fix-stagehand-search-wait-flake branch from 2375c69 to c4d4dc8 Compare December 3, 2026 06:05
The test bounded the whole replay by its timeout plus the call slack,
but the replay also checks the target, readies the document watch, and
acts through the browser runtime, which together took over the bound
on a slow Windows runner. The answer stays held until the test releases
it, so a replay that returns before then ended its wait at the timeout;
the test now asserts that instead of a wall-clock bound.
The held answer showed only that the replay stopped waiting before the
answer came, so a wait that ran seconds past its time still passed. The
test now times the wait for the held window directly, which reads no
page, so the browser's pace stays out of the bound. Its watchdog also
cancels the replay and waits for it before the browser is cleaned up.
Timing the held-window wait on its own lost coverage of the deadline
the replay passes to it. The test now bounds the replay from when it
acted, as the old check did from its start, so the checks before the
action, which run at the browser's pace, stay out of the bound while a
late deadline still fails it.
Timing the replay from when it acted still counted the document watch,
which runs at the browser's pace, so a slow runner could still fail
the bound. The test goes back to timing the held-window wait alone,
which reads no page, and keeps the held answer as the proof that the
replay stopped waiting at its timeout.
@yohamta0
yohamta0 force-pushed the fix-stagehand-search-wait-flake branch from c4d4dc8 to 4de61da Compare December 3, 2026 06:27

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

windows-ci Run the Windows tests on this pull request, without conformance and E2E

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant