fix(preview): keep one browser page across thread switches #18873
main fromt3/takeover-pr-18584-fixes·opened View on GitHubAgents 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:
After closing the panel and switching threads, sign-in and saved page state remain:

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
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge added labelsmacroscope-review
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅ Codex Live turn messages 2 2 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB −24 B (−0.5%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB −24 B (−2.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB −41 B (−0.2%) 29.3 KiB ✅ Claude Live turn messages 2 1 −1 (−50.0%) 8 ✅ Baseline:
5d6e419· PR result:b9fa58f· Source CI: successScenario 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.
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.tsapps/desktop/src/ipc/methods/preview.tsapps/desktop/src/preload.tsapps/desktop/src/preview/DesktopBrowserHost.test.tsapps/desktop/src/preview/DesktopBrowserHost.tsapps/desktop/src/preview/Manager.tsapps/server/src/preview/Manager.test.tsapps/server/src/preview/Manager.tsapps/server/src/preview/ServerBrowser.test.tsapps/server/src/preview/ServerBrowser.tsapps/server/src/preview/ServerBrowserPage.test.tsapps/server/src/preview/ServerBrowserPage.tsapps/web/src/browser/ElectronBrowserHost.tsxapps/web/src/browser/HostedBrowserWebview.test.tsxapps/web/src/browser/agentFrameRequests.test.tsapps/web/src/browser/agentFrameRequests.tsapps/web/src/browser/previewRuntime.test.tsapps/web/src/browser/previewRuntime.tsapps/web/src/components/preview/PreviewView.test.tsxapps/web/src/components/preview/PreviewView.tsxapps/web/src/components/preview/ThreadPreviewMiniPlayer.tsxapps/web/src/components/preview/previewFallback.test.tsxapps/web/src/components/preview/usePreviewBridge.test.tsapps/web/src/components/preview/usePreviewBridge.tspackages/contracts/src/ipc.tspackages/contracts/src/preview.test.tspackages/contracts/src/preview.tspackages/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.tsPreview snapshots and automation status include an optional nativeorheadlessserver 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.tsThe 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.tsxScreenshot 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.tsWeb 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 tabSuggested reviewers:
maria-rcks,juliusmarminge
Merge Risk: ⚪ Minimal · up to
b9fa5The reviewed changes preserve the native tab across thread switches, with no confirmed issue requiring a fix before merge.
Pre-merge checks ·
6-
Passed checks (6 passed)-
Check name Status Explanation Description check The 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 check The description identifies the primary issue as #16901and explains the relationship to replacement PR#18584and reused work from#18217. The stated changes align with the linked issue objective.Out of Scope Changes check The 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 check The title clearly and concisely describes the primary change: preserving one browser page across thread switches. Linked Issues check Issue #16901requires one page for the agent and the browser panel after a late desktop attach.ServerBrowser.tsnow selects and recordsserverPageMode, keeps a selectedheadlesspage across rea…Out of Scope Changes check The 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
-
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?
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
178095052028e6c46066736ada5e69ec256b0ec39b1a6df8b182b9d9e6bced2eand contains the 10-second desktop attach wait and the existing-tab early return in theattachedhandler. Separately inspected main was13aa882c22d584de5388dfce3b3ca413387ba059; that is not an attribution of the installed build.Observed sequence while completing Workana onboarding:
- 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.
- A fresh
preview_open({profileId:"default", reuseExistingTab:false, open:true, url:"https://www.workana.com/worker-onboarding-steps"})took about 11.3 seconds and returnedavailable:true,visible:false, viewport 1280x800. It redirected to login (301), then a Cloudflare verification page (403), rather than the user's form. - A subsequent fresh open returned in about 2 seconds, without a viewport field. This time
preview_snapshotread 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_statusstill answered promptly withavailable:true, the onboarding URL, andloading:false. We could not verify the selections persisted. - A fresh background tab again took about 12 seconds and reached login/verification. We closed that diagnostic tab through
t3_preview_closeand 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.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
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).