Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): desktop backend now exits when its launcher dies #20277

Mergedbompus(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/20277/headmerged by juliusmarminge View on GitHub

After an app update kills the WSL launcher, the old desktop backend now shuts itself down instead of lingering and blocking the replacement.

Problem

In #19735 the updater stops the Windows wsl.exe launcher, but the Linux server it started keeps running. It keeps serving HTTP and keeps the home ownership lock, so the replacement the desktop launches exits with code 78 (ServerAlreadyRunningError) and the environment disappears from the app.

A desktop-launched backend reads its bootstrap envelope once and never checks its launcher again, so nothing tells it the launcher is gone.

Change

In desktop mode with a bootstrap token, the server polls its parent pid every 2 seconds. When the parent differs from the one it started under, it logs the launcher and new parent pids and ends the way SIGTERM does: the server scope closes normally (ownership lock and runtime state released) and the process exits.

  • Any parent change counts, not only a move to pid 1: in the repro the orphan was adopted by a subreaper (pid 1800227), not init.
  • Not watched: a backend that already starts under pid 1, and Windows, where the original parent id outlives the parent.
  • Web mode, t3 serve and t3 start without a desktop bootstrap token are unchanged.

The change is a new launcherWatch.ts (45 lines) and 11 lines in cli/server.ts, plus tests.

Scope and approval

Addresses #19735 (open, reported by three users, not yet triaged by maintainers). I am submitting under the small, focused bug fix exception: one cause, no new setting, no change to defaults or to any non-desktop mode. If you would rather settle direction in a discussion first, I will move it there. This does not change what the desktop does on stop; it makes the server notice a launcher that was already killed.

Verification

Run on 3db1b082e1:

  • vp test run src/launcherWatch.test.ts: 4 passed. They cover a parent change including to a non-1 pid, a launcher already gone before the watch began, a backend started under pid 1 (not watched), and win32 (not watched). Removing either guard fails its test.
  • vp lint on the three changed files: exit 0. tsc --noEmit in apps/server: exit 0.
  • Disposable repro, Linux only: a fake launcher keeps the bootstrap pipe open and feeds a desktop envelope with --bootstrap-fd 0; I SIGKILL only that launcher, then start a replacement on the same home.
Old backend after launcher is killedReplacement launch
upstream/mainalive, HTTP 200, parent changed to 1800227exits 78
with this changelogs desktop launcher is gone { launcherPid, parentPid } and exitsstarts and runs

Not verified: a real nightly update on Windows with WSL, and the exact Windows relay kill sequence. In a passive capture of a real update the backend's parent changed from the relay pid to 1 during the stop, which is the signal this relies on. A replacement launched within the roughly 2-second poll plus shutdown window can still be refused, and the desktop does not retry after exit 78; that is unchanged here.

Written with Claude Sonnet 5.5 in Claude Code, run from T3 Code.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Approvability

      Verdict: Approved at 3db1b08

      Macroscope's review found this PR approvable — This is a focused desktop-backend lifecycle fix that terminates only bootstrap-launched servers whose launcher has disappeared, while preserving other server modes and adding targeted platform and orphaning tests. It introduces no schema, deployment, default, or static-analysis changes.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. 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: 09805a61-6581-46e2-b37c-abcaa2b93004
      📥 Commits

      Reviewing files that changed from the base of the PR and between cfafb4bb54d244e4612f5681aad3832ea64cb0fb and 3db1b082e1d10b2a7296eb63c4279b82c39a0b90.

      📒 Files selected for processing: 3
      • apps/server/src/cli/server.ts
      • apps/server/src/launcherWatch.test.ts
      • apps/server/src/launcherWatch.ts

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

      📝 Walkthrough

      The server adds a launcher-loss watcher. In desktop mode with a bootstrap token, the server races its execution against the watcher and interrupts when the watcher detects launcher loss.

      Changes: Launcher Loss Handling

      Layer / File(s)Summary
      Detect launcher loss
      apps/server/src/launcherWatch.ts, apps/server/src/launcherWatch.test.ts
      awaitLauncherLoss polls the launcher’s parent PID and completes when it changes. It remains active on Windows and when the launcher PID is at most 1. Tests cover these cases.
      Apply launcher-loss handling to desktop server execution
      apps/server/src/cli/server.ts
      When the configuration is desktop mode and a bootstrap token is defined, server execution races against awaitLauncherLoss and is interrupted on launcher loss. Other configurations run without the race.

      Priority: ⬇️ Low

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

      Change: Bug fix

      Sequence Diagram(s)

      sequenceDiagram
        participant runServerCommand
        participant serverEffect
        participant awaitLauncherLoss
        participant ParentPID
        runServerCommand->>serverEffect: Start server in desktop mode
        runServerCommand->>awaitLauncherLoss: Race server against launcher-loss watch
        awaitLauncherLoss->>ParentPID: Poll parent PID
        ParentPID-->>awaitLauncherLoss: Return changed parent PID
        awaitLauncherLoss-->>runServerCommand: Complete on launcher loss
        runServerCommand->>serverEffect: Interrupt server effect

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to 3db1b

      The desktop backend releases its ownership lock after launcher loss, allowing a replacement launch once shutdown completes. No merge-blocking issue is established.

      Security architecture risk: 🔵 Low · up to 3db1b

      The change is narrowly gated to desktop launches with bootstrap credentials and reuses existing scoped shutdown and ownership cleanup. No introduced security weakness was identified. Remaining uncertainty concerns the complete launcher-loss and replacement-startup sequence in a real desktop environment.

      Retained concerns No architecture-level concerns identified.

      Security review details

      Security Blast Radius

      • inferred — The new shutdown authority affects the supervised backend instance and resources owned by its server scope, including its configured runtime-state directory. The change adds no cross-instance shutdown command or additional privilege.

      Trust Boundaries and Controls

      • observed — The production caller supplies no watcher overrides: shutdown is driven by process.ppid and the platform service. Injected PID getters and launcher IDs appear in the local tests, not as request-controlled production inputs. Consequently, the routed test entrypoint does not establish a new remote shutdown path.

      Resilience and Maintainability Implications

      • observed — Existing ownership cleanup removes persisted runtime state only when ownerId matches and ensures database closure even if state cleanup fails. Existing tests cover preserving another owner’s record and reacquiring ownership after scope closure. These controls predate the PR and are reused by the new interruption path.
      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title is concise, uses the conventional commit format, and clearly describes the main server behavior change.
      Description checkPassedThe description includes all required sections. It explains the problem, implementation, scope and approval basis, focused verification results, known limitations, and agent attribution.
      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.
      ✨ 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.
    4. juliusmarminge merged thisecb8ddd

    5. juliusmarminge closed this

Sign in to join this conversation.