The best way to control Claude Code, Codex and more from any computer or phone
fix(server): recover service PATH after a slow login shell probe (#23356)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 11, 2026 at 12:02 UTC
686121d470d9ebf10cab115dcecc91ea697e7803
2 files changed
+89
-4
apps/server/src/os-jank.test.ts
+53
@@ -64,6 +64,59 @@ effectIt.effect("hydrates PATH when the desktop handoff is absent", () =>
64
),
65
);
66
67
+const timedOut = (file: string) =>
68
+ Object.assign(new Error(`spawnSync ${file} ETIMEDOUT`), { code: "ETIMEDOUT" });
69
+
70
+effectIt.effect("waits longer for a login shell that times out at startup", () =>
71
+ Effect.acquireUseRelease(
72
+ Effect.sync(() =>
73
+ vi.spyOn(NodeChildProcess, "execFileSync").mockImplementation((file, _args, options) => {
74
+ // This profile takes 8 seconds while the machine is under load.
75
+ if ((options?.timeout ?? 0) < 8_000) throw timedOut(String(file));
76
+ return "__T3CODE_ENV_PATH_START__\n/opt/tools/bin\n__T3CODE_ENV_PATH_END__\n";
77
+ }),
78
+ ),
79
+ () =>
80
+ Effect.gen(function* () {
81
+ const env: NodeJS.ProcessEnv = { SHELL: "/bin/zsh", PATH: "/usr/bin" };
82
+
83
+ yield* fixPath().pipe(
84
+ Effect.provideService(HostProcess.Platform, "linux"),
85
+ Effect.provideService(HostProcess.Environment, env),
86
+ Effect.provide(NodeServices.layer),
87
+ );
88
+
89
+ assert.equal(env.PATH, "/opt/tools/bin:/usr/bin");
90
+ }),
91
+ (probe) => Effect.sync(() => probe.mockRestore()),
92
+ ),
93
+);
94
+
95
+effectIt.effect("waits longer for only one hung login shell", () =>
96
+ Effect.acquireUseRelease(
97
+ Effect.sync(() =>
98
+ vi.spyOn(NodeChildProcess, "execFileSync").mockImplementation((file) => {
99
+ throw timedOut(String(file));
100
+ }),
101
+ ),
102
+ (probe) =>
103
+ Effect.gen(function* () {
104
+ const env: NodeJS.ProcessEnv = { SHELL: "/bin/zsh", PATH: "/usr/bin" };
105
+
106
+ yield* fixPath().pipe(
107
+ Effect.provideService(HostProcess.Platform, "linux"),
108
+ Effect.provideService(HostProcess.Environment, env),
109
+ Effect.provide(NodeServices.layer),
110
+ );
111
+
112
+ const timeouts = probe.mock.calls.map(([, , options]) => options?.timeout);
113
+ assert.equal(timeouts.filter((timeout) => (timeout ?? 0) > 5_000).length, 1);
114
+ assert.equal(env.PATH, "/usr/bin");
115
+ }),
116
+ (probe) => Effect.sync(() => probe.mockRestore()),
117
+ ),
118
+);
119
+
120
effectIt.effect("keeps mise's PATH record with the login shell PATH", () =>
121
Effect.acquireUseRelease(
122
Effect.sync(() =>
apps/server/src/os-jank.ts
+36
-4
@@ -10,6 +10,8 @@ import {
10
import * as Effect from "effect/Effect";
11
import * as FileSystem from "effect/FileSystem";
12
import * as Path from "effect/Path";
13
+// @effect-diagnostics-next-line nodeBuiltinImport:off -- the shared login shell probe runs synchronously through execFileSync.
14
+import * as NodeChildProcess from "node:child_process";
15
import * as NodeOS from "node:os";
16
17
function logPathHydrationWarning(message: string, error?: unknown): void {
@@ -18,16 +20,46 @@ function logPathHydrationWarning(message: string, error?: unknown): void {
20
);
21
}
22
23
+// mise's record of the PATH entries it added. It must travel with the
24
+// shell's PATH, or `mise x` can rebuild PATH behind a same-named wrapper
25
+// (`exec mise x claude -- claude`) that then re-runs itself forever.
26
+const LOGIN_SHELL_ENVIRONMENT_NAMES = ["PATH", "__MISE_DIFF", "JAVA_HOME"];
27
+const SLOW_LOGIN_SHELL_TIMEOUT_MS = 20_000;
28
+
29
+function readSlowLoginShellEnvironment(shell: string): Partial<Record<string, string>> {
30
+ return readEnvironmentFromLoginShell(
31
+ shell,
32
+ LOGIN_SHELL_ENVIRONMENT_NAMES,
33
+ (file, args, options) =>
34
+ NodeChildProcess.execFileSync(file, args, {
35
+ ...options,
36
+ timeout: SLOW_LOGIN_SHELL_TIMEOUT_MS,
37
+ }),
38
+ );
39
+}
40
+
41
function hydratePosixPath(env: NodeJS.ProcessEnv, platform: NodeJS.Platform): void {
42
let shellEnvironment: Partial<Record<string, string>> = {};
43
+ let waitedForSlowShell = false;
44
for (const shell of listLoginShellCandidates(platform, env.SHELL)) {
45
try {
25
- // mise's record of the PATH entries it added. It must travel with the
26
- // shell's PATH, or `mise x` can rebuild PATH behind a same-named wrapper
27
- // (`exec mise x claude -- claude`) that then re-runs itself forever.
28
- shellEnvironment = readEnvironmentFromLoginShell(shell, ["PATH", "__MISE_DIFF", "JAVA_HOME"]);
46
+ shellEnvironment = readEnvironmentFromLoginShell(shell, LOGIN_SHELL_ENVIRONMENT_NAMES);
47
} catch (error) {
48
logPathHydrationWarning(`Failed to read PATH from login shell ${shell}.`, error);
49
+ // A profile can be slow only while the machine boots. Wait for it once,
50
+ // here: providers copy this env when they are built, so a later read
51
+ // would never reach them.
52
+ if (!waitedForSlowShell && (error as NodeJS.ErrnoException | null)?.code === "ETIMEDOUT") {
53
+ waitedForSlowShell = true;
54
+ try {
55
+ shellEnvironment = readSlowLoginShellEnvironment(shell);
56
+ } catch (retryError) {
57
+ logPathHydrationWarning(
58
+ `Failed to read PATH from slow login shell ${shell}.`,
59
+ retryError,
60
+ );
61
+ }
62
+ }
63
}
64
65
if (shellEnvironment.PATH) break;