Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): a desktop backend whose launcher died shuts down cleanly instead of crashing #22471

MergedSunkenInTime(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/22471/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

A desktop-launched WSL backend whose launcher was killed, before and after. Disposable WSL2 distro, nightly v0.1.1-nightly.20261020.3411 with only t3 swapped for this branch's build. strace of the server process:

main
write(1, "...desktop launcher is gone; shutting down the backend...", ...) = -1 EPIPE
exit_group(1)                                   # server-runtime.json left behind

this PR
write(1, "...desktop launcher is gone; shutting down the backend...", ...) = -1 EPIPE
unlink(".../userdata/server-runtime.json") = 0
exit_group(130)                                 # normal interrupt shutdown

Problem

#20277 made a desktop backend shut down when its launcher dies. The case it was written for is #19735, where an app update kills wsl.exe but the Linux server keeps running and holds the T3 home, so every replacement exits with code 78. The launcher is also the only reader of the backend's stdout and stderr. So when the watch fires, its own "launcher is gone" warning is written to a closed pipe. Node raises EPIPE as an unhandled stream error event, and the process crashes with exit code 1 in the middle of shutdown. The ownership lock is released only because the process died, and server-runtime.json stays behind. Any later log line during shutdown hits the same problem.

Change

In desktop mode, runServerCommand adds error listeners to process.stdout and process.stderr that ignore EPIPE and ERR_STREAM_DESTROYED and rethrow anything else. Logs after the launcher is gone are dropped, and shutdown runs to the end. t3 serve, t3 start and web mode are unchanged.

Scope and approval

A follow-up fix to #20277 for #19735.

Verification

Live, by GPT-6 Astra on Windows 11 with WSL 2.7.11 and a disposable Ubuntu 24.04 distro. The backend was launched the way the desktop does it: wsl.exe -d … --exec env PATH=… t3 --bootstrap-fd 0 with the bootstrap envelope on stdin. A preload ignored SIGHUP so the server survives as in the field reports, a separate wsl.exe … sleep kept the distro alive, and the run ended with taskkill /pid <wsl.exe> /T /F.

  • Stock nightly: the watch fired, its write hit EPIPE, exit code 1, and server-runtime.json was left behind.
  • This branch: the watch fired, its write hit the same EPIPE, no uncaught exception, the runtime record was removed and ownership released, exit code 130.
  • In both runs a replacement launch then took ownership and answered HTTP 200.
  • The built bundle and the installed executable were grepped for the new listeners.

Not covered: ERR_STREAM_DESTROYED wasn't triggered separately. There's no unit test, because one would only show that Node stops treating a stream error as fatal once there's a listener. The live run is the proof. The clean shutdown takes about 3 s after taskkill returns, versus 0.35 s for the crash, so a replacement launched right away can still hit code 78 while the old server is finishing. A separate PR makes the desktop wait for the Linux server to exit before it launches a replacement.

Made with Claude Opus 5.5 in T3 Code (Claude Code harness); live verification by GPT-6 Astra (Codex).

    1. Approvability

      Verdict: Approved at 7b29281

      Macroscope's review found this PR approvable — This narrowly scoped server fix handles expected EPIPE/ERR_STREAM_DESTROYED errors from a closed desktop launcher while preserving unrelated stream failures, allowing the existing shutdown cleanup to finish. Non-desktop paths and product defaults are unchanged.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    2. Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: b4197459-f60e-4361-85fa-2a5dfebd8b6a
      📥 Commits

      Reviewing files that changed from the base of the PR and between 7e289ae1f77b9137580688aaccf00d48906984ad and 7b29281549783e32097894da4a6ac75243ed844b.

      📒 Files selected for processing: 1
      • apps/server/src/cli/server.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

      📝 Walkthrough

      The server command now handles closed stdout and stderr pipes from the desktop launcher. It ignores EPIPE and ERR_STREAM_DESTROYED errors and rethrows other errors.

      Changes: Launcher Pipe Handling

      Layer / File(s)Summary
      Handle closed launcher pipes
      apps/server/src/cli/server.ts
      A new handler ignores EPIPE and ERR_STREAM_DESTROYED errors and rethrows other errors. runServerCommand registers the handler on stdout and stderr before starting the launcher-loss race.

      Priority: ⬇️ Low

      Estimated code review effort: 2 (Simple) | ~5 minutes

      Change: Bug fix

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to 7b292

      No actionable merge-blocking risk is identified in the reviewed change.

      Architecture risk: 🔵 Low · up to 7b292

      The change affects 1 system.

      Changed systems: apps/server

      Architecture concerns No architecture-level concerns identified.

      Review details

      Systems and components

      • observed — apps/server (service) was modified; 1 changed file maps to changed impact.

      Before / after behavior

      • observed — Modified behavior in apps/server/src/cli/server.ts: Added ignoreClosedLauncherPipe, which ignores closed-pipe stream errors (EPIPE and ERR_STREAM_DESTROYED) and throws all other errors.
      • observed — Modified behavior in apps/server/src/cli/server.ts: runServerCommand now registers the closed-pipe error handler on process.stdout and process.stderr before starting the desktop launcher-loss race.
      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main fix: preventing a desktop backend from crashing when its launcher closes.
      Description checkPassedThe description includes complete Problem, Change, Scope and approval, and Verification sections. It explains the failure, the implementation, the focused scope, and detailed live verification results…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Description check

      Explanation

      The description includes complete Problem, Change, Scope and approval, and Verification sections. It explains the failure, the implementation, the focused scope, and detailed live verification results. It references related issues but does not include an explicit maintainer approval comment; this is a minor omission because the fix is clearly scoped and well documented.

      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.

Sign in to join this conversation.