Skip to content

Commit 8856e3b

Browse files
fix(server): read PATH from the user's own shell, at most once per 10 s
Discovery also runs from thread views, the command palette and mobile, so each one spawned an interactive login shell; one read now serves 10 s. A failing or empty login shell no longer falls through to /bin/bash or /bin/zsh and merges their PATH: it logs a warning and leaves PATH alone. AI-assisted; verified with the tests and tools listed above.
1 parent 02c8b25 commit 8856e3b

2 files changed

Lines changed: 25 additions & 29 deletions

File tree

‎apps/server/src/os-jank.ts‎

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -186,38 +186,34 @@ const readLoginShellOutput = Effect.fn("readLoginShellOutput")(
186186
Effect.timeoutOption(LOGIN_SHELL_TIMEOUT),
187187
);
188188

189-
/**
190-
* Re-reads PATH from the login shell so tools installed after startup become
191-
* spawnable without restarting. Unlike the startup hydration it never blocks
192-
* the event loop, and it runs even when the desktop prepared the environment,
193-
* because that capture was taken once at launch. Failure leaves PATH alone.
194-
*/
189+
// Runs even when the desktop prepared the environment: that capture was taken
190+
// once at launch. Only the user's own shell counts; a fallback shell's PATH is
191+
// not their environment. Failure leaves PATH alone.
195192
export const refreshPathFromLoginShell = Effect.fn("refreshPathFromLoginShell")(function* () {
196193
const platform = yield* HostProcess.Platform;
197194
if (platform !== "darwin" && platform !== "linux") return;
198195
const env = yield* HostProcess.Environment;
196+
const [shell] = listLoginShellCandidates(platform, env.SHELL);
197+
if (!shell) return;
199198

200-
for (const shell of listLoginShellCandidates(platform, env.SHELL)) {
201-
const output = yield* readLoginShellOutput(shell).pipe(
202-
Effect.catchCause((cause) =>
203-
Effect.logWarning(`Failed to read PATH from login shell ${shell}.`, cause).pipe(
204-
Effect.as(Option.some("")),
205-
),
199+
const output = yield* readLoginShellOutput(shell).pipe(
200+
Effect.catchCause((cause) =>
201+
Effect.logWarning(`Failed to read PATH from login shell ${shell}.`, cause).pipe(
202+
Effect.as(Option.some("")),
206203
),
204+
),
205+
);
206+
if (Option.isNone(output)) {
207+
yield* Effect.logWarning(
208+
`Timed out reading PATH from login shell ${shell} after ${Duration.format(LOGIN_SHELL_TIMEOUT)}; PATH is unchanged.`,
207209
);
208-
// A slow profile is the user's real environment; a fallback shell's PATH
209-
// would not be, and trying it would multiply the wait.
210-
if (Option.isNone(output)) {
211-
yield* Effect.logWarning(
212-
`Timed out reading PATH from login shell ${shell} after ${Duration.format(LOGIN_SHELL_TIMEOUT)}; PATH is unchanged.`,
213-
);
214-
return;
215-
}
216-
const shellEnvironment = extractEnvironmentValues(output.value, LOGIN_SHELL_ENV_NAMES);
217-
if (shellEnvironment.PATH) {
218-
applyLoginShellEnvironment(env, platform, shellEnvironment);
219-
return;
220-
}
210+
return;
211+
}
212+
const shellEnvironment = extractEnvironmentValues(output.value, LOGIN_SHELL_ENV_NAMES);
213+
if (shellEnvironment.PATH) {
214+
applyLoginShellEnvironment(env, platform, shellEnvironment);
215+
} else {
216+
yield* Effect.logWarning(`Login shell ${shell} printed no PATH; PATH is unchanged.`);
221217
}
222218
});
223219

‎apps/server/src/sourceControl/SourceControlDiscovery.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ export const make = Effect.gen(function* () {
7777
const process = yield* VcsProcess.VcsProcess;
7878
const sourceControlProviders = yield* SourceControlProviderRegistry.SourceControlProviderRegistry;
7979
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
80-
// Every discovery (page open, Rescan, Publish) re-reads the login shell so a
81-
// tool installed since launch resolves here and in every later spawn.
82-
// Clients cache discovery; concurrent calls share one in-flight shell.
80+
// Discovery re-reads the login shell so a tool installed since launch
81+
// resolves here and in every later spawn. Thread views, the palette and
82+
// mobile also run discovery, so one interactive shell serves a short window.
8383
const refreshPath = yield* refreshPathFromLoginShell().pipe(
8484
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
85-
Effect.cachedWithTTL(Duration.zero),
85+
Effect.cachedWithTTL(Duration.seconds(10)),
8686
);
8787

8888
const probe = <Kind extends VcsDriverKind>(

0 commit comments

Comments
 (0)