@devries-cameron20 / t3code Mirror · read-only / commits / e1fad19018
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 21, 19:45 UTC

fix(desktop): a login shell slower than 5s at launch still yields its PATH (#35033)

Julius Marminge committed Nov 12, 2026 at 02:31 UTC e1fad19018bbc6aae612f2b2226133f10912cb62
2 files changed +91 -9
apps/desktop/src/shell/DesktopShellEnvironment.test.ts
+46
@@ -637,6 +637,52 @@ describe("DesktopShellEnvironment", () => {
637 }),
638 );
639
640 + it.effect("recovers the login-shell PATH when the first probe outlasts the timeout", () =>
641 + Effect.gen(function* () {
642 + const env: NodeJS.ProcessEnv = { SHELL: "/bin/zsh", PATH: "/usr/bin:/bin:/usr/sbin:/sbin" };
643 + const output = envOutput({ PATH: "/opt/homebrew/bin:/usr/bin" });
644 + let shellProbes = 0;
645 + yield* runShellEnvironment({
646 + env,
647 + platform: "darwin",
648 + handler: () => "",
649 + processSpawner: ChildProcessSpawner.make((command) => {
650 + if (command._tag !== "StandardCommand" || command.command !== "/bin/zsh") {
651 + return Effect.succeed(makeProcess(""));
652 + }
653 + shellProbes += 1;
654 + if (shellProbes > 1) return Effect.succeed(makeProcess(output));
655 + // A cold start: the first login shell answers, but only after 7s.
656 + const slow = Effect.sleep("7 seconds");
657 + const stdout = Stream.fromEffect(slow.pipe(Effect.as(textEncoder.encode(output))));
658 + return Effect.succeed(
659 + ChildProcessSpawner.makeHandle({
660 + pid: ChildProcessSpawner.ProcessId(125),
661 + stdout,
662 + stderr: Stream.empty,
663 + all: stdout,
664 + exitCode: slow.pipe(Effect.as(ChildProcessSpawner.ExitCode(0))),
665 + isRunning: Effect.succeed(true),
666 + kill: () => Effect.void,
667 + stdin: Sink.drain,
668 + getInputFd: () => Sink.drain,
669 + getOutputFd: () => Stream.empty,
670 + unref: Effect.succeed(Effect.void),
671 + }),
672 + );
673 + }),
674 + use: (service) =>
675 + Effect.gen(function* () {
676 + yield* service.installIntoProcess;
677 + yield* TestClock.adjust("10 minutes");
678 + return true;
679 + }),
680 + }).pipe(Effect.provide(Logger.layer([])));
681 +
682 + assert.equal(env.PATH, "/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin");
683 + }),
684 + );
685 +
686 it.effect("loads PowerShell profile environment on Windows", () =>
687 Effect.gen(function* () {
688 const env: NodeJS.ProcessEnv = {
apps/desktop/src/shell/DesktopShellEnvironment.ts
+45 -9
@@ -117,6 +117,8 @@ const LOCALE_ENV_NAMES = ["LANG", "LC_ALL", "LC_CTYPE"] as const;
117 const FALLBACK_LC_CTYPE = "en_US.UTF-8";
118 const WINDOWS_SHELL_CANDIDATES = ["pwsh.exe", "powershell.exe"] as const;
119 const LOGIN_SHELL_TIMEOUT = Duration.seconds(5);
120 +// A profile can be slow only while the machine boots; one longer wait covers it.
121 +const SLOW_LOGIN_SHELL_TIMEOUT = Duration.seconds(20);
122 const LAUNCHCTL_TIMEOUT = Duration.seconds(2);
123 const PROCESS_TERMINATE_GRACE = Duration.seconds(1);
124
@@ -261,7 +263,11 @@ const runCommandOutput = Effect.fn("desktop.shellEnvironment.runCommandOutput")(
263 readonly env: NodeJS.ProcessEnv;
264 readonly timeout: Duration.Duration;
265 readonly shell?: boolean;
264 -}): Effect.fn.Return<string, never, ChildProcessSpawner.ChildProcessSpawner> {
266 +}): Effect.fn.Return<
267 + string,
268 + DesktopShellEnvironmentCommandTimeoutError,
269 + ChildProcessSpawner.ChildProcessSpawner
270 +> {
271 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
272 const fiber = yield* Effect.scoped(
273 Effect.gen(function* () {
@@ -317,21 +323,34 @@ const runCommandOutput = Effect.fn("desktop.shellEnvironment.runCommandOutput")(
323 return output.value;
324 }
325
320 - const error = new DesktopShellEnvironmentCommandTimeoutError({
326 + return yield* new DesktopShellEnvironmentCommandTimeoutError({
327 probe: input.probe,
328 executable: executableName(input.command),
329 argumentCount: input.args.length,
330 timeoutMs: Duration.toMillis(input.timeout),
331 });
326 - yield* logShellEnvironmentCommandError(error);
327 - return "";
332 });
333
334 +const orEmptyOnTimeout = <R>(
335 + effect: Effect.Effect<string, DesktopShellEnvironmentCommandTimeoutError, R>,
336 +): Effect.Effect<string, never, R> =>
337 + effect.pipe(
338 + Effect.catchTags({
339 + DesktopShellEnvironmentCommandTimeoutError: (error) =>
340 + logShellEnvironmentCommandError(error).pipe(Effect.as("")),
341 + }),
342 + );
343 +
344 const readLoginShellEnvironment = (
345 shell: string,
346 names: ReadonlyArray<string>,
347 env: NodeJS.ProcessEnv,
334 -): Effect.Effect<EnvironmentPatch, never, ChildProcessSpawner.ChildProcessSpawner> =>
348 + timeout: Duration.Duration,
349 +): Effect.Effect<
350 + EnvironmentPatch,
351 + DesktopShellEnvironmentCommandTimeoutError,
352 + ChildProcessSpawner.ChildProcessSpawner
353 +> =>
354 names.length === 0
355 ? Effect.succeed({})
356 : runCommandOutput({
@@ -339,7 +358,7 @@ const readLoginShellEnvironment = (
358 command: shell,
359 args: ["-ilc", buildEnvironmentCaptureCommand(shell, names)],
360 env,
342 - timeout: LOGIN_SHELL_TIMEOUT,
361 + timeout,
362 }).pipe(Effect.map((output) => extractEnvironment(output, names)));
363
364 const readLaunchctlPath = (env: NodeJS.ProcessEnv) =>
@@ -349,7 +368,7 @@ const readLaunchctlPath = (env: NodeJS.ProcessEnv) =>
368 command: "/bin/launchctl",
369 args: ["getenv", "PATH"],
370 timeout: LAUNCHCTL_TIMEOUT,
352 - }).pipe(Effect.map(trimNonEmpty));
371 + }).pipe(orEmptyOnTimeout, Effect.map(trimNonEmpty));
372
373 const readWindowsEnvironment = Effect.fn("desktop.shellEnvironment.readWindowsEnvironment")(
374 function* (
@@ -374,7 +393,7 @@ const readWindowsEnvironment = Effect.fn("desktop.shellEnvironment.readWindowsEn
393 args,
394 env,
395 timeout: LOGIN_SHELL_TIMEOUT,
377 - });
396 + }).pipe(orEmptyOnTimeout);
397 const environment = extractEnvironment(output, names);
398 if (Object.keys(environment).length > 0) {
399 return environment;
@@ -429,10 +448,27 @@ const installPosixEnvironment = Effect.fn("desktop.shellEnvironment.installPosix
448 const userShells = [config.env.SHELL?.trim(), readUserLoginShell()];
449
450 let answeredBy: string | undefined;
451 + let waitedForSlowShell = false;
452 for (const shell of listLoginShellCandidates(config.platform, config.env.SHELL)) {
453 + const read = (timeout: Duration.Duration) =>
454 + readLoginShellEnvironment(shell, LOGIN_SHELL_ENV_NAMES, config.env, timeout);
455 Object.assign(
456 shellEnvironment,
435 - yield* readLoginShellEnvironment(shell, LOGIN_SHELL_ENV_NAMES, config.env),
457 + yield* read(LOGIN_SHELL_TIMEOUT).pipe(
458 + Effect.catchTags({
459 + DesktopShellEnvironmentCommandTimeoutError: (error) => {
460 + const retry = !waitedForSlowShell;
461 + waitedForSlowShell = true;
462 + return logShellEnvironmentCommandError(error).pipe(
463 + Effect.andThen(retry ? read(SLOW_LOGIN_SHELL_TIMEOUT) : Effect.succeed({})),
464 + );
465 + },
466 + }),
467 + Effect.catchTags({
468 + DesktopShellEnvironmentCommandTimeoutError: (error) =>
469 + logShellEnvironmentCommandError(error).pipe(Effect.as({})),
470 + }),
471 + ),
472 );
473 if (shellEnvironment.PATH) {
474 answeredBy = shell;