Skip to content

fix(serve): start Linux headless serve on X11 so an inherited Wayland session can't abort it - #29260

Merged
nwparker merged 3 commits into
mainfrom
nwparker/serve-xvfb-pin-x11
Oct 16, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/serve-xvfb-pin-x11

Conversation

@nwparker

@nwparker nwparker commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​254 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​248
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​99 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​98

ELI5

On Linux, orca serve can run with no screen at all: it starts its own invisible X display (Xvfb). But if the environment still says "this login session is Wayland" (common after you log out of a GNOME desktop and a systemd user service keeps running), Chromium tries to use Wayland, cannot find a Wayland display, and quits. This change makes serve start Chromium on X11, which is the display it just set up.

What Changed

  • Before: with XDG_SESSION_TYPE=wayland and no DISPLAY, orca serve prints Failed to initialize Wayland platform, exits with status 1, and never binds its port.
  • After: serve starts normally on its own Xvfb. When an X display is already set (DISPLAY=:0, for example through XWayland), serve now uses it as X11 instead of quietly running on Wayland, where its hidden browser windows never paint.

Mechanism: Chromium chooses its display platform, and locks that choice in, before Orca's main code runs. Electron's PreSandboxStartup calls OzonePlatform::PreSandboxStartup(), using the auto hint, which reads XDG_SESSION_TYPE / WAYLAND_DISPLAY / ELECTRON_OZONE_PLATFORM_HINT. So --ozone-platform=x11 has to be on the command line when the process starts. Changing app.commandLine afterwards does nothing.

  • CLI launches (orca serve, orca-ide serve, and a direct <binary> serve, which already runs through the CLI): the CLI adds --ozone-platform=x11 when it starts the Electron serve process on Linux (src/cli/runtime/launch.ts).
  • orcad's headless browser sidecar (also a serve process) gets the same switch (src/main/orcad/electron-serve-browser-process.ts).
  • A direct <binary> --serve (the command in the issue) has no CLI in front of it. Before anything else starts, the launch redirect that already exec's direct serve (src/main/startup/cli-launch-redirect.ts) now checks whether Chromium picked Wayland. If it did, it re-runs the same binary with the switch added, using the same process.execve it already uses. The process ID stays the same, so systemd, the AppImage runtime and signals keep working, and the restarted process sees the switch, so it cannot loop.
  • An explicit --ozone-platform=... on the command line is never overridden. A --ozone-platform-hint (Arch's electron-flags.conf adds one) is only a preference, so it is overridden. The desktop app (not serve), macOS and Windows are unchanged.

Why

Serve's browser panes already need X11: the code starts Xvfb even when Wayland is available. The missing piece was telling Chromium to use it. Other options I looked at:

  • Changing the switch from main-process JavaScript, as in the closed fix(serve): pin Ozone to X11 for Linux headless serve #18475 and the first version of this PR, does not work. I checked this against a real Electron 43 in a Linux container: with XDG_SESSION_TYPE=wayland it still exits with Failed to initialize Wayland platform.
  • Clearing XDG_SESSION_TYPE cannot happen before Chromium reads it unless a wrapper does it, and it would also change what child terminals inherit.
  • app.relaunch() would start a new process ID, which breaks systemd supervision. Exec keeps the same process ID.

Pinning on the CLI spawn means the common path never needs a re-exec. The re-exec only covers launches that come in without the CLI.

Not in this PR: the Xvfb left running after the old crash. On the next start, serve finds the live display on :99 and uses it again, so these do not pile up. Once X11 is pinned, Electron connects, and -terminate cleans Xvfb up as designed. After a re-exec, the two zygote helpers from the first start remain as zombie entries (already exited, using no resources) until serve exits. This happens only on the direct --serve + Wayland path.

Linked Issue

Fixes #25400

Visual Proof

N/A. Nothing in the UI changes; this is a Chromium startup switch for headless serve.

Testing

  • Real Electron 43.7.x on Linux (arm64 container, Xvfb on :99, XDG_SESSION_TYPE=wayland, no DISPLAY or WAYLAND_DISPLAY): with no change, it exits with code 1 (Failed to initialize Wayland platform). Changing app.commandLine from main also exits with code 1. With --ozone-platform=x11 on argv, it starts and capturePage returns 800x573. Exec'ing itself with the switch added first keeps the same process ID, starts, captures, and leaves no processes behind after exit.

  • New src/main/startup/headless-serve-x11-reexec.test.ts fakes Electron's platform choice. It covers every combination of XDG_SESSION_TYPE (wayland / x11 / unset), DISPLAY (set / unset) and WAYLAND_DISPLAY (set / unset), for both a direct --serve and a CLI-started launch, and checks that the result is always X11. It also covers an inherited ELECTRON_OZONE_PLATFORM_HINT=wayland, an explicit --ozone-platform=wayland, a -- terminator, desktop and macOS launches, and an exec that is unavailable or fails. With the fix stubbed out, 19 of 30 fail.

  • Tests in cli-launch-redirect.test.ts, launch.test.ts (including the Linux AppImage case) and the orcad sidecar test cover the call sites. pnpm tc and pnpm run check:code-quality:changed pass.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

SSH: serve and orcad run on remote Linux hosts; this is exactly that path. There is no wire or protocol change, so mixed client and server versions are unaffected. An older CLI starting a newer app falls back to the re-exec. Cross-platform: every new path is gated on linux.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

Next included review available in 12 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9f4d64f4-fe60-45e8-bada-d2788c0d9d39
📥 Commits

Reviewing files that changed from the base of the PR and between 83dcc7d and f17d17c.

📒 Files selected for processing: 10
  • src/cli/runtime/launch.test.ts
  • src/cli/runtime/launch.ts
  • src/main/orcad/electron-serve-browser-process.test.ts
  • src/main/orcad/electron-serve-browser-process.ts
  • src/main/startup/cli-launch-redirect.test.ts
  • src/main/startup/cli-launch-redirect.ts
  • src/main/startup/headless-serve-x11-reexec.test.ts
  • src/main/startup/headless-serve-x11-reexec.ts
  • src/shared/headless-serve-ozone-platform.test.ts
  • src/shared/headless-serve-ozone-platform.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

…dless serve

Chromium caches its Ozone platform in PreSandboxStartup, before main JS runs,
so app.commandLine changes cannot move it off Wayland. Pin X11 on the CLI and
orcad serve spawns, and re-exec in-process serve (same pid) when Electron
already resolved Wayland.
@nwparker nwparker changed the title fix(serve): pin headless Linux serve to X11 so an inherited Wayland session can't abort startup fix(serve): start Linux headless serve on X11 so an inherited Wayland session can't abort it Oct 15, 2026
@nwparker
nwparker merged commit a542367 into main Oct 16, 2026
51 checks passed
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.

[Bug]: Linux headless orca serve exits when XDG_SESSION_TYPE=wayland is set, instead of using its own Xvfb

1 participant