fix(desktop): --version segfaults without a display - #7256
Conversation
Headless `t3code --version` walked DesktopApp.startup into ElectronApp.whenReady, so Ozone crashed before any version printed. Match whole-token --version/-V in isVersionRequest and print+exit in main.ts before DesktopApp.program. Implemented with grok-4.5 in T3 Code.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b6a1984. Configure here.
ApprovabilityVerdict: Approved 69817a1 ... You can customize Macroscope's approvability policy. Learn more. |
console.log then process.exit can drop piped stdout on Electron before whenReady. writeStdoutLineSync writes fd 1, swallows EPIPE, then main still process.exit(0). Implemented with grok-4.6 in T3 Code.

Fixes #5474
What Changed
DesktopPreReadyPlatform.isVersionRequestreturns true only for the whole tokens--versionand-V.main.tschecks that predicate immediately beforeDesktopApp.programand, on a match, writes the version withwriteStdoutLineSync(fd 1, swallows EPIPE) thenprocess.exit(0). Layers andwhenReadynever run on that path.console.logthenprocess.exitcan drop piped stdout on Electron before ready.Why
env -u DISPLAY -u WAYLAND_DISPLAY t3code --versionprinted Ozone "Missing X server" and exited 139. Packagers and headless scripts expect a version string and exit 0.--no-sandboxstill never printed the version (it only avoided the SIGSEGV on teardown).DesktopApp.startupalways awaitselectronApp.whenReady, which initializes Ozone.DesktopPreReadyPlatformalready owns pre-ready command-line reads. A one-function argv predicate there hides token matching; print+exit stays at themain.tscall site soapp.exitteardown cannot still fault without a display. Handling version after ElectronApp/DesktopApp services exist still walks the ready path unless it special-cases beforewhenReady.The server CLI already prints a version (
apps/server/src/bin.ts:65). This is the desktop binary.Test
detects --version and -V as whole-token version requestsfailed onupstream/mainbefore the fix:TypeError: isVersionRequest is not a function(1 failed | 4 passed). It passes once the pure predicate exists.writes a version line to stdout synchronously and swallows EPIPEcovers the flush path Bugbot flagged.vp test run apps/desktop/src/app/DesktopPreReadyPlatform.test.ts apps/desktop/src/app/DesktopEarlyElectronStartup.test.ts— 13 passed (6 + 7).vp linton the three files: 0 warnings/errors.vp run --filter @t3tools/desktop typecheck: our files clean (pre-existing suggestions remain inDesktopBackendPool.test.tsandDesktopWslEnvironment.ts).DISPLAYunset. Did not run web, mobile, or server suites.UI Changes
No UI change.
Deliberately not included
-v(DesktopPreReadyPlatform.ts:33, asserted false atDesktopPreReadyPlatform.test.ts:88): the issue workaround mentioned it; Chromium also uses-vfor verbosity.packaging/aur/t3code-bin/PKGBUILD:76-79): still justexec AppRun "$@".DesktopApp.ts:275-278).--no-sandboxonly changes teardown, not version printing.--versionafter Ozone starts.ElectronApp.whenReadystill requires a display for normal launches (ElectronApp.ts:133-139).DesktopApp.startupstill always awaitswhenReadyfor normal launches (DesktopApp.ts:275).apps/server/src/bin.ts:65).Electron.app.exitteardown (ElectronApp.ts:143-146).DesktopPreReadyPlatform.ts:70-80).Checklist
Implemented with grok-4.5 in T3 Code.
Note
Low Risk
Small, early-exit path with unit tests; normal GUI startup is unchanged.
Overview
Fixes headless
t3code --version(no display) exiting with Ozone errors or a segfault instead of printing the version and exiting 0.DesktopPreReadyPlatformgainsisVersionRequest(whole argv tokens--versionand-Vonly—not-v,--version=…, or similar) andwriteStdoutLineSync, which writes one line to stdout and ignoresEPIPE.In
main.ts, that check runs after the runtime layer is defined but beforeDesktopApp.programstarts, so the Effect stack andwhenReady/ display init never run on the version path. A match printsElectron.app.getVersion()andprocess.exit(0).Tests cover argv matching and stdout/EPIPE behavior.
Reviewed by Cursor Bugbot for commit 69817a1. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix
--versionsegfault by handling version flag before display initializationWhen the desktop app is invoked with
--versionor-V, it previously tried to initialize a display before printing the version, causing a segfault in headless environments.isVersionRequestin DesktopPreReadyPlatform.ts to detect whole-token--versionor-Vflags (ignoring variants like--version=1or-v).writeStdoutLineSyncto write the version string to stdout synchronously, suppressingEPIPEerrors.Macroscope summarized 69817a1.