Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 43 additions & 46 deletions apps/server/src/provider/ProviderRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1375,57 +1375,24 @@ 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,
auth: { status: "authenticated" },
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: [],
Expand All @@ -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(
Expand All @@ -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"),
Expand Down
22 changes: 14 additions & 8 deletions apps/server/src/provider/ProviderRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
42 changes: 32 additions & 10 deletions packages/provider-fx/src/server/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,27 @@ function processHandle(stdout: string, code: number, answered: Effect.Effect<voi
});
}

// `fx models --json` from fx 0.0.13, ids trimmed.
const FX_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"],
});

/** Answers `fx` invocations by their arguments and records which ran. */
const check = (statusJson: string, versionDelay: Duration.Input = 0) =>
const check = (
statusJson: string,
versionDelay: Duration.Input = 0,
modelsJson: string = FX_MODELS_JSON,
) =>
Effect.gen(function* () {
const outputs: Record<string, string> = {
"--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<string> = [];
const spawner = ChildProcessSpawner.make((command) => {
Expand Down Expand Up @@ -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");
}),
);
});
6 changes: 2 additions & 4 deletions packages/provider-fx/src/server/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading