Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(preview): keep browsers that answer at their own deadline #15338

ClosedPixPMusic(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/15338/headopened View on GitHub

Problem

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

  • PreviewAutomationBroker waits timeoutMs + 2.5s before treating a request as unanswered. Hosts still receive the original timeoutMs, 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 answers waitFor with a timeout exactly at timeoutMs, while a focused host on another machine is connected. On main, the next navigate fails on the other host with Preview 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 after preview_click goes unanswered. On main, the next preview_status fails; 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 run for PreviewAutomationBroker.test.ts, McpHttpServer.test.ts, and toolkits/preview: 68 passed. Server tsc --noEmit clean; lint and format clean for apps/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 localhost only. Same prompt both runs: preview_status, an unmatched preview_wait_for (2 s), preview_navigate to 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: closeConnection at the deadline, then Mac A's respond, then reconnect.
    • After: no eviction. Mac A's answer is accepted, navigate and status stay on Mac A's tab_2 with 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).
BeforeAfter
RecordingRecording
Session moved to the other Mac's tab after the timeoutSession stays on the original tab

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

    2. 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.

    3. juliusmarminge closed this

    4. Approvability

      Verdict: Approved at 38e6de1

      Macroscope'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).
    5. Recordings for the two-Mac reproduction described above, uploaded here so they're viewable inline. Same prompt in both runs: preview_status, an unmatched preview_wait_for (2 s), preview_navigate to a page served only on Mac A's localhost, 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's tab_2 is lost.
      • After (broker reply grace): no eviction. Navigate and status stay on Mac A's tab_2 with the page loaded. The wait_for error 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

Sign in to join this conversation.