fix(server): keep preview hosts when optional page metadata times out #12279
main fromrefs/pull/12279/head·opened View on GitHubProblem#
The preview toolkit follows most browser operations with a best-effort status read (500 ms budget) to fill toolIcon.pageUrl. The broker treats every unanswered deadline as a dead host and disconnects it, so one slow metadata reply evicted the only desktop host. Every later preview_* call then failed with No preview automation host is available until the desktop app reconnected, even though the primary action had succeeded and the lookup failure was already swallowed.
Change#
PreviewAutomationInvokeInput gains disconnectOnTimeout. The metadata lookup passes false, so its timeout fails only that call: the action result still returns without an icon, and the host stays routable. A reply that lands after the deadline is dropped by the existing pending-request cleanup. Unanswered primary operations keep evicting the host (now with main's stream completion) as #11381 intended.
Scope and approval#
Fixes #12273, triaged as an accepted bug by a maintainer: https://github.com/pingdotgg/t3code/issues/12273#issuecomment-5718528512. Restarting the desktop app was the only recovery.
Verification#
Problem established: the new MCP toolkit test (click OK, follow-up status stalls past 500 ms, late reply, then preview_status on the same host) reproduces the no-host failure.
Checks run on the current head (rebased on main):
vp test run src/mcp/McpHttpServer.test.ts src/mcp/PreviewAutomationBroker.test.ts(apps/server): 56 passed.- With the
disconnectOnTimeout: falseline removed from the handler, the new test fails (keeps the host when the optional page metadata lookup times out), confirming it covers the fix. vp lintandvp fmt --checkon the changed files: clean.- Server typecheck was not completed locally on this head (machine resource limits); relying on CI.
Not checked: a real desktop host with a slow page. No UI changes.
Created with Claude Opus 5 in Claude Code in T3 Code. Rebased and PR body updated by Claude Opus 5.5 in Claude Code.
- 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:XS
Approvability#
Verdict: Approved at
f679989Macroscope's review found this PR approvable — This is a focused server bug fix that preserves existing timeout handling for primary operations while preventing an optional page-metadata lookup from evicting a live preview host. The added integration test covers the timeout, late response cleanup, successful action result, and continued host availability.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).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:
8b75ceaf-459e-4243-aded-12f54e618a29📥 Commits
Reviewing files that changed from the base of the PR and between 243e489402439856e1706f5d057b0a29eebf04ed and f6799892191362948da8027c1e14da63b7584c44.
📒 Files selected for processing (2)
apps/server/src/mcp/McpHttpServer.test.tsapps/server/src/mcp/PreviewAutomationBroker.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
📝 Walkthrough
Walkthrough#
The preview broker can retain a host when an optional metadata status request times out. The preview handler uses this option. A regression test checks that the click succeeds and that a later status call still reports the host and expected tab.
Changes#
Preview timeout retention
Layer / File(s) Summary Broker timeout policy
apps/server/src/mcp/PreviewAutomationBroker.tsPreviewAutomationInvokeInputaddsdisconnectOnTimeout. When set tofalse, a timeout returnsPreviewAutomationTimeoutErrorwithout disconnecting the host.Metadata status integration and regression coverage
apps/server/src/mcp/toolkits/preview/handlers.ts,apps/server/src/mcp/McpHttpServer.test.tsThe optional status lookup sets disconnectOnTimeout: falseand retains its 500 ms timeout. The test checks that the click succeeds with empty structured content, then verifies that a later status call reports the available host and expected tab.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarmingeMerge Risk: ⚪ Minimal · up to
f6799An optional page-URL metadata lookup timing out no longer disconnects the preview host, so later preview operations keep working. Primary operation timeouts still disconnect the host. The change is narrow and tested, and no merge-blocking risk was identified.
Security Architecture Review#
Security architecture risk: 🔵 Low · up to
f6799The change is narrowly applied to optional metadata reads. Primary operations retain their existing timeout behavior, and callers do not gain a new way to choose the retention policy. Risk is low, with limited uncertainty about metadata requests that remain queued after their deadline.
Retained concerns No architecture-level concerns identified.
Security review details
Security Blast Radius
- inferred — The changed failure outcome affects the selected preview-host connection and sessions assigned to it: an optional metadata deadline no longer retires that shared connection. The reviewed routing path still selects hosts within the invocation’s environment and preserves live provider-session assignments rather than silently moving them between desktops.
Trust Boundaries and Controls
- observed — Responses must match a pending request’s request ID, client ID, and connection generation. Matching removes the pending entry atomically; invocation finalization also removes it on failure or interruption. A late response after timeout therefore cannot complete a later request through the reviewed broker path.
Resilience and Maintainability Implications
- observed — Retaining the host does not cancel a request already offered to its queue; cleanup removes response-tracking state only. Default timeout eviction still clears and ends the queue, while actual disconnection or replacement retires the old generation. Generation checks prevent stale cleanup from closing a successor, and sequence checks protect current-tab assignment from older results.
Hardening Proposals
- proposed — Consider restricting timeout retention to explicitly classified read-only operations. This would preserve the intended metadata use while preventing future internal callers from applying the broad boolean to mutating operations. Current production wiring does not demonstrate that misuse.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation Linked Issues check ✅ Passed Issue #12273requires an optionaltoolIcon.pageUrltimeout to omit metadata without evicting the preview automation host.PreviewAutomationInvokeInputaddsdisconnectOnTimeout, and the best-effo…Out of Scope Changes check ✅ Passed The changes are limited to timeout behavior in PreviewAutomationBroker.ts, the optional metadata request inhandlers.ts, and regression coverage inMcpHttpServer.test.ts. These changes directly …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 3… Title check ✅ Passed The title clearly and concisely describes the main fix: preventing preview hosts from being disconnected when optional page metadata times out. Description check ✅ Passed The description covers the problem, implementation, scope and approval, and verification. It includes the linked issue, focused regression coverage, test results, lint and format checks, and the uncom… ✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create a new PR
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
Note
Written by
claude-opus-5-5on behalf of MariaHi! We are cleaning up open PRs, and this one appears to have been created with an older model (
opus 5). If this change is really important, we recommend rebuilding the PR with a newer model if possible.maria-rcks closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed