Repository navigation
fix(serve): pin Ozone to X11 for Linux headless serve - #18475
krystianmagdziarz wants to merge 1 commit into
Conversation
Headless serve disables the GPU and renders browser pages into a hidden BrowserWindow. That pair only paints on X11: on Wayland, Page.startScreencast emits no frames and capturePage hangs, so every remote browser pane stayed on "This pane is rendered from the active runtime server". A systemctl --user serve unit inherits the desktop session's WAYLAND_DISPLAY / XDG_SESSION_TYPE, and Electron resolves its platform hint into --ozone-platform before this code runs, so the serve path silently ran on Wayland. Appending the switch is a no-op once it carries a value, so drop the resolved one first. An explicit --ozone-platform on argv is still honoured. The path already assumed X11 -- it starts Xvfb when DISPLAY is unset -- but returned early without pinning the platform when DISPLAY was already set. Verified on Ubuntu 25.04 (GNOME/Wayland, Xwayland :0): with this change a page in a headless serve runtime captures (87450-byte PNG) where it previously failed with "Screenshot timed out -- the browser tab may not be visible". Claude-Session: https://claude.ai/code/session_01TrgJtaxJcbuwgnyUgehMMr
📝 WalkthroughWalkthroughThe startup flow now pins Chromium to X11 when no explicit Merge Risk: 🔵 Low · up to Headless serve now pins Chromium to X11 by default, but similarly named command-line arguments can inadvertently suppress that pin and retain the blank-pane and screenshot-timeout behavior in affected Linux sessions. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, implementation, rationale, visual impact, testing, platforms, and AI use. However, it does not provide the required linked issue and omits the Review, Agent skill upstream boundary, Notes, and Checklist sections.
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/startup/ensure-virtual-display.test.ts (1)
125-126: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the required call order.
This test confirms that both calls occur, but it does not confirm that
removeSwitch('ozone-platform')occurs beforeappendSwitch('ozone-platform', 'x11'). If a future change reverses the calls, this test can still pass while the resolved platform remains incorrect. Add a relative-order assertion for these two specific calls.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 455c3662-69d7-4fae-a2a1-c76c7c43347c
📒 Files selected for processing (2)
src/main/startup/ensure-virtual-display.test.tssrc/main/startup/ensure-virtual-display.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| // BrowserWindow with the GPU disabled above never paints and browser panes stay blank. Overriding | ||
| // the resolved value is the only way to reach X11; an explicit command-line choice still wins. | ||
| function pinOzonePlatformToX11(): void { | ||
| if (process.argv.some((arg) => arg.startsWith('--ozone-platform'))) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Match the complete switch name.
startsWith('--ozone-platform') also treats --ozone-platform-debug and --ozone-platformx as explicit platform selections. The helper then skips the X11 pin, so headless serve can retain the Wayland failure mode. Match only --ozone-platform or --ozone-platform=....
Proposed fix
- if (process.argv.some((arg) => arg.startsWith('--ozone-platform'))) {
+ if (process.argv.some((arg) => /^--ozone-platform(?:=|$)/.test(arg))) {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (process.argv.some((arg) => arg.startsWith('--ozone-platform'))) { | |
| if (process.argv.some((arg) => /^--ozone-platform(?:=|$)/.test(arg))) { |
🧰 Tools
🪛 ast-grep (0.45.2)
[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { spawn, type ChildProcess } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
(detect-child-process-typescript)
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
ensure-virtual-display.ts— addspinOzonePlatformToX11(), invoked fromconfigureHeadlessServeChromiumFlags(). It drops any Electron-resolvedozone-platformswitch and pinsx11, so offscreen serve windows render on X11 instead of a desktop session's Wayland (where a GPU-disabled hidden window never paints). An explicit--ozone-platforminprocess.argvis respected.ensure-virtual-display.test.ts— adds aremoveSwitchmock plus two tests: one asserting the x11 pin (including theremoveSwitchthat makes it effective), one asserting an explicit--ozone-platform=waylandis left alone.
ℹ️ One claim in the PR description is slightly off
The body states hasUsableLinuxDisplay() is "the only other reader of the switch". enableMainProcessGpuFeatures() in src/main/startup/configure-process.ts:319 also reads getSwitchValue('ozone-platform'), and it runs in serve mode before the pin (preflight invokes it at main-process-preflight.ts:316, then the pin at :319). This is benign in practice — with disable-gpu set the GPU process doesn't exist, so the Wayland-detected disable-gpu-sandbox it may append is inert — but the reasoning isn't quite complete.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Closing this — I need to resubmit without some metadata that ended up in the commit message. Apologies for the noise. |

ELI5
On Linux,
orca serverenders remote browser pages into an invisible window with the GPU turned off. That combination only produces frames on X11 — but the serve path never said "use X11", so on a host with a desktop session logged in Chromium ran on Wayland instead, the invisible window never painted, and every remote browser pane stayed blank forever. This pins the platform to X11, which is what the serve path already assumed.What Changed
configureHeadlessServeChromiumFlags()now pins--ozone-platform=x11for Linux headless serve. Electron has already resolved its platform hint into that switch by the time this runs, andappendSwitchdoes not override a switch that already carries a value, so the resolved value is dropped withremoveSwitchfirst. An explicit--ozone-platformonprocess.argvis left alone.Why
ensureVirtualDisplayForHeadlessServe()disables the GPU unconditionally, and the offscreen browser backend renders into a hiddenBrowserWindow. On Wayland that pair never paints:Page.startScreencastemits no frames andcapturePage()hangs, so remote browser panes sit on "This pane is rendered from the active runtime server" while navigation, page titles, DOM andorca snapshotall keep working — nothing that needs pixels succeeds.A
systemctl --userserve unit inherits the desktop session'sWAYLAND_DISPLAY/XDG_SESSION_TYPE=wayland, so Ozone selected Wayland. The function already starts Xvfb (X11) whenDISPLAYis unset and documents "Offscreen serve windows require X11"; the gap was the early return whenDISPLAYis set, which accepted the inherited display without pinning the platform.Measured with a standalone Electron harness on the affected host — same page, hidden
BrowserWindow,Page.startScreencastobserved for 10s:DISPLAY=:0via Xwayland)Only that one combination fails, and it is what
orca serveproduced.--use-gl=swiftshaderdoes not help (0 frames); a visible window does (3 frames), which is why the desktop app was never affected.No behaviour change for hosts that already worked: with
DISPLAYunset Orca starts its own Xvfb (X11) exactly as before.hasUsableLinuxDisplay()— the only other reader of the switch — is called solely on the non-serve path and earlier in startup, so its result cannot shift.Linked Issue
None filed — the full root cause, the measurements and the repro steps are in this PR, so a separate issue looked redundant. Happy to open one if you would rather track it separately.
The closest existing report is #11492 (macOS, visible window, compositor parked by display sleep): same symptom family, different cause and platform.
Visual Proof
N/A — no UI or interaction change; this is a Chromium startup switch. The observable difference is that pages in a headless serve runtime produce frames at all, captured here against a real serve instance on Ubuntu 25.04 (GNOME/Wayland, Xwayland
:0):Before
After
Testing
Host: Ubuntu 25.04, GNOME/Wayland session with Xwayland on
:0,orca serverun as asystemctl --userunit — the configuration that reproduces the bug.End-to-end, against a real runtime rather than only unit tests:
:6769with an isolatedHOME, inheriting the sameDISPLAY/WAYLAND_DISPLAY/XDG_SESSION_TYPEas the live unit. Created a page against it and captured: timeout before, 87450-byte PNG after (see Visual Proof).appendSwitchis not enough: with the guard that skipped when the switch already had a value, the GPU process still came up--ozone-platform=waylandand the capture still timed out. Dropping the resolved value first is what actually reaches X11.BrowserWindow+Page.startScreencast, 10s) to fill in the matrix above.Automated:
pnpm test src/main/startup/ensure-virtual-display.test.ts— 35 passed.oxlintandoxfmt --checkclean on both files;tsc --noEmit -p config/tsconfig.node.jsonclean.Platforms actually tested: Linux (serve host). Not tested on macOS or Windows; the changed branch is Linux-and-serve-only and returns early elsewhere.
Two tests added: one asserting the x11 pin (including the
removeSwitchthat makes it effective), one asserting an explicit--ozone-platformis respected.AI Disclosure
Investigated and drafted with Claude Opus 5 (Claude Code): root-cause analysis, the measurement harness, the patch and the tests, then verified end-to-end on the affected host.