Skip to content

Commit 61981f6

Browse files
Bil0000claude
andcommitted
fix(server): reply with the machine catalog when a cwd scan fails for on-demand clients
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 791c9f1 commit 61981f6

4 files changed

Lines changed: 52 additions & 2 deletions

File tree

‎apps/server/src/ws.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,31 @@ it.effect("on-demand clients get provider config without workspace snapshots", (
964964
refreshed.providers.map((entry) => [entry.workspaceSnapshots, entry.slashCommands]),
965965
[[[snapshotFor("/b", "2026-10-25T00:00:00.000Z")], []]],
966966
);
967+
// A failed scan still gives a client without the machine catalog its commands.
968+
yield* server.write(0, {
969+
_tag: "Request",
970+
id: RpcMessage.RequestId("refresh-failed-scan"),
971+
tag: WS_METHODS.serverRefreshProviders,
972+
payload: {
973+
instanceId,
974+
cwd: "/c",
975+
workspaceSnapshotsOnDemand: true,
976+
providerCatalogsOnDemand: true,
977+
},
978+
headers: Headers.empty,
979+
});
980+
const fallback = (yield* Queue.take(responses)) as {
981+
readonly providers: ReadonlyArray<ServerProvider>;
982+
};
983+
assert.deepEqual(fallback.providers[0]?.workspaceSnapshots, [
984+
{
985+
cwd: "/c",
986+
checkedAt: provider.checkedAt,
987+
slashCommands: provider.slashCommands,
988+
slashCommandsPending: true,
989+
skills: [],
990+
},
991+
]);
967992
yield* server.write(0, { _tag: "Interrupt", requestId: configRequest, interruptors: [] });
968993
}).pipe(
969994
Effect.provide(

‎apps/server/src/ws.ts‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,26 @@ export const resolveOpenDiscoveryForConfig = <T, D, E1, R1, E2, R2, E3, R3, E4,
406406
},
407407
{ concurrency: "unbounded" },
408408
).pipe(Effect.map(({ editorConfig, ...endpoints }) => ({ ...editorConfig, ...endpoints })));
409+
// A failed scan leaves no cwd snapshot, so a client without the machine catalog gets it
410+
// as a pending snapshot, which it shows while it retries the scan.
411+
function workspaceSnapshotOrCatalog(
412+
provider: ServerProvider,
413+
cwd: string,
414+
catalogOnDemand: boolean,
415+
) {
416+
const snapshots = (provider.workspaceSnapshots ?? []).filter((snapshot) => snapshot.cwd === cwd);
417+
if (snapshots.length > 0 || !catalogOnDemand) return snapshots;
418+
return [
419+
{
420+
cwd,
421+
checkedAt: provider.checkedAt,
422+
slashCommands: provider.slashCommands,
423+
slashCommandsPending: true,
424+
skills: provider.skills,
425+
},
426+
];
427+
}
428+
409429
function withoutWorkspaceSnapshots(
410430
providers: ReadonlyArray<ServerProvider>,
411431
catalogsPerCwd: ReadonlySet<string> = new Set(),
@@ -2431,8 +2451,10 @@ export const layerWsRpc = (
24312451
models: [],
24322452
slashCommands: [],
24332453
skills: [],
2434-
workspaceSnapshots: (provider.workspaceSnapshots ?? []).filter(
2435-
(snapshot) => snapshot.cwd === cwd,
2454+
workspaceSnapshots: workspaceSnapshotOrCatalog(
2455+
provider,
2456+
cwd,
2457+
input.providerCatalogsOnDemand === true,
24362458
),
24372459
})),
24382460
};

‎packages/client-runtime/src/state/server.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,7 @@ export function createServerEnvironmentAtoms<R, E>(
13761376
...input,
13771377
workspaceSnapshotsOnDemand: true,
13781378
...(options.usageLimitsCommand === true ? { usageLimitsCommand: true } : {}),
1379+
...(options.providerCatalogsOnDemand === true ? { providerCatalogsOnDemand: true } : {}),
13791380
}),
13801381
onSuccess: ({ environmentId, input }, registry, result) =>
13811382
Effect.sync(() => {

‎packages/contracts/src/rpc.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,8 @@ export const WsServerRefreshProvidersRpc = Rpc.make(WS_METHODS.serverRefreshProv
653653
workspaceSnapshotsOnDemand: Schema.optional(Schema.Boolean),
654654
/** As on `subscribeServerConfig`: add /usage-limits to the replied snapshot. */
655655
usageLimitsCommand: Schema.optional(Schema.Boolean),
656+
/** As on `subscribeServerConfig`: a failed cwd scan replies with the machine catalog as a pending snapshot. */
657+
providerCatalogsOnDemand: Schema.optional(Schema.Boolean),
656658
}),
657659
success: ServerProviderUpdatedPayload,
658660
error: Schema.Union([EnvironmentAuthorizationError, ProviderSetupError]),

0 commit comments

Comments
 (0)