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 |
ApprovabilityVerdict: Needs human review Diff is too large for automated approval analysis. A human reviewer should evaluate this PR. 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. |
- Preserve upstream attribution for single-origin browser dev - Document optional preferred ports and collision handling
…ion-reliability # Conflicts: # apps/desktop/src/preview/Manager.test.ts # apps/desktop/src/preview/Manager.ts # apps/server/src/mcp/toolkits/preview/tools.ts # apps/web/src/browser/HostedBrowserWebview.tsx # apps/web/src/browser/browserSurfaceStore.ts # apps/web/src/browser/hostedBrowserWebviewStyle.test.ts # apps/web/src/browser/hostedBrowserWebviewStyle.ts # apps/web/src/components/preview/PreviewAutomationHosts.tsx # apps/web/src/components/preview/previewAutomationOpenReadiness.test.ts # apps/web/src/components/preview/previewAutomationOpenReadiness.ts
- Preserve namespaced active surface identifiers across inline previews - Keep timeout diagnostics consistent for hidden and competing surfaces - Restore complete behavior-level branch documentation
- preserve bounded preview automation around upstream changes - adopt normalized preview action results and registration safeguards 🤖 Co-authored by GPT-5 in Codex via Codex
…ion-reliability # Conflicts: # apps/web/src/components/preview/previewAutomationOpenReadiness.ts # packages/contracts/src/ipc.ts
- resolve browser defaults once per automation open request - pass one presentation decision into reused-tab readiness - document merged defaults and focused verification results 🤖 Co-authored by GPT-5 in Codex via T3 Code
- hydrate browser defaults before reading the open request session - prevent reused-tab opens from mixing server epochs 🤖 Co-authored by GPT-5 in Codex via T3 Code
There was a problem hiding this comment.
UI consistency review: one accessibility-semantics finding on the new background-capture staging path in HostedBrowserWebview.tsx. Everything else in scope (shared Input/Button usage in PairingRouteSurface.tsx, inline wrapper geometry kept in hostedBrowserWebviewStyle.ts, no global CSS or primitive overrides) looks consistent.
Posted via Macroscope — UI Consistency
- reject expired open mutations before starting side effects - clamp viewport polling and revalidate runtime identity - hide inactive capture guests from host assistive technology - document focused tests and integrated verification limits 🤖 Co-authored by GPT-5 in Codex via T3 Code
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 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 6716ed7. Configure here.
- Bound failed recording-start cleanup and always release its slot - Retry appearance changes when a replacement rejects the stale command - Reuse validated artifact keys across desktop save timeout retries 🤖 Co-authored by GPT-5 in Codex via T3 Code

