diff --git a/apps/server/src/provider/ProviderRegistry.test.ts b/apps/server/src/provider/ProviderRegistry.test.ts index 27c1cd15a8d79..2ea6d98c083c5 100644 --- a/apps/server/src/provider/ProviderRegistry.test.ts +++ b/apps/server/src/provider/ProviderRegistry.test.ts @@ -1375,48 +1375,15 @@ it.layer( ); }); - it("drops Grok models a completed probe no longer advertises", () => { + it.each([ + ["grok", "warning"], + ["cursor", "error"], + ["muse", "error"], + ["fx", "warning"], + ] as const)("drops %s models a completed listing no longer returns", (driver, failedStatus) => { const previousProvider = { - instanceId: ProviderInstanceId.make("grok"), - driver: ProviderDriverKind.make("grok"), - status: "ready", - enabled: true, - installed: true, - auth: { status: "authenticated" }, - checkedAt: "2026-09-30T00:00:00.000Z", - version: "1.0.44", - models: [ - { slug: "grok-4.7", name: "Grok 4.7", isCustom: false, capabilities: null }, - { slug: "codexhub-removed", name: "Removed", isCustom: false, capabilities: null }, - ], - slashCommands: [], - skills: [], - } as const satisfies ServerProvider; - const refreshedProvider = { - ...previousProvider, - checkedAt: "2026-09-30T00:01:00.000Z", - models: [previousProvider.models[0]], - } satisfies ServerProvider; - const acpFailedProvider = { - ...refreshedProvider, - status: "warning", - message: "Grok CLI is installed but ACP initialize failed.", - } satisfies ServerProvider; - - assert.deepStrictEqual( - ProviderRegistry.mergeProviderSnapshot(previousProvider, refreshedProvider).models, - [previousProvider.models[0]], - ); - assert.deepStrictEqual( - ProviderRegistry.mergeProviderSnapshot(previousProvider, acpFailedProvider).models, - [...previousProvider.models], - ); - }); - - it("drops Cursor models a completed catalog read no longer returns", () => { - const previousProvider = { - instanceId: ProviderInstanceId.make("cursor"), - driver: ProviderDriverKind.make("cursor"), + instanceId: ProviderInstanceId.make(driver), + driver: ProviderDriverKind.make(driver), status: "ready", enabled: true, installed: true, @@ -1424,8 +1391,8 @@ it.layer( checkedAt: "2026-10-30T00:00:00.000Z", version: "1.0.0", models: [ - { slug: "composer-2", name: "Composer 2", isCustom: false, capabilities: null }, - { slug: "retired-model-x", name: "Retired", isCustom: false, capabilities: null }, + { slug: "current-model", name: "Current", isCustom: false, capabilities: null }, + { slug: "retired-model", name: "Retired", isCustom: false, capabilities: null }, ], slashCommands: [], skills: [], @@ -1437,9 +1404,7 @@ it.layer( } satisfies ServerProvider; const failedProvider = { ...refreshedProvider, - status: "error", - auth: { status: "unknown" }, - message: "Cursor SDK model discovery timed out.", + status: failedStatus, } satisfies ServerProvider; assert.deepStrictEqual( @@ -1452,6 +1417,38 @@ it.layer( ); }); + it.each(["kiro", "claudeAgent"] as const)( + "keeps %s models a ready probe can omit", + (driver) => { + const previousProvider = { + instanceId: ProviderInstanceId.make(driver), + driver: ProviderDriverKind.make(driver), + status: "ready", + enabled: true, + installed: true, + auth: { status: "authenticated" }, + checkedAt: "2026-10-30T00:00:00.000Z", + version: "1.0.0", + models: [ + { slug: "built-in-model", name: "Built-in", isCustom: false, capabilities: null }, + { slug: "listed-model", name: "Listed", isCustom: false, capabilities: null }, + ], + slashCommands: [], + skills: [], + } as const satisfies ServerProvider; + const partialProvider = { + ...previousProvider, + checkedAt: "2026-10-30T00:01:00.000Z", + models: [previousProvider.models[0]], + } satisfies ServerProvider; + + assert.deepStrictEqual( + ProviderRegistry.mergeProviderSnapshot(previousProvider, partialProvider).models, + [...previousProvider.models], + ); + }, + ); + it("retains stale OpenCode models when a refresh fails or lists none", () => { const previousProvider = { instanceId: ProviderInstanceId.make("opencode"), diff --git a/apps/server/src/provider/ProviderRegistry.ts b/apps/server/src/provider/ProviderRegistry.ts index f1ae2e51637cc..f23058f1b88c5 100644 --- a/apps/server/src/provider/ProviderRegistry.ts +++ b/apps/server/src/provider/ProviderRegistry.ts @@ -210,20 +210,26 @@ const shouldRetainMissingProviderModels = (provider: ServerProvider): boolean => ); } - if ( - provider.driver === ProviderDriverKind.make("grok") || - provider.driver === ProviderDriverKind.make("cursor") - ) { - // Grok and Cursor report ready only after they discover a model list; the pending, - // failed, empty-inventory, and logged-out probes are warning/error. - return !(provider.installed && provider.status === "ready"); + if (provider.driver === ProviderDriverKind.make("kiro")) { + // Kiro is ready once `whoami` confirms the account, even when `--list-models` failed and + // the snapshot fell back to the built-in list. + return true; + } + + if (provider.driver === ProviderDriverKind.make("claudeAgent")) { + // Claude Code keeps one gateway model cache per Claude home, for one base URL at a time, so a + // ready probe can omit this instance's gateway models after another instance or a terminal + // `claude` on a different gateway rewrote that cache. + return true; } const isAntigravity = provider.driver === ProviderDriverKind.make("antigravity"); const isCodex = provider.driver === ProviderDriverKind.make("codex"); const isOpenCode = provider.driver === ProviderDriverKind.make("opencode"); if (!isAntigravity && !isCodex && !isOpenCode) { - return true; + // Any other driver must report ready only after a completed model listing, or opt out above: + // a ready list is authoritative, and warning/error probes keep the old models. + return !(provider.installed && provider.status === "ready"); } if ( diff --git a/packages/provider-fx/src/server/status.test.ts b/packages/provider-fx/src/server/status.test.ts index 3f9ae01ae969a..1fc41ccf03385 100644 --- a/packages/provider-fx/src/server/status.test.ts +++ b/packages/provider-fx/src/server/status.test.ts @@ -38,21 +38,27 @@ function processHandle(stdout: string, code: number, answered: Effect.Effect +const check = ( + statusJson: string, + versionDelay: Duration.Input = 0, + modelsJson: string = FX_MODELS_JSON, +) => Effect.gen(function* () { const outputs: Record = { "--version": "fx 0.0.13\n", "status --json": statusJson, - // `fx models --json` from fx 0.0.13, ids trimmed. - "models --json": JSON.stringify({ - kind: "models", - count: 2, - shown_count: 2, - more_count: 0, - private_models_hidden: false, - ids: ["anthropic/claude-sonnet-5.5", "anthropic/claude-opus-5.5"], - }), + "models --json": modelsJson, }; const invoked: Array = []; const spawner = ChildProcessSpawner.make((command) => { @@ -150,4 +156,20 @@ describe("checkFxProviderStatus", () => { assert.equal(unknown.draft.auth.status, "unknown"); }), ); + + // A ready snapshot drops models it does not list, so only a real listing may report ready. + it.effect("treats `fx models` output without ids as a failed listing", () => + Effect.gen(function* () { + const signedIn = JSON.stringify({ kind: "status", auth: "fx login" }); + const reshaped = yield* check(signedIn, 0, JSON.stringify({ kind: "models", models: [] })); + assert.equal(reshaped.draft.status, "warning"); + assert.deepEqual( + reshaped.draft.models.map((model) => model.slug), + ["default"], + ); + + const empty = yield* check(signedIn, 0, JSON.stringify({ kind: "models", ids: [] })); + assert.equal(empty.draft.status, "ready"); + }), + ); }); diff --git a/packages/provider-fx/src/server/status.ts b/packages/provider-fx/src/server/status.ts index 581b9549199e3..fb32eced1d190 100644 --- a/packages/provider-fx/src/server/status.ts +++ b/packages/provider-fx/src/server/status.ts @@ -131,9 +131,7 @@ const FxStatus = Schema.fromJsonString( }), ); const decodeFxStatus = Schema.decodeUnknownOption(FxStatus); -const FxModels = Schema.fromJsonString( - Schema.Struct({ ids: Schema.optional(Schema.Array(Schema.String)) }), -); +const FxModels = Schema.fromJsonString(Schema.Struct({ ids: Schema.Array(Schema.String) })); const decodeFxModels = Schema.decodeUnknownOption(FxModels); const VERSION_PROBE_TIMEOUT_MS = 10_000; @@ -203,7 +201,7 @@ export const checkFxProviderStatus = Effect.fn("checkFxProviderStatus")(function ); const status = Option.flatMap(yield* read(["status", "--json"]), decodeFxStatus); const listed = Option.flatMap(yield* read(["models", "--json"]), decodeFxModels).pipe( - Option.map((models) => models.ids?.flatMap((id) => nonEmptyTrimmed(id) ?? []) ?? []), + Option.map((models) => models.ids.flatMap((id) => nonEmptyTrimmed(id) ?? [])), ); const auth = fxAuth(Option.getOrUndefined(status)?.auth); const defaultModel = nonEmptyTrimmed(Option.getOrUndefined(status)?.model);