Skip to content

[perf-remote] perf(renderer): park hidden remote browser screencasts - #13608

Merged
nwparker merged 3 commits into
mainfrom
nwparker/perf-remote-pause-hidden-screencasts
Aug 11, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/perf-remote-pause-hidden-screencasts

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Summary

Parks remote-browser screencasts when the Orca window stays hidden:

  • shares the emulator stream's reactive window-visibility gate with remote browser panes
  • waits 500ms before parking so a quick app switch does not reconnect the stream
  • unsubscribes the existing screencast while preserving the remote page, last frame, and page handle
  • resumes immediately when the window becomes visible or real input proves macOS visibility is stale
  • preserves the existing active/inactive-pane gate, explicit reconnect behavior, retry cancellation, and lifecycle-generation fencing

ELI5

A remote browser is a little like a video call with a browser running on another computer. Before, Orca kept asking that computer to take, compress, send, and decode new pictures even while the Orca window was minimized or covered up. Now Orca hangs up only the video feed after half a second. It leaves the browser page and its last picture in place, then reconnects the feed when you come back instead of creating a new browser page.

This is structural hardening for the observed remote-host slowdown. It is not presented as a confirmed root-cause fix for the v1.4.177 to v1.4.178 regression.

Screenshots

No visual change.

Work bounds

Scenario Before After
Active remote browser while Orca stays hidden Screencast remains subscribed indefinitely Unsubscribe is requested after the 500ms grace
Each delivered frame Host capture/JPEG work, network transfer, renderer buffer copy + Blob/object URL + image decode + three React state-write calls No new delivered-frame work after renderer teardown
Quick hide/show under 500ms Stream remains live Unchanged; the timer is canceled and no reconnect occurs
Return after parking an established page N/A Reuses the stored remote page handle and starts one replacement stream; no browser.tabCreate
Retained hidden state Live stream plus current frame One last-frame object URL and the existing remote page

The parked request is the existing JPEG-quality-70 browser.screencast, capped at 3840x2160 and configured for every second compositor frame. The bound applies per mounted active remote-browser pane. It does not park the remote page's JavaScript, session-tab mirrors, native-chat streams, file watchers, or other runtime subscriptions.

Revealing an established pane performs the existing two browser.tabShow calls, one status.get, and one new screencast subscription. It does not create another page.

The 500ms value is the requested grace. Chromium may schedule a hidden renderer timer later because background throttling remains enabled. Once cleanup runs, renderer callbacks and tokens are retired immediately; the host's existing Page.stopScreencast command retains its bounded 8-second debugger timeout.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test with ORCA_CROSS_VERSION_BASELINE_REF=v1.4.177: 4,596 files / 49,269 tests passed; 16 files / 99 tests skipped
  • pnpm build — full native packaging not run; pnpm build:electron-vite passed
  • Added or updated high-quality tests that would catch regressions

Additional checks:

  • focused remote stream + visibility suites: 52/52 tests passed
  • deterministic tests cover 499ms quick return, the 500ms park boundary, initial hidden mount, inactive pane, stale macOS visibility recovery after a completed park, cleanup, same-page reopen, one browser.tabCreate, and restored live status
  • pnpm check:code-quality:changed
  • pnpm check:react-doctor:changed
  • pnpm check:max-lines-ratchet
  • git diff --check
  • production Electron main/preload/renderer build

The unpinned suite can select an unrelated repository-history tag named v799, whose tree predates this repository layout. The full run therefore pins the intended release baseline, v1.4.177.

AI Review Report

Three read-only adversarial passes traced the renderer effect, preload/main unsubscribe path, host CDP teardown, page-handle reuse, generation fencing, retry/liveness cancellation, StrictMode replay, and the full readiness checklist.

The review loop specifically caught or closed these risks:

  • visibility had to be reactive rather than sampled once when the effect opened
  • stale macOS document.visibilityState recovery needed coverage after the stream was already parked
  • page reuse needed an assertion that reopening produces two streams for the same page with only one creation RPC
  • visibility-gating the viewport observer would introduce a late-resize/reopen race without additional cancellation, so that unrelated path stays unchanged
  • the hook harness initially recreated its fake lifecycle on render; production uses one stable lifecycle and the corrected test now models it

Final readiness verdict: no P0, P1, or production P2 findings.

The review covered SSH/relay disconnects, late subscription resolution, in-flight page creation, repeated hide/show, stale visibility, cleanup and retry bounds, mixed client/host versions, folder workspaces, macOS/Linux/Windows behavior, and mobile-facing compatibility.

Security Audit

No dependency, command execution, parser, filesystem, auth, secret, persistence, IPC/RPC method, schema, stream opcode, or remote-wire payload changes. The renderer only changes when it holds an existing validated screencast subscription. Unsubscribe retains the existing ownership checks and dedicated transport cleanup.

Notes

  • Mixed client/server versions remain compatible because no exchanged content or host behavior changes.
  • An established remote page is preserved. If its initial creation is still in flight when parking wins, the existing cancellation path closes it and a later reveal may create it again.
  • A decode already in flight is invalidated by the stream token and revokes its object URL instead of publishing a hidden frame.
  • The viewport observer remains active while hidden; a resize can issue its existing bounded viewport RPCs, but it cannot start a parked stream because restart requires a current subscription.
  • The remote page and its JavaScript intentionally remain alive, and one last frame remains retained until replacement or unmount.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@nwparker, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 6 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c8a4eefd-7481-4650-8b6d-87c60dc481e2

📥 Commits

Reviewing files that changed from the base of the PR and between 94a4756 and 48a090b.

