Skip to content

feat(serve): add --no-offscreen-browser flag - #13434

Open
IamCoder18 wants to merge 1 commit into
stablyai:mainfrom
IamCoder18:feat/serve-no-offscreen-browser
Open

IamCoder18 wants to merge 1 commit into
stablyai:mainfrom
IamCoder18:feat/serve-no-offscreen-browser

Conversation

@IamCoder18

Copy link
Copy Markdown

Summary

Adds --no-offscreen-browser to orca serve. When set, the headless runtime skips registering the OffscreenBrowserBackend, so browser pane requests from a paired remote/mobile client return null instead of spawning a Chromium BrowserWindow renderer (~50–150 MB per open pane).

Wire-through is end-to-end:

  • CLI: flag added to BOOLEAN_FLAGS, the serve spec, and the argv rewrite from CLI-form to --serve-no-offscreen-browser.
  • CLI shim: serveOrcaApp accepts noOffscreenBrowser and forwards --serve-no-offscreen-browser to the spawned Electron child.
  • Main process: ServeOptions carries the flag, parsed in getServeOptions. The offscreen backend registration at the headless branch is gated on !serveOptions.noOffscreenBrowser. ensureVirtualDisplayForHeadlessServe accepts 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 — clean
  • pnpm typecheck — clean
  • pnpm test — pnpm exec vitest run src/cli/serve-electron-flag-parity.test.ts is 11/11 pass; the parity test enumerates the spec's allowedFlags and verifies the CLI-to---serve-* argv rewrite, that serveOrcaApp spawns with the matching --serve-<flag>, and that getServeOptions reads the same name. Adding no-offscreen-browser to the spec means this test now covers the new flag end-to-end automatically. src/main/startup and src/main/browser suites 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 build exits 0. The dev binary built by build:cli + build:electron-vite was also used for the memory profiling below.
  • Added or updated high-quality tests: no new tests were added because serve-electron-flag-parity.test.ts already 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 serve 6 times across both configurations on Linux, profiling RSS of the full process tree after readiness:

Config Total RSS Notes
baseline 860 MB offscreen backend registered, no panes open
--no-offscreen-browser 860 MB identical idle cost

The 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:

  • Cross-platform compatibility: macOS and Windows are unaffected. ensureVirtualDisplayForHeadlessServe returns process.platform !== 'linux' immediately for non-Linux, so the new branch is unreachable. The CLI shim and getServeOptions paths are platform-agnostic. Shortcuts, labels, and paths are not touched. Verified by reading the new branch's location in ensureVirtualDisplayForHeadlessServe and confirming it's gated on process.platform === 'linux'.
  • SSH/remote/local: The flag only affects the headless orca serve path. 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.
  • Agent/integration compatibility: The agent hooks server and the PTY runtime are independent of the offscreen browser backend. No provider-specific code is touched.
  • Performance risk: At idle, the flag has no measurable memory impact (profiled: 860 MB → 860 MB). The Chromium flags are still applied, so Electron's main process boot cost is identical. The per-pane win is real but only when a pane is actually opened.
  • UI quality: No UI change. No new shadcn primitives, no tokens, no styling.
  • Bug caught during profiling: First cut placed configureHeadlessServeChromiumFlags() after the noOffscreenBrowser early return, which meant the --disable-dev-shm-usage flag was missing in the no-offscreen case. The Chromium gpu-process then spawned without that flag and used ~36 MB more. Fixed by moving the flag call before the early return at src/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.

  • Input handling: The flag is a boolean. It goes through the standard CLI boolean-flag pipeline (BOOLEAN_FLAGS set, argv rewrite, process.argv.includes check) — no string parsing, no path interpolation, no shell expansion.
  • Command execution: The flag is appended to the Electron child argv in serveOrcaApp. No new shell invocation. The CLI shim's childArgs.push('--serve-no-offscreen-browser') is a static string.
  • Path handling: None added.
  • Auth/secrets: None touched. The flag does not affect pairing, no-pairing, mobile-pairing, or web client URL emission.
  • Dependencies: None added.
  • IPC: No new IPC channels. The flag affects startup-time registration only. The runtime correctly returns null from getOffscreenBrowserBackend() when the backend is not set, so a paired client's browser pane request fails gracefully rather than crashing.
  • Remote wire compatibility: The new flag is host-side only and does not change anything a paired client exchanges with the host. Existing clients paired to a serve that starts with --no-offscreen-browser will 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

  • Linux only: ensureVirtualDisplayForHeadlessServe is already Linux-only; on macOS and Windows the flag is a no-op (the function returns process.platform !== 'linux' before reaching the new branch).
  • Behavior on a host with no DISPLAY and no Xvfb binary: the baseline already warns and returns false from the function; --no-offscreen-browser is equivalent in that case.
  • Operators who do not need browser panes can opt in to this flag to prevent accidental pane opens (e.g., from a paired client) and reclaim the per-pane Chromium renderer cost.
  • The Xvfb dependency in docs/reference/headless-linux-server.md remains — Electron still needs a display on Linux; the comment in ensure-virtual-display.ts:5-9 documents that --headless and --ozone-platform=headless both crash with this Electron version, so the Xvfb path is the only viable one.
  • Not in this PR: lazy Xvfb spawn (defer to first browser pane request) is a separate optimization that would compound with this flag, but it changes the existing eager-spawn contract and should be a follow-up.

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.
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 664246f4-9c8c-451e-9ca2-08c1683fb7da

📥 Commits

Reviewing files that changed from the base of the PR and between 403c60b and e3a0dc4.

📒 Files selected for processing (7)
  • src/cli/args.ts
  • src/cli/handlers/core.ts
  • src/cli/runtime/launch.ts
  • src/cli/specs/serve.ts
  • src/main/index.ts
  • src/main/startup/ensure-virtual-display.ts
  • src/main/startup/serve-mode-argv.ts

📝 Walkthrough

Walkthrough

The serve command now supports --no-offscreen-browser. The flag is parsed, documented, forwarded to the Orca process, and normalized to --serve-no-offscreen-browser. Headless serve mode passes the option to virtual-display initialization, skips display setup when disabled, and avoids installing the offscreen browser backend.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the new --no-offscreen-browser flag for the serve command.
Description check ✅ Passed The description covers the required summary, screenshots, testing, AI review, security audit, and platform-specific notes with detailed verification.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

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.

@IamCoder18

Copy link
Copy Markdown
Author

Yay review passes! Hope this gets merged. This is my first PR here!

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants