fix(preview): keep browsers that answer at their own deadline #15338
main fromrefs/pull/15338/head·opened View on GitHubProblem#
A preview_wait_for that doesn't match evicts the healthy Browser host that ran it. The host polls for the full timeoutMs and starts counting only after the request reaches it. The broker evicts on no answer after that same timeoutMs, measured from when it queued the request. So the host's "timed out" answer always arrives just after eviction and is discarded. Once the session's host is evicted, the next call goes to whichever connected desktop ranks first, including one on another machine that can't reach the environment's localhost, and the session stays there.
The 500 ms best-effort status lookup after clicks and types can evict a healthy host the same way when it's slow, for example over a relay.
Fixes #15335.
Change#
PreviewAutomationBrokerwaitstimeoutMs + 2.5sbefore treating a request as unanswered. Hosts still receive the originaltimeoutMs, so agent-visible timeouts don't change. A host that truly never answers is still evicted, as #12535 intended, just 2.5 s later.- The post-action status lookup bounds only the caller's wait (
Effect.timeoutOption(500)). An abandoned request leaves the host assigned, so missing metadata no longer evicts it.
Host selection is unchanged. Sessions still stay pinned to their browser (#13064). Choosing between desktops on different machines is a separate product question, raised in a discussion rather than here.
Scope and approval#
This is a small fix for an obvious bug: a host that answers on time is treated as dead. The existing test "keeps a host that responds with an operation timeout" already asserts that a timeout answer must not evict the host. It passes only because the test host answers instantly. The change is server-only, with no contract, client, or settings changes, so it also fixes desktops that are already installed.
Verification#
- Two new regression tests, both failing on main and passing with the fix:
PreviewAutomationBroker.test.ts, "keeps a pinned host whose timeout answer arrives at the operation deadline": a pinned host answerswaitForwith a timeout exactly attimeoutMs, while a focused host on another machine is connected. On main, the next navigate fails on the other host withPreview automation navigate failed on client remote.With the fix, it stays on the pinned host and tab.McpHttpServer.test.ts, "keeps the browser host when the page lookup after an action is slow": the status lookup afterpreview_clickgoes unanswered. On main, the nextpreview_statusfails; with the fix, it's served by the same host.
- The three existing eviction tests now advance the clock past the grace period. They still prove that unanswered hosts are evicted, pending requests fail, buffered actions are discarded, and late answers are ignored.
vp test runforPreviewAutomationBroker.test.ts,McpHttpServer.test.ts, andtoolkits/preview: 68 passed. Servertsc --noEmitclean; lint and format clean forapps/server/src/mcp.- Real two-Mac reproduction over LAN, with an isolated dev environment on Mac A and a second T3 Code Desktop on Mac B showing the same thread's Browser panel. The fixture page is served on Mac A's
localhostonly. Same prompt both runs:preview_status, an unmatchedpreview_wait_for(2 s),preview_navigateto the fixture,preview_status.- Before: the server evicted Mac A's browser at exactly 2 s and discarded Mac A's own timeout answer that arrived right after. Navigate then went to Mac B and failed after 15 s, and the final status shows Mac B's tab (
tab_3, unavailable). Server traces confirm this in each run:closeConnectionat the deadline, then Mac A'srespond, then reconnect. - After: no eviction. Mac A's answer is accepted, navigate and status stay on Mac A's
tab_2with the fixture loaded, and Mac B never receives a request. - The window size differs between takes (Mac A's window was full-screened between runs).
- Before: the server evicted Mac A's browser at exactly 2 s and discarded Mac A's own timeout answer that arrived right after. Navigate then went to Mac B and failed after 15 s, and the final status shows Mac B's tab (
| Before | After |
|---|---|
| Recording | Recording |
![]() | ![]() |
Known gap: with the fix, an unmatched wait_for reports waitFor failed on client … instead of timed out. The desktop's own PreviewAutomationTimeoutError loses its tag crossing Electron IPC (#15336). That's pre-existing and also hides invalid-selector errors. Before this fix, the server's own timeout masked it for wait_for. It's fixed separately.
Model: Claude Opus 5.5 & Claude Fable 5.1 & GPT-6 Astra | Harness: Claude Code & Codex in T3 Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge closed this
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved at
38e6de1Macroscope's review found this PR approvable — This is a narrowly scoped preview timeout bug fix with two production changes and targeted regression tests. It preserves normal operation and host pinning while retaining bounded eviction for truly unanswered hosts, without changing contracts, product settings, or deployment behavior.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Recordings for the two-Mac reproduction described above, uploaded here so they're viewable inline. Same prompt in both runs:
preview_status, an unmatchedpreview_wait_for(2 s),preview_navigateto a page served only on Mac A'slocalhost,preview_status. Mac B, a second desktop on the same environment, has the thread's Browser panel open.- Before (
main@ fffe6e6c82): the broker evicts Mac A at the 2 s deadline and drops Mac A's own timeout reply. Navigate then goes to Mac B and fails after 15 s, and the final status shows Mac B's tab (tab_3, unavailable). The agent'stab_2is lost. - After (broker reply grace): no eviction. Navigate and status stay on Mac A's
tab_2with the page loaded. Thewait_forerror reads "failed on client" instead of "timed out" because of #15336.
Canonical issue: #12898 (open fix #12899). Cross-machine failover: #13540 (open fix #13772).
Before
https://github.com/user-attachments/assets/6c99b0b5-1948-41af-9ae2-f6733e04592a
After
https://github.com/user-attachments/assets/42225d4d-7b20-4f99-9d7c-4dba1aa56cf1
- Before (
Sign in to join this conversation.


Note
Grok responding on behalf of Julius.
Closing as superseded. This PR only targeted #15335, which was closed as a duplicate of #12898. Open fix attempt for the canonical issue: #12899.