📒 Files selected for processing (12)
  • config/localization-coverage-allowlist.json
  • config/scripts/audit-localization-coverage.mjs
  • config/scripts/audit-localization-coverage.test.mjs
  • src/renderer/src/components/browser-pane/BrowserPane.tsx
  • src/renderer/src/components/browser-pane/remote-browser-stream-lifecycle-test-harness.ts
  • src/renderer/src/components/browser-pane/remote-browser-stream-lifecycle.test.ts
  • src/renderer/src/components/browser-pane/use-remote-browser-stream-activation.test.ts
  • src/renderer/src/components/browser-pane/use-remote-browser-stream-activation.ts
  • src/renderer/src/components/emulator-pane/emulator-device-frame-visibility.test.tsx
  • src/renderer/src/components/emulator-pane/use-emulator-stream-window-visibility.ts
  • src/renderer/src/hooks/use-window-stream-visibility.test.ts
  • src/renderer/src/hooks/use-window-stream-visibility.ts
📝 Walkthrough

Walkthrough

The change adds shared window visibility tracking with delayed stream parking and stale-document recovery. The emulator visibility hook now re-exports the shared implementation. A new remote browser activation hook controls stream opening and cleanup based on pane activity and window visibility. Browser pane integration uses the new hook. Tests cover delayed parking, reopening, visibility transitions, active-pane changes, stale visibility recovery, unsubscription, and reuse of the existing remote page.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the primary performance change: parking hidden remote browser screencasts.
Description check ✅ Passed The description includes all required sections, testing details, review findings, security audit, platform coverage, and the unrun full build limitation.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch nwparker/perf-remote-pause-hidden-screencasts

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 requested a review from brennanb2025 as a code owner August 11, 2026 07:51
@nwparker nwparker closed this Aug 11, 2026
@nwparker nwparker reopened this Aug 11, 2026
nwparker and others added 3 commits August 11, 2026 01:15
Restores the WHY behind the '|| isDocumentVisibilityProvenStale()' term the
emulator-module dedupe dropped, and pins it plus the close-tab-while-parked
path with tests. Extracts the lifecycle harness so the spec stays under
max-lines without a suppression.

Co-authored-by: Orca <[email protected]>
@nwparker
nwparker force-pushed the nwparker/perf-remote-pause-hidden-screencasts branch from 037ea1b to 48a090b Compare August 11, 2026 08:17
@nwparker
nwparker merged commit 33e8d89 into main Aug 11, 2026
44 checks passed
nwparker added a commit that referenced this pull request Aug 11, 2026
The stream-gating hook (#13608) and the subscription parking installer
(#13621) each reimplemented `isWindowVisible() || isDocumentVisibilityProvenStale()`
plus its visibilitychange + stale-recovery subscription, and each carried
its own 500ms park delay that agreed only by coincidence.

Extract both into `lib/window-park-visibility.ts` and leave the two
consumers as thin wrappers: `useWindowStreamVisible` feeds the snapshot
and subscribe into `useSyncExternalStore`, the parking installer calls
them imperatively. The subscribe now always uses the defensive
`typeof document` guard the parking side already had, and registers
stale recovery before the visibilitychange listener so the stale latch
is cleared before the callback reads it.

Both park delays now derive from one `WINDOW_HIDE_PARK_GRACE_MS`: they
debounce the same signal against the same user behaviour (a quick
app-switch round trip). The parking side's 8x reveal-side backoff stays
where it is - that models its own resume cost, not the grace window.

Renderer-authoritative gating (#13622 native chat, #13634 editor panels)
is deliberately left alone; it keys off Zustand routing state, not OS
visibility.

Also switch the active-runtime ref writes in web-session-tabs-sync to
`useLayoutEffect` so no resume event can land between paint and the
passive flush, and correct the stale comment above them - the install
effect reads neither ref (both readers are gated on `isVisibilityResume`).
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#13608)

* perf(renderer): park hidden remote browser screencasts

* test(renderer): pin stale-visibility term and parked-unmount teardown

Restores the WHY behind the '|| isDocumentVisibilityProvenStale()' term the
emulator-module dedupe dropped, and pins it plus the close-tab-while-parked
path with tests. Extracts the lifecycle harness so the spec stays under
max-lines without a suppression.

Co-authored-by: Orca <[email protected]>

* fix(ci): exclude test-support modules from the localization audit

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…yai#13778)

The stream-gating hook (stablyai#13608) and the subscription parking installer
(stablyai#13621) each reimplemented `isWindowVisible() || isDocumentVisibilityProvenStale()`
plus its visibilitychange + stale-recovery subscription, and each carried
its own 500ms park delay that agreed only by coincidence.

Extract both into `lib/window-park-visibility.ts` and leave the two
consumers as thin wrappers: `useWindowStreamVisible` feeds the snapshot
and subscribe into `useSyncExternalStore`, the parking installer calls
them imperatively. The subscribe now always uses the defensive
`typeof document` guard the parking side already had, and registers
stale recovery before the visibilitychange listener so the stale latch
is cleared before the callback reads it.

Both park delays now derive from one `WINDOW_HIDE_PARK_GRACE_MS`: they
debounce the same signal against the same user behaviour (a quick
app-switch round trip). The parking side's 8x reveal-side backoff stays
where it is - that models its own resume cost, not the grace window.

Renderer-authoritative gating (stablyai#13622 native chat, stablyai#13634 editor panels)
is deliberately left alone; it keys off Zustand routing state, not OS
visibility.

Also switch the active-runtime ref writes in web-session-tabs-sync to
`useLayoutEffect` so no resume event can land between paint and the
passive flush, and correct the stale comment above them - the install
effect reads neither ref (both readers are gated on `isVisibilityResume`).
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