PR id: 4577
PR url: #4577
PR title: Harden preview automation reliability
PR target: pingdotgg/t3code:main
PR head: Quicksaver:fix/preview-automation-reliability
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, runtime guest replacement, renderer presentation races, and stalled debugger sessions.
New tabs acknowledge creation without waiting on cold renderer readiness, reused tabs retain stable visibility checks, and exact epoch-scoped runtime guest ids keep automation aligned with the intended Electron target. Snapshots preserve semantic page data when raster capture is unavailable, while one-shot background capture stages the retained inactive guest without changing the user's selected tab or focusing the native guest.
What Changed
timeouts so increasing a requested timeout never reduces its execution window.
capturePagefallback, PNG validation and resizing, structured failure logging, and degraded semantic snapshots withscreenshot: null.deadline while reserving time for fallback capture and semantic result
settlement.
skips CDP capture before any command starts.
PreviewAutomationTargetUnavailableErrorwhen a server-epoch change replaces the runtime guest, preventing stale operations from adopting the replacement target.so short open requests do not overshoot their deadline.
resize, reveal, and navigation mutations so expired open requests cannot
start late side effects after settings or session synchronization.
revalidated epoch-scoped runtime identity after every awaited guest read.
HOSToverrides, while preserving IPv6 proxying for explicit IPv6 backend binds.host accessibility tree without affecting CDP accessibility snapshots.
dev:desktopruns under<base>/userdata/electronso a worktree desktop does not reuse incompatible IndexedDB state from an installed or earlier development profile.BRANCH_DETAILS.md.Why
Preview automation could fail with generic execution errors or timeouts during cold startup, after an offscreen guest stalled CDP initialization, when a background tab lacked a presentable compositor surface, or when a server epoch replaced the runtime guest during an in-flight operation. Screenshot failures could also discard otherwise usable semantic page state, staging a native guest could cover the T3 interface, and isolated desktop development could inherit incompatible persisted browser state.
These changes make automation deadlines and target identity explicit end to end, recover control sessions after stalls, decouple new-tab creation from renderer readiness, isolate development profiles, and preserve useful semantic results even when raster evidence is temporarily unavailable.
Validation
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/browserRecording.test.ts apps/web/src/browser/browserSurfaceStore.test.ts apps/web/src/browser/hostedBrowserWebviewStyle.test.ts apps/web/src/browser/browserViewportActions.test.ts apps/web/src/browser/browserViewportLayout.test.ts apps/web/src/browser/previewRuntimeTabId.test.ts apps/web/src/components/auth/PairingRouteSurface.logic.test.ts apps/web/src/components/preview/previewAutomationOpenReadiness.test.ts apps/web/src/components/preview/previewAutomationOverlayReadiness.test.ts apps/web/src/components/preview/previewAutomationPresentation.test.ts apps/web/src/components/preview/previewAutomationRequestConsumer.test.ts apps/web/src/components/preview/previewNavigationReadiness.test.ts apps/web/src/components/preview/previewViewportReadiness.test.ts apps/web/src/components/preview/previewViewportRollback.test.ts packages/contracts/src/ipc.test.ts packages/contracts/src/preview.test.tspassed all 287 tests across 19 files. The two unchanged desktop path-fixture files omitted from this Windows run retain eight documented POSIX-versus-Windows assertion failures.open, monotonic short-deadline handling, remaining desktop input budgets,
non-throwing best-effort settling, bounded overlay status calls, post-status
runtime replacement rejection, deadline-clamped presentation, overlay,
navigation, and visibility polling, handled delayed capture rejection, and
snapshot rejection after a server-epoch replacement.
appearance work detaches cleanly, does not persist a late preference, and
lets queued evaluation reattach before sending its first command.
RegistryContextaccess inPreviewAutomationHosts.tsx; none are in the follow-up changes.dev:desktopinstance using the worktree user-data override paired successfully and remained usable through repeated renderer/CDP inspection and raster capture; an archive worktree client loaded its seeded project without the previous IndexedDBVersionError.5744/13784completed first-navigation pairing, loaded the seeded Preview Reliability thread, and rendered the right-panel surface chooser. The non-Electron client could not exercise the Browser surface.5744/13784paired through Playwright, loaded the React app shell, and reported no browser-console errors. The affected mutation paths remain Electron-only and therefore cannot execute in the non-Electron web client; focused renderer, contracts, server, and desktop tests cover their deadline and cleanup behavior.git diff --check upstream/main...HEADpassed.Proof
No additional proof artifacts are included. Product-native hidden, non-selected
preview_snapshotcapture is not covered end to end in the isolated worktree desktop because the controlled web client is non-Electron and agent preview tools may remain attached to the installed T3 Code host; focused automated coverage exercises the target identity, deadline, capture, presentation, pairing, and contract behavior.Note
High Risk
Changes span security-adjacent automation (CDP, screenshots, recording artifacts), core desktop preview infrastructure, and nullable snapshot contracts that all MCP/web consumers must handle.
Overview
This PR makes collaborative preview automation bounded and recoverable across the renderer, MCP layer, contracts, and Electron PreviewManager.
Desktop CDP and snapshots: Automation operations run under monotonic execution budgets with response grace; control sessions initialize lazily, detach on timeout without breaking unrelated queued work, and support stale-session retry. Snapshots prefer CDP compositor capture (with a target-bridge path for background tabs), fall back to
capturePage, validate PNGs, and return semantic data withscreenshot: nullwhen raster capture fails. Color scheme, recording start/stop, and artifact save accept deadlines; saves use an idempotency key for retries.Web renderer: Reference-counted background presentation stages nearly transparent guests for one-shot snapshots without focusing native UI; surface subscriptions are scoped per runtime tab. The automation consumer maps broker stalls to
PreviewAutomationTimeoutErrorand clamps polling and bridge calls to remaining budgets. Open/readiness policies distinguish new vs reused tabs and abort on runtime guest replacement.Contracts / MCP: Snapshot screenshots are nullable; MCP omits image content when capture is missing. Tool handlers propagate
timeoutMsfor press, scroll, appearance, and recording.Other:
T3CODE_DESKTOP_USER_DATA_DIRisolates worktree Electron profiles;/pairclaims tokens from later hash changes with a serialized submission queue;BRANCH_DETAILS.mddocuments behavior and verification.Reviewed by Cursor Bugbot for commit b584620. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Harden preview automation reliability with execution budgets, background snapshots, and deadline-bounded recording
PreviewAutomationHost) and request consumer, rejecting withPreviewAutomationHostDeadlineExceededErrorwhen the budget is exhausted instead of awaiting indefinitely.PreviewManager, replacingwc.capturePage; snapshot results may now carry a null screenshot when neither capture path succeeds.timeoutMsfrom MCP tools through IPC handlers to the desktop bridge and native operations.stopBrowserRecording/finalizeBrowserRecordingso stop-deadline failures preserve captured chunks for a subsequent retry.previewAutomationOverlayReadiness,previewAutomationPresentation,previewViewportReadiness) with strict deadline-clamped polling loops.HostedBrowserWebviewvia reference-counted leases inbrowserSurfaceStore, rendering a near-transparent webview above the active surface without intercepting pointer events.DesktopPreviewBridgeinterface signatures are extended with new required parameters; implementors must updatesetColorScheme,startScreencast,stopScreencast,saveScreencast, andsnapshot.Macroscope summarized b584620.