From 70db2edcdec9d9bf92b9ad6943e1f718633ccfec Mon Sep 17 00:00:00 2001 From: Josh Gratton Date: Sat, 13 Jun 2026 09:41:52 -0400 Subject: [PATCH] fix(desktop): repair the WSL backend's PATH so provider CLIs resolve The WSL server spawns provider update commands (e.g. `npm install -g @openai/codex@latest`) by name, but `wsl.exe -- node` leaves the resolved Node's bin dir off the process PATH, so npm/npx (and the installed CLIs like codex) weren't found and the update failed with "npm: NotFound". Provider maintenance already runs per-backend server, so this broke updates for every provider in the WSL backend, and in WSL-only mode there's no Windows fallback to mask it. Launch the WSL server through a shell that front-loads the resolved Node's bin dir (plus the standard system dirs) onto PATH, then `exec` the same absolute Node. exec preserves fd 0, so the bootstrap-over-stdin delivery is unchanged. npm/npx and globally-installed provider CLIs now resolve to the distro's Node toolchain. Verified on a packaged build in WSL-only mode: the backend still starts cleanly through the shell wrapper, and the server's PATH resolves and runs npm. --- .../backend/DesktopBackendConfiguration.ts | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/apps/desktop/src/backend/DesktopBackendConfiguration.ts b/apps/desktop/src/backend/DesktopBackendConfiguration.ts index 44f36ca9c9..375269cb9d 100644 --- a/apps/desktop/src/backend/DesktopBackendConfiguration.ts +++ b/apps/desktop/src/backend/DesktopBackendConfiguration.ts @@ -462,21 +462,29 @@ const resolveWslStartConfig = Effect.fn("desktop.backendConfiguration.resolveWsl } satisfies DesktopBackendManager.DesktopBackendStartConfig; } + // The WSL server spawns commands its providers reference by name — `npm`/`npx` + // for provider updates, and the installed CLIs themselves (e.g. `codex`). Those + // live in the resolved Node's bin dir, which `wsl.exe -- node` does NOT put on + // the process PATH, so `npm install -g ...` fails with NotFound. Launch through + // a shell that front-loads that bin dir (plus the standard system dirs) onto + // PATH, then `exec` the resolved Node. exec keeps fd 0, so the + // bootstrap-over-stdin delivery is unchanged, and we still run the exact + // version-managed Node node-pty was built against (not a bare `node`), + // regardless of PATH ordering. + const lastSlash = preflight.nodePath.lastIndexOf("/"); + const nodeBinDir = lastSlash > 0 ? preflight.nodePath.slice(0, lastSlash) : "/usr/bin"; + const wslShellQuote = (value: string): string => `'${value.replaceAll("'", "'\\''")}'`; + const launchPathPrefix = `${nodeBinDir}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin`; + const wslServerCommand = [ + `export PATH=${wslShellQuote(launchPathPrefix)}:"$PATH"`, + `exec ${wslShellQuote(preflight.nodePath)} ${wslShellQuote(preflight.linuxEntryPath)} --bootstrap-fd 0${devUrlArgs + .map((arg) => ` ${wslShellQuote(arg)}`) + .join("")}`, + ].join("; "); + return { ...baseConfig, - args: [ - ...distroArgs, - "--", - // Absolute node path resolved by the preflight after the shared remote - // resolver repaired PATH. `wsl.exe -- node` would run against the bare - // non-login PATH and hit /usr/bin/node instead of the version-managed - // node node-pty was built against. - preflight.nodePath, - preflight.linuxEntryPath, - "--bootstrap-fd", - "0", - ...devUrlArgs, - ], + args: [...distroArgs, "--", "bash", "-c", wslServerCommand], preflightFailure: Option.none(), } satisfies DesktopBackendManager.DesktopBackendStartConfig; });