Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Preview automation routes to a suspended mobile client and times out instead of failing over or reporting it #11167

Closedtuesdyaai5(GitHub profile, opens in a new tab) opened this issue 1 comment

Before submitting

  • I searched existing issues and did not find an exact duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Summary

When a T3 Connect client registers as a preview automation host and is then backgrounded (observed on the iOS app), the page gets suspended by the mobile OS. The WebSocket stays half-open but the client stops answering automation commands. The server keeps treating it as an available host, so every preview_* call is dispatched to the zombie client and fails. Multiple agents across multiple threads hit the same registered client id repeatedly (PreviewAutomationExecutionError "... failed on client preview-...", PreviewAutomationTimeoutError after 15–30s, or interruption). There is no failover to a healthy client, and preview_status keeps reporting available: true because it reflects registration, not responsiveness.

Server-side evidence observed during one session:

  • preview_status → available: true, while open / navigate / evaluate / resize / waitFor all failed or timed out against a single client id.
  • The suspended client's TCP connection showed a non-empty send queue (frames queued, peer not reading) — the half-open socket of a suspended mobile page.
  • Failures persisted across threads and agents until the mobile client returned to the foreground or the server was restarted.

Steps to reproduce

  1. Connect both a desktop client and the iOS client to a server over T3 Connect.
  2. Register a preview from the iOS client, then background the iOS app long enough for the page to be suspended.
  3. From any agent thread, call preview_status (reports available), then call preview_open or preview_navigate.

Expected behavior

  • The server health-checks preview hosts (ping/pong plus an in-flight deadline) and stops routing to unresponsive clients, failing over to a healthy host when one exists.
  • preview_status distinguishes "registered" from "responsive", and indicates which client would host the next command, so agents don't burn retries on a dead peer.
  • Mobile clients unregister or mark themselves inactive on visibility change / suspension, so the server can skip them.

Actual behavior

preview_status reports available; preview_open, preview_navigate, preview_evaluate, preview_resize, and wait-type calls fail with PreviewAutomationExecutionError ("... failed on client preview-...") or time out after 15–30s, repeatedly, until the suspended client is foregrounded/closed or the server is restarted.

Impact

Major degradation or frequent failure

  • #6355 (thread-switch detaches preview)
  • #8732 (navigate timeout misreporting)
  • #7870 (post-restart credential loss)
  1. Triage

    Confirmed as a server routing bug. The broker treats a still-registered WebSocket as a live preview host and never fails over on timeout.

    What the code does today

    PreviewAutomationBroker pins a provider session to one host (environmentId + providerSessionId) so a multi-step browser flow does not jump between independent cookie/DOM runtimes. A lease is considered live as long as that client's automation stream is still in the clients map. The only prune/failover path is an actual stream disconnect.

    That matches the tests:

    • failover happens only after the host disconnects
    • a live assignment is not moved to another capable runtime

    There is no ping/pong, last-ack, or unhealthy-client state. invoke defaults to a 15s in-flight deadline (timeoutMs; navigate/wait-style tools can go higher). On timeout it raises PreviewAutomationTimeoutError and removes the pending request only — the assignment stays, so the next preview_* call hits the same client. That produces the repeated PreviewAutomationExecutionError / PreviewAutomationTimeoutError (… failed on client preview-…) across threads.

    preview_status is not a broker health check. It is invoke("status") on the assigned host. On the desktop host, available means “this runtime has an automation bridge,” not “this peer is reading the socket.” If a cheap status still gets through (or succeeded before suspend) while later open / navigate / evaluate stall, you get exactly the reported shape: available: true plus 15–30s failures. If the peer is fully frozen, preview_status should time out too — there is still no responsive field and no “next host would be X” signal.

    Host focus is only document.hasFocus() (focus/blur). Nothing unregisters on visibilitychange, pagehide, or mobile AppState background.

    iOS repro caveat

    PreviewAutomationHosts is Electron-only (isElectron && previewBridge?.automation). apps/mobile does not call previewAutomation.connect. Client ids preview-<hex> come from the web/desktop host helper.

    So “register a preview from the iOS app, then background it” may not be reproducible on current main unless some other preview-* host (desktop renderer, or a webview running that host) is the one that froze. The server bug is still real for any half-open host: sleeping laptop, frozen renderer, partitioned TCP with a non-empty send queue.

    Mobile already reconnects the app WebSocket after ≥10s in background; that is unrelated to preview-host teardown.

    • #6355 — leaving a thread detaches the desktop preview
    • #8732 — preview_navigate reports timeout after a successful navigation
    • #7870 — preview tools vanish after server restart (in-memory MCP credentials)
    • #6317 — inverse: macOS window close drops the host
    • #8981 — desktop background-automation hardening (open)

    Suggested fix

    1. Broker (primary): on in-flight timeout / unanswered request, evict that assignment and quarantine the client (or require a health ack before reuse). Then select the next capable host in the same environment. Keep the stickiness comment in mind: failover will change cookie/DOM runtime, which is still better than pinning a dead peer.
    2. preview_status: distinguish registered vs responsive, and include the clientId that would handle the next command.
    3. Hosts (secondary): desktop/web should focusHost(false) or drop the automation stream on hide/suspend. Mobile unregister only matters once a mobile host exists.

    No code change from this triage. Happy to turn the broker eviction/failover path into a PR if you want that next.

  2. juliusmarminge added labelsbug

  3. juliusmarminge added labelsvia-triage

  4. juliusmarminge closed this

Sign in to join this conversation.