Harden preview automation reliability#4577
Conversation
Report background presentation deadlines as typed timeouts.
Bound background leases and preserve short request timeouts. Isolate queued CDP timeouts and handle hidden empty tabs.
Preserve control deadlines and screenshot recovery. Default legacy snapshot IPC and scope loopback host overrides.
- Release background capture leases when staged operations time out - Keep desktop wait operations inside caller timeout budgets
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 4 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 01debc6. Configure here.
ApprovabilityVerdict: Needs human review This PR introduces significant runtime behavior changes including bounded automation timeouts, CDP session recovery, background tab screenshot staging, and a schema change making screenshots nullable. The cross-cutting nature and new failure recovery mechanisms warrant human review. You can customize Macroscope's approvability policy. Learn more. |
- Clamp background capture staging to current renderer bounds - Share host deadlines and pass snapshot budgets through desktop IPC - Retain presentation leases until timed-out captures settle - Add focused regression coverage for all review findings
|
Follow-up to Macroscope’s approvability summary: all five inline findings were addressed in 27d0818, each thread now has a concrete resolution reply, and all review threads are resolved. The feature-focused suite passes with 11 files and 119 tests; targeted lint and affected-package typechecks also pass. |
- Use selected panel state for background capture - Bound compositor frames and release stalled staging leases - Cover panel-switch and paused-frame regressions
|
Follow-up to Macroscope's approvability summary: the two later inline findings were addressed in bfe907c and both threads are resolved. Background capture now follows selected panel state, paused compositor-frame waits release staging before desktop capture begins, and the feature-focused suite passes with 11 files and 121 tests. |

Summary
Hardens collaborative preview automation across the web host, MCP server, shared contracts, and Electron CDP controller so operations remain bounded and recoverable through cold tab startup, background-tab capture, renderer presentation races, and stalled debugger sessions.
New tabs acknowledge creation without waiting on cold renderer readiness, existing tabs retain stable visibility checks, and snapshots preserve semantic page data when raster capture is unavailable. Background snapshots keep inactive guests mounted and offscreen without changing the user's selected tab or focusing the native guest.
What Changed
capturePagefallback, PNG validation and resizing, structured failure logging, and degraded semantic snapshots withscreenshot: null.127.0.0.1for composite, web, and desktop modes without leaking the genericHOSToverride into server-only runs.BRANCH_DETAILS.md.Why
Preview automation could fail with generic execution errors or timeouts during cold startup, after an offscreen guest stalled CDP initialization, or while a background tab lacked a presentable compositor surface. Screenshot failures could also discard otherwise usable semantic page state, and staging a native guest for capture could cover the T3 interface or change the user's active tab.
These changes make automation deadlines explicit end to end, recover control sessions after stalls, decouple new-tab creation from renderer readiness, and preserve useful semantic results even when raster evidence is temporarily unavailable.
Validation
pnpm exec vp test run scripts/dev-runner.test.ts apps/desktop/src/preview/Manager.test.ts apps/server/src/mcp/McpHttpServer.test.ts apps/web/src/browser/browserSurfaceStore.test.ts apps/web/src/browser/hostedBrowserWebviewStyle.test.ts apps/web/src/components/auth/PairingRouteSurface.logic.test.ts apps/web/src/components/preview/previewAutomationOpenReadiness.test.ts apps/web/src/components/preview/previewAutomationPresentation.test.ts apps/web/src/components/preview/previewAutomationRequestConsumer.test.ts packages/contracts/src/ipc.test.ts packages/contracts/src/preview.test.tspassed with 11 files and 121 tests.@t3tools/web,@t3tools/desktop, and@t3tools/contracts.5744/13784, registered this worktree as a project, and reached its new-thread screen.git diff --check upstream/main...HEADpassed.Proof
No additional proof artifacts are included; the focused automated coverage exercises the affected deadline, capture, presentation, pairing, and contract behavior.
Note
High Risk
Wide behavioral change across CDP lifecycle, snapshot contracts (
screenshotnullable), open/readiness semantics, and timeout propagation; integrators and agents must handle null screenshots and new timeout surfaces.Overview
Preview automation is hardened across Electron, the web renderer, MCP, and contracts so operations stay within deadlines, recover from stalled CDP sessions, and still return useful semantic snapshots when raster capture fails.
Desktop (
PreviewManager) wraps control sessions in caller-aware timeouts (with response grace), lazy-attaches debuggers on register, detaches poisoned sessions on timeout without breaking queued work, and routes snapshots through CDPPage.captureScreenshotwith boundedcapturePagefallback. Screenshots are validated/resized; failures yieldscreenshot: nullwhile page state, AX tree, and diagnostics still return. Click/type/wait propagatetimeoutMs; DevTools close triggers bounded color-scheme restore.Web host adds reference-counted background capture leases (offscreen staging, compositor-frame wait, no tab focus), open policies that acknowledge new tabs immediately vs waiting for stable visibility on reused tabs, host response budgets with typed timeout errors, and pairing that reacts to
hashchangewith one-shot token claims.Contracts/MCP make snapshot
screenshotnullable; MCP omits image content when absent. Snapshot IPC gains optionalbackgroundandtimeoutMs(defaults preserve legacy behavior).Dev runner standardizes loopback URLs and Vite
HOSTon127.0.0.1for composite/web/desktop modes.BRANCH_DETAILS.mddocuments expected behavior and test command.Reviewed by Cursor Bugbot for commit bfe907c. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Harden preview automation reliability with per-operation timeouts and background capture support
PreviewAutomationHostDeadlineExceededError,PreviewAutomationTimeoutError) instead of hanging indefinitely.capturePage; the screenshot field inPreviewAutomationSnapshotis now nullable when capture fails.browserSurfaceStore.PreviewAutomationHostsuses a structured open-wait policy (resolvePreviewAutomationOpenWaitPolicy) to acknowledge new tabs immediately and conditionally wait for overlay/visibility on reused tabs.PairingRouteSurfacereplaces ref-based one-shot auto-submit with Set-based deduplication and adds ahashchangelistener to handle tokens arriving after mount.VITE_HTTP_URL,VITE_WS_URL, andVITE_DEV_SERVER_URLacross all dev modes.PreviewAutomationSnapshot.screenshotis nownull-able — consumers that assumed a non-null screenshot must handle the null case.Macroscope summarized bfe907c.