Skip to content

fix(desktop): --version segfaults without a display - #7256

Open
matsvarn wants to merge 2 commits into
pingdotgg:mainfrom
matsvarn:prep/5474
Open

fix(desktop): --version segfaults without a display#7256
matsvarn wants to merge 2 commits into
pingdotgg:mainfrom
matsvarn:prep/5474

Conversation

@matsvarn

@matsvarn matsvarn commented Aug 16, 2026

Copy link
Copy Markdown

Fixes #5474

What Changed

DesktopPreReadyPlatform.isVersionRequest returns true only for the whole tokens --version and -V. main.ts checks that predicate immediately before DesktopApp.program and, on a match, writes the version with writeStdoutLineSync (fd 1, swallows EPIPE) then process.exit(0). Layers and whenReady never run on that path. console.log then process.exit can drop piped stdout on Electron before ready.

Why

env -u DISPLAY -u WAYLAND_DISPLAY t3code --version printed Ozone "Missing X server" and exited 139. Packagers and headless scripts expect a version string and exit 0. --no-sandbox still never printed the version (it only avoided the SIGSEGV on teardown).

DesktopApp.startup always awaits electronApp.whenReady, which initializes Ozone. DesktopPreReadyPlatform already owns pre-ready command-line reads. A one-function argv predicate there hides token matching; print+exit stays at the main.ts call site so app.exit teardown cannot still fault without a display. Handling version after ElectronApp/DesktopApp services exist still walks the ready path unless it special-cases before whenReady.

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 requests failed on upstream/main before 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 EPIPE covers 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 lint on the three files: 0 warnings/errors.
  • vp run --filter @t3tools/desktop typecheck: our files clean (pre-existing suggestions remain in DesktopBackendPool.test.ts and DesktopWslEnvironment.ts).
  • Did not launch a packaged Linux binary with DISPLAY unset. Did not run web, mobile, or server suites.

UI Changes

No UI change.

Deliberately not included

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

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.

DesktopPreReadyPlatform gains isVersionRequest (whole argv tokens --version and -V only—not -v, --version=…, or similar) and writeStdoutLineSync, which writes one line to stdout and ignores EPIPE.

In main.ts, that check runs after the runtime layer is defined but before DesktopApp.program starts, so the Effect stack and whenReady / display init never run on the version path. A match prints Electron.app.getVersion() and process.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 --version segfault by handling version flag before display initialization

When the desktop app is invoked with --version or -V, it previously tried to initialize a display before printing the version, causing a segfault in headless environments.

  • Adds isVersionRequest in DesktopPreReadyPlatform.ts to detect whole-token --version or -V flags (ignoring variants like --version=1 or -v).
  • Adds writeStdoutLineSync to write the version string to stdout synchronously, suppressing EPIPE errors.
  • In main.ts, checks for the version flag before app startup, prints the Electron app version, and exits with code 0.

Macroscope summarized 69817a1.

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

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2fe55196-7461-4cd5-960f-fb3d7b72338a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Aug 16, 2026
@matsvarn
matsvarn marked this pull request as ready for review August 16, 2026 20:52

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

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

Comment thread apps/desktop/src/main.ts
@macroscopeapp

macroscopeapp Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: t3code --version segfaults without a display instead of printing the version

1 participant