From 6d1c2754981a703b66b835458e6e9849b4b41024 Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Fri, 16 Jan 2026 12:48:52 -0800 Subject: [PATCH 1/3] fix(desktop): use consistent env for persistent terminal sessions The daemon-based terminal manager was merging the daemon's process.env with the filtered environment from buildTerminalEnv(). This caused inconsistent behavior between persistent and non-persistent modes: - Non-persistent: uses only the filtered env from buildTerminalEnv() - Persistent: merged daemon's process.env + filtered env The daemon's process.env could be stale (from when daemon was first spawned) or contain different values than expected, leading to unpredictable terminal environments. Now both modes use only the filtered env from buildTerminalEnv(), ensuring consistent and predictable behavior. --- apps/desktop/src/main/terminal-host/session.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/apps/desktop/src/main/terminal-host/session.ts b/apps/desktop/src/main/terminal-host/session.ts index 10972a41726..8d6b6adce50 100644 --- a/apps/desktop/src/main/terminal-host/session.ts +++ b/apps/desktop/src/main/terminal-host/session.ts @@ -169,16 +169,13 @@ export class Session { const { cwd, cols, rows, env = {} } = options; - // Build environment - filter out undefined values and ELECTRON_RUN_AS_NODE - const processEnv: Record = {}; - for (const [key, value] of Object.entries(process.env)) { - if (key === "ELECTRON_RUN_AS_NODE") continue; - if (value !== undefined) { - processEnv[key] = value; - } - } - Object.assign(processEnv, env); - processEnv.TERM = "xterm-256color"; + // Use the environment passed from the main process (already filtered by buildTerminalEnv). + // This matches the non-persistent mode behavior - only use the filtered env, + // not the daemon's process.env which may have stale or different values. + const processEnv: Record = { + ...env, + TERM: "xterm-256color", + }; // Get shell args const shellArgs = this.getShellArgs(this.shell); From 64e29dd85f5a466248256358c141ae7acbe2fdce Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Fri, 16 Jan 2026 14:21:09 -0800 Subject: [PATCH 2/3] Revert "fix(desktop): use consistent env for persistent terminal sessions" This reverts commit 6d1c2754981a703b66b835458e6e9849b4b41024. --- apps/desktop/src/main/terminal-host/session.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/desktop/src/main/terminal-host/session.ts b/apps/desktop/src/main/terminal-host/session.ts index 8d6b6adce50..10972a41726 100644 --- a/apps/desktop/src/main/terminal-host/session.ts +++ b/apps/desktop/src/main/terminal-host/session.ts @@ -169,13 +169,16 @@ export class Session { const { cwd, cols, rows, env = {} } = options; - // Use the environment passed from the main process (already filtered by buildTerminalEnv). - // This matches the non-persistent mode behavior - only use the filtered env, - // not the daemon's process.env which may have stale or different values. - const processEnv: Record = { - ...env, - TERM: "xterm-256color", - }; + // Build environment - filter out undefined values and ELECTRON_RUN_AS_NODE + const processEnv: Record = {}; + for (const [key, value] of Object.entries(process.env)) { + if (key === "ELECTRON_RUN_AS_NODE") continue; + if (value !== undefined) { + processEnv[key] = value; + } + } + Object.assign(processEnv, env); + processEnv.TERM = "xterm-256color"; // Get shell args const shellArgs = this.getShellArgs(this.shell); From ac423f0b566aa147ac4ebd0f819c90b2730661d6 Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Fri, 16 Jan 2026 14:22:00 -0800 Subject: [PATCH 3/3] Reapply "fix(desktop): use consistent env for persistent terminal sessions" This reverts commit 64e29dd85f5a466248256358c141ae7acbe2fdce. --- apps/desktop/src/main/terminal-host/session.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/apps/desktop/src/main/terminal-host/session.ts b/apps/desktop/src/main/terminal-host/session.ts index 10972a41726..8d6b6adce50 100644 --- a/apps/desktop/src/main/terminal-host/session.ts +++ b/apps/desktop/src/main/terminal-host/session.ts @@ -169,16 +169,13 @@ export class Session { const { cwd, cols, rows, env = {} } = options; - // Build environment - filter out undefined values and ELECTRON_RUN_AS_NODE - const processEnv: Record = {}; - for (const [key, value] of Object.entries(process.env)) { - if (key === "ELECTRON_RUN_AS_NODE") continue; - if (value !== undefined) { - processEnv[key] = value; - } - } - Object.assign(processEnv, env); - processEnv.TERM = "xterm-256color"; + // Use the environment passed from the main process (already filtered by buildTerminalEnv). + // This matches the non-persistent mode behavior - only use the filtered env, + // not the daemon's process.env which may have stale or different values. + const processEnv: Record = { + ...env, + TERM: "xterm-256color", + }; // Get shell args const shellArgs = this.getShellArgs(this.shell);