fix(desktop): an AppImage launch drops earlier launches' mount dirs from the server PATH #18808
MergedMnigos(GitHub profile, opens in a new tab)merged 8 commits into
main fromrefs/pull/18808/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/desktop/src/shell/appImageStaleMounts.ts lines 30 to 34OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +14,21 @@14+ * Non-AppImage envs are returned as is.15+ *16+ * Can fold into the shared `appImageRuntimeEnv` helper once #16679 lands.17+ */18+export function stripStaleAppImageMounts(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {19+ if (env.APPIMAGE === undefined && env.APPDIR === undefined) return env;20+21+ const appDir = env.APPDIR?.replace(/\/+$/, "");22+ const scrubbed: NodeJS.ProcessEnv = { ...env };23+ for (const key of APPIMAGE_SEARCH_PATH_ENV_KEYS) {24+ const value = env[key];25+ if (value === undefined) continue;26+ const kept = value.split(":").filter((segment) => {27+ const mountRoot = APPIMAGE_MOUNT_ROOT.exec(segment)?.[1];28+ return mountRoot === undefined || mountRoot === appDir;29+ });30+ if (kept.some((segment) => segment.length > 0)) {31+ scrubbed[key] = kept.join(":");32+ } else if (value.length > 0) {33+ delete scrubbed[key];34+ }apps/desktop/src/shell/appImageStaleMounts.ts lines 26 to 26OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +6,21 @@6+const APPIMAGE_MOUNT_ROOT = /^(.*?\/\.mount_[^/]+)(?:\/|$)/;7+8+/**9+ * Removes search-path segments that point into another AppImage launch's10+ * `.mount_*` dir. Launching T3 Code from a terminal or agent that inherited an11+ * earlier launch's env stacks every older mount onto PATH; once one of them is12+ * unmounted, every spawn that walks PATH (git, shells) fails with ENOTCONN.13+ * Segments under the current APPDIR stay, as do all non-mount segments.14+ * Non-AppImage envs are returned as is.15+ *16+ * Can fold into the shared `appImageRuntimeEnv` helper once #16679 lands.17+ */18+export function stripStaleAppImageMounts(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {19+ if (env.APPIMAGE === undefined && env.APPDIR === undefined) return env;20+21+ const appDir = env.APPDIR?.replace(/\/+$/, "");22+ const scrubbed: NodeJS.ProcessEnv = { ...env };23+ for (const key of APPIMAGE_SEARCH_PATH_ENV_KEYS) {24+ const value = env[key];25+ if (value === undefined) continue;26+ const kept = value.split(":").filter((segment) => {
juliusmarminge added labelsmacroscope-review
coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
apps/desktop/src/shell/appImageStaleMounts.ts lines 27 to 28OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +8,21 @@8+/**9+ * Removes search-path segments that point into another AppImage launch's10+ * `.mount_*` dir. Launching T3 Code from a terminal or agent that inherited an11+ * earlier launch's env stacks every older mount onto PATH; once one of them is12+ * unmounted, every spawn that walks PATH (git, shells) fails with ENOTCONN.13+ * Segments under the current APPDIR stay, as do all non-mount segments.14+ * Non-AppImage envs are returned as is.15+ *16+ * Can fold into the shared `appImageRuntimeEnv` helper once #16679 lands.17+ */18+export function stripStaleAppImageMounts(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {19+ if (env.APPIMAGE === undefined && env.APPDIR === undefined) return env;20+21+ const appDir = env.APPDIR?.replace(/\/+$/, "");22+ const scrubbed: NodeJS.ProcessEnv = { ...env };23+ for (const key of APPIMAGE_SEARCH_PATH_ENV_KEYS) {24+ const value = env[key];25+ if (value === undefined) continue;26+ const kept = value.split(":").filter((segment) => {27+ const mountRoot = APPIMAGE_MOUNT_ROOT.exec(segment)?.[1];28+ return mountRoot === undefined || mountRoot === appDir;apps/desktop/src/shell/appImageStaleMounts.ts lines 30 to 33OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +13,21 @@13+ * Segments under the current APPDIR stay, as do all non-mount segments.14+ * Non-AppImage envs are returned as is.15+ *16+ * Can fold into the shared `appImageRuntimeEnv` helper once #16679 lands.17+ */18+export function stripStaleAppImageMounts(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {19+ if (env.APPIMAGE === undefined && env.APPDIR === undefined) return env;20+21+ const appDir = env.APPDIR?.replace(/\/+$/, "");22+ const scrubbed: NodeJS.ProcessEnv = { ...env };23+ for (const key of APPIMAGE_SEARCH_PATH_ENV_KEYS) {24+ const value = env[key];25+ if (value === undefined) continue;26+ const kept = value.split(":").filter((segment) => {27+ const mountRoot = APPIMAGE_MOUNT_ROOT.exec(segment)?.[1];28+ return mountRoot === undefined || mountRoot === appDir;29+ });30+ if (kept.some((segment) => segment.length > 0)) {31+ scrubbed[key] = kept.join(":");32+ } else if (value.length > 0) {33+ delete scrubbed[key];coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
apps/desktop/src/shell/appImageStaleMounts.ts line 1OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +1 @@1+// @effect-diagnostics-next-line nodeBuiltinImport:off - Pure string normalization of env paths, no filesystem access.coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge assignedjuliusmarminge
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged this5bed8e4
juliusmarminge closed this
Sign in to join this conversation.

macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed