fix(server): tell agents when a preview tab fell back to the headless browser#22894

open2
main
fix/issue-22882
opened6d agobyJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 6d ago

Problem

When a desktop webview attaches after the ten-second wait, automation keeps using its headless fallback without telling the agent that the desktop has a different cookie store. This addresses #22882.

Change

Add one optional desktopFallback field to preview open/status and snapshot results. It reports attach-timeout, then late-attach if the desktop attaches afterward, including while fallback creation is pending. Late attachment logs a warning and keeps the active page stable. Adopted popups inherit the fallback signal. The contract explains the separate cookie store and close-first retry procedure.

Scope and approval

Fixes #22882

Triaged bug via the automated issue flow.

Verification

Validation:

  • Before implementation: two regression tests failed, with 22 existing tests passing. Open/status/snapshot payloads omitted the fallback signal.
  • After implementation: 27 ServerBrowser tests and 3 contract tests pass. Payloads show desktopFallback: "attach-timeout" after timeout and desktopFallback: "late-attach" after the later attachment.
  • Tests advance TestClock through the supplied attach timeout and deliver the attached event through the fake desktop channel. Coverage includes attachment while context creation is pending and adopted popups. Removing the pending-tab wait makes the creation-race test fail.
  • Targeted lint, formatting, and server/contracts typechecks pass.
  • Codex GPT-6.1-Sol and Claude Opus 5.5 code reviews: MERGE.
  • Independent evidence audits from both models: SUFFICIENT for the server-side signal. The existing production channel timer is not exercised; the creation-race branch proof relies on the recorded mutation failure under current scheduling.
  • cannot-verify desktop live: this VM has no desktop app. Verification uses the ServerBrowser harness and fake desktop channel.

Implementation and tests: GPT-6.1-Sol through the Codex harness in T3 Code. Review and evidence audit: GPT-6.1-Sol/Codex and Claude Opus 5.5/Claude Agent SDK.

Checks

24 successful · 10 skipped
All checks passed
647f882

Added 2 commits

  • fix(server): preserve desktop fallback state for preview popups647f882
  • fix(server): surface desktop browser fallback state8ee38af
Synced from GitHub

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 KiB0 B (0.0%)6.8 KiB✅
ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
ClaudeLive turn messages220 (0.0%)8✅

Baseline: 448b8a9 · PR result: 647f882 · 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.

Synced from GitHub

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: 6db225c8-d01d-465a-8ccb-ae345e00396b
📥 Commits

Reviewing files that changed from the base of the PR and between 448b8a918694e84137f850c6526d75aacfb2292d and 647f882675cc6cf8c312b65bdfb1424e9e8e165f.

📒 Files selected for processing: 3
  • apps/server/src/preview/ServerBrowser.test.ts
  • apps/server/src/preview/ServerBrowser.ts
  • packages/contracts/src/previewAutomation.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

📝 Walkthrough

Preview tabs now record whether desktop attachment timed out or arrived late. Open, status, and snapshot results report this state, and adopted popups inherit it. Late attachment waits for pending tab creation, then marks the existing headless tab as late-attach without replacing it.

Changes: Desktop attach fallback

Layer / File(s)Summary
Fallback status and reporting
packages/contracts/src/previewAutomation.ts, apps/server/src/preview/ServerBrowser.ts, apps/server/src/preview/ServerBrowser.test.ts
The status and snapshot contracts include the optional desktopFallback field. Status and snapshot results return the tab's value. Tests cover reporting attach-timeout.
Timeout fallback and late attach
apps/server/src/preview/ServerBrowser.ts, apps/server/src/preview/ServerBrowser.test.ts
Tabs created before desktop attachment is established receive attach-timeout. Late attach handling waits for pending tab creation and marks the existing fallback tab as late-attach. Tests cover timeout fallback and late-attach timing.
Popup fallback inheritance
apps/server/src/preview/ServerBrowser.ts, apps/server/src/preview/ServerBrowser.test.ts
Adopted popups inherit the opener's fallback state and context. Tests cover both fallback states.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

mermaid
1sequenceDiagram
2 participant DesktopAttachStream
3 participant ServerBrowser
4 participant ContextProvider
5 participant PreviewTab
6 DesktopAttachStream->>ServerBrowser: Attachment times out
7 ServerBrowser->>ContextProvider: Create headless context
8 ContextProvider-->>ServerBrowser: Return context and page
9 DesktopAttachStream->>ServerBrowser: Send late attach event
10 ServerBrowser->>ServerBrowser: Wait for pending tab creation
11 ServerBrowser->>PreviewTab: Set late-attach and retain existing page

Possibly related issues

  • pingdotgg/t3code#22882 — The issue describes a late desktop webview attach after the wait period; this change reports the late attach state and exposes fallback status.
  • pingdotgg/t3code#16901 — The issue describes desktop and server pages diverging after delayed attachment; this change retains the existing headless tab when a late attach arrives.

Suggested reviewers: maria-rcks

Merge Risk: ⚪ Minimal · up to 647f8

The fallback status, late-attach handling, and popup inheritance are ready to merge after normal checks.

Pre-merge checks: Passed 4
Check nameStatusExplanation
Title checkPassedThe title clearly describes the primary server change: reporting when a preview tab falls back to the headless browser.
Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
Description checkPassedThe description includes all required sections, links issue #22882, explains the change, and provides detailed verification results and limitations. The scope section does not include an explicit main…
Full details: Description check

Explanation

The description includes all required sections, links issue #22882, explains the change, and provides detailed verification results and limitations. The scope section does not include an explicit maintainer approval comment, but the description is otherwise complete and focused.

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

Synced from GitHub

Approvability

Verdict: Approved at 647f882

Macroscope's review found this PR approvable — The PR adds an optional fallback-status signal for preview automation and preserves it across late desktop attachment and popup adoption without swapping the active page. Runtime impact is localized, backward-compatible, and covered by focused regression tests.

You can add or adjust custom eligibility rules. Learn more.