Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): preview_wait_for stops at its timeout when the page stops answering #32846

MergedEntrpi(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/32846/headmerged by maria-rcks View on GitHub

Problem

preview_wait_for can run past its timeoutMs forever. ServerBrowserPage.waitFor checks its deadline only after every check in a poll round has settled. The selector check awaits Playwright's locator.count() and the text check awaits page.evaluate(). Neither takes a timeout. When one stalls, the wait never ends. This happens on a desktop-drawn tab whose Playwright utility world does not answer, on a page with a busy main thread, or when a dialog opens during the wait.

The stuck wait holds the tab's SessionControl queue. Every later action on that tab then times out at the broker. Each broker timeout disconnects the shared server-browser host (#16921), so preview tools fail for a moment in every thread, not only the one that waited.

Change

waitFor now creates one expiry timer per call. The timer starts after the target locator is resolved, so a stale-ref error leaves no timer behind. Each poll's checks and each 100 ms poll sleep race against that timer. finally clears the timer on every path. evaluate and snapshot in the same module already use this expiry shape.

The race is on each inner await, not one race around the whole loop. So the loop itself stops at the deadline and does not keep polling CDP in the background. The Date.now() deadline is gone. The error tag (PreviewAutomationTimeoutError) and message do not change, so agents see the same text as before.

One behaviour change: the timeout is now a real deadline. Before, a wait always finished one full round of checks before it could fail. Now a very small timeoutMs (such as 1 ms) can fail on an element that is present, if the timer fires before the first CDP reply. evaluate already behaves this way. With normal timeouts nothing else changes.

What this does not do:

  • It does not cancel the stalled Playwright read. That read stays pending until it settles or the page closes. The checks only read, so no Runtime.terminateExecution is sent.
  • Budgets still start when the run starts, not when the request arrives. A wait queued more than about 1 s behind another action on the same tab can still overrun the broker grace. That is part of the broker's timeout handling and is out of scope here. #23564 answers the caller at its deadline at the request level, but the waitFor loop itself keeps polling, so the two fit together.
  • type without a target probes the focused element with the same unbounded count(). #32845 fixes that separately.

Only apps/server/src/preview/ServerBrowserPage.ts (waitFor) and its test file change. No contract, broker, SessionControl or model-facing text changes.

Scope and approval

This is a very small fix for an obvious bug: a wait that takes a timeout can never time out. The fix is about 20 lines in one function, with one failing-first test. It changes no contract and no model-facing text. preview_wait_for is the only entry point, and it is server-only, so all clients, providers and connection modes get the fix from the same code. Per CONTRIBUTING.md, a focused fix like this can go straight to a PR.

Verification

Base: upstream main 09a54f01bc. Rebased onto cec8d73a1f to resolve a test-file conflict with #31925, which added its own describe block in the same place. vp run check:changed passes again on the rebased branch (33 tests in the 2 changed files).

New test: apps/server/src/preview/ServerBrowserPage.test.ts > "server browser wait" > "ends at its timeout when a check never answers". It uses a fake page whose locator().count() never settles, plus vitest fake timers. It records the failure in a variable instead of awaiting the promise, so on main it fails at once and does not hang until the test timeout.

  • On main it fails: after 300 ms of fake time no error has been thrown (expected undefined to match object { tag: "PreviewAutomationTimeoutError" }). The loop is still waiting on the count() and never reaches its deadline check.
  • With the fix, the whole file passes (25 of 25).
  • vp run check:changed passes on a fresh run: format, lint, knip, graphql, typecheck of the 3 affected packages, and the tests beside the changes (2 files).
  • Evals: none. No model-facing text changed, and no eval case belongs to this fix. The tool description, schema, error tag and message are the same.

Runtime check in a real client: a dev desktop build with this fix and other preview fixes, on a desktop-drawn tab. An agent kept the page's main thread busy for 12 s, then called preview_wait_for with text: "never appears" and timeoutMs: 2000. It got the timeout error after 2.0 s. Later calls on the same tab (preview_status, then preview_act type) worked, and no call reported "No preview automation host is available".

Before and after, with no dev server: real headless Chromium through playwright-core, calling ServerBrowserPage.waitFor directly. The page keeps its main thread busy for 5000 ms. Then waitFor({ text: "never appears", timeoutMs: 2000 }) runs, followed by a second wait for text that appears once the page is free.

[fix]  waitFor { text: 'never appears', timeoutMs: 2000 }
[fix]  waitFor rejected after 2011ms: PreviewAutomationTimeoutError: Waited 2000ms without every condition holding.
[fix]  follow-up waitFor { text: 'ready', timeoutMs: 10000 } resolved after 2946ms
[main] waitFor { text: 'never appears', timeoutMs: 2000 }
[main] waitFor rejected after 4959ms: PreviewAutomationTimeoutError: Waited 2000ms without every condition holding.
[main] follow-up waitFor { text: 'ready', timeoutMs: 10000 } resolved after 3ms

On main, the 2000 ms wait lasts as long as the page is busy, and its message still says 2000 ms. Here the page frees itself after 5 s. When the read never answers, as on the desktop-drawn tabs where this was seen, the main-branch wait never ends. With the fix it ends at 2 s.

Built with Claude Opus 5.5 in Claude Code (run from T3 Code); reviewed by GPT-6.1 Sol in Codex.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Approved at 0d2de89

      Macroscope's review found this PR approvable — Preview waits now stop at their existing timeout even when page checks stop responding. The change is limited to wait scheduling and cleanup, with no changes to product defaults or persistent data.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      waitFor now races condition checks and polling delays against a timeout. The timeout rejects with PreviewAutomationTimeoutError, and the timer is cleared when the wait ends or fails. A test covers a locator check that does not resolve.

      Changes: Preview wait timeout

      Layer / File(s)Summary
      Enforce and test wait timeouts
      apps/server/src/preview/ServerBrowserPage.ts, apps/server/src/preview/ServerBrowserPage.test.ts
      waitFor races each condition check and polling delay against a timer that rejects with PreviewAutomationTimeoutError. The timer is cleared in finally. A test verifies the timeout error when a locator check does not resolve.

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

      Change: Bug fix

      Possibly related issues

      • pingdotgg/t3code#32848: This change bounds a stalled waitFor check, but does not restore the missing utility world or fix locator-based actions and snapshots.
      • pingdotgg/t3code#32849: This change addresses the wait timeout response, but does not cancel the stalled read or resolve the broader queue and cross-tab effects.

      Suggested labels: bugfix

      Suggested reviewers: juliusmarminge

      Merge Risk: Minimal · up to f7e78

      The wait timeout is enforced even when a page check stops answering. No merge-blocking issue was identified.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title clearly summarizes the main change: preview_wait_for now stops at its timeout when the page stops responding.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Description checkPassedThe description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the bug, the fix, why the focused change needs no prior approval, and the tests and ru…
      Full details: Description check

      Explanation

      The description includes the required Problem, Change, Scope and approval, and Verification sections. It explains the bug, the fix, why the focused change needs no prior approval, and the tests and runtime checks performed.

      Finishing Touches

      Generate unit tests (beta)

      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Recent review info

      Run configuration

      Commits

      Reviewing files that changed from the base of the PR and between 0d2de89c0d604a3f8f5ba7cb72dc24512b5b5d3c and f7e78588768f2457f2159133b3fb4329b28e62a7.

      Files selected for processing: 2

      • apps/server/src/preview/ServerBrowserPage.test.ts
      • apps/server/src/preview/ServerBrowserPage.ts

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

    4. Worker16 bounded technical assessment — not a formal GitHub review

      Receiving task: Superboard OS and desktop / 6ae9048924888191ba619eb5249ca846 Invocation: 76ce0654-4a28-8325-9979-ebef21ea3b19 Setup marker: HL-SB-20261102

      Candidate and bounded source scope

      T3 Code PR #32846, author Entrpi, branch fix/preview-wait-for-deadline, remains OPEN at exact HEAD 0d2de89c0d604a3f8f5ba7cb72dc24512b5b5d3c, based on main@09a54f01bc0ae83865347a965ced50f8c8ec2953.

      Reviewed only:

      • apps/server/src/preview/ServerBrowserPage.ts
      • apps/server/src/preview/ServerBrowserPage.test.ts

      The original author retains both paths and the branch. Worker16 claims no source or branch custody.

      Source assessment

      The previous waitFor loop checked its deadline only after all poll checks settled. The selector path awaits Playwright locator.count(); the text path awaits page.evaluate(). Either can remain pending and hold the per-tab action queue indefinitely.

      The candidate now starts one expiry timer and races both the checks and each poll sleep against it, clearing the timer in finally. The unchanged contract bounds optional timeoutMs to >0 and <=60,000 ms. The new regression exercises a never-resolving locator count and expects PreviewAutomationTimeoutError.

      I found no demonstrated P1/P2 in this bounded two-file source delta. The implementation intentionally does not cancel the underlying read-only Playwright request after the wait promise times out; that limitation is disclosed in the PR. This assessment does not claim that the separate missing-utility-world defect in #32848 is repaired.

      Exact-head verification readback

      All-event SHA inventory returned six runs for this exact head:

      • CI #42455151374 — SUCCESS; all eight Test Server shards, Test, Lint, Build/Typecheck and Check succeeded.
      • Test Server 4 job #128652460277 executed ServerBrowserPage.test.ts: 25/25 PASS.
      • Agent Context Budget #42455151361 — SUCCESS.
      • Mobile Fingerprint Check #42455151377 — SUCCESS.
      • PR Vouch #42455151239 and PR Size #42455151237 — SUCCESS.
      • Mobile EAS Preview #42455151430 — SKIPPED.
      • Mobile Native Static Analysis, Test Web, Rust and Release Smoke were SKIPPED, not passed.

      Current T3 main is ade473018d32003658b7d38693e083ee2e314bd8, six commits beyond the PR base. A path comparison shows no overlap between those main-only changes and these two PR paths. That is structural non-overlap, not a tested current-main composition; the author still needs an ordinary forward integration and fresh exact-head CI.

      T3 policy / review boundary

      Trusted T3 policy was read at current main ade473018d32003658b7d38693e083ee2e314bd8 (AGENTS, CONTRIBUTING, contribution-triage skill and exemptions). Author Entrpi is not in the explicit exemption list. The current PR labels are only vouch:unvouched and size:S; the configured macroscope-review trigger label is absent. Macroscope's Approvability comment is not the configured deeper-review trigger. This connection has pull-only / no-triage permission on T3, so Worker16 did not mutate labels or submit a formal review.

      Next action: T3's authorized maintainer/triage owner must finish the normal eligibility routing and apply the verified review trigger if eligible. After the author forward-integrates current main and reruns the relevant checks on the resulting exact head, a qualified separate reviewer can perform the formal review. No CI dispatch, admission bypass, source edit, branch update or merge was performed here.

      Desktop/browser live user-session acceptance remains NOT RUN; it is not being used as a blanket source-merge veto.

    5. Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified in a real dev environment

      verified as-is at f7e78588768f2457f2159133b3fb4329b28e62a7. reproduced first on github/main@e4d86abca9 in a separate worktree. installed dependencies and ran one isolated dev server at a time. used repository playwright with /usr/bin/google-chrome, created the project and thread through the web app, and submitted real codex gpt-6.1-sol turns through the local proxy. no mocks or seeded fixtures.

      the agent opened a background preview tab, confirmed visible text + selector + url conditions, then scheduled a real 20-second busy loop in the page. it immediately requested a 2000ms missing-text wait, followed by a 1000ms url-only wait on the same still-busy tab. provider protocol durations:

      main: missing-text wait -> 3015ms, timeout
      main: immediate url-only wait -> host unavailable
      pr:   missing-text wait -> 2077ms, timeout
      pr:   immediate url-only wait -> 569ms, success

      combined text/selector/url waits succeeded before and after the stall on both revisions. post-stall snapshots and tab closure succeeded. the pr avoided main's host disconnection. the transport reports the existing generic timeout wording on both revisions. screenshot timings include small orchestration overhead; the transcript uses provider protocol durations.

      blacksmith verification passed: all 31 existing browser-page tests, then vp run check:changed cec8d73a1f0fd3bd9a48df88640436e73a04afa3 (format, lint, knip, graphql, affected typechecks, 33 tests across two files). no source changes or pushes were needed.

      command transcript

      main: 2-second wait overruns and the next call loses its host

      pr: wait returns at its deadline and the next call succeeds while busy

      Not verified

      native desktop-drawn tabs, indefinitely stalled utility worlds, modal dialogs, native ios/android, macos/windows, relay/tunnel connections, and other providers were not exercised on this linux vm. the live reproduction covers the real busy-main-thread path.

    6. tanstack-source added labelsbug

    7. maria-rcks merged this43ba03c

    8. maria-rcks closed this

Sign in to join this conversation.