Skip to content

fix(desktop): agent screenshots of an unwatched preview wait for its animations - #41233

Open
juliusmarminge wants to merge 1 commit into
mainfrom
factory/issue-34707-a1795408351
Open

juliusmarminge wants to merge 1 commit into
mainfrom
factory/issue-34707-a1795408351

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

When the T3 window was minimized or covered, an agent's first screenshot of a background preview tab could show an animation half done, even long after it should have finished. Chromium defers a guest's animations while it is not drawn, so they only started once the capture made the tab draw. Now a screenshot of a guest that was not already drawn first lets the page settle: it waits two frames, then waits for its running finite animations to finish, capped at 1 second. Screenshots of an already-drawn guest are unchanged.

Fixes #34707

Reproduction on main

Commit: origin/main 9d3054a. Machine: pooled Mac, macOS 26.6.2 arm64, T3CODE_DEV_SEED=0 vp run dev:desktop (fresh worktree database, onboarding completed with a click). A local page at http://127.0.0.1:8765/ exposes window.go(n), which replaces a full-viewport red div and runs el.animate([{opacity:0},{opacity:1}],{duration:150}). Project added with t3 project add; each pass was a Claude Haiku thread started with t3 thread start <proj> <prompt> --provider claudeAgent --model haiku --wait, prompting: preview_open url=http://127.0.0.1:8765/ open=false (Browser panel never shows it), then 8 times: preview_evaluate (async()=>{const r=window.go(N);await new Promise(r2=>setTimeout(r2,600));return r})() followed by preview_snapshot save=true. The centre pixel of each saved screenshot was sampled (pure rgb(255,0,0) = fade finished). Results: window in front 0/8 mid-fade; window minimized (AXMinimized) 1/8 mid-fade (run 1 = rgb(255,122,122)); minimized again 1/8 (run 1 = rgb(255,125,125)); window fully covered by a full-screen Finder window 1/8 (run 1 = rgb(255,115,115)). In each hidden pass the first snapshot is caught at about half opacity, 600 ms after a 150 ms fade began; the later ones are finished. Unlike the report, on this macOS 26.6.2 Mac the covered and minimized snapshots on main did not time out (#23139 was not hit). Evidence (left: minimized run 1 mid-fade, right: run 2 finished): https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/5ec50978cfe11a11/compare.png

Evidence

Being captured: before and after in the real app. This section is filled in before the pull request can merge.

Tests

  • vp test run src/preview/DesktopBrowserHost.test.ts (apps/desktop): 44 passed, including the extended 'sends a screenshot once the client draws the guest at full detail, or soon after' case
  • vp run check:changed: format, lint, knip, typecheck (2 packages) and the test file all passed
  • Real Electron probe under headless-desktop running the settle expression: 150 ms fade returned in 183 ms with opacity 1; infinite animation and no animation each returned in about 50 ms

Not in this change

  • A visible guest whose client never reports it drawn at full detail already waits the full 1 s CAPTURE_DRAW_WAIT before every screenshot.
  • document.getAnimations() only covers the top document, so animations inside iframes are not waited for.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 23, 2026
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Undrawn guest captures now wait for page animations to settle after the draw wait. The wait has a one-second limit. Already-drawn guests still proceed to capture immediately.

Changes: Guest capture timing

Layer / File(s) Summary
Animation settling and capture ordering
apps/desktop/src/preview/DesktopBrowserHost.ts, apps/desktop/src/preview/DesktopBrowserHost.test.ts
The host waits for two animation frames and finite running animations, with a one-second fallback, before capturing an undrawn guest. Tests verify the evaluation-before-screenshot order and that capture proceeds when the evaluation remains unanswered.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: homemadetoast57

Merge Risk: Minimal · up to 8ff70

Screenshots of undrawn preview guests now wait briefly for finite animations to settle, capped at one second. Already-drawn guests are unchanged. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change (agent screenshots of an unwatched preview wait for animations) and the scope (desktop). It matches the main change in DesktopBrowserHost.ts and its test: undrawn guests now…
Description check Passed The description follows the template sections: Problem, Change, Scope, Verification, and the agent attribution line. The Problem and Change sections are clear and explain the root cause (Chromium defe…
Linked Issues check Passed Issue #34707 requires that a screenshot of an undrawn preview guest show animations in their settled state. The diff to apps/desktop/src/preview/DesktopBrowserHost.ts adds settleAnimations, which runs…
Out of Scope Changes check Passed The code diff touches only DesktopBrowserHost.ts (new constants, settleAnimations helper, and its use in paintUntilAnswered) and its test file. Every hunk serves the settle-before-capture objective fr…
Full details: Title check

Explanation

The title names the change (agent screenshots of an unwatched preview wait for animations) and the scope (desktop). It matches the main change in DesktopBrowserHost.ts and its test: undrawn guests now wait for a page-side animation settle before capture. It is specific and follows the conventional commit style of the template.

Full details: Description check

Explanation

The description follows the template sections: Problem, Change, Scope, Verification, and the agent attribution line. The Problem and Change sections are clear and explain the root cause (Chromium defers animations while a guest is not drawn) and the fix (settle step with a 1 s cap). Scope links issue #34707. Verification lists focused tests and a real Electron probe, with observed results. The Evidence section is a placeholder that says it will be filled in before merge, so a before/after screenshot or recording is still missing. The template requires visual evidence for UI-timing changes, so this is a gap to close before merge. The description also says the reproduction on main did not hit the covered-window timeout, which is useful context. Overall the description is mostly complete.

Full details: Linked Issues check

Explanation

Issue #34707 requires that a screenshot of an undrawn preview guest show animations in their settled state. The diff to apps/desktop/src/preview/DesktopBrowserHost.ts adds settleAnimations, which runs before send() in paintUntilAnswered only when the guest is not in drawnTabs. The page-side SETTLE_ANIMATIONS script waits two requestAnimationFrame frames, then waits for running animations whose effect endTime is finite (Number.isFinite), then waits one more frame. Infinite animations are excluded, as the issue asks. Already-drawn guests still send at once, as the issue expects. The host also resolves after 1 second on its own timer, so an unresponsive page only delays the capture. The test file change extends the screenshot timing test to check that Runtime.evaluate runs before the capture, and that capture proceeds after 1 second when the settle command never answers. Deviation noted: the issue proposed a cap of at most 500 ms, and the PR uses 1 second (CAPTURE_SETTLE_WAIT). The issue presents its fix as a possible direction, and the expected behavior (fade finished at snapshot time) is met by the implementation. The PR also reports a main reproduction that did not hit the covered-window timeout. That finding does not change the code requirement. The author's test and probe results were not re-run in this review; the assessment relies on the diff.

Full details: Out of Scope Changes check

Explanation

The code diff touches only DesktopBrowserHost.ts (new constants, settleAnimations helper, and its use in paintUntilAnswered) and its test file. Every hunk serves the settle-before-capture objective from #34707. The PR description's non-code sections (evidence placeholder, reproduction notes, authorship) are not code changes. The stated exclusions (CAPTURE_DRAW_WAIT behavior for never-drawn visible guests, iframe animations) are documented limits, not out-of-scope edits.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7e5a439 and 8ff7030.

Files selected for processing: 2

  • apps/desktop/src/preview/DesktopBrowserHost.test.ts
  • apps/desktop/src/preview/DesktopBrowserHost.ts

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Agent screenshots of an unwatched desktop preview catch animations mid-way

1 participant