fix(server): keep the preview host after an optional status timeout #14552
main fromrefs/pull/14552/head·opened View on GitHubFixes #12778
Why#
On Windows desktop (T3 0.0.42), asking Codex to use the T3 browser fails with “no preview automation host is available in this environment.” The screenshot is that broker error after a short turn that also read page metadata. Codex then stops, because the error tells the model not to retry.
The desktop browser host was registered. The next preview_* call had nobody to route to.
What Changed#
After most preview tools, the server does a best-effort page-icon status with a 500ms deadline. PreviewAutomationBroker.awaitResponse treated every unanswered deadline as host death and disconnected that client. Swallowing the timeout in PreviewToolkit.invoke did not undo the disconnect. A desktop session has one host, so the following preview tool returned PreviewAutomationNoAvailableHostError.
Optional reads can now set disconnectOnTimeout: false. The metadata lookup does. An unanswered primary operation still drops the host, because the client may have applied the action before becoming unreachable.
This is the same eviction as #12273. #12535 already completes the registration stream so the desktop re-registers about a second later, which is why a later turn can work. It does not help the in-flight turn: the error says not to retry, so Codex stops inside that gap.
Windows .cmd spawn, MCP URL quoting, and the WSL bind address were traced and are not this failure. The tool reached the server and returned the broker’s no-host error, so the MCP session was up.
Scope and approval#
Triaged in #12778 (accepted, via-triage) as a real desktop preview-host failure. The change is the optional-read timeout path in the preview broker and the metadata lookup that uses it. Primary timeouts still disconnect. No contract, client, or provider-adapter change.
Verification#
vp test run src/mcp/PreviewAutomationBroker.test.ts src/mcp/McpHttpServer.test.tsfromapps/server: 57 passed, including- broker: an optional 500ms status timeout leaves the host registered and a later status succeeds
- MCP:
preview_clickstill returns success when the following metadata status times out, and a laterpreview_statusis not an error
- Negative check: with
disconnectOnTimeout: falseremoved from the metadata lookup, the MCP follow-uppreview_statusis an error (isError: true). Restoring the flag makes that assertion pass. vp fmtandvp linton the four touched files.- Not run: a Windows desktop session, and repo-wide
vp check/ full typecheck. Residual risk: a primary timeout (for example a 15sevaluate, zoomedpreview_resize, orpreview_wait_fordeadline race) still evicts the only host for about a second, and a session whose host never registered is unchanged.
UI Changes#
None. This is a server-only change.
Checklist#
- This PR is small and focused
- I explained what changed and why
- I included before/after screenshots for any UI changes (none: server-only)
- I included a video for animation/interaction changes (none)
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
fc1cb91b-72e4-45e0-b55b-2687987ea021📥 Commits
Reviewing files that changed from the base of the PR and between 71a90ae70e3ff880396363809bd9bfcfd520f30c and 05bae6dc1c65e43473e847d1cb94260485da4a84.
📒 Files selected for processing (4)
apps/server/src/mcp/McpHttpServer.test.tsapps/server/src/mcp/PreviewAutomationBroker.test.tsapps/server/src/mcp/PreviewAutomationBroker.tsapps/server/src/mcp/toolkits/preview/handlers.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
📝 Walkthrough
Walkthrough#
The broker adds an option to keep a host connected when a request times out. The preview status lookup uses this option. New tests cover broker timeout behavior and a preview click followed by a status request.
Changes#
Preview status timeout handling
Layer / File(s) Summary Broker timeout option and behavior
apps/server/src/mcp/PreviewAutomationBroker.ts,apps/server/src/mcp/PreviewAutomationBroker.test.tsThe broker accepts disconnectOnTimeoutand skips host disconnection when it isfalse. The test verifies that a later status request succeeds.Preview status lookup and click regression test
apps/server/src/mcp/toolkits/preview/handlers.ts,apps/server/src/mcp/McpHttpServer.test.tsThe preview status lookup sets disconnectOnTimeout: false. The test verifies that a timed-out status request does not prevent the click or a subsequent status response.Priority: ⬆️ High
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarmingeMerge Risk: ⚪ Minimal · up to
05baeOptional metadata timeouts no longer disconnect the preview host, while primary timeout behavior remains unchanged. No actionable merge-blocking risk was identified.
Security Architecture Review#
Security architecture risk: 🔵 Low · up to
05baeBackground metadata reads can now time out without making browser automation unavailable. Action timeouts retain their previous behavior, and callers gain no new browser authority. The change is narrow, although concurrent recovery behavior has not been fully validated at runtime.
Retained concerns No architecture-level concerns identified.
Security review details
Security Blast Radius
- inferred — The changed exposure is host availability after a background read, not additional browser operations or target authority. Public tool callers cannot select the new timeout policy through the inspected MCP schemas or handler request construction.
Trust Boundaries and Controls
- observed — Preview capability checks remain before broker invocation. Existing connection-generation and tab-sequence checks constrain assignment updates; replacing or evicting a connection removes its assignments and pending requests. The new timeout branch does not modify these controls.
Resilience and Maintainability Implications
- observed — Static regression assertions cover primary-timeout eviction, failure of another request on the evicted connection, rejection of stale connection traffic, and successful follow-up status after an optional timeout. The MCP regression also asserts that a click succeeds despite metadata timeout. These are inspected expectations, not executed validation results.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation Title check ✅ Passed The title clearly and concisely describes the main fix: preserving the preview host after an optional status timeout. Description check ✅ Passed The description is complete and follows the required structure. It explains the problem, change, scope and approval, verification results, limitations, and UI impact. It also identifies tests that wer… Linked Issues check ✅ Passed Issue #12778requires the AI to use the T3 browser. The PR changes the preview broker so an optional 500 ms metadata status timeout returns a timeout error without disconnecting the registered host. T…Out of Scope Changes check ✅ Passed The changes stay within issue #12778. They modify the server preview broker, the related optional metadata lookup, and focused regression tests. These changes directly address the reported loss of the…Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 4… ✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Autopilot is currently an internal CodeRabbit preview.
Comment `@coderabbitai help` to get the list of available commands.juliusmarminge added labelsmacroscope-review
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Closing: this is already fixed on main by #15328, which skips the disconnect when a background status read (
updateCurrentTab: false) times out and adds a matching broker test. This PR's end-to-end regression test also passes on unchanged main.macodev00(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Approvability#
Verdict: Approved at
05bae6dMacroscope's review found this PR approvable — This is a small, well-scoped server bug fix that preserves existing primary timeout behavior while preventing an optional metadata read from evicting the preview host. Targeted broker and MCP tests cover the changed flow, with no product-default, schema, infrastructure, or static-analysis changes.
Notes:
- Diff unchanged. Approvability was decided on eligibility alone.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).