fix(provider): drop removed custom models from the model picker (#9075)

Co-authored-by: Claude Fable 5.1 <[email protected]>
This commit is contained in:
Wout StiensandClaude Fable 5.1 authored and GitHub committed 2026-09-02 00:07:19 -04:00
1 parent e7deb2aaf4
commit 941acb4f91
6 files changed
+116 -7

No files matched your search

@@ -620,6 +620,44 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
);
});
it("drops custom models the refreshed snapshot no longer carries", () => {
const previousProvider = {
instanceId: ProviderInstanceId.make("claudeAgent"),
driver: ProviderDriverKind.make("claudeAgent"),
status: "ready",
enabled: true,
installed: true,
auth: { status: "authenticated" },
checkedAt: "2026-04-14T00:00:00.000Z",
version: "2.1.0",
models: [
{
slug: "claude-sonnet-4-6",
name: "Sonnet 4.6",
isCustom: false,
capabilities: null,
},
{
slug: "removed-custom",
name: "removed-custom",
isCustom: true,
capabilities: null,
},
],
slashCommands: [],
skills: [],
} as const satisfies ServerProvider;
const refreshedProvider = {
...previousProvider,
checkedAt: "2026-04-14T00:01:00.000Z",
models: [previousProvider.models[0]],
} satisfies ServerProvider;
assert.deepStrictEqual(mergeProviderSnapshot(previousProvider, refreshedProvider).models, [
...refreshedProvider.models,
]);
});
it("drops stale OpenCode models missing from a successful refresh", () => {
const previousProvider = {
instanceId: ProviderInstanceId.make("opencode"),
@@ -105,9 +105,13 @@ const mergeProviderModels = (
nextModels: ReadonlyArray<ServerProvider["models"][number]>,
): ReadonlyArray<ServerProvider["models"][number]> => {
const shouldRetainMissingModels = shouldRetainMissingProviderModels(provider);
// Custom rows are derived from settings and every snapshot carries the full
// current list, so a custom model missing from `nextModels` was removed by
// the user and must not be resurrected from the previous snapshot.
const retainablePreviousModels = previousModels.filter((model) => !model.isCustom);
if (shouldRetainMissingModels && nextModels.length === 0 && previousModels.length > 0) {
return previousModels;
if (shouldRetainMissingModels && nextModels.length === 0 && retainablePreviousModels.length > 0) {
return retainablePreviousModels;
}
const previousBySlug = new Map(previousModels.map((model) => [model.slug, model] as const));
@@ -123,7 +127,7 @@ const mergeProviderModels = (
});
const nextSlugs = new Set(nextModels.map((model) => model.slug));
return shouldRetainMissingModels
? [...mergedModels, ...previousModels.filter((model) => !nextSlugs.has(model.slug))]
? [...mergedModels, ...retainablePreviousModels.filter((model) => !nextSlugs.has(model.slug))]
: mergedModels;
};
@@ -182,6 +182,35 @@ it.layer(NodeServices.layer)("providerStatusCache", (it) => {
);
});
it("does not resurrect cached custom models that settings no longer declare", () => {
const builtIn = {
slug: "gpt-5.4",
name: "GPT-5.4",
isCustom: false,
capabilities: emptyCapabilities,
} as const;
const cachedCodex = makeProvider(CODEX_DRIVER, {
models: [
builtIn,
{
slug: "removed-custom",
name: "removed-custom",
isCustom: true,
capabilities: emptyCapabilities,
},
],
});
const fallbackCodex = makeProvider(CODEX_DRIVER, { models: [builtIn] });
assert.deepStrictEqual(
hydrateCachedProvider({
cachedProvider: cachedCodex,
fallbackProvider: fallbackCodex,
}).models,
[builtIn],
);
});
it("ignores stale cached enabled state when the provider is now disabled", () => {
const cachedCodex = makeProvider(CODEX_DRIVER, {
checkedAt: "2026-04-10T12:00:00.000Z",
@@ -20,7 +20,13 @@ const mergeProviderModels = (
cachedModels: ReadonlyArray<ServerProvider["models"][number]>,
): ReadonlyArray<ServerProvider["models"][number]> => {
const fallbackSlugs = new Set(fallbackModels.map((model) => model.slug));
return [...fallbackModels, ...cachedModels.filter((model) => !fallbackSlugs.has(model.slug))];
// The fallback snapshot is built from current settings and already carries
// every custom model, so cached custom rows that are not in it were removed
// while the cache was stale and must not come back.
return [
...fallbackModels,
...cachedModels.filter((model) => !model.isCustom && !fallbackSlugs.has(model.slug)),
];
};
export const orderProviderSnapshots = (
+23
View File
@@ -226,6 +226,29 @@ describe("instance-scoped model selection", () => {
]);
});
it("drops server-reported custom rows that are no longer in settings", () => {
const baseProvider = provider({
instanceId: "claude_openrouter",
models: ["claude-sonnet-4-6"],
});
const providers = [
{
...baseProvider,
models: [
...baseProvider.models,
{ slug: "removed/custom", name: "removed/custom", isCustom: true, capabilities: {} },
],
},
];
const openrouter = deriveProviderInstanceEntries(providers)[0]!;
expect(
getAppModelOptionsForInstance(settingsWithProviderInstances(), openrouter).map(
(option) => option.slug,
),
).toEqual(["claude-sonnet-4-6", "openai/gpt-5.5"]);
});
it("applies persisted per-instance model ordering", () => {
const providers = [
provider({
+12 -3
View File
@@ -179,7 +179,12 @@ export function getAppModelOptions(
selectedModel?: string | null,
): AppModelOption[] {
const rawModels = getProviderModels(providers, provider);
const options: AppModelOption[] = rawModels.map(toAppModelOption);
// Server-reported custom rows mirror settings and can lag a removal, so
// only built-ins are taken from the snapshot; custom rows are rebuilt from
// settings below.
const options: AppModelOption[] = rawModels
.filter((model) => !model.isCustom)
.map(toAppModelOption);
const seen = new Set(options.map((option) => option.slug));
const builtInModelSlugs = new Set(
Arr.filterMap(getProviderModels(providers, provider), (model) =>
@@ -225,14 +230,18 @@ export function getAppModelOptions(
* when present, falling back to the legacy per-kind
* `settings.providers[driverKind].customModels` bucket for default
* instances only. This keeps two instances of the same kind from leaking
* custom slugs into each other.
* custom slugs into each other. Custom rows reported by the server are
* ignored so a slug removed in Settings disappears without waiting for the
* next provider probe.
*/
export function getAppModelOptionsForInstance(
settings: UnifiedSettings,
entry: ProviderInstanceEntry,
selectedModel?: string | null,
): AppModelOption[] {
const options: AppModelOption[] = entry.models.map(toAppModelOption);
const options: AppModelOption[] = entry.models
.filter((model) => !model.isCustom)
.map(toAppModelOption);
const seen = new Set(options.map((option) => option.slug));
const builtInModelSlugs = new Set(
Arr.filterMap(entry.models, (model) =>