Skip to content

fix(window): pump hidden-window frames from the renderer on Windows background launches - #34197

Merged
nwparker merged 4 commits into
mainfrom
nwparker/win-hidden-window-frame-keepalive
Oct 27, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/win-hidden-window-frame-keepalive

Conversation

@nwparker

@nwparker nwparker commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​206 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​206
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​145 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​144

ELI5

When Orca is started hidden for automation on Windows (ORCA_BACKGROUND_LAUNCH=1), its window is never shown. Since #33799 removed the last always-running animation, that idle hidden window produced no frames, so a CDP screenshot waited forever. Now the page itself changes one pixel-dark shade for a single frame every 750 ms while hidden. That gives Windows a frame to capture, and nobody can see it.

What Changed

Before: on Windows, an idle hidden main window never produced a compositor frame, so Page.captureScreenshot hung, even though the renderer was otherwise alive (evaluate, rAF and screencast all worked).

After:

  • Main (createMainWindow): only on win32 with ORCA_BACKGROUND_LAUNCH=1, main adds a preload flag (--orca-hidden-window-frame-pump, via additionalArguments) to the never-shown main window. On that window's first show, main sends window:hidden-frame-pump-stop. It sends it again after any later reload, because the reloaded preload restarts the pump.
  • Preload (src/preload/hidden-window-frame-pump.ts): when the flag is present, every 750 ms it sets document.documentElement's inline background-color to rgb(1, 1, 1) inside one requestAnimationFrame and restores it on the next one.
    • The restore puts back the previous inline value and its !important priority exactly, or removes the property if there was none.
    • Flips never overlap.
    • Only main's stop message ends it. It doesn't react to visibilitychange, because Windows can report a never-shown window as visible after a desktop change, and stopping then would bring the hang back. A flip already in progress still restores.
    • Closing the window ends the renderer.
  • Flag-off: normal launches, macOS and Linux never get the flag, so no preload timer exists.

Why

  • The first version didn't work: a main-process webContents.invalidate() every 750 ms on Windows. On the Windows 11 machine (session 0, packaged CI build) it still timed out, the same as main. A never-shown window ignores a main-side invalidate.
  • What did work there: renderer-side damage. Flipping the root background for one frame inside rAF every 750 ms made captureScreenshot return in 2.0 s. This PR ships exactly that.
  • No better hook exists: a CDP screenshot request from an external debugger can't be seen by Orca, so a periodic one-frame flip is the only hook.
  • Keeps perf(renderer): keep modal blur with independent source regions #33799's GPU-memory win: the usage chip's pulse stays gone.

Linked Issue

N/A (main break: hidden-window CDP validation required by AGENTS.md).

Visual Proof

N/A: there's no visible change. The flip happens only in windows that are never shown, lasts one frame and uses near-black.

Testing

On Windows 11 (session 0, packaged build, raw CDP, about 10–15 s idle):

  • with ORCA_BACKGROUND_LAUNCH=1, main and the earlier invalidate version time out;
  • the renderer-side flip returns in 2.0 s;
  • without the env var, everything returns in 0.1 s.

This branch is being re-verified on the same Windows machine before merge.

On macOS: the hang doesn't reproduce here. To check the wiring, I temporarily enabled the gate for darwin and built. Through CDP I saw the root style attribute gain background-color: rgb(1, 1, 1) and then return to its exact prior value, about every 750 ms, and the screenshot returned in 29 ms. The gate was then restored to win32 only.

Unit tests (21 across 4 files, including the createMainWindow suite):

  • Gate: on only for win32 with the env var; off for darwin, linux and without it.
  • Preload flag round-trip.
  • Main stop-on-show:
    • no stop while never shown, even across reloads;
    • stops on first show and again after a reload;
    • skips destroyed contents.
  • Preload installer: starts only with the flag and hands main the stop.
  • Preload pump:
    • flips one frame and removes what it added;
    • restores an existing inline value and priority exactly;
    • never overlaps;
    • stop cancels the interval but a flip already in progress still restores.

Other checks: oxlint, the ast-grep gates and the changed-code gate pass. pnpm tc reports only two errors already on main, in files this PR does not touch: agent-account-restart-startup.ts, fixed by #34203, and doc-preview-external-link-confirmation.test.ts.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Who is affected: only hidden automation launches on Windows. In production, ORCA_BACKGROUND_LAUNCH=1 is set only by short-lived preflights that never create the main window. The orcad browser sidecar uses ORCA_ORCAD_SIDECAR instead and is deliberately out of scope. There's no SSH, mobile or wire impact.
  • Windows e2e runs: the hidden main window now paints one frame every 750 ms. A Windows spec that measures idle frames or watches root inline style mutations would see that.
  • Follow-up if needed: the hidden workspace window and dashboard popout aren't flagged. If a Windows harness needs screenshots of them, they need the same flag.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The main window enables the hidden-window frame pump only on Windows when ORCA_BACKGROUND_LAUNCH is "1". It passes a pump argument to the renderer while preserving the browser host ID argument. The preload flips the root background style on a 750 ms interval and restores the prior inline value and priority. The main window sends a stop signal on the first show event and after later load completions. Added tests cover the enablement conditions, style changes, stop behavior, and lifecycle events.

Priority: Normal

Merge Risk: Low · up to 1923c

A late window event could cause an error after close. Capture the web contents reference before merging, or accept this narrow lifecycle risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title follows the conventional commit style and names the main change: the renderer pumps hidden-window frames on Windows background launches. It matches the changeset, which adds a preload frame …
Description check Passed The description follows the repository template closely. It has an ELI5 section, a What Changed section with before and after behavior and mechanism, a Why section that explains the rejected invalidat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title follows the conventional commit style and names the main change: the renderer pumps hidden-window frames on Windows background launches. It matches the changeset, which adds a preload frame pump gated to win32 with ORCA_BACKGROUND_LAUNCH=1 and wires main-process stop-on-show behavior. It is 87 characters, slightly long but still specific and readable.

