fix(server): keep preview hosts that report a waitFor miss at the deadline #12899
main fromrefs/pull/12899/head·opened View on GitHubWhat Changed#
PreviewAutomationInvokeInput gains an optional replyGraceMs. The broker waits timeoutMs + replyGraceMs before it treats a request as unanswered and evicts the host. The request sent to the host, the error context, and the reported timeoutMs do not change.
preview_wait_for passes 1500 ms of grace. No other operation changes: click, type, navigate, resize, evaluate, and the optional status lookup keep their current deadlines.
Why#
preview_wait_for forwarded the same timeoutMs as the broker deadline and as the desktop operation timeout. The desktop waitFor polls until that deadline and only then reports the miss, so its reply landed after the broker had already evicted the host. One unmatched wait dropped a live desktop runtime. On released nightlies the next call returns PreviewAutomationNoAvailableHostError until the desktop reloads. On main with #12535 the host re-registers after one second, but the session loses its pinned tab and the honest miss still counts as a dead-host eviction.
#11381 states the contract: a host that replies with an operation-level timeout remains available. The existing broker test covers that only for an immediate reply. #12407 described this exact race and was accepted in triage; the reporter closed it without a fix.
The grace lives on the broker input rather than in the waitFor handler's timeoutMs so the error still reports the caller's deadline. Inflating timeoutMs made the message read timed out after 6500ms for a 5000 ms wait. A host that stays silent past timeoutMs + replyGraceMs is still evicted, so a frozen host is released as before.
Fixes #12898. Same race as #12407.
Validation#
vp test run apps/server/src/mcp/McpHttpServer.test.ts apps/server/src/mcp/PreviewAutomationBroker.test.ts: 51 passed (2 new). Both new tests fail onmainwithout the source change: the MCP test getsisError: trueon the follow-uppreview_status, the broker test getsPreviewAutomationNoAvailableHostErrorinstead of the routed status.- New broker test: host answers the
waitForwith an operation-level timeout attimeoutMs + 100under the test clock; the error carriestimeoutMs: 5000and a laterstatusroutes to the same host. - New MCP test:
preview_wait_forwithtimeoutMs: 5000returnsPreview automation waitFor timed out after 5000ms.;preview_statuson the same host then succeeds. vp run typecheckinapps/server: exit 0.vp lintandvp fmt --checkon the four changed files: clean.- Not run: a live desktop reproduction against this branch. The failing sequence was observed on t3 v0.0.43-nightly.20260917.1866 with a macOS desktop client, from provider logs; the new tests reproduce the same timing through the real broker and MCP toolkit.
Checklist#
- This PR is small and focused
- I explained what changed and why
- I included before/after screenshots for any UI changes (not applicable)
- I included a video for animation/interaction changes (not applicable)
Model: Claude Fable 5.1. Harness: Claude Code in T3 Code.
🤖 Generated with Claude Code
Summary by CodeRabbit#
- Bug Fixes
- Improved preview automation reliability when
preview_wait_forresponses arrive shortly after the caller’s deadline. - Preview hosts now remain available for subsequent status checks after an honest wait timeout.
- Added coverage for delayed responses and continued routing to the correct preview host.
- Improved preview automation reliability when
- 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
Understand this PR’s impact
Explore downstream dependencies and potential security impact with Blast Radius.
Important
Review skipped#
Review was skipped as selected files did not have any reviewable changes.
⚙️ Run configuration
Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
7c5593dc-5ad8-4f32-8515-38bf9343c268📥 Commits
Reviewing files that changed from the base of the PR and between 49576f11105a65fe53db076bb592eb23bc617de4 and 9f9fdeeae1ff04dbf77e780b8108c2d182342da6.
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- 🔍 Trigger review
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:
37b67cb9-2fbe-46e5-9ba6-615d1c96f964📥 Commits
Reviewing files that changed from the base of the PR and between 1de563c1491c7d82563e4553bf5bf689ce6adbb9 and 49576f11105a65fe53db076bb592eb23bc617de4.
📒 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: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
The broker now supports an optional reply grace period.
preview_wait_foruses a 1,500 ms grace period, and tests verify that delayed timeout replies do not evict the preview host.Changes#
Preview wait grace handling
Layer / File(s) Summary Broker reply grace handling
apps/server/src/mcp/PreviewAutomationBroker.ts,apps/server/src/mcp/PreviewAutomationBroker.test.tsThe broker accepts optional replyGraceMsmetadata and waits fortimeoutMs + replyGraceMs. Tests verify that a delayedwaitFortimeout reply preserves host availability.Preview wait integration
apps/server/src/mcp/toolkits/preview/handlers.ts,apps/server/src/mcp/McpHttpServer.test.tsPreview handlers forward the grace period, and preview_wait_foruses 1,500 ms. HTTP server tests verify that a laterpreview_statuscall reaches the same host after a timeout reply.Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarminge🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation Title check ✅ Passed The title clearly and concisely describes the primary fix: retaining preview hosts after a waitFor miss at the deadline. Description check ✅ Passed The description includes complete What Changed and Why sections, explains the broker-only grace behavior, documents issue context and validation results, and addresses the non-applicable UI checklist … Linked Issues check ✅ Passed Issue [ #12898] requires an unsuccessfulpreview_wait_forto returnPreviewAutomationTimeoutError, preserve the callertimeoutMs, keep the host and pinned session available, route later calls to …Out of Scope Changes check ✅ Passed The changes are limited to the broker timeout input, preview handler forwarding and configuration, and automated broker and MCP tests. These changes directly support issue [ #12898] by adding broker-on…Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 4 files. ✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create a new PR
Comment `@coderabbitai help` to get the list of available commands.juliusmarminge added labelsmacroscope-review
I hit #12898 independently today and reproduced it on two Macs with server traces (my duplicate is #15335, and my closed PR #15338 took the same approach). The broker-side grace in this PR fixes the eviction I saw. Some findings from running the fix on real hardware:
- On a real desktop, an unmatched wait will read "failed on client", not "timed out". The tests here fake a host that replies
_tag: "PreviewAutomationTimeoutError". A real desktop's reply loses that tag over Electron IPC (#15336, confirmed in triage), so the renderer reportsPreviewAutomationExecutionError. With the grace in place, my after run on two Macs returnedPreview automation waitFor failed on client preview-…for an unmatched 2 s wait. Before, the broker's own timeout produced "timed out", which hid this. The assertion that the message reads "timed out after 5000ms" passes only because of the fake host. It may be worth landing a #15336 fix alongside this, or at least noting the message change. - The race isn't specific to
waitFor. Navigate readiness, resize (waitForRenderedViewport), andopenwith a URL on a reused tab also spend the fulltimeoutMson the host before answering. The 500 ms best-effort status lookup after click and type (#12273) evicts through the same broker rule. Applying the grace once inPreviewAutomationBroker.invokefor every request covers all of them without per-call opt-in. For the status lookup, bounding only the caller's wait (Effect.timeoutOption(500)around the invoke) keeps tool latency unchanged without evicting. #15338 has both, with regression tests. - Minor: no test shows that a
waitForthat never answers is still evicted once the grace expires. The existing eviction tests only cover operations with zero grace.
Two-machine evidence, relevant to #13540: Mac A ran the thread and served a page on its own
localhost, and Mac B had the same thread's Browser panel open. One unmatchedpreview_wait_for(2 s) went like this:- the broker evicted Mac A at exactly 2 s;
- Mac A's own timeout reply arrived and was dropped;
- Mac A reconnected a second later;
- the next
preview_navigatewent to Mac B, which can't reach Mac A'slocalhost; - the session stayed on Mac B.
With broker-wide grace, Mac A kept the session and navigate succeeded there. Before/after recordings and the trace timeline are on #15338.
- On a real desktop, an unmatched wait will read "failed on client", not "timed out". The tests here fake a host that replies
Note
Grok responding on behalf of Julius.
Thanks for digging into this and for the detailed write-up. The same broker deadline race was fixed in #17693, which just merged: the broker now gives the host a short reply allowance past the operation budget, so an honest
waitFormiss no longer evicts a live host. That also closed #12898, so I'm closing this one as superseded. If you still see the eviction on a build that includes #17693, please open a fresh issue with the log.juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This is a focused, well-tested server fix that adds a 1.5-second grace period to the default
preview_wait_forhost deadline. Because that changes production default timing and host-retention behavior for all such calls, human review is required.No code changes detected at
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).9f9fdee. Prior analysis still applies.