@devries-cameron20 / t3code Mirror · read-only / commits / cef6f7ae5e
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 23, 03:00 UTC

fix(server): keep workspace skills when provider health fails (#18309)

Nikita Maximilian Grimm committed Oct 18, 2026 at 21:52 UTC cef6f7ae5ebf201ea9a6d977f771bff7109f9cb3
6 files changed +245 -43
apps/server/src/provider/Drivers/CodexDriver.test.ts
+25
@@ -9,6 +9,7 @@ import { expect, it } from "@effect/vitest";
9 import { EnvironmentId, ProviderInstanceId, ProviderSessionId, ThreadId } from "@t3tools/contracts";
10 import * as HostProcess from "@t3tools/shared/HostProcess";
11 import * as Effect from "effect/Effect";
12 +import * as Exit from "effect/Exit";
13 import * as Deferred from "effect/Deferred";
14 import * as Fiber from "effect/Fiber";
15 import * as FileSystem from "effect/FileSystem";
@@ -140,9 +141,17 @@ it.layer(layerTest)("CodexDriver", (it) => {
141 > = [];
142
143 let interruptedChecks = 0;
144 + let failAcquire = false;
145 const startupChecksInterrupted = yield* Deferred.make<void>();
146 const acquire = () =>
147 Effect.suspend(() => {
148 + if (failAcquire)
149 + return Effect.fail(
150 + new CodexInstallation.CodexInstallationError({
151 + operation: "acquire",
152 + detail: "The fixture runtime is unavailable",
153 + }),
154 + );
155 if (interruptedChecks === 2) return Effect.succeed(executable);
156 interruptedChecks += 1;
157 return (
@@ -207,6 +216,18 @@ it.layer(layerTest)("CodexDriver", (it) => {
216 expect(restored.runtimePaths?.shadowHomePath).toContain(
217 `providers/codex/${instanceId}/shadow`,
218 );
219 + // The fixture app-server cannot start, so the workspace scan fails
220 + // instead of passing the machine snapshot off as the workspace's skills.
221 + const scan = yield* instance.snapshotForCwd!(serverConfig.stateDir).pipe(Effect.exit);
222 + expect(Exit.isFailure(scan)).toBe(true);
223 + // The account is still signed in, so a runtime that cannot start is a
224 + // failed scan too, not the machine snapshot's inventory.
225 + failAcquire = true;
226 + const runtimeScan = yield* instance.snapshotForCwd!(serverConfig.stateDir).pipe(
227 + Effect.exit,
228 + );
229 + failAcquire = false;
230 + expect(Exit.isFailure(runtimeScan)).toBe(true);
231 yield* Deferred.await(observedAccount);
232
233 const threadId = ThreadId.make("managed-account-thread");
@@ -238,6 +259,10 @@ it.layer(layerTest)("CodexDriver", (it) => {
259 expect(after.installed).toBe(true);
260 expect(after.models).toEqual([]);
261 expect(Option.isNone(yield* store.get)).toBe(true);
262 + // Signed out, there is no runtime to scan with, so the machine
263 + // snapshot's empty inventory stands instead of a failed scan.
264 + const signedOutScan = yield* instance.snapshotForCwd!(serverConfig.stateDir);
265 + expect(signedOutScan.skills).toEqual([]);
266 }).pipe(
267 Effect.provideService(ServerSecretStore.ServerSecretStore, secrets),
268 Effect.provideService(
apps/server/src/provider/Drivers/CodexManagedProvider.ts
+36 -13
@@ -284,21 +284,44 @@ export const makeManagedCodexProvider = Effect.fn("makeManagedCodexProvider")(fu
284 snapshotForCwd: (cwd: string) =>
285 enabled
286 ? resolveRuntime.pipe(
287 - Effect.flatMap((effective) =>
288 - probeCodexSkillsForCwd({
289 - binaryPath: effective.config.binaryPath,
290 - homePath: effective.config.homePath,
291 - launchArgs: effective.config.launchArgs,
292 - cwd,
293 - environment: effective.environment,
294 - }),
295 - ),
296 - Effect.flatMap((skills) =>
297 - snapshot.getSnapshot.pipe(Effect.map((draft) => ({ ...draft, skills }))),
298 - ),
287 + Effect.matchEffect({
288 + // Signed out or not set up, there is nothing to scan with and the
289 + // machine snapshot's empty inventory says as much. Otherwise the
290 + // runtime failed for a signed-in account (a token refresh or
291 + // reconnect) or before the first check, and the scan failed.
292 + onFailure: (cause) =>
293 + snapshot.getSnapshot.pipe(
294 + Effect.filterOrFail(
295 + (machine) => machine.auth.status === "unauthenticated",
296 + () => cause,
297 + ),
298 + ),
299 + onSuccess: (effective) =>
300 + probeCodexSkillsForCwd({
301 + binaryPath: effective.config.binaryPath,
302 + homePath: effective.config.homePath,
303 + launchArgs: effective.config.launchArgs,
304 + cwd,
305 + environment: effective.environment,
306 + }).pipe(
307 + Effect.flatMap((skills) =>
308 + snapshot.getSnapshot.pipe(Effect.map((draft) => ({ ...draft, skills }))),
309 + ),
310 + ),
311 + }),
312 Effect.scoped,
313 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
301 - Effect.catch(() => snapshot.getSnapshot),
314 + // Fail rather than return the machine snapshot: the registry
315 + // publishes any returned snapshot as this workspace's inventory.
316 + Effect.mapError(
317 + (cause) =>
318 + new ProviderDriverError({
319 + driver: DRIVER,
320 + instanceId,
321 + detail: `Failed to probe Codex skills for '${cwd}'`,
322 + cause,
323 + }),
324 + ),
325 )
326 : snapshot.getSnapshot,
327 } satisfies ProviderInstance;
apps/server/src/provider/ProviderRegistry.test.ts
+142 -9
@@ -65,6 +65,7 @@ import type {
65 } from "@t3tools/provider-core/server/driver";
66 import * as ProviderInstanceRegistry from "./ProviderInstanceRegistry.ts";
67 import * as ProviderRegistry from "./ProviderRegistry.ts";
68 +import { ProviderDriverError } from "./Errors.ts";
69 import { makeManualOnlyProviderMaintenanceCapabilities } from "@t3tools/provider-core/server/maintenanceResolver";
70 const decodeServerSettings = Schema.decodeSync(ServerSettings);
71 const encodeServerSettings = Schema.encodeSync(ServerSettings);
@@ -1866,12 +1867,6 @@ it.layer(
1867 slashCommands: [{ name: "project" }],
1868 skills: [{ name: "project", path: "/workspace/SKILL.md", enabled: true }],
1869 } as const satisfies ServerProvider;
1869 - const pendingScopedProvider = {
1870 - ...scopedProvider,
1871 - status: "error",
1872 - installed: false,
1873 - slashCommands: [],
1874 - } as const satisfies ServerProvider;
1870 const snapshotCalls = yield* Ref.make(0);
1871 const scopedResult = yield* Ref.make<ProviderWorkspaceSnapshot>({
1872 ...scopedProvider,
@@ -1884,7 +1879,7 @@ it.layer(
1879 readonly started: Deferred.Deferred<void>;
1880 readonly release: Deferred.Deferred<void>;
1881 } | null>(null);
1887 - const returnPendingSnapshot = yield* Ref.make(true);
1882 + const failScan = yield* Ref.make(true);
1883 const probeStarted = yield* Deferred.make<void>();
1884 const releaseProbe = yield* Deferred.make<void>();
1885 const makeInstance = (
@@ -1920,7 +1915,13 @@ it.layer(
1915 const firstInstance = makeInstance(machineProvider, () =>
1916 Effect.gen(function* () {
1917 yield* Ref.update(snapshotCalls, (count) => count + 1);
1923 - if (yield* Ref.get(returnPendingSnapshot)) return pendingScopedProvider;
1918 + if (yield* Ref.get(failScan)) {
1919 + return yield* new ProviderDriverError({
1920 + driver,
1921 + instanceId,
1922 + detail: "The workspace scan failed.",
1923 + });
1924 + }
1925 yield* Deferred.succeed(probeStarted, undefined);
1926 yield* Deferred.await(releaseProbe);
1927 const result = yield* Ref.get(scopedResult);
@@ -1977,7 +1978,7 @@ it.layer(
1978 const registry = yield* ProviderRegistry.ProviderRegistry;
1979 yield* registry.refreshWorkspaceSnapshot({ instanceId, cwd: "/workspace" });
1980 assert.strictEqual((yield* registry.getProviders)[0]?.workspaceSnapshots, undefined);
1980 - yield* Ref.set(returnPendingSnapshot, false);
1981 + yield* Ref.set(failScan, false);
1982 const workspaceUpdate = yield* registry.streamChanges.pipe(
1983 Stream.runHead,
1984 Effect.forkChild,
@@ -2089,6 +2090,138 @@ it.layer(
2090 }),
2091 );
2092
2093 + it.effect("publishes workspace skills while machine health is in error", () =>
2094 + Effect.gen(function* () {
2095 + const driver = ProviderDriverKind.make("codex");
2096 + const instanceId = ProviderInstanceId.make("codex");
2097 + const healthyProvider = {
2098 + instanceId,
2099 + driver,
2100 + status: "ready",
2101 + enabled: true,
2102 + installed: true,
2103 + auth: { status: "authenticated" },
2104 + checkedAt: "2026-06-10T00:00:00.000Z",
2105 + version: "1.0.0",
2106 + models: [],
2107 + slashCommands: [COMPACT_SLASH_COMMAND],
2108 + skills: [],
2109 + } as const satisfies ServerProvider;
2110 + // Codex's account check failed; its skill scan did not.
2111 + const unhealthyProvider = {
2112 + ...healthyProvider,
2113 + status: "error",
2114 + auth: { status: "unknown" },
2115 + message: "Codex app-server provider probe failed: unauthorized (401).",
2116 + slashCommands: [],
2117 + } as const satisfies ServerProvider;
2118 + const firstSkills = [{ name: "first", path: "/workspace/first/SKILL.md", enabled: true }];
2119 + const laterSkills = [{ name: "later", path: "/workspace/later/SKILL.md", enabled: true }];
2120 + const scanResult = yield* Ref.make<ProviderWorkspaceSnapshot>({
2121 + ...healthyProvider,
2122 + skills: firstSkills,
2123 + });
2124 + const instance: ProviderInstance = {
2125 + instanceId,
2126 + driverKind: driver,
2127 + continuationIdentity: { driverKind: driver, continuationKey: "codex:instance:codex" },
2128 + displayName: undefined,
2129 + enabled: true,
2130 + snapshot: {
2131 + resolveMaintenance: () =>
2132 + Effect.succeed(
2133 + makeManualOnlyProviderMaintenanceCapabilities({
2134 + provider: driver,
2135 + packageName: null,
2136 + }),
2137 + ),
2138 + getSnapshot: Effect.succeed(unhealthyProvider),
2139 + refresh: Effect.succeed(unhealthyProvider),
2140 + streamChanges: Stream.empty,
2141 + applyUsageLimits: () => Effect.void,
2142 + },
2143 + snapshotForCwd: () => Ref.get(scanResult),
2144 + orchestrationAdapter: {} as ProviderInstance["orchestrationAdapter"],
2145 + textGeneration: {} as ProviderInstance["textGeneration"],
2146 + };
2147 + const layerInstanceRegistry = Layer.succeed(
2148 + ProviderInstanceRegistry.ProviderInstanceRegistry,
2149 + {
2150 + getInstance: (requestedId) =>
2151 + Effect.succeed(requestedId === instanceId ? instance : undefined),
2152 + listInstances: Effect.succeed([instance]),
2153 + listUnavailable: Effect.succeed([]),
2154 + streamChanges: Stream.empty,
2155 + subscribeChanges: Effect.flatMap(PubSub.unbounded<void>(), PubSub.subscribe),
2156 + },
2157 + );
2158 + const scope = yield* Scope.make();
2159 + yield* Effect.addFinalizer(() => Scope.close(scope, Exit.void));
2160 + const runtimeServices = yield* Layer.build(
2161 + ProviderRegistry.layer.pipe(
2162 + Layer.provideMerge(layerInstanceRegistry),
2163 + Layer.provideMerge(
2164 + ServerConfig.layerTest(process.cwd(), {
2165 + prefix: "t3-provider-registry-unhealthy-workspace-",
2166 + }),
2167 + ),
2168 + Layer.provideMerge(NodeServices.layer),
2169 + ),
2170 + ).pipe(Scope.provide(scope));
2171 +
2172 + yield* Effect.gen(function* () {
2173 + const registry = yield* ProviderRegistry.ProviderRegistry;
2174 + const workspaceOf = Effect.map(
2175 + registry.getProviders,
2176 + (providers) => providers[0]?.workspaceSnapshots?.[0],
2177 + );
2178 + yield* registry.refreshWorkspaceSnapshot({ instanceId, cwd: "/workspace" });
2179 + assert.deepStrictEqual((yield* workspaceOf)?.slashCommands, [COMPACT_SLASH_COMMAND]);
2180 +
2181 + // An expired scan runs while the account check fails: the skills are
2182 + // current, but commands that ride on the health check are unknown.
2183 + yield* TestClock.adjust(PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS);
2184 + yield* Ref.set(scanResult, { ...unhealthyProvider, skills: laterSkills });
2185 + yield* registry.refreshWorkspaceSnapshot({ instanceId, cwd: "/workspace" });
2186 + const unhealthy = yield* workspaceOf;
2187 + assert.deepStrictEqual(unhealthy?.skills, laterSkills);
2188 + assert.deepStrictEqual(unhealthy?.slashCommands, [COMPACT_SLASH_COMMAND]);
2189 + assert.strictEqual(unhealthy?.slashCommandsPending, true);
2190 + const provider = (yield* registry.getProviders)[0];
2191 + assert.strictEqual(provider?.status, "error");
2192 + assert.strictEqual(provider?.message, unhealthyProvider.message);
2193 +
2194 + // A pending entry is rescanned on the next request; an empty scan
2195 + // removes the skills.
2196 + yield* Ref.set(scanResult, { ...unhealthyProvider, skills: [] });
2197 + yield* registry.refreshWorkspaceSnapshot({ instanceId, cwd: "/workspace" });
2198 + assert.deepStrictEqual((yield* workspaceOf)?.skills, []);
2199 +
2200 + // A driver that discovers its own commands reports them even while
2201 + // health is in error.
2202 + const discoveredCommand = { name: "review", description: "Review changes" };
2203 + yield* Ref.set(scanResult, {
2204 + ...unhealthyProvider,
2205 + slashCommands: [discoveredCommand],
2206 + slashCommandsPending: false,
2207 + });
2208 + yield* registry.refreshWorkspaceSnapshot({ instanceId, cwd: "/workspace" });
2209 + const discovered = yield* workspaceOf;
2210 + assert.deepStrictEqual(discovered?.slashCommands, [discoveredCommand]);
2211 + assert.strictEqual(discovered?.slashCommandsPending, undefined);
2212 +
2213 + // Once health recovers, the next scan restores the full entry.
2214 + yield* TestClock.adjust(PROVIDER_WORKSPACE_SNAPSHOT_TTL_MS);
2215 + yield* Ref.set(scanResult, { ...healthyProvider, skills: laterSkills });
2216 + yield* registry.refreshWorkspaceSnapshot({ instanceId, cwd: "/workspace" });
2217 + const recovered = yield* workspaceOf;
2218 + assert.deepStrictEqual(recovered?.skills, laterSkills);
2219 + assert.deepStrictEqual(recovered?.slashCommands, [COMPACT_SLASH_COMMAND]);
2220 + assert.strictEqual(recovered?.slashCommandsPending, undefined);
2221 + }).pipe(Effect.provide(runtimeServices));
2222 + }),
2223 + );
2224 +
2225 it.effect("refreshes OpenCode catalogs and preserves other providers", () =>
2226 Effect.gen(function* () {
2227 const codexDriver = ProviderDriverKind.make("codex");
apps/server/src/provider/ProviderRegistry.ts
+23 -18
@@ -910,25 +910,30 @@ export const layer = Layer.effect(
910 : Effect.void;
911 return yield* refreshMachineSnapshot.pipe(
912 Effect.andThen(instance.snapshotForCwd(input.cwd)),
913 + // A failed scan fails this effect, so a returned snapshot is a real
914 + // inventory even while the provider's health check reports an error.
915 Effect.flatMap((scopedSnapshot) =>
914 - scopedSnapshot.status === "error" && scopedSnapshot.slashCommandsPending === undefined
915 - ? Ref.get(providersRef)
916 - : instanceRegistry.getInstance(input.instanceId).pipe(
917 - Effect.flatMap((currentInstance) => {
918 - if (currentInstance !== instance) return Ref.get(providersRef);
919 - return updateProviders((currentProviders) =>
920 - currentProviders.map((candidate) =>
921 - candidate.instanceId === input.instanceId &&
922 - Equal.equals(workspaceSnapshotOf(candidate), scannedFrom)
923 - ? upsertProviderWorkspaceSnapshot(candidate, input.cwd, {
924 - ...scopedSnapshot,
925 - checkedAt: scannedAt,
926 - })
927 - : candidate,
928 - ),
929 - );
930 - }),
931 - ),
916 + instanceRegistry.getInstance(input.instanceId).pipe(
917 + Effect.flatMap((currentInstance) => {
918 + if (currentInstance !== instance) return Ref.get(providersRef);
919 + return updateProviders((currentProviders) =>
920 + currentProviders.map((candidate) =>
921 + candidate.instanceId === input.instanceId &&
922 + Equal.equals(workspaceSnapshotOf(candidate), scannedFrom)
923 + ? upsertProviderWorkspaceSnapshot(candidate, input.cwd, {
924 + ...scopedSnapshot,
925 + checkedAt: scannedAt,
926 + // Unless the driver reports its own command discovery,
927 + // commands come from the health check. A failed check
928 + // leaves them unknown, so keep the last ones and retry.
929 + slashCommandsPending:
930 + scopedSnapshot.slashCommandsPending ?? scopedSnapshot.status === "error",
931 + })
932 + : candidate,
933 + ),
934 + );
935 + }),
936 + ),
937 ),
938 Effect.ensuring(
939 claimed
packages/provider-opencode/src/server/driver.ts
+14 -2
@@ -380,10 +380,18 @@ export const OpenCodeDriver: ProviderDriver<
380 skills: openCodeRuntime.loadOpenCodeSkills(client),
381 commands: OpenCodeRuntime.loadOpenCodeCommands(client).pipe(
382 Effect.timeout("10 seconds"),
383 - Effect.orElseSucceed(() => []),
383 + Effect.option,
384 ),
385 },
386 { concurrency: "unbounded" },
387 + ).pipe(
388 + // Only a finished lookup is reported as complete. A failed one leaves
389 + // the flag unset, so the registry decides from the provider's health.
390 + Effect.map(({ skills, commands }) => ({
391 + skills,
392 + commands: Option.getOrElse(commands, () => []),
393 + slashCommandsPending: Option.isSome(commands) ? false : undefined,
394 + })),
395 );
396 const loadWorkspaceForCwd = (cwd: string) =>
397 effectiveConfig.serverUrl.trim().length > 0
@@ -487,16 +495,20 @@ export const OpenCodeDriver: ProviderDriver<
495 ...machineSnapshot,
496 skills: openCode2SkillsToServerProviderSkills(skills),
497 slashCommands: openCode2CommandsToServerProviderSlashCommands(commands),
498 + // A finished scan lists at least the built-ins. None means it
499 + // timed out, so the registry decides from the provider's health.
500 + slashCommandsPending: commands.length > 0 ? false : undefined,
501 })),
502 ),
503 v1: Effect.all([
504 snapshot.getSnapshot,
505 loadWorkspaceForCwd(cwd).pipe(Effect.timeout("20 seconds")),
506 ]).pipe(
496 - Effect.map(([machineSnapshot, { skills, commands }]) => ({
507 + Effect.map(([machineSnapshot, { skills, commands, slashCommandsPending }]) => ({
508 ...machineSnapshot,
509 skills: openCodeSkillsToServerProviderSkills(skills),
510 slashCommands: openCodeCommandsToServerProviderSlashCommands(commands),
511 + slashCommandsPending,
512 })),
513 Effect.mapError(
514 (cause) =>
packages/provider-pi/src/server/driver.ts
+5 -1
@@ -202,7 +202,11 @@ export const PiDriver: ProviderDriver<PiSettings, PiDriverEnv, Path.Path> = {
202 ),
203 ),
204 ]).pipe(
205 - Effect.map(([machineSnapshot, commands]) => ({ ...machineSnapshot, ...commands })),
205 + Effect.map(([machineSnapshot, commands]) => ({
206 + ...machineSnapshot,
207 + ...commands,
208 + slashCommandsPending: false,
209 + })),
210 ),
211 orchestrationAdapter,
212 textGeneration,