waitForDesktopOverlay waited for the desktop preview overlay using request.timeoutMs, the exact deadline the broker uses to abandon the request, so both expired at the same instant: the broker always fired its generic PreviewAutomationTimeoutError first and dropped the deferred, and the host's precise overlay error was reported into a request nobody was listening to. Agents retried doomed calls because "Preview automation evaluate timed out after 15000ms." says nothing about the overlay never becoming available.
The broker now hands the host a wait budget below its own deadline (timeoutMs minus a tenth, capped at 1s — 14000ms for the default 15000ms request), so a host that gives up still has room to say why over the wire. Caller-facing semantics are unchanged: the broker still abandons at the full timeoutMs and still reports that number.
Landing the response in time is only half of it: PreviewAutomationTimeoutError.message ignored the remote message, so the reason would still have been invisible. Host timeouts now carry a closed timeoutStage vocabulary (overlay, navigation, viewport) in the response detail — no remote text is echoed, matching the existing structured-diagnostics policy — and the caller's message reads Preview automation snapshot timed out after 15000ms waiting for the preview overlay to become available. Per-operation input.timeoutMs on navigate/resize is clamped to the wire budget so it cannot re-open the same race.
Fixes #8257
Not addressed here, both filed as separate concerns in the issue's "supporting observations": preview_snapshot still flattens every failure to "Preview snapshot failed." in content (its reason now reaches structuredContent/logs but the fixed text was a deliberate hardening against Cause.pretty leakage, so changing it is its own decision), and these calls still record as Success spans. The desktop waitFor deadline in apps/desktop/src/preview/Manager.ts shares the same collision with input.timeoutMs, untouched here.
Verification:
vp test run apps/server/src/mcp/ apps/web/src/components/preview/ — 28 files, 144 tests pass.
- Both new broker tests fail on the unfixed code (
expected [ 15000, 200 ] to deeply equal [ 14000, 180 ], and the caller receiving a stage-less generic timeout), so they pin the regression rather than the implementation.
vp run --filter @t3tools/contracts typecheck, --filter t3 typecheck, --filter @t3tools/web typecheck clean (server prints only pre-existing suggestions in unrelated files).
vp lint and vp fmt --check clean on the six touched files.
- No dev server or browser was launched; the desktop overlay path itself is not exercised by automated tests.
Implemented with Claude Opus via the Claude Code harness.
Note
Medium Risk
Changes preview automation timeout semantics (hosts get less wall time) and error shaping on a critical agent-facing path; behavior is covered by new broker tests but desktop overlay timing is not fully exercised in CI.
Overview
Fixes a race where the broker and preview host shared the same deadline, so the broker’s generic PreviewAutomationTimeoutError usually won before the host could report why (e.g. overlay never registered).
The broker now routes a shorter wait budget to hosts (hostResponseBudgetMs: caller timeout minus min(1000ms, 10%)) while still abandoning the caller at the full timeoutMs. Host navigate/resize waits use waitBudgetMs so per-operation input.timeoutMs cannot exceed that wire budget.
Host timeout failures carry a closed timeoutStage (overlay, navigation, viewport) in response detail; the broker validates and maps it onto PreviewAutomationTimeoutError, with stage-specific caller messages. Unknown stages are dropped. Contracts, host error serialization, and broker tests cover budget routing and stage forwarding.
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 8fac6348db56fb3be5a4456283b1e4b0f26e238e. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
Note
Forward PreviewAutomationTimeoutError with timeoutStage to automation callers#
- Broker now sends the host a reduced timeout (
hostResponseBudgetMs) so the host can report failures before the broker's own deadline; broker-side timeout is clamped to a minimum of 2ms via MINIMUM_BROKER_TIMEOUT_MS
- Host timeout error classes (
PreviewAutomationOverlayTimeoutError, PreviewAutomationNavigationTimeoutError, PreviewAutomationViewportTimeoutError) now expose a timeoutStage getter, and serializePreviewAutomationHostError includes it in the wire detail
classifyResponseError in PreviewAutomationBroker parses the remote timeoutStage and attaches it to the surfaced PreviewAutomationTimeoutError; unrecognized stages are ignored and yield a generic timeout message
- Host per-operation waits (navigation readiness, viewport render) are now capped by
waitBudgetMs, the smaller of the per-operation timeout and the broker-supplied budget
- Behavioral Change: the host receives a strictly smaller timeout than the broker's overall invoke timeout;
PreviewAutomationTimeoutError may now carry an optional timeoutStage field of type PreviewAutomationTimeoutStage (closed literal: overlay, navigation, viewport) and produces a stage-specific message when present
Macroscope summarized 8fac634.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
89b3a22d-0138-4ce1-96c8-d1e402f2d0c9You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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