Skip to content
Source
Sign inSign up
pingdotgg/t3code

Add desktop WSL backend mode #2353

ClosedJgratton24(GitHub profile, opens in a new tab)wants to merge 15 commits intomain fromrefs/pull/2353/headopened View on GitHub

What Changed

Adds an opt-in Windows desktop mode that keeps the Electron UI native while launching the local T3 Code backend inside WSL. Scoped to the desktop backend lifecycle path — complements rather than replaces the broader WSL-hosted interop work in #170.

Architecture:

  • DesktopWslEnvironment service (apps/desktop/src/wsl/DesktopWslEnvironment.ts): Effect-based service that detects WSL availability, lists distros, pre-warms the VM, converts Windows paths via wslpath, resolves the user's Linux home dir (cached per distro), and prepares node-pty inside the target distro. Toolchain pre-flight names the specific missing tools (node, make, g++, python3) with an actionable apt-install line up front, before any rebuild attempt.
  • Pure path helpers (apps/desktop/src/wsl/wslPathParsing.ts): wsl.exe --list --verbose parser, UNC-path distro extraction, picker default-path resolution (~, ~/..., /..., and \\wsl.localhost\...), and strict DISTRO_NAME_PATTERN. Fully unit-tested.
  • WSL spawn path (apps/desktop/src/backend/DesktopBackendConfiguration.ts): when wslMode === "wsl", the backend manager spawns wsl.exe -d <distro> -- node <linux-entry> --bootstrap-fd 0 --dev-url <url>. Bootstrap JSON is delivered on stdin (extra stdio fds do not survive the wsl.exe bridge); the dev-server URL is passed as a CLI flag because WSLENV translation of URL-shaped values is unreliable. t3Home is omitted from the bootstrap so the Linux backend uses its own home directory — keeping per-backend state (env-id, threads, projects) cleanly partitioned.
  • Settings (apps/desktop/src/settings/DesktopAppSettings.ts): new wslMode and wslDistro fields persisted with strict distro-name validation. setWslMode returns a { changed } discriminator so the IPC handler can skip the restart when the toggle is a no-op.
  • IPC (apps/desktop/src/ipc/methods/wsl.ts): getWslState and setWslBackend methods. The swap stops the running backend in-process, starts the new one, waits for ready with a 2-minute bound, and rolls back to the previous mode on timeout. The rollback's own readiness is checked and surfaces a distinct "degraded state" message if it also fails.
  • Renderer swap flow (apps/web/src/components/settings/ConnectionsSettings.tsx): a "Backend runtime" <Select> with an AlertDialog confirmation, phased loading copy (Restarting backend… → Re-establishing session… → Syncing threads…), and a 180s global ceiling. WS connection events are silenced via suppressReconnect for the duration of the swap so toasts don't flash during the deliberate disconnect. After the new backend's HTTP readiness, the renderer re-authenticates (each backend signs sessions with its own key, so the old cookie 401s), drops the previous env's slice from environmentStateById, and waits for the new welcome event before declaring success.
  • Folder picker (apps/desktop/src/ipc/methods/window.ts): when WSL mode is on, the picker default path resolves through the same pure helper, and ~/... paths expand against the user's actual Linux home (cached per-distro) instead of the /home parent.
  • Server bootstrap fix (apps/server/src/bootstrap.ts): EACCES on the inherited stdin fd is treated as a duplication error so the /proc/self/fd/<fd> fallback path applies under WSL.

Why

Closes #2346 and #192 — the original community ask for WSL support (105 👍, 23 comments). Running the desktop app on Windows currently means launching the backend directly under Windows, which forces users with a WSL-based dev setup to either run the desktop app inside WSL (no native UX) or fall back to the web UI. This change keeps the Electron UI native on Windows while letting the backend run alongside the user's existing Linux toolchain.

The PR is size:XL, but the implementation is partitioned by responsibility: the DesktopWslEnvironment service and pure path helpers are independently testable, the WSL spawn branch in DesktopBackendConfiguration is a self-contained addition, and the renderer swap UX is localized to ConnectionsSettings.tsx. There is no straightforward way to split this without either shipping a permanently-disabled feature flag or merging the UI before the backend works behind it.

UI Changes

Adds a "Backend runtime" selector to the Connections settings panel: a design-system <Select> listing Local (Windows) and one entry per discovered WSL distro (default distro marked). Picking a different value opens an AlertDialog confirming the swap, which transitions through Restarting backend… → Re-establishing session… → Syncing threads… while the backend restarts, the renderer re-bootstraps, and the new welcome event arrives. Toasts surface success and error states.

WSL backend off

WSL backend off

WSL backend on with Ubuntu selected

WSL backend on

Confirmation dialog before a swap

Enable WSL backend confirmation dialog

The dialog sets the cold-start time expectation ("this may take a little while") and notes that each backend keeps its own threads — switching back returns the original list rather than wiping it.

Phased loading during a swap

Restarting backend loading state

Verification

  • bun run typecheck clean
  • bun run lint clean (no new warnings introduced by this PR)
  • bun --filter @t3tools/desktop run test — covers DesktopWslEnvironment toolchain parsing and the wslPathParsing helpers. Pre-existing failures in DesktopAppIdentity/DesktopEnvironment are unrelated Windows path-normalization issues that also fail on the parent commit.
  • bun --filter @t3tools/web run test
  • Full end-to-end pass on Windows 11 / Ubuntu (WSL2): Windows → WSL → Windows backend swaps with cold VM start, folder picker resolving a WSL ~/project initialPath against the user's real home dir, re-picking the resolved-default distro confirmed as a no-op (no dialog, no restart), and the rollback path when the target distro is broken.

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

