Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(preview): keep one browser page across thread switches #18873

Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 7 commits intomain fromt3/takeover-pr-18584-fixesopened View on GitHub

Agents and the Browser panel can show different pages for one tab when the desktop attaches late. Hidden desktop screenshots can also wait forever and block later browser tools.

Keep the existing headless page and stream it to every client. A late desktop attach cannot replace its cookies, DOM, form state, downloads, or recording. Native tabs still render in the desktop. Hidden native captures request frames even when their thread shell is missing; active turns retain their frame lease. Captures stop waiting after five seconds, without blocking later actions or starting overlapping captures.

Replacement for #18584. The six original commits and their authorship are preserved. Reuses Davide Sala's streaming work from #18217, with co-author credit, excluding its separate profile-recovery change. Fixes #16901.

Verification

  • 154 focused tests across 11 files pass. Tests cover late attach, preserved downloads and recordings, close/retry races, native frame leases, and the next action after capture timeout.
  • Server, desktop, web, and contracts typechecks pass. Scoped lint and formatting pass with existing React warnings.
  • One integrated check against isolated test state: sign in, type and save a note, close the panel, switch threads, return, and reopen. The same page state remains.
  • Real Electron hidden-webview fixture: capture stayed pending without frame-request delivery, then completed in 196 ms with delivery. This uses the actual host, relay, renderer lease, and webview style. It does not exercise the entire packaged desktop IPC chain.
  • Web/desktop panel and floating preview paths updated. Remote and mobile clients keep streaming through the existing server path; native mobile was not tested. No provider-specific behavior or user guidance changes.

Evidence

Reported split before the fix:

Reported split: one tab, two pages

After closing the panel and switching threads, sign-in and saved page state remain:

Same signed-in page after returning

Browser continuity recording · Hidden native capture

New evidence is hosted externally because the available Browser profile is not signed in to GitHub for attachment upload. No evidence files are committed.

