feat(desktop): run the WSL backend from the Linux CLI archive #11511
Mergedjuliusmarmingemerged 1 commit into
sea/archive-only fromrefs/pull/11511/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -711,10 +729,13 @@711729 // for provider updates, and the installed CLIs themselves (e.g. `codex`). Those712- // live in the resolved Node's bin dir, which `wsl.exe -- node` does NOT put on730+ // live on the user's login-shell PATH, which `wsl.exe --exec` does NOT put on713731 // the process PATH, so `npm install -g ...` fails with NotFound. Pass the714- // user PATH entries captured by the login-shell preflight. Every dynamic715- // value is a separate argv entry under `wsl.exe --exec`; no shell command is716- // involved, so Windows cannot mangle nested quotes and stdin remains reserved717- // for the bootstrap envelope.718- const lastSlash = preflight.nodePath.lastIndexOf("/");719- const nodeBinDir = lastSlash > 0 ? preflight.nodePath.slice(0, lastSlash) : "/usr/bin";720- const launchPath = `${nodeBinDir}:${WSL_SERVER_SYSTEM_PATH}:${preflight.resolvedPath}`;732+ // user PATH entries captured by the preflight. Every dynamic value is a733+ // separate argv entry under `wsl.exe --exec`; no shell command is involved,734+ // so Windows cannot mangle nested quotes and stdin remains reserved for the735+ // bootstrap envelope. A node-script runtime additionally leads with the736+ // probed Node's bin dir so the server cannot pick up a different node than737+ // the one node-pty was probed with.738+ const runtime = preflight.runtime;739+ const launchPath =740+ runtime.kind === "executable"741+ ? `${WSL_SERVER_SYSTEM_PATH}:${preflight.resolvedPath}`@@ -3847,8 +3706,7 @@38473706 yield* stageClerkPasskeyNativeBinaries(stageAppDir, options.platform, options.arch);38483707 yield* stageKeyringNativeBinaries(stageAppDir, options.platform, options.arch);384937083850- // WSL is Windows-only, so only the Windows artifact carries the server3851- // sidecar (which embeds the Linux node-pty prebuild); other platforms3852- // ignore the prebuild input.3709+ // Only the Windows artifact carries the server sidecar and the WSL runtime;3710+ // other platforms ignore the --wsl-runtime input.38533711 if (options.platform === "win" && windowsServerAsarPath) {38543712 yield* stageWindowsServerSidecar({@@ -281,15 +302,7 @@281302 `ready_marker="$runtime_root/${WSL_RUNTIME_READY_MARKER}"`,282- // The native payload is the part of the tree the WSL backend actually283- // dlopens, and the only part a user can plausibly break by hand. Checking284- // node-pty's package.json alone let a runtime whose pty.node had gone285- // missing stay cache-ready forever: every launch reused it and then failed286- // the native probe, with no reinstall and no fallback. Match on the glob287- // rather than a mapped `uname -m` so this stays a presence check; the probe288- // is what decides whether the binary is the right arch and loadable.289- "node_pty_payload_present() {",290- ' for candidate in "$1"/node_modules/node-pty/prebuilds/linux-*/pty.node; do',291- ' [ -f "$candidate" ] || continue',292- ' [ -f "${candidate%/*}/t3code-wsl-node-pty.json" ] || continue',293- " return 0",294- " done",295- " return 1",303+ // The runtime is a self-contained `t3` executable with Node inside, so the304+ // readiness proof is the same one the SSH runner and the CLI installers305+ // use: the file is executable and `t3 --version` exits 0. That covers the306+ // truncated-binary and wrong-arch cases without a separate native probe.307+ "runtime_entry_runs() {",308+ ' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null 2>&1',@@ -371,16 +388,14 @@388+ // it runs here; there is no Node to find or node-pty to load.389+ const stagedProbe = yield* wslEnv.probeRuntime(runningDistro, runtime.linuxAppRoot);390+ if (stagedProbe.ok) {371391 yield* wslServerTree.cleanupLegacy;372392 return {373393 _tag: "Ready",374394 runningDistro,375395 windowsEntryPath: environment.backendEntryPath,376- linuxEntryPath: `${runtime.linuxAppRoot}/apps/server/dist/bin.mjs`,377- nodePath: stagedNodePty.nodePath,378- resolvedPath: stagedNodePty.resolvedPath,396+ runtime: { kind: "executable", entryPath: `${runtime.linuxAppRoot}/t3` },397+ resolvedPath: stagedProbe.resolvedPath,379398 runtimeId: input.runtimeArchive.runtimeId,380399 } as const;381400 }382- // A transport failure says nothing about the staged tree, so it is383- // retried against the same cache rather than spending a second probe on384- // the mounted tree and risking a needless reinstall.385- if (!stagedNodePty.fatal) return failedNodePty(stagedNodePty);386401 yield* Effect.logWarning(
- @@ -712,9 +730,13 @@712- // live in the resolved Node's bin dir, which `wsl.exe -- node` does NOT put on730+ // live on the user's login-shell PATH, which `wsl.exe --exec` does NOT put on713731 // the process PATH, so `npm install -g ...` fails with NotFound. Pass the714- // user PATH entries captured by the login-shell preflight. Every dynamic715- // value is a separate argv entry under `wsl.exe --exec`; no shell command is716- // involved, so Windows cannot mangle nested quotes and stdin remains reserved717- // for the bootstrap envelope.718- const lastSlash = preflight.nodePath.lastIndexOf("/");719- const nodeBinDir = lastSlash > 0 ? preflight.nodePath.slice(0, lastSlash) : "/usr/bin";720- const launchPath = `${nodeBinDir}:${WSL_SERVER_SYSTEM_PATH}:${preflight.resolvedPath}`;732+ // user PATH entries captured by the preflight. Every dynamic value is a733+ // separate argv entry under `wsl.exe --exec`; no shell command is involved,734+ // so Windows cannot mangle nested quotes and stdin remains reserved for the735+ // bootstrap envelope. A node-script runtime additionally leads with the736+ // probed Node's bin dir so the server cannot pick up a different node than737+ // the one node-pty was probed with.738+ const runtime = preflight.runtime;739+ const launchPath =740+ runtime.kind === "executable"741+ ? `${WSL_SERVER_SYSTEM_PATH}:${preflight.resolvedPath}`742+ : `${nodeBinDirOf(runtime.nodePath)}:${WSL_SERVER_SYSTEM_PATH}:${preflight.resolvedPath}`;@@ -660,3 +671,17 @@660671 return `WSL distro is missing required tools: ${issues.join(", ")}. Install ${remediations.join(" and ")}, then retry.`;661672 };662673674+const probeWslRuntimeImpl = (675+ distro: string | null,676+ linuxAppRoot: string,677+): Effect.Effect<ProbeWslRuntimeResult, never, ChildProcessSpawner.ChildProcessSpawner> =>678+ Effect.gen(function* () {679+ const probe = yield* runWslShell(distro, RUNTIME_PROBE_SCRIPT(linuxAppRoot), PROBE_TIMEOUT, {680+ resolveNode: false,681+ });682+ const transportFailureReason = formatWslShellTransportFailureReason(683+ probe.transportFailure,684+ "the staged runtime",685+ );686+ if (transportFailureReason !== null) {687+ return { ok: false, reason: transportFailureReason } as const;
juliusmarminge merged this0754920
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result:
11b815e· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.