@devries-cameron20 / t3code Mirror · read-only / commits / 5bed8e4df6
Fork 0

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, 00:30 UTC

fix(desktop): an AppImage launch drops earlier launches' mount dirs from the server PATH (#18808)

Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

Igor Makowski committed Oct 20, 2026 at 04:50 UTC 5bed8e4df6fbaf35e8c660195ee23338fd702910
2 files changed +77
apps/desktop/src/shell/DesktopShellEnvironment.test.ts
+43
@@ -530,6 +530,49 @@ describe("DesktopShellEnvironment", () => {
530 }),
531 );
532
533 + it.effect("drops earlier AppImage launches' mount dirs from the search paths on linux", () =>
534 + Effect.gen(function* () {
535 + const current = "/var/tmp/.mount_cur";
536 + const env: NodeJS.ProcessEnv = {
537 + SHELL: "/bin/zsh",
538 + APPIMAGE: "/home/me/T3-Code.AppImage",
539 + APPDIR: `${current}/`,
540 + PATH: `${current}/usr/bin:/tmp/.mount_old/usr/bin:/usr/bin`,
541 + LD_LIBRARY_PATH: `/tmp/.mount_old/usr/lib:${current}/usr/lib::/opt/lib`,
542 + XDG_DATA_DIRS: "/tmp/.mount_old/usr/share:/var/tmp/.mount_cur2/usr/share",
543 + };
544 +
545 + yield* runShellEnvironment({
546 + env,
547 + platform: "linux",
548 + handler: () => envOutput({ PATH: "/tmp/.mount_older/usr/bin:/home/me/.local/bin" }),
549 + });
550 +
551 + assert.equal(env.PATH, `/home/me/.local/bin:${current}/usr/bin:/usr/bin`);
552 + assert.equal(env.LD_LIBRARY_PATH, `${current}/usr/lib::/opt/lib`);
553 + assert.equal(env.XDG_DATA_DIRS, undefined);
554 + }),
555 + );
556 +
557 + it.effect("keeps AppImage-looking search paths outside an AppImage launch", () =>
558 + Effect.gen(function* () {
559 + const env: NodeJS.ProcessEnv = {
560 + SHELL: "/bin/zsh",
561 + PATH: "/tmp/.mount_old/usr/bin:/usr/bin",
562 + LD_LIBRARY_PATH: "/tmp/.mount_old/usr/lib",
563 + };
564 +
565 + yield* runShellEnvironment({
566 + env,
567 + platform: "linux",
568 + handler: () => envOutput({ PATH: "/usr/bin" }),
569 + });
570 +
571 + assert.equal(env.PATH, "/usr/bin:/tmp/.mount_old/usr/bin");
572 + assert.equal(env.LD_LIBRARY_PATH, "/tmp/.mount_old/usr/lib");
573 + }),
574 + );
575 +
576 it.effect("prefers login-shell desktop session hints over inherited values on linux", () =>
577 Effect.gen(function* () {
578 const env: NodeJS.ProcessEnv = {
apps/desktop/src/shell/DesktopShellEnvironment.ts
+34
@@ -114,6 +114,37 @@ const readEnvPath = (env: NodeJS.ProcessEnv): Option.Option<string> =>
114
115 const normalizeRuntimeDir = (value: string): string => value.replace(/\/+$/u, "");
116
117 +const APPIMAGE_SEARCH_PATH_ENV_NAMES = ["PATH", "LD_LIBRARY_PATH", "XDG_DATA_DIRS"] as const;
118 +
119 +// The AppImage runtime mounts each launch at `$TMPDIR/.mount_<id>` and prepends
120 +// it to the search paths above. A launch started from a shell that inherited an
121 +// earlier launch's env carries that mount too, and once it is unmounted every
122 +// spawn that walks PATH (git first of all) fails with ENOTCONN.
123 +const APPIMAGE_MOUNT_ROOT = /^(.*?\/\.mount_[^/]+)(?:\/|$)/u;
124 +
125 +const stripStaleAppImageMounts = (env: NodeJS.ProcessEnv): void => {
126 + if (env.APPIMAGE === undefined && env.APPDIR === undefined) return;
127 + const appDir = env.APPDIR === undefined ? undefined : normalizeRuntimeDir(env.APPDIR);
128 + for (const name of APPIMAGE_SEARCH_PATH_ENV_NAMES) {
129 + const value = env[name];
130 + if (value === undefined) continue;
131 + // glibc's loader also splits LD_LIBRARY_PATH on `;`.
132 + const segments = value.split(name === "LD_LIBRARY_PATH" ? /[:;]/u : ":");
133 + const kept = segments.filter((segment) => {
134 + const mountRoot = APPIMAGE_MOUNT_ROOT.exec(segment)?.[1];
135 + return mountRoot === undefined || mountRoot === appDir;
136 + });
137 + if (kept.length === segments.length) continue;
138 + if (kept.length === 0) {
139 + delete env[name];
140 + } else {
141 + // An empty segment is the current dir to the loader and to PATH lookup,
142 + // but a lone one joins to "", which reads as unset.
143 + env[name] = kept.join(":") || ":";
144 + }
145 + }
146 +};
147 +
148 const linuxRuntimeDirCandidates = (
149 env: NodeJS.ProcessEnv,
150 uid: number | undefined,
@@ -430,6 +461,9 @@ const installPosixEnvironment = Effect.fn("desktop.shellEnvironment.installPosix
461 if (Option.isSome(mergedPath)) {
462 config.env.PATH = mergedPath.value;
463 }
464 + // The server, relaunch and updater all inherit process.env, so scrubbing
465 + // here keeps earlier AppImage launches' mounts out of every one of them.
466 + stripStaleAppImageMounts(config.env);
467 if (!config.env.SSH_AUTH_SOCK && shellEnvironment.SSH_AUTH_SOCK) {
468 config.env.SSH_AUTH_SOCK = shellEnvironment.SSH_AUTH_SOCK;
469 }