Original work by Theo Browne with Claude Opus 5.5 in Claude Code. Streaming contribution by Davide Sala. Reworked and verified with GPT-6.1 Sol in Codex.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. juliusmarminge added labelsmacroscope-review

    3. Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR changes browser-page ownership, native versus headless rendering, reconnect behavior, and screenshot capture across server, desktop, web, and shared contracts. Its broad cross-layer runtime impact and changed default fallback behavior require human review despite extensive focused tests.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
      CodexLive turn messages220 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB−24 B (−0.5%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB−24 B (−2.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB−41 B (−0.2%)29.3 KiB✅
      ClaudeLive turn messages21−1 (−50.0%)8✅

      Baseline: 5d6e419 · PR result: b9fa58f · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    5. Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Team
      • Run ID: 0d01fdbe-1541-49ec-9745-7ade95cb0d96
      📥 Commits

      Reviewing files that changed from the base of the PR and between 5d6e4192bfcf9eca09741605e12c72b5970025e4 and b9fa58f765e44c374c2bfbffaa07f9d0f240b102.

      📒 Files selected for processing (28)
      • apps/desktop/src/ipc/channels.ts
      • apps/desktop/src/ipc/methods/preview.ts
      • apps/desktop/src/preload.ts
      • apps/desktop/src/preview/DesktopBrowserHost.test.ts
      • apps/desktop/src/preview/DesktopBrowserHost.ts
      • apps/desktop/src/preview/Manager.ts
      • apps/server/src/preview/Manager.test.ts
      • apps/server/src/preview/Manager.ts
      • apps/server/src/preview/ServerBrowser.test.ts
      • apps/server/src/preview/ServerBrowser.ts
      • apps/server/src/preview/ServerBrowserPage.test.ts
      • apps/server/src/preview/ServerBrowserPage.ts
      • apps/web/src/browser/ElectronBrowserHost.tsx
      • apps/web/src/browser/HostedBrowserWebview.test.tsx
      • apps/web/src/browser/agentFrameRequests.test.ts
      • apps/web/src/browser/agentFrameRequests.ts
      • apps/web/src/browser/previewRuntime.test.ts
      • apps/web/src/browser/previewRuntime.ts
      • apps/web/src/components/preview/PreviewView.test.tsx
      • apps/web/src/components/preview/PreviewView.tsx
      • apps/web/src/components/preview/ThreadPreviewMiniPlayer.tsx
      • apps/web/src/components/preview/previewFallback.test.tsx
      • apps/web/src/components/preview/usePreviewBridge.test.ts
      • apps/web/src/components/preview/usePreviewBridge.ts
      • packages/contracts/src/ipc.ts
      • packages/contracts/src/preview.test.ts
      • packages/contracts/src/preview.ts
      • packages/contracts/src/previewAutomation.ts

      Included review availability: This review used your included allowance. 9 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 10 reviews per hour.

      📝 Walkthrough

      Walkthrough

      The change adds explicit native or headless backing to server preview sessions. Server browser selection and status use that mode. Screenshot requests can notify the desktop to keep a tab drawing, while web previews select the native surface or server stream based on the reported mode.

      Changes

      Server preview rendering and capture

      Layer / File(s)Summary
      Page-mode contract and session state
      packages/contracts/src/preview.ts, packages/contracts/src/previewAutomation.ts, packages/contracts/src/preview.test.ts, apps/server/src/preview/Manager.ts, apps/server/src/preview/Manager.test.ts
      Preview snapshots and automation status include an optional native or headless server page mode. The server manager accepts and updates that mode for server sessions and publishes resize events when it changes.
      Server page selection and lifecycle
      apps/server/src/preview/ServerBrowser.ts, apps/server/src/preview/ServerBrowser.test.ts
      The server browser selects and reports page backing, preserves headless mode during reattachment, and handles popup adoption, tab closure, and fallback behavior. Tests cover these paths and tab limits.
      Frame-capture request and drawing lease
      apps/server/src/preview/ServerBrowserPage.ts, apps/server/src/preview/ServerBrowserPage.test.ts, apps/desktop/src/preview/DesktopBrowserHost.ts, apps/desktop/src/preview/DesktopBrowserHost.test.ts, apps/desktop/src/preview/Manager.ts, apps/desktop/src/ipc/*, apps/desktop/src/preload.ts, packages/contracts/src/ipc.ts, apps/web/src/browser/ElectronBrowserHost.tsx, apps/web/src/browser/agentFrameRequests.ts, apps/web/src/browser/agentFrameRequests.test.ts, apps/web/src/browser/HostedBrowserWebview.test.tsx
      Screenshot capture rejects overlapping requests and times out after five seconds. Matching desktop frame requests are forwarded to web listeners, which hold drawing activity for the tab and release it when appropriate.
      Web rendering by server page mode
      apps/web/src/browser/previewRuntime.ts, apps/web/src/browser/previewRuntime.test.ts, apps/web/src/components/preview/PreviewView.tsx, apps/web/src/components/preview/PreviewView.test.tsx, apps/web/src/components/preview/ThreadPreviewMiniPlayer.tsx, apps/web/src/components/preview/previewFallback.test.tsx, apps/web/src/components/preview/usePreviewBridge.ts, apps/web/src/components/preview/usePreviewBridge.test.ts
      Web previews do not select native rendering or desktop overlays for headless server tabs. Tests cover switching to the server stream and clearing desktop state.

      Priority: ➖ Normal

      Estimated code review effort: 4 (Complex) | ~45 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Sequence Diagram(s)

      sequenceDiagram
        participant ServerBrowserPage
        participant DesktopBrowserHost
        participant PreviewManager
        participant installPreviewEventForwarding
        participant DesktopPreload
        participant ElectronBrowserHost
        ServerBrowserPage->>DesktopBrowserHost: Send Page.captureScreenshot command
        DesktopBrowserHost->>PreviewManager: Publish frame request with tab key
        PreviewManager->>installPreviewEventForwarding: Deliver matching tab ID
        installPreviewEventForwarding->>DesktopPreload: Send preview frame-request IPC
        DesktopPreload->>ElectronBrowserHost: Notify onFrameRequest listener
        ElectronBrowserHost->>ElectronBrowserHost: Hold frames for the requested tab

      Suggested reviewers: maria-rcks, juliusmarminge

      Merge Risk: ⚪ Minimal · up to b9fa5

      The reviewed changes preserve the native tab across thread switches, with no confirmed issue requiring a fix before merge.

      Pre-merge checks · Passed 6
      Passed Passed checks (6 passed)
      Check nameStatusExplanation
      Description checkPassedThe description explains the problem, change, scope, verification, test results, limitations, and evidence. It does not use every template heading or include an explicit maintainer approval comment, b…
      Linked Issues checkPassedThe description identifies the primary issue as #16901 and explains the relationship to replacement PR #18584 and reused work from #18217. The stated changes align with the linked issue objective.
      Out of Scope Changes checkPassedThe changes across server, desktop, web, contracts, and tests directly support browser-page continuity, native/headless rendering, frame capture leases, and capture timeouts. No unrelated changes are …
      Title checkPassedThe title clearly and concisely describes the primary change: preserving one browser page across thread switches.
      Linked Issues checkPassedIssue #16901 requires one page for the agent and the browser panel after a late desktop attach. ServerBrowser.ts now selects and records serverPageMode, keeps a selected headless page across rea…
      Out of Scope Changes checkPassedThe changed files support the same preview ownership and streaming behavior. The frame-request IPC, capture leases, five-second capture timeout, and retry protection keep hidden streamed pages usable …
      ✨ Finishing Touches
      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.
    6. Thanks for carrying over the streaming work from #18217. My change addressed the agent/panel split by preserving the headless page. The frame leases complement that by keeping hidden native tabs rendering for capture across thread switches. Good to see the timeout and in-flight guard too, so a stalled capture doesn’t hold up subsequent browser actions. P.S. For the co-author credit, could you use my verified email linked to @davidesala23?

    7. Additional packaged-desktop evidence from 17 October, with the user's permission. This is a report from the installed app, not validation of this PR.

      Environment: T3 Code (Beta), macOS 26.6.1 arm64, Codex provider (GPT-6.1-Sol). Installed Info.plist reports version/build 0.1.0; we could not establish its source commit. The read-only server bundle extract has SHA-256 178095052028e6c46066736ada5e69ec256b0ec39b1a6df8b182b9d9e6bced2e and contains the 10-second desktop attach wait and the existing-tab early return in the attached handler. Separately inspected main was 13aa882c22d584de5388dfce3b3ca413387ba059; that is not an attribution of the installed build.

      Observed sequence while completing Workana onboarding:

      1. The user's integrated Browser panel showed the authenticated onboarding form. The agent's tools on the corresponding tab showed a public/signed-out page; the panel's address bar could follow the agent's URL while its content remained on onboarding.
      2. A fresh preview_open({profileId:"default", reuseExistingTab:false, open:true, url:"https://www.workana.com/worker-onboarding-steps"}) took about 11.3 seconds and returned available:true, visible:false, viewport 1280x800. It redirected to login (301), then a Cloudflare verification page (403), rather than the user's form.
      3. A subsequent fresh open returned in about 2 seconds, without a viewport field. This time preview_snapshot read the actual onboarding form. Two click calls returned success. A later click rejected a stale ref; refreshing the snapshot then timed out. Both a snapshot retry and a minimal DOM evaluation timed out at 15 seconds. preview_status still answered promptly with available:true, the onboarding URL, and loading:false. We could not verify the selections persisted.
      4. A fresh background tab again took about 12 seconds and reached login/verification. We closed that diagnostic tab through t3_preview_close and preserved the form tab.

      Raw errors:

      Preview snapshot failed: Preview automation snapshot timed out after 15000ms.
      Preview automation evaluate timed out after 15000ms.

      These observations fit both page divergence (#16901) and a stalled operation blocking later work (#16921). We did not capture desktop attachment timing, a paused debugger, or a capture stack, so the exact stall cause is unproven. We also did not isolate thread switching as its trigger.

      Useful packaged-desktop acceptance checks for this PR: the user and agent read/write the same harmless form after a thread switch; a hidden-tab capture completes or times out and the next DOM operation still works; status identifies the actual page backing. The distinction between continuity and profile recovery also matters: preserving and streaming an existing headless page fixes the two-page confusion, but this case does not establish recovery of a login entered in the separate Electron page. We understand that profile recovery is outside this PR.

      Reported by Codex on the user's behalf. No account identifiers, cookies, credentials, or private screenshots are included.

    8. Note

      🤖 Claude Opus 5.5 responding on behalf of Theo

      Closing in favor of #22877. It fixes the same two bugs in about 130 lines. Main already covers part of this work: #19919 opens background agent tabs in the desktop, and #20446 stops a stuck snapshot after 10 s.

Sign in to join this conversation.