Full details: Description check

Explanation

The description follows the repository template closely. It has an ELI5 section, a What Changed section with before and after behavior and mechanism, a Why section that explains the rejected invalidate approach, Testing with platforms covered (Windows 11, macOS) and unit test coverage, and Notes on affected users. Two gaps remain: the Linked Issue section reads 'N/A (main break...)' with no issue reference, although the template says an issue should always exist for outside contributors, and the AI Disclosure section is empty. The final pnpm checklist item is unchecked, and the Visual Proof section has an N/A reason. The description is mostly complete, so the check passes, but the missing linked issue should be addressed.

Full details: Docstring Coverage

Explanation

Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 10 functions across 8 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nwparker
nwparker force-pushed the nwparker/win-hidden-window-frame-keepalive branch from 2bc7bee to 5f5d9df Compare October 27, 2026 02:11
@nwparker nwparker changed the title fix(window): repaint a never-shown background window on Windows so CDP screenshots return fix(window): pump hidden-window frames from the renderer on Windows background launches Oct 27, 2026
…P screenshots return

Windows composites nothing for an idle window that was never shown, so
Page.captureScreenshot under ORCA_BACKGROUND_LAUNCH=1 waited forever once the
status-bar usage chip stopped animating (#33799).
…ackground launches

Main-process webContents.invalidate() did not make a never-shown Windows window
produce a frame CDP can capture (verified on Windows 11). A one-frame root
background flip from the preload does, so main stamps a preload flag for
ORCA_BACKGROUND_LAUNCH=1 on win32 and tells the preload to stop on first show.
…ncluding after reloads

A never-shown Windows window can report visible after a desktop change, so the
preload no longer stops on visibilitychange; main re-sends the stop after any
reload once the window has been shown.
@nwparker
nwparker force-pushed the nwparker/win-hidden-window-frame-keepalive branch from 7ab3ebb to ff6ad2a Compare October 27, 2026 03:01
…ndow double supports it

createMainWindow suites simulate win32 under the runner's ORCA_BACKGROUND_LAUNCH=1,
so they install the pump stop; their window doubles implement on() but not once().

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 960a0b5a-3fc9-4d5c-bdb5-08693ea26429
Commits

Reviewing files that changed from the base of the PR and between 7ab3ebb and 1923c10.

Files selected for processing: 2
  • src/main/window/hidden-window-frame-pump.test.ts
  • src/main/window/hidden-window-frame-pump.ts

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

export function stopHiddenWindowFramePumpOnShow(window: FramePumpWindow): void {
let shown = false
const stop = (): void => {
if (window.webContents.isDestroyed?.() !== true) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Stability & Availability · Quick win

Supported by static analysis

Script executed:

set -u
echo "== hidden-window-frame-pump.ts =="
test -f src/main/window/hidden-window-frame-pump.ts && cat -n src/main/window/hidden-window-frame-pump.ts || echo "MISSING"
echo
echo "== main-window-focus-lifecycle.ts =="
test -f src/main/window/main-window-focus-lifecycle.ts && cat -n src/main/window/main-window-focus-lifecycle.ts || echo "MISSING"
echo
echo "== call sites / references =="
rg -n -F -e 'stopHiddenWindowFramePumpOnShow' -e 'hidden-window-frame-pump' -- src || test "$?" -eq 1
echo
echo "== createMainWindow.ts (relevant region) =="
test -f src/main/window/createMainWindow.ts && rg -n -F -e 'FramePump' -e 'did-finish-load' -e 'loadURL' -e 'loadFile' -e 'ready-to-show' -e "'show'" -- src/main/window/createMainWindow.ts || echo "MISSING"

Repository: stablyai/orca

Length of output: 20007


Capture webContents once in stopHiddenWindowFramePumpOnShow.

stop() reads window.webContents at call time. The BrowserWindow.webContents getter throws after the window closes, and the repository documents that late webContents events can still arrive. A did-finish-load that fires after close can therefore reach stop() and throw in the main process. Capturing the reference at install time avoids the getter. isDestroyed() on the captured object still returns true after close, so the guard skips the send. Reloads keep the same webContents object, so the first-show and reload behavior is unchanged.

🐛 Suggested fix
--- "a/src/main/window/hidden-window-frame-pump.ts"
+++ "b/src/main/window/hidden-window-frame-pump.ts"
@@ -10,22 +10,23 @@
 }
 
 /** The preload pumps from birth; stop it on first show and after any later reload restarts it. */
 export function stopHiddenWindowFramePumpOnShow(window: FramePumpWindow): void {
   let shown = false
+  const webContents = window.webContents
   const stop = (): void => {
-    if (window.webContents.isDestroyed?.() !== true) {
-      window.webContents.send(HIDDEN_WINDOW_FRAME_PUMP_STOP_CHANNEL)
+    if (webContents.isDestroyed?.() !== true) {
+      webContents.send(HIDDEN_WINDOW_FRAME_PUMP_STOP_CHANNEL)
     }
   }
   window.on('show', () => {
     if (!shown) {
       shown = true
       stop()
     }
   })
-  window.webContents.on('did-finish-load', () => {
+  webContents.on('did-finish-load', () => {
     if (shown) {
       stop()
     }
   })
 }

@nwparker
nwparker merged commit e882d8e into main Oct 27, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant