@devries-cameron20 / t3code-1 / commits / ab43269d55
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(desktop): remove stale AppImage mounts from cached PATH (#30824)

Co-authored-by: maria-rcks <maria@kuuro.net>

Lakshmi Tanmay committed Nov 19, 2026 at 11:27 UTC ab43269d5598d30a2c4b283f8f384c00cd4fcc0f
2 files changed +144 -23
apps/desktop/src/shell/DesktopShellEnvironment.test.ts
+127 -23
@@ -184,30 +184,134 @@ function runShellEnvironment(input: {
184 }
185
186 describe("DesktopShellEnvironment", () => {
187 - it.effect("does not wait for discovery when the cache is missing", () =>
188 - Effect.gen(function* () {
189 - const started = yield* Deferred.make<void>();
190 - const release = yield* Deferred.make<void>();
191 - yield* runShellEnvironment({
192 - env: { SHELL: "/test-shell", PATH: "/usr/bin" },
193 - platform: "darwin",
194 - handler: () => "",
195 - processSpawner: ChildProcessSpawner.make(() =>
196 - Deferred.succeed(started, undefined).pipe(
197 - Effect.andThen(Deferred.await(release)),
198 - Effect.as(makeProcess(envOutput({ PATH: "/fresh/bin" }))),
199 - ),
200 - ),
201 - use: (service) =>
202 - Effect.gen(function* () {
203 - const startup = yield* service.installIntoProcess.pipe(Effect.forkChild);
204 - yield* Deferred.await(started);
205 - assert.isDefined(startup.pollUnsafe());
206 - yield* Deferred.succeed(release, undefined);
207 - return yield* service.awaitDiscovery;
187 + it.effect.each([
188 + { platform: "linux" as const, runtime: { APPDIR: "/opt/t3.AppDir/" }, scrub: true },
189 + { platform: "linux" as const, runtime: { APPIMAGE: "/opt/T3.AppImage" }, scrub: true },
190 + { platform: "linux" as const, runtime: {}, scrub: false },
191 + { platform: "darwin" as const, runtime: { APPDIR: "/opt/t3.AppDir/" }, scrub: false },
192 + ])(
193 + "keeps AppImage mounts out of cached and discovered PATH: %j",
194 + ({ platform, runtime, scrub }) =>
195 + Effect.gen(function* () {
196 + const fs = yield* FileSystem.FileSystem;
197 + const stateDir = yield* fs.makeTempDirectoryScoped();
198 + const cachePath = `${stateDir}/shell-environment-cache.json`;
199 + const inheritedPath =
200 + "/tmp/.mount_T3-Codold123/usr/bin:/launcher/bin:/opt/t3.AppDir/usr/bin";
201 + const cachedPath = "/cached/bin:/tmp/.mount_T3-Codcache1/usr/bin";
202 + const discoveredPath = "/fresh/bin:/tmp/.mount_T3-Codprobe1/usr/bin";
203 + const retainedPath = "/tmp/tools:/tmp/.mount_Other123/usr/bin:/opt/t3.AppDir-backup/bin";
204 + const cleanInherited = scrub
205 + ? `/launcher/bin${runtime.APPDIR ? "" : ":/opt/t3.AppDir/usr/bin"}`
206 + : inheritedPath;
207 + const cleanCached = scrub ? "/cached/bin" : cachedPath;
208 + const cleanDiscovered = scrub ? "/fresh/bin" : discoveredPath;
209 + const env: NodeJS.ProcessEnv = {
210 + ...runtime,
211 + SHELL: "/bin/bash",
212 + PATH: `${inheritedPath}:${retainedPath}`,
213 + };
214 + yield* fs.writeFileString(
215 + cachePath,
216 + encodeCache({
217 + version: 1,
218 + key: JSON.stringify([platform, "/test-home", "/bin/bash", ""]),
219 + environment: { PATH: cachedPath, __MISE_DIFF: "cached-mise" },
220 }),
209 - });
210 - }),
221 + );
222 + const started = yield* Deferred.make<void>();
223 + const release = yield* Deferred.make<void>();
224 + const probePath = yield* Deferred.make<string | undefined>();
225 + yield* runShellEnvironment({
226 + env,
227 + platform,
228 + stateDir,
229 + handler: () => "",
230 + processSpawner: ChildProcessSpawner.make((command) =>
231 + Effect.gen(function* () {
232 + const value =
233 + command._tag === "StandardCommand" ? command.options.env?.PATH : undefined;
234 + const path = typeof value === "string" ? value : undefined;
235 + yield* Deferred.succeed(probePath, path);
236 + yield* Deferred.succeed(started, undefined);
237 + yield* Deferred.await(release);
238 + return makeProcess(
239 + envOutput({ PATH: `${discoveredPath}:${path}`, __MISE_DIFF: "fresh-mise" }),
240 + );
241 + }),
242 + ),
243 + use: (service) =>
244 + Effect.gen(function* () {
245 + yield* service.installIntoProcess;
246 + const expectedCached = `${cleanCached}:${cleanInherited}:${retainedPath}`;
247 + assert.equal(env.PATH, expectedCached);
248 + assert.equal(env.__MISE_DIFF, "cached-mise");
249 + const cached = yield* Stream.runHead(service.updates);
250 + assert.equal(Option.getOrThrow(cached).environment.PATH, expectedCached);
251 + yield* Deferred.await(started);
252 + assert.equal(yield* Deferred.await(probePath), `${cleanInherited}:${retainedPath}`);
253 + yield* Deferred.succeed(release, undefined);
254 + yield* service.awaitDiscovery;
255 + const expectedFresh = `${cleanDiscovered}:${cleanInherited}:${retainedPath}`;
256 + assert.equal(env.PATH, expectedFresh);
257 + assert.equal(env.__MISE_DIFF, "fresh-mise");
258 + const fresh = yield* Stream.runHead(service.updates);
259 + assert.equal(Option.getOrThrow(fresh).environment.PATH, expectedFresh);
260 + return true;
261 + }),
262 + });
263 + const cached = yield* fs.readFileString(cachePath).pipe(Effect.flatMap(decodeCache));
264 + assert.equal(cached.environment.PATH, env.PATH);
265 + assert.equal(cached.environment.__MISE_DIFF, "fresh-mise");
266 + }).pipe(Effect.provide(NodeServices.layer)),
267 + );
268 +
269 + it.effect.each([
270 + { platform: "darwin" as const, env: { PATH: "/usr/bin" }, expectedPath: "/usr/bin" },
271 + {
272 + platform: "linux" as const,
273 + env: { APPDIR: "/tmp/.mount_T3-Codnew123", PATH: ":/tmp/.mount_T3-Codold123/bin::/usr/bin:" },
274 + expectedPath: "::/usr/bin:",
275 + },
276 + {
277 + platform: "linux" as const,
278 + env: { APPDIR: "/tmp/.mount_T3-Codnew123", PATH: "/tmp/.mount_T3-Codnew123/bin" },
279 + expectedPath: undefined,
280 + },
281 + ])(
282 + "does not wait for discovery when the cache is missing: %j",
283 + ({ platform, env: initial, expectedPath }) =>
284 + Effect.gen(function* () {
285 + const started = yield* Deferred.make<void>();
286 + const release = yield* Deferred.make<void>();
287 + const env: NodeJS.ProcessEnv = { SHELL: "/test-shell", ...initial };
288 + let probePath: string | undefined;
289 + yield* runShellEnvironment({
290 + env,
291 + platform,
292 + handler: () => "",
293 + processSpawner: ChildProcessSpawner.make((command) =>
294 + Effect.gen(function* () {
295 + const value =
296 + command._tag === "StandardCommand" ? command.options.env?.PATH : undefined;
297 + probePath = typeof value === "string" ? value : undefined;
298 + yield* Deferred.succeed(started, undefined);
299 + yield* Deferred.await(release);
300 + return makeProcess(envOutput({ PATH: "/fresh/bin" }));
301 + }),
302 + ),
303 + use: (service) =>
304 + Effect.gen(function* () {
305 + const startup = yield* service.installIntoProcess.pipe(Effect.forkChild);
306 + yield* Deferred.await(started);
307 + assert.isDefined(startup.pollUnsafe());
308 + assert.equal(env.PATH, expectedPath);
309 + assert.equal(probePath, expectedPath);
310 + yield* Deferred.succeed(release, undefined);
311 + return yield* service.awaitDiscovery;
312 + }),
313 + });
314 + }),
315 );
316
317 it.effect(
apps/desktop/src/shell/DesktopShellEnvironment.ts
+17
@@ -669,6 +669,21 @@ export const make = Effect.gen(function* () {
669 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
670 const scope = yield* Scope.Scope;
671 const env = process.env;
672 + const isLinuxAppImage =
673 + environment.platform === "linux" && (env.APPIMAGE !== undefined || env.APPDIR !== undefined);
674 + const appDir = env.APPDIR?.replace(/\/+$/u, "");
675 + const stripAppImagePaths = (target: NodeJS.ProcessEnv) => {
676 + if (!isLinuxAppImage || target.PATH === undefined) return;
677 + // Cached PATHs can outlive the AppImage mount that originally contributed them.
678 + const kept = target.PATH.split(":").filter(
679 + (entry) =>
680 + !(appDir && (entry === appDir || entry.startsWith(`${appDir}/`))) &&
681 + !/^\/tmp\/\.mount_T3-[^/]+(?:\/|$)/u.test(entry),
682 + );
683 + if (kept.length > 0) target.PATH = kept.join(":");
684 + else delete target.PATH;
685 + };
686 + stripAppImagePaths(env);
687 const inherited = { ...env };
688 const key = encodeCacheKey([
689 environment.platform,
@@ -706,6 +721,7 @@ export const make = Effect.gen(function* () {
721 budget,
722 });
723 const { prepared } = discovery;
724 + stripAppImagePaths(fresh);
725 const patch = Object.fromEntries(
726 Object.keys(ShellEnvironmentPatch.fields).map((name) => [name, fresh[name] ?? null]),
727 );
@@ -767,6 +783,7 @@ export const make = Effect.gen(function* () {
783 return typeof value === "string" ? [[name, value]] : [];
784 }),
785 );
786 + stripAppImagePaths(cached);
787 const baseline = { ...inherited };
788 const cachedPath = cached.PATH;
789 if (cachedPath) {