fix(desktop): a stalled capture no longer freezes picture-in-picture #24057
main fromrefs/pull/24057/head·merged by maria-rcks View on GitHubProblem#
Picture-in-picture frame capture (capturePreviewFrame in apps/desktop/src/preview/Manager.ts, operation frameCapture.capturePage) awaits wc.capturePage() with no timeout. The comment above CAPTURE_PAGE_ATTEMPT_TIMEOUT_MS in the same file says cold guests can reject capturePage or never settle it. When a capture never settles:
- While opening PiP:
openPictureInPicturerunsstartFrameCaptureand only then callsshowInactive. The initial frame capture hangs, so the PiP window stays hidden. The tab'spictureInPicturestate is never published and the session'sreadydeferred never completes. A second PiP click for the same tab waits onreadyforever. - While PiP is running: the frame loop captures one frame at a time (
Effect.forever(sleep → capturePreviewFrame)). One stalled capture freezes the loop for good, and nothing is logged.
Change#
The PiP capture now uses the same bound as capturePageWithRetry and the recording warmup from #20085: Effect.timeout(CAPTURE_PAGE_ATTEMPT_TIMEOUT_MS), with the TimeoutError mapped to PreviewOperationError. Both callers already handle that error. The initial capture logs "Initial background preview frame was not ready; capture will retry." and PiP opens anyway. The loop logs "Background preview frame capture failed." and moves on to the next tick. Like the warmup, the underlying native capturePage can't be cancelled. We just stop waiting for it, and once the scope or webContents has changed, a late result is ignored by the existing checks.
Scope and approval#
This is a very small, focused fix for an obvious bug, so it doesn't need a prior issue. Manager.ts already documents that capturePage can stall and bounds every other capturePage call with CAPTURE_PAGE_ATTEMPT_TIMEOUT_MS: screenshots through capturePageWithRetry, and the recording warmup added in #20085. The PiP frame capture is the one call site that missed it. The change reuses the existing constant and error-mapping pattern and doesn't change any product behavior beyond PiP recovering instead of hanging.
Verification#
I added a regression test to apps/desktop/src/preview/Manager.test.ts: "shows picture-in-picture and keeps capturing after stalled captures". It is an it.effect test on TestClock, with no sleeps or real timeouts. The fake guest's first two capturePage calls never settle (the initial PiP frame and the first loop tick), and later calls resolve. The test opens PiP and advances the clock by 1000 ms. It then asserts that the window was shown and the open completed. Finally it advances another 500 ms and asserts that the loop delivered a frame to the PiP window.
vp test run apps/desktop/src/preview/Manager.test.ts -t "shows picture-in-picture and keeps capturing after stalled captures"
- Before the fix (unmodified
Manager.ts): fails withAssertionError: expected "vi.fn()" to be called once, but got 0 timesonpictureInPictureWindow.showInactive. The PiP window is never shown. - After the fix:
Tests 1 passed | 55 skipped.
An earlier run of the full file with the fix applied (vp test run apps/desktop/src/preview/Manager.test.ts) passed 56/56.
vp run check:changed upstream/main: format, lint, knip, typecheck (2 packages) and test (1 file) all pass.
Not checked: I did not reproduce a genuinely cold guest whose capturePage never settles in the running desktop app. The stall is simulated with a never-settling promise, based on the failure mode the file already documents.
Implemented with Claude Opus 5.5 via Claude Code (running in T3 Code).
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
165ec9cMacroscope's review found this PR approvable — This focused fix adds the existing 1-second capture timeout to PiP frame capture, allowing initialization and the recurring loop to recover from stalled native calls. The accompanying regression test covers the stalled initial and loop captures, with no product-default or static-analysis changes.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: d7a8d6f
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
c625a803-096b-4f35-9e46-4a46fb49b432
📥 Commits
-
Reviewing files that changed from the base of the PR and between d7a8d6f32001444e013aa07c8a468ce3e987f9cf and 165ec9c92661bb5978f2218308489cf2f6b43c95.
📒 Files selected for processing: 2
-
apps/desktop/src/preview/Manager.test.tsapps/desktop/src/preview/Manager.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
-
📝 Walkthrough
-
The preview manager now limits picture-in-picture frame captures to 1,000 ms and maps timeout failures to
PreviewOperationError. A test checks window visibility and resumed capture updates while captures are stalled.Changes: Picture-in-picture frame capture
Layer / File(s) Summary Bound picture-in-picture frame capture
apps/desktop/src/preview/Manager.ts,apps/desktop/src/preview/Manager.test.tscapturePreviewFrameapplies a 1,000 ms timeout tocapturePage()and maps timeout failures toPreviewOperationError. The test checks that the picture-in-picture window becomes visible and that a later capture update occurs while captures remain unresolved.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related issues
pingdotgg/t3code#7212— The timeout bounds a picture-in-picturecapturePage()attempt, but the reported error-state handling is not added.
Suggested reviewers:
juliusmarminge
Merge Risk: 🔵 Low · up to
165ec-
Picture-in-picture can recover from stalled captures, but a prolonged stall may leave pending captures accumulating. This is a bounded follow-up risk, not a demonstrated merge blocker.
Pre-merge checks:
4-
Check name Status Explanation Description check The description includes all required sections. It explains the stalled-capture problem, the timeout-based fix, the focused scope rationale, regression test coverage, verification results, and the unt… Title check The title clearly and concisely describes the primary fix: preventing stalled captures from freezing picture-in-picture. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Description check
-
Explanation
The description includes all required sections. It explains the stalled-capture problem, the timeout-based fix, the focused scope rationale, regression test coverage, verification results, and the untested cold-guest scenario.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Note
Written by
gpt-6.1-solon behalf of MariaVerified in a real dev environment#
verified unchanged head
165ec9c92661bb5978f2218308489cf2f6b43c95on this linux vm. installed both checkouts withvp i, ran background dev stacks one at a time, and exercised the real electron desktop client with playwright. projects and threads were created through the app; real codexgpt-6.1-solturns completed on both main and the pr and reported their actual checkout sha.reproduced the failure on
github/main(6575ce3250) using browser > preview menu > "Open separate preview window". briefly suspended only the task-owned native gpu process, leaving the app and server running. no mock or replacement ofcapturePagewas used.same native stall, sampled after 3.5 seconds: main: pip visible=false; appears only after gpu resumes pr: pip visible=true while gpu is still suspended pr: initial capture logs TimeoutError after 1s pr: background captures log TimeoutError and retry resume: real 539 x 870 page frames arrive page-down: delivered frame changes (53,711 -> 54,951 bytes)the blank pip window during suspension is expected because the native gpu cannot produce a frame. it receives the real github page after resume. close/reopen also works, and "Capture screenshot" saves a valid 539 x 870 png, which i opened and inspected.
blacksmith-check:vp i && vp test run apps/desktop/src/preview/Manager.test.tspassed all 56 tests. no source changes or pushes were needed.before, main stays hidden during the native stall:

after, the pr opens picture-in-picture during the stall and restores frames:

the original mp4 recordings were watched completely; uploaded playback and seeking passed. these animated copies preserve the full ten seconds. inline animation was checked on github; the git.cafe web view currently reduces external media to links. command transcript.
Not verified#
macos, windows, native ios/android, and recording start/stop. i did not reproduce a spontaneous cold-guest hang or leave native captures permanently stalled; the reproduced stall was induced by suspending the real gpu for about four seconds. long-term accumulation of unresolved native captures remains unverified.
a shell-quoting error while preparing this comment also accidentally invoked the test locally; that invocation failed during setup with
TypeError: Cannot read properties of undefined (reading 'config'). the deliberate remote blacksmith run above passed all 56 tests.maria-rcks merged thisae45ccd
maria-rcks closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes