diff --git a/apps/server/src/provider/ProviderRegistry.test.ts b/apps/server/src/provider/ProviderRegistry.test.ts
index e4ec16b77dde0..69b7bd9eb2c1d 100644
--- a/apps/server/src/provider/ProviderRegistry.test.ts
+++ b/apps/server/src/provider/ProviderRegistry.test.ts
@@ -565,6 +565,11 @@ const layerTestNodeServices = Layer.mergeAll(
Layer.succeed(ServerEnvironment.ServerEnvironmentIdentity, {
getEnvironmentId: Effect.succeed(EnvironmentId.make("00000000-0000-4000-8000-000000000001")),
}),
+ // A login shell that prints nothing, so refreshes never take PATH from the developer's profile.
+ Layer.effect(
+ HostProcess.Environment,
+ Effect.sync(() => ({ ...process.env, SHELL: "/usr/bin/true" })),
+ ),
// An empty home, so the developer's own Claude settings never reach provider probes.
Layer.effect(
HostProcess.HomeDirectory,
@@ -2562,10 +2567,37 @@ it.layer(
}),
);
- it.effect(
- "rebuilds only instances missing their CLI when a refresh finds a new Windows PATH",
- () => {
- const env: NodeJS.ProcessEnv = { PATH: "C:\\Windows" };
+ // A login shell stand-in that prints the capture with one more PATH entry, as a profile edited
+ // after launch would.
+ const withLateLoginShell = (effect: (shell: string) => Effect.Effect) =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const dir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-login-shell-" });
+ const shell = `${dir}/sh`;
+ yield* fs.writeFileString(
+ shell,
+ '#!/bin/sh\nPATH=/opt/late:/usr/bin exec /bin/sh -c "$2"\n',
+ );
+ yield* fs.chmod(shell, 0o755);
+ return yield* effect(shell);
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer));
+
+ it.effect.each([
+ {
+ name: "Windows PATH",
+ platform: "win32" as const,
+ path: "C:\\Windows",
+ expectedPath: "C:\\Windows;C:\\Tools",
+ },
+ {
+ name: "login-shell PATH",
+ platform: "linux" as const,
+ path: "/usr/bin",
+ expectedPath: "/opt/late:/usr/bin",
+ },
+ ])("rebuilds only instances missing their CLI when a refresh finds a new $name", (host) =>
+ withLateLoginShell((shell) => {
+ const env: NodeJS.ProcessEnv = { PATH: host.path, SHELL: shell };
return Effect.gen(function* () {
const driver = ProviderDriverKind.make("codex");
const makeInstance = (id: string, installed: boolean): ProviderInstance => {
@@ -2627,7 +2659,9 @@ it.layer(
}),
),
Layer.provideMerge(
- ServerConfig.layerTest(process.cwd(), { prefix: "t3-provider-registry-path-" }),
+ ServerConfig.layerTest(process.cwd(), {
+ prefix: "t3-provider-registry-path-",
+ }),
),
Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
),
@@ -2636,16 +2670,16 @@ it.layer(
yield* registry.refresh();
- assert.strictEqual(env.PATH, "C:\\Windows;C:\\Tools");
+ assert.strictEqual(env.PATH, host.expectedPath);
assert.deepStrictEqual(rebuilt, [[ProviderInstanceId.make("missing")]]);
}).pipe(
- Effect.provideService(HostProcess.Platform, "win32"),
+ Effect.provideService(HostProcess.Platform, host.platform),
Effect.provideService(HostProcess.Environment, env),
Effect.provideService(WindowsShellEnvironment, () =>
Effect.succeed({ PATH: "C:\\Windows;C:\\Tools" }),
),
);
- },
+ }),
);
it.effect("rescans a requested cwd whose snapshot is still current", () =>
diff --git a/apps/server/src/provider/ProviderRegistry.ts b/apps/server/src/provider/ProviderRegistry.ts
index 43f57bb99a777..43d66cd1ca049 100644
--- a/apps/server/src/provider/ProviderRegistry.ts
+++ b/apps/server/src/provider/ProviderRegistry.ts
@@ -26,12 +26,14 @@ import * as Ref from "effect/Ref";
import * as Scope from "effect/Scope";
import * as Stream from "effect/Stream";
import * as Semaphore from "effect/Semaphore";
+import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
+import * as HostProcess from "@t3tools/shared/HostProcess";
import * as ProviderLatestVersions from "@t3tools/provider-core/server/ProviderLatestVersions";
import * as ModelManifest from "./ModelManifest.ts";
import { applyProviderCompatibility } from "./providerCompatibility.ts";
import * as ServerConfig from "../config.ts";
-import { refreshWindowsPath } from "../os-jank.ts";
+import { refreshPathFromLoginShell, refreshWindowsPath } from "../os-jank.ts";
import * as ProviderInstanceRegistry from "./ProviderInstanceRegistry.ts";
import * as ProviderInstanceRegistryMutator from "./ProviderInstanceRegistryMutator.ts";
import {
@@ -747,7 +749,20 @@ export const layer = Layer.effect(
// A refresh is how a user asks T3 to see a CLI installed since launch; a burst shares one probe.
// Drivers copy the environment when built, so instances still missing their CLI are rebuilt
// on the new PATH. They cannot have live sessions, and installed ones keep theirs.
+ // Compared with the last PATH seen here, since other features re-read the login shell too.
+ const hostEnvironment = yield* HostProcess.Environment;
+ const readHostPath = () => hostEnvironment.PATH ?? hostEnvironment.Path ?? hostEnvironment.path;
+ const lastHostPathRef = yield* Ref.make(readHostPath());
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const refreshHostPath = yield* refreshWindowsPath().pipe(
+ Effect.andThen(refreshPathFromLoginShell()),
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
+ Effect.andThen(
+ Effect.suspend(() => {
+ const path = readHostPath();
+ return Ref.getAndSet(lastHostPathRef, path).pipe(Effect.map((last) => last !== path));
+ }),
+ ),
Effect.flatMap((changed) =>
changed
? Ref.get(providersRef).pipe(
diff --git a/apps/server/src/provider/providerCompatibility.test.ts b/apps/server/src/provider/providerCompatibility.test.ts
index 83947bedf9213..1629c7e492fb5 100644
--- a/apps/server/src/provider/providerCompatibility.test.ts
+++ b/apps/server/src/provider/providerCompatibility.test.ts
@@ -1,6 +1,7 @@
import { assert, describe, it } from "@effect/vitest";
import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
import * as NodeServices from "@effect/platform-node/NodeServices";
+import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Deferred from "effect/Deferred";
import * as Fiber from "effect/Fiber";
import * as Effect from "effect/Effect";
@@ -329,6 +330,8 @@ it.effect("a remote policy refresh preserves a newer health result on the regist
),
),
),
+ // A login shell that prints nothing, so the refresh never takes PATH from the developer's profile.
+ Effect.provideService(HostProcess.Environment, { ...process.env, SHELL: "/usr/bin/true" }),
);
}),
);