terminal-code icon indicating copy to clipboard operation
terminal-code copied to clipboard

Linux: tode >= 0.4.0 cannot start without DISPLAY/WAYLAND_DISPLAY (headless fallback lost in the pixel migration)

Open ibrmora opened this issue 1 month ago • 1 comments

Summary

On Linux, when tode runs in a shell that has neither DISPLAY nor WAYLAND_DISPLAY — for example a pane of a persistent terminal multiplexer whose server was started over SSH, a CI job, or a container — it exits before drawing anything:

Missing X server or $DISPLAY
The platform failed to initialize.  Exiting.

The same shell works if Electron is given the headless ozone switches:

--ozone-platform=headless --screen-info={8192x8192}

terminal-browser, the other app built on the same pixel engine, is unaffected because its CLI adds exactly those switches when no display variables exist. tode used to get that fallback for free: up to v0.3.4 it launched panes through the terminal-browser CLI. Since the pixel migration in v0.4.0 it spawns Electron directly, so the fallback is gone.

Environment

  • Ubuntu 24.04.5 LTS, GNOME 46 on Wayland (a real compositor is running; only the pane's env lacks the vars)
  • tode v0.4.3 (stable), @zenbu-labs/pixel 0.0.23, Electron 44.2.0
  • herdr 0.9.5 (tmux-like terminal workspace; panes are children of a long-lived headless server)
  • Repro is display-server independent; the host below happens to be Wayland

Steps to reproduce

  1. Make the server that owns your panes be born without a graphical environment, e.g. first attach to herdr over SSH, or start any tmux-like server from an SSH login. Panes then see XDG_SESSION_TYPE=tty, no WAYLAND_DISPLAY, no DISPLAY.
  2. From such a pane: tode.
  3. tode exits immediately; ~/.local/state/tode/daemon/daemon.log shows:
[77746:1104/164644.980721:ERROR:ui/ozone/platform/x11/ozone_platform_x11.cc:257] Missing X server or $DISPLAY
[77746:1104/164644.980781:ERROR:ui/aura/env.cc:246] The platform failed to initialize.  Exiting.

Expected

tode starts (as it does in a normal terminal tab on the same machine), or at least fails with a message that explains what is missing.

Actual

Electron picks the X11 backend, finds no $DISPLAY, and aborts before the window/daemon can run.

Minimal evidence

Probe entry (whenReady → print → exit) run with pixel's Electron binary and bootstrap.js, in the display-less pane env:

argv result
(nothing) Missing X server or $DISPLAY → platform init failed
--screen-info={8192x8192} same failure
--ozone-platform=headless --screen-info={8192x8192} DISPLAY-OK

And in the installed tree there is no headless handling at all:

$ grep -rn "ozone-platform\|headless\|WAYLAND_DISPLAY" ~/.local/lib/tode/dist
(no matches)

Root cause

src/launch.ts spawns Electron without any Chromium switches:

const child = spawn(electronBinary(), [bootstrapEntry(), daemonEntry()], { … });   // daemon

function windowCommand(url, options) {
  const command = [process.execPath, path.resolve(__dirname, "main.js"), "--window", url];
  …
}

src/runtime/launcher.ts resolves electronBinary()/bootstrapEntry() straight into @zenbu-labs/pixel, so pixel's own CLI launcher — @zenbu-labs/pixel/dist/bin.js, which contains the fallback — never runs.

Bisect

  • v0.3.4 (src/launch.ts): panes were launched through the pinned terminal-browser runtime CLI — spawn(this.runtime.bin, ["open", ...browserArgv(url, this.options)]). That CLI does if (process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) argv = [...argv, "--ozone-platform=headless", "--screen-info={8192x8192}"], so tode inherited it.
  • v0.4.0 (557d0af, PR #35 "Add transparency, migrate to pixel"): pane/daemon launched with pixel's Electron binary directly → fallback lost. Still true in v0.4.3.

Suggested patch

Mirror the guard pixel and terminal-browser already use:

function headlessArgs(): string[] {
  return process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY
    ? ["--ozone-platform=headless", "--screen-info={8192x8192}"]
    : [];
}

// spawnDaemon()
const child = spawn(electronBinary(), [bootstrapEntry(), daemonEntry(), ...headlessArgs()], { … });

// windowCommand()
const command = [process.execPath, path.resolve(__dirname, "main.js"), ...headlessArgs(), "--window", url];

bootstrap.js already strips --ozone-platform= / --screen-info= from process.argv before requiring the entry, so passing them before --window/after daemonEntry() is safe.

(Whether the resulting headless frames composite correctly in tode's renderer still needs a smoke test; I only verified that Electron starts headless, which is the current blocker. Happy to test a build.)

Workaround (current)

In ~/.bashrc, inside the pane:

if [ -z "$WAYLAND_DISPLAY" ] && [ -S "${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/wayland-0" ]; then
  export WAYLAND_DISPLAY=wayland-0
  export XDG_SESSION_TYPE=wayland
fi

That works only where a compositor exists; it cannot help a genuinely headless host — which is why a headless fallback in tode itself is worth having.

Related

  • Terminal-browser equivalent guard: zenbu-labs/terminal-browser, cli/src/main.ts (also pixel/packages/pixel/src/bin.ts)
  • herdr env inheritance: herdrdev/herdr#2448 (tmux-style session.update_environment in PR #2854)
  • zenbu-labs/terminal-code#19 — same topology question (remote herdr panes + tode frontend)

ibrmora avatar Nov 04 '26 16:11 ibrmora

Linux: tode daemon gets no headless ozone switches without DISPLAY or WAYLAND_DISPLAY

Problem

On Linux, tode launches its Electron daemon with only [bootstrap.js, daemon.js] as arguments, even when DISPLAY and WAYLAND_DISPLAY are both unset. In that case Chromium picks X11 and exits with "Missing X server or $DISPLAY". terminal-browser and pixel's own CLI add --ozone-platform=headless --screen-info={8192x8192} in this case, but tode does not.

Steps to reproduce

  1. On Linux, open a shell with no DISPLAY and no WAYLAND_DISPLAY (for example a tmux-like pane whose server started over SSH).
  2. Run tode.
  3. Read ~/.local/state/tode/daemon/daemon.log.
  4. Code-level check: build with npx tsc -p tsconfig.json; node scripts/write-cjs-boundary.js, then run node --test test/headless.test.js. The test stubs child_process.spawn and records the argv that spawnDaemon() passes to Electron.

Expected

With DISPLAY and WAYLAND_DISPLAY unset on Linux, the Electron argv includes --ozone-platform=headless and --screen-info={8192x8192}, and tode starts.

Actual

The Electron argv is [bootstrap.js, daemon.js] with no ozone switches, and the daemon log shows "Missing X server or $DISPLAY" followed by "The platform failed to initialize. Exiting."

Cause

In src/launch.ts, spawnDaemon() runs spawn(electronBinary(), [bootstrapEntry(), daemonEntry()], …) with no Chromium switches. windowCommand(), used for --split panes, also builds [process.execPath, main.js, "--window", url] with no switches. src/runtime/launcher.ts points directly at pixel's Electron binary and bootstrap.js, so the headless fallback in pixel's CLI (@zenbu-labs/pixel/dist/bin.js) never runs. The source has no check for DISPLAY or WAYLAND_DISPLAY anywhere.

Evidence

Reproduction on main@b049d7c:

https://github.com/user-attachments/assets/bcb9c69e-40ad-4a9a-94b9-524ad46774d4

Simulated: The test and demo stub child_process.spawn to record the argv that spawnDaemon() builds (reached through Pane.open with PIXEL_EMBED=1 and PIXEL_TTY=/dev/null); they do not start the real Electron binary or check that tode draws correctly in headless mode.

Reproduced on main@b049d7c by the test test/headless.test.js:

duration_ms: 16.875645
  type: 'test'
  location: '/home/zenbu/base/test/headless.test.js:39:1'
  failureType: 'testCodeFailure'
  error: 'daemon argv lacks --ozone-platform=headless: ["/home/zenbu/base/node_modules/@zenbu-labs/pixel/dist/bootstrap.js","/home/zenbu/base/dist/app/daemon.js"]'
  code: 'ERR_ASSERTION'
  name: 'AssertionError'
  expected: true
  actual: false
  operator: '=='
  stack: |-
    TestContext.<anonymous> (/home/zenbu/base/test/headless.test.js:57:10)
    process.processTicksAndRejections (node:internal/process/task_queues:103:5)
    async Test.run (node:internal/test_runner/test:1054:7)
    async startSubtestAfterBootstrap (node:internal/test_runner/harness:296:3)
  ...
1..1
# tests 1
# suites 0
# pass 0
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms 360.957943
Extra information
Job 41866359157-1
Handler issue.enhance
Classification bug
Sandbox docker · linux
Test command npx tsc -p tsconfig.json > /dev/null; node scripts/write-cjs-boundary.js && node --test test/headless.test.js
Log GitHub Actions run

zenbu-bot[bot] avatar Nov 04 '26 16:11 zenbu-bot[bot]