The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 01:45 UTC
fix(desktop): preserve WSL runtime installation errors (#21658)
Co-authored-by: Kalven Schraut <kalvens@rtvision.com>
Julius Marminge committed
Oct 19, 2026 at 13:19 UTC
1a552d16a254ef0bdc4898d3a93c32d312a9b398
4 files changed
+51
-8
apps/desktop/src/backend/DesktopBackendConfiguration.test.ts
+30
@@ -551,6 +551,7 @@ describe("DesktopBackendConfiguration", () => {
551
archiveHash: "b".repeat(64),
552
wsl: () => ({
553
prepareRuntime: () => ({ ok: false, reason: "archive is corrupt" }),
554
+ invalidateRuntime: () => Effect.die("failed staging must not invalidate a runtime"),
555
ensureNodePty: (_distro, root) => {
556
observedNodePtyRoots.push(root);
557
return { ok: true, nodePath: "/usr/bin/node", resolvedPath: "/usr/bin:/bin" };
@@ -615,6 +616,35 @@ describe("DesktopBackendConfiguration", () => {
616
);
617
});
618
619
+ it.effect("resolveWsl preserves the staging error when the mounted fallback is fatal", () =>
620
+ withPackagedWslHarness(
621
+ {
622
+ archiveHash: "b".repeat(64),
623
+ wsl: () => ({
624
+ prepareRuntime: () => ({
625
+ ok: false,
626
+ reason:
627
+ "t3: error while loading shared libraries: libatomic.so.1: cannot open shared object file",
628
+ }),
629
+ ensureNodePty: () => ({
630
+ ok: false,
631
+ reason: "the packaged Linux node-pty binary was not included",
632
+ fatal: true,
633
+ }),
634
+ }),
635
+ },
636
+ () =>
637
+ Effect.gen(function* () {
638
+ const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
639
+ const config = yield* configuration.resolveWsl({ port: 5000, distro: "Ubuntu" });
640
+ const failure = Option.getOrThrow(config.preflightFailure);
641
+
642
+ assert.isTrue(failure.fatal);
643
+ assert.include(failure.reason, "libatomic.so.1");
644
+ }),
645
+ ),
646
+ );
647
+
648
it.effect("resolveWsl keeps the staged runtime when the mounted tree fails too", () => {
649
const stagedAppRoot = "/home/test/.t3/wsl-runtime/cache";
650
const invalidatedRuntimeIds: string[] = [];
apps/desktop/src/backend/DesktopBackendConfiguration.ts
+3
-2
@@ -386,7 +386,7 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
386
: ({ ok: true, windowsEntryPath, linuxAppRoot: mountedAppRoot.value } as const);
387
});
388
389
- let stagedFailure: { readonly runtimeId: string; readonly reason: string } | undefined;
389
+ let stagedFailure: { readonly runtimeId?: string; readonly reason: string } | undefined;
390
const failedStaged = (failure: { readonly reason: string }) =>
391
({
392
_tag: "Failed",
@@ -417,6 +417,7 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
417
);
418
stagedFailure = { runtimeId: input.runtimeArchive.runtimeId, reason: stagedProbe.reason };
419
} else {
420
+ stagedFailure = { reason: runtime.reason };
421
yield* Effect.logWarning(
422
"Could not stage the WSL runtime; launching from the mounted server tree instead.",
423
{ reason: runtime.reason },
@@ -446,7 +447,7 @@ const runWslPreflight = Effect.fn("desktop.backendConfiguration.wslPreflight")(f
447
: failedNodePty(nodePtyResult);
448
}
449
449
- if (stagedFailure) {
450
+ if (stagedFailure?.runtimeId) {
451
yield* wslEnv.invalidateRuntime(runningDistro, stagedFailure.runtimeId);
452
}
453
apps/desktop/src/wsl/DesktopWslEnvironment.test.ts
+16
-4
@@ -286,7 +286,7 @@ describe("WSL runtime cache", () => {
286
287
expect(script).toContain('runtime_parent="$HOME/.t3/wsl-runtime"');
288
expect(script).toContain(' [ -f "$ready_marker" ] &&');
289
- expect(script).toContain(' runtime_entry_runs "$runtime_root" &&');
289
+ expect(script).toContain(' runtime_entry_runs "$runtime_root" 2>/dev/null &&');
290
expect(script).toContain("if runtime_is_ready; then");
291
expect(script).not.toContain("bin.mjs");
292
expect(script).not.toContain("node-pty");
@@ -366,7 +366,7 @@ describe("WSL runtime cache", () => {
366
"b".repeat(64),
367
);
368
369
- expect(script).toContain(' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null 2>&1');
369
+ expect(script).toContain(' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null');
370
371
const entryCheckDefined = script.indexOf("runtime_entry_runs() {");
372
const readinessDefined = script.indexOf("runtime_is_ready() {");
@@ -478,14 +478,14 @@ describe.skipIf(posixShellRunner === null)("WSL runtime install script (executed
478
fixtures.length = 0;
479
});
480
481
- const createFixture = () => {
481
+ const createFixture = (serverEntry = SERVER_ENTRY_SOURCE) => {
482
const result = runShell(
483
[
484
"set -eu",
485
"work=$(mktemp -d)",
486
'stage="$work/stage/t3-0.0.0-linux-x64"',
487
'mkdir -p "$stage/node_modules/node-pty/build/Release" "$work/home"',
488
- `printf '%s' ${sh(SERVER_ENTRY_SOURCE)} > "$stage/t3"`,
488
+ `printf '%s' ${sh(serverEntry)} > "$stage/t3"`,
489
'chmod +x "$stage/t3"',
490
`printf '%s' 'pty-native-payload' > "$stage/node_modules/node-pty/build/Release/pty.node"`,
491
`tar -czf "$work/wsl-runtime.tar.gz" -C "$work/stage" t3-0.0.0-linux-x64`,
@@ -599,6 +599,18 @@ describe.skipIf(posixShellRunner === null)("WSL runtime install script (executed
599
expect(parseWslRuntimeRoot(warm.stdout)).toBe(fixture.runtimeRoot);
600
});
601
602
+ it("retains the loader error when a bundled executable needs a missing system library", () => {
603
+ const fixture = createFixture(
604
+ '#!/bin/sh\nprintf "error while loading shared libraries: libatomic.so.1: cannot open shared object file\\n" >&2\nexit 127\n',
605
+ );
606
+
607
+ const result = fixture.install();
608
+
609
+ expect(result.status).not.toBe(0);
610
+ expect(result.stderr).toContain("libatomic.so.1");
611
+ expect(parseWslRuntimeRoot(result.stdout)).toBeNull();
612
+ });
613
+
614
it("reinstalls a cache whose executable was truncated", () => {
615
const fixture = createFixture();
616
expect(fixture.install().status).toBe(0);
apps/desktop/src/wsl/DesktopWslEnvironment.ts
+2
-2
@@ -275,7 +275,7 @@ export const buildWslRuntimeInstallScript = (
275
`runtime_root="$runtime_parent/${safeRuntimeId}"`,
276
`ready_marker="$runtime_root/${WSL_RUNTIME_READY_MARKER}"`,
277
"runtime_entry_runs() {",
278
- ' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null 2>&1',
278
+ ' [ -x "$1/t3" ] && "$1/t3" --version >/dev/null',
279
"}",
280
// Hashing the entry is what tells a working cache from one whose `t3` was
281
// swapped or half-written after install: the file is still there and may
@@ -286,7 +286,7 @@ export const buildWslRuntimeInstallScript = (
286
"}",
287
"runtime_is_ready() {",
288
' [ -f "$ready_marker" ] &&',
289
- ' runtime_entry_runs "$runtime_root" &&',
289
+ ' runtime_entry_runs "$runtime_root" 2>/dev/null &&',
290
` recorded_entry_digest=$(tr -d '[:space:]' < "$ready_marker" 2>/dev/null) &&`,
291
' [ -n "$recorded_entry_digest" ] &&',
292
' [ "$recorded_entry_digest" = "$(runtime_server_entry_digest "$runtime_root")" ]',