Skip to content

fix(serve): pin Ozone to X11 for Linux headless serve - #18475

Closed
krystianmagdziarz wants to merge 1 commit into
stablyai:mainfrom
krystianmagdziarz:fix/serve-pin-ozone-x11
Closed

krystianmagdziarz wants to merge 1 commit into
stablyai:mainfrom
krystianmagdziarz:fix/serve-pin-ozone-x11

Conversation

@krystianmagdziarz

@krystianmagdziarz krystianmagdziarz commented Sep 3, 2026 •

Copy link
Copy Markdown

ELI5

On Linux, orca serve renders 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=x11 for Linux headless serve. Electron has already resolved its platform hint into that switch by the time this runs, and appendSwitch does not override a switch that already carries a value, so the resolved value is dropped with removeSwitch first. An explicit --ozone-platform on process.argv is left alone.

Why

ensureVirtualDisplayForHeadlessServe() disables the GPU unconditionally, and the offscreen browser backend renders into a hidden BrowserWindow. On Wayland that pair never paints: Page.startScreencast emits no frames and capturePage() hangs, so remote browser panes sit on "This pane is rendered from the active runtime server" while navigation, page titles, DOM and orca snapshot all keep working — nothing that needs pixels succeeds.

A systemctl --user serve unit inherits the desktop session's WAYLAND_DISPLAY / XDG_SESSION_TYPE=wayland, so Ozone selected Wayland. The function already starts Xvfb (X11) when DISPLAY is unset and documents "Offscreen serve windows require X11"; the gap was the early return when DISPLAY is 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.startScreencast observed for 10s:

ozone platform GPU frames
wayland disabled 0
wayland default 3
x11 (Xvfb) disabled 3
x11 (inherited DISPLAY=:0 via Xwayland) disabled 3

Only that one combination fails, and it is what orca serve produced. --use-gl=swiftshader does 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 DISPLAY unset 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

$ orca screenshot --format png
CDP error (Page.captureScreenshot): Screenshot timed out — the browser tab may not be
visible or the window may not have focus.

After

$ orca screenshot --format png
Screenshot captured (png, 87450 bytes)

Testing

Host: Ubuntu 25.04, GNOME/Wayland session with Xwayland on :0, orca serve run as a systemctl --user unit — the configuration that reproduces the bug.

End-to-end, against a real runtime rather than only unit tests:

  • Applied the equivalent change to a copy of the installed 1.4.195 app and ran that copy as a second serve instance on :6769 with an isolated HOME, inheriting the same DISPLAY / WAYLAND_DISPLAY / XDG_SESSION_TYPE as the live unit. Created a page against it and captured: timeout before, 87450-byte PNG after (see Visual Proof).
  • That run is also what showed a plain appendSwitch is not enough: with the guard that skipped when the switch already had a value, the GPU process still came up --ozone-platform=wayland and the capture still timed out. Dropping the resolved value first is what actually reaches X11.
  • Characterised the failure with a standalone Electron harness (hidden BrowserWindow + Page.startScreencast, 10s) to fill in the matrix above.

Automated:

  • pnpm test src/main/startup/ensure-virtual-display.test.ts — 35 passed.
  • Same tests against the unmodified upstream source file — 1 failed / 34 passed, so the new regression test does fail without the change.
  • oxlint and oxfmt --check clean on both files; tsc --noEmit -p config/tsconfig.node.json clean.

Platforms actually tested: Linux (serve host). Not tested on macOS or Windows; the changed branch is Linux-and-serve-only and returns early elsewhere.

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

Two tests added: one asserting the x11 pin (including the removeSwitch that makes it effective), one asserting an explicit --ozone-platform is 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.

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

coderabbitai Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The startup flow now pins Chromium to X11 when no explicit --ozone-platform argument exists. It removes the resolved ozone-platform switch before appending the X11 value. Tests verify the call order for a live X display and verify that an explicit Wayland argument prevents both operations.

Merge Risk: 🔵 Low · up to 77470

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning 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… Link an issue in the Linked Issue section, or create one if none exists. Complete the omitted template sections, including the Agent skill upstream boundary declaration and the relevant Notes and Checklist items.
✅ Passed checks (3 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 main change: pinning Ozone to X11 for Linux headless serve.
Full details: Description check

Explanation

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.

  • Fix all pre-merge checks with AI

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.

@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

🧹 Nitpick comments (1)
src/main/startup/ensure-virtual-display.test.ts (1)

125-126: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the required call order.

This test confirms that both calls occur, but it does not confirm that removeSwitch('ozone-platform') occurs before appendSwitch('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

📥 Commits

Reviewing files that changed from the base of the PR and between 67e2234 and 774708e.

📒 Files selected for processing (2)
  • src/main/startup/ensure-virtual-display.test.ts
  • src/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'))) {

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.

🎯 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.

Suggested change
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)

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

✅ No new issues found.

Reviewed changes

  • ensure-virtual-display.ts — adds pinOzonePlatformToX11(), invoked from configureHeadlessServeChromiumFlags(). It drops any Electron-resolved ozone-platform switch and pins x11, 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-platform in process.argv is respected.
  • ensure-virtual-display.test.ts — adds a removeSwitch mock plus two tests: one asserting the x11 pin (including the removeSwitch that makes it effective), one asserting an explicit --ozone-platform=wayland is 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.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@krystianmagdziarz

Copy link
Copy Markdown
Author

Closing this — I need to resubmit without some metadata that ended up in the commit message. Apologies for the noise.

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