Note

Add WSL backend mode to the desktop app

  • Adds a DesktopWslEnvironment service (DesktopWslEnvironment.ts) that detects WSL availability, lists distros, converts paths, and verifies/builds node-pty inside a WSL distro.
  • Extends DesktopBackendStartConfig and resolveBackendStartConfig to launch the backend via wsl.exe when WSL mode is active, forwarding selected secrets and merging WSLENV; falls back to the Windows backend if WSL is unavailable.
  • Adds getWslState and setWslBackend IPC handlers and preload bridge methods so the renderer can query and switch backend runtime.
  • Adds a 'Backend runtime' dropdown and confirmation dialog to Connections Settings (ConnectionsSettings.tsx) that restarts the backend, reauthenticates, and waits for the new welcome event.
  • Persists wslMode and wslDistro in DesktopAppSettings with validation and safe defaults.
  • Introduces suppressReconnect to silence connection-state toasts during the backend swap.
  • Risk: WSL backend swap has a 6-minute global timeout; on failure it attempts rollback but if rollback also times out the IPC call fails with WslBackendSwapError.
Macroscope summarized 00b200c.

Note

High Risk Large cross-cutting change to backend spawn, env/bootstrap partitioning, and auth/session flow on swap; failures are mitigated by rollback and Windows fallback when WSL is missing, but misconfiguration or partial swap timeouts can still strand users until restart.

Overview Adds an opt-in WSL backend for the Windows desktop: the Electron shell stays native while the local server can run inside a chosen WSL distro via wsl.exe, with separate data homes so Windows and WSL threads do not collide.

Desktop main process: New DesktopWslEnvironment (distro list, pre-warm, wslpath, Linux home, node-pty toolchain checks). DesktopBackendConfiguration picks WSL vs Windows spawn: WSL uses stdin bootstrap (--bootstrap-fd 0), optional --dev-url, strips T3CODE_HOME from the child env, merges WSLENV for API keys, and omits t3Home in bootstrap; if WSL is requested but unavailable, it falls back to Windows instead of a stuck preflight loop. DesktopBackendManager gains configurable args/env delivery, preflight-only restart paths, and waitForReady for swaps. Persisted wslMode / wslDistro in app settings with distro name validation.

IPC & renderer: getWslState / setWslBackend stop/restart the backend with a 2-minute readiness wait and automatic settings rollback on failure. Connections settings get a Backend runtime selector (confirm dialog, phased progress, reauth after swap, welcome sync). suppressReconnect hides WS toasts during intentional swaps; folder picker defaults resolve to WSL UNC paths when in WSL mode. Server bootstrap treats stdin EACCES like other fd duplication errors under WSL.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 00b200cbd783e1cd26400bfd2e8f330f0a06cb73. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      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

      Run ID: 79caec88-84c6-4b1a-ad62-5a66d02a2bd5

      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
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      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 and usage tips.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. 💡 Codex Review

      Here are some automated review suggestions for this pull request.

      Reviewed commit: a574cbb5d0

      ℹ️ About Codex in GitHub

      Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

      • Open a pull request for review
      • Mark a draft as ready
      • Comment "@codex review".

      If Codex has suggestions, it will comment; otherwise it will react with 👍.

      Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      This PR introduces a substantial new feature (WSL backend mode) with ~2000 lines across multiple new files, new IPC methods, settings, and UI components. Additionally, there are unresolved review comments including a high-severity timeout race condition that warrants human attention.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. Wow great work! Will find some time to test and review next week!

    6. @Jgratton24 is attempting to deploy a commit to the Ping Labs Team on Vercel.

      A member of the Team first needs to authorize it.

    7. Still on my list of things to review! I've not forgotten

    8. juliusmarmingecommented

      anything i need to do to get it working? i just installed wsl on my windows laptop and tried activating this, but getting Error invoking remote method 'desktop:wsl-set-config': Error: Could not start the backend inside WSL.

      EDIT 1: ah i must have node installed on the wsl box image

      EDIT 2: Fixed that, now issues with node-gyp: image

    9. @juliusmarminge Just reproduced this. It's a missing toolchain in your WSL distro, not a desktop bug. node-pty is a native module and the desktop rebuilds it on first launch via node-gyp inside the distro, which needs make, g++, and python3. Ubuntu's default WSL image doesn't ship those.

      Quick fix:

      sudo apt install -y build-essential python3

      then re-toggle WSL mode in settings.

      The "exit 1 / gyp ERR! not ok" tail is unhelpful because I was truncating the build output and cutting off the actual g++: command not found line. Pushed 54d092a1 to add a pre-flight probe that names the missing tools up front

    10. do we also detect a potentially missing node binary? Related-ish to #2504

    11. Good catch, we weren't. Just pushed 8fd37b42 to add node to the pre-flight probe, with its own install hint (nvm instead of apt).

      #2504 was useful context btw. Our WSL path uses bash -l -s so login shell PATH pulls in nvm/volta/etc already, so no need for the discovery routine you wrote for sh -s. engine range check is worth porting separately though

    12. Yea we require quite modern node version so should be called out and verified otherwise we get bug reports for weird shit

    13. Done, just pushed 24130e44. Probe now reads engines.node from apps/server/package.json and rejects WSL distros whose Node is too old, naming both the actual version and the required range. Helper is a TS port of your satisfiesRange from #2504, kept desktop-local for now. Whichever PR merges second can lift it into packages/shared

Sign in to join this conversation.