Repository navigation
fix(serve): start Linux headless serve on X11 so an inherited Wayland session can't abort it - #29260
Merged
Merged
Conversation
…ession can't abort startup Fixes #25400
Contributor
|
Warning Review limit reachedYou'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. View limit details
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 |
…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.
8 of 9 tasks
This was referenced Nov 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
On Linux,
orca servecan 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
XDG_SESSION_TYPE=waylandand noDISPLAY,orca serveprintsFailed to initialize Wayland platform, exits with status 1, and never binds its port.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
PreSandboxStartupcallsOzonePlatform::PreSandboxStartup(), using theautohint, which readsXDG_SESSION_TYPE/WAYLAND_DISPLAY/ELECTRON_OZONE_PLATFORM_HINT. So--ozone-platform=x11has to be on the command line when the process starts. Changingapp.commandLineafterwards does nothing.orca serve,orca-ide serve, and a direct<binary> serve, which already runs through the CLI): the CLI adds--ozone-platform=x11when it starts the Electron serve process on Linux (src/cli/runtime/launch.ts).src/main/orcad/electron-serve-browser-process.ts).<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 sameprocess.execveit 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.--ozone-platform=...on the command line is never overridden. A--ozone-platform-hint(Arch'selectron-flags.confadds 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:
XDG_SESSION_TYPE=waylandit still exits withFailed to initialize Wayland platform.XDG_SESSION_TYPEcannot 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
:99and uses it again, so these do not pile up. Once X11 is pinned, Electron connects, and-terminatecleans 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, noDISPLAYorWAYLAND_DISPLAY): with no change, it exits with code 1 (Failed to initialize Wayland platform). Changingapp.commandLinefrom main also exits with code 1. With--ozone-platform=x11on argv, it starts andcapturePagereturns 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.tsfakes Electron's platform choice. It covers every combination ofXDG_SESSION_TYPE(wayland / x11 / unset),DISPLAY(set / unset) andWAYLAND_DISPLAY(set / unset), for both a direct--serveand a CLI-started launch, and checks that the result is always X11. It also covers an inheritedELECTRON_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 tcandpnpm run check:code-quality:changedpass.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)