Repository navigation
feat(serve): add --no-offscreen-browser flag - #13434
IamCoder18 wants to merge 1 commit into
Conversation
Skips registering the offscreen BrowserWindow backend in headless 'orca serve'. Browser pane requests from a paired client will return null instead of spawning a Chromium renderer (~50-150 MB per open pane). Wire-through: - CLI: add flag to BOOLEAN_FLAGS, spec, argv rewrite - Shimmer: forward --serve-no-offscreen-browser to the spawned Electron child - Main: parse flag, gate runtime.setOffscreenBrowserBackend, skip Xvfb spawn (Chromium flags still applied so Electron boots without a display) At idle with no browser panes open, RSS is unchanged from baseline (verified across 6 profiling runs on Linux). The savings materialize only when a remote client opens a browser pane.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThe 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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 |
|
Yay review passes! Hope this gets merged. This is my first PR here! |
Summary
Adds
--no-offscreen-browsertoorca serve. When set, the headless runtime skips registering theOffscreenBrowserBackend, so browser pane requests from a paired remote/mobile client return null instead of spawning a ChromiumBrowserWindowrenderer (~50–150 MB per open pane).Wire-through is end-to-end:
BOOLEAN_FLAGS, theservespec, and the argv rewrite from CLI-form to--serve-no-offscreen-browser.serveOrcaAppacceptsnoOffscreenBrowserand forwards--serve-no-offscreen-browserto the spawned Electron child.ServeOptionscarries the flag, parsed ingetServeOptions. The offscreen backend registration at the headless branch is gated on!serveOptions.noOffscreenBrowser.ensureVirtualDisplayForHeadlessServeaccepts the flag and skips the Xvfb subprocess spawn — but still applies the headless Chromium flags (disableHardwareAcceleration,disable-dev-shm-usage,disable-gpu) so Electron can boot without an X server, since the main process itself still needs a display on Linux.Screenshots
No visual change. This is a CLI flag affecting server-only behavior.
Testing
pnpm lint— cleanpnpm typecheck— cleanpnpm test—pnpm exec vitest run src/cli/serve-electron-flag-parity.test.tsis 11/11 pass; the parity test enumerates the spec'sallowedFlagsand verifies the CLI-to---serve-*argv rewrite, thatserveOrcaAppspawns with the matching--serve-<flag>, and thatgetServeOptionsreads the same name. Addingno-offscreen-browserto the spec means this test now covers the new flag end-to-end automatically.src/main/startupandsrc/main/browsersuites pass (794/794).pnpm build— full build pipeline runs clean:typecheck,build:relay,build:cli,build:electron-vite,verify:built-skills-cli(393 closure files + 5 commands pass),build:web-from-renderer(861 files, 41.8 MiB),build:native(skipped macOS computer build on Linux).pnpm run buildexits 0. The dev binary built bybuild:cli+build:electron-vitewas also used for the memory profiling below.serve-electron-flag-parity.test.tsalready covers the wiring end-to-end (CLI spec, argv rewrite, launch.ts, getServeOptions). A test that asserts the actual offscreen-backend-skip behavior would need a paired client and Electron runtime, which is out of scope for the unit suite and better suited to e2e.Memory profiling
Built the dev binary and ran
orca serve6 times across both configurations on Linux, profiling RSS of the full process tree after readiness:--no-offscreen-browserThe offscreen backend is already lazy at the per-pane level, so the per-process savings only kick in when a remote client opens a browser pane (~50–150 MB per pane).
AI Review Report
Reviewed the change with the assistant. Main risks checked:
ensureVirtualDisplayForHeadlessServereturnsprocess.platform !== 'linux'immediately for non-Linux, so the new branch is unreachable. The CLI shim andgetServeOptionspaths are platform-agnostic. Shortcuts, labels, and paths are not touched. Verified by reading the new branch's location inensureVirtualDisplayForHeadlessServeand confirming it's gated onprocess.platform === 'linux'.orca servepath. Local desktop and SSH worktree flows are not touched.initializeBrowserSessionsForApp(the session registry) is still called at startup, so runtime profile commands continue to work.configureHeadlessServeChromiumFlags()after thenoOffscreenBrowserearly return, which meant the--disable-dev-shm-usageflag was missing in the no-offscreen case. The Chromiumgpu-processthen spawned without that flag and used ~36 MB more. Fixed by moving the flag call before the early return atsrc/main/startup/ensure-virtual-display.ts:114. Re-profiled: both configs now identical at idle.Security Audit
Reviewed for input handling, command execution, path handling, auth, secrets, dependencies, and IPC.
BOOLEAN_FLAGSset, argv rewrite,process.argv.includescheck) — no string parsing, no path interpolation, no shell expansion.serveOrcaApp. No new shell invocation. The CLI shim'schildArgs.push('--serve-no-offscreen-browser')is a static string.getOffscreenBrowserBackend()when the backend is not set, so a paired client's browser pane request fails gracefully rather than crashing.--no-offscreen-browserwill see the same wire shape they would for any serve; only browser-pane RPCs will fail with null, which the existing runtime handles.No follow-up needed.
Notes
ensureVirtualDisplayForHeadlessServeis already Linux-only; on macOS and Windows the flag is a no-op (the function returnsprocess.platform !== 'linux'before reaching the new branch).DISPLAYand noXvfbbinary: the baseline already warns and returnsfalsefrom the function;--no-offscreen-browseris equivalent in that case.docs/reference/headless-linux-server.mdremains — Electron still needs a display on Linux; the comment inensure-virtual-display.ts:5-9documents that--headlessand--ozone-platform=headlessboth crash with this Electron version, so the Xvfb path is the only viable one.