Skip to content

Commit 6f05db6

Browse files
StiensWoutclaude
andcommitted
fix(provider): drop removed custom models from the model picker
Removing a custom model in Settings left it in the model picker. The server aggregator merged each refreshed snapshot with the previous one and retained every model missing from the new snapshot, so the removed custom row came back on every probe and was persisted to the boot cache. The web picker also took custom rows straight from the server snapshot. Custom rows are settings-owned and every snapshot carries the full current list, so the aggregator and boot-cache merges now never retain previous custom rows, and the web option builders only take built-ins from the snapshot and rebuild custom rows from settings. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 2d156a8 commit 6f05db6

6 files changed

Lines changed: 116 additions & 7 deletions

File tree

‎apps/server/src/provider/Layers/ProviderRegistry.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,44 @@ it.layer(Layer.mergeAll(NodeServices.layer, ServerSettingsModule.layerTest(), Te
620620
);
621621
});
622622

623+
it("drops custom models the refreshed snapshot no longer carries", () => {
624+
const previousProvider = {
625+
instanceId: ProviderInstanceId.make("claudeAgent"),
626+
driver: ProviderDriverKind.make("claudeAgent"),
627+
status: "ready",
628+
enabled: true,
629+
installed: true,
630+
auth: { status: "authenticated" },
631+
checkedAt: "2026-04-14T00:00:00.000Z",
632+
version: "2.1.0",
633+
models: [
634+
{
635+
slug: "claude-sonnet-4-6",
636+
name: "Sonnet 4.6",
637+
isCustom: false,
638+
capabilities: null,
639+
},
640+
{
641+
slug: "removed-custom",
642+
name: "removed-custom",
643+
isCustom: true,
644+
capabilities: null,
645+
},
646+
],
647+
slashCommands: [],
648+
skills: [],
649+
} as const satisfies ServerProvider;
650+
const refreshedProvider = {
651+
...previousProvider,
652+
checkedAt: "2026-04-14T00:01:00.000Z",
653+
models: [previousProvider.models[0]],
654+
} satisfies ServerProvider;
655+
656+
assert.deepStrictEqual(mergeProviderSnapshot(previousProvider, refreshedProvider).models, [
657+
...refreshedProvider.models,
658+
]);
659+
});
660+
623661
it("drops stale OpenCode models missing from a successful refresh", () => {
624662
const previousProvider = {
625663
instanceId: ProviderInstanceId.make("opencode"),

‎apps/server/src/provider/Layers/ProviderRegistry.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,13 @@ const mergeProviderModels = (
105105
nextModels: ReadonlyArray<ServerProvider["models"][number]>,
106106
): ReadonlyArray<ServerProvider["models"][number]> => {
107107
const shouldRetainMissingModels = shouldRetainMissingProviderModels(provider);
108+
// Custom rows are derived from settings and every snapshot carries the full
109+
// current list, so a custom model missing from `nextModels` was removed by
110+
// the user and must not be resurrected from the previous snapshot.
111+
const retainablePreviousModels = previousModels.filter((model) => !model.isCustom);
108112

109-
if (shouldRetainMissingModels && nextModels.length === 0 && previousModels.length > 0) {
110-
return previousModels;
113+
if (shouldRetainMissingModels && nextModels.length === 0 && retainablePreviousModels.length > 0) {
114+
return retainablePreviousModels;
111115
}
112116

113117
const previousBySlug = new Map(previousModels.map((model) => [model.slug, model] as const));
@@ -123,7 +127,7 @@ const mergeProviderModels = (
123127
});
124128
const nextSlugs = new Set(nextModels.map((model) => model.slug));
125129
return shouldRetainMissingModels
126-
? [...mergedModels, ...previousModels.filter((model) => !nextSlugs.has(model.slug))]
130+
? [...mergedModels, ...retainablePreviousModels.filter((model) => !nextSlugs.has(model.slug))]
127131
: mergedModels;
128132
};
129133

‎apps/server/src/provider/providerStatusCache.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,35 @@ it.layer(NodeServices.layer)("providerStatusCache", (it) => {
182182
);
183183
});
184184

185+
it("does not resurrect cached custom models that settings no longer declare", () => {
186+
const builtIn = {
187+
slug: "gpt-5.4",
188+
name: "GPT-5.4",
189+
isCustom: false,
190+
capabilities: emptyCapabilities,
191+
} as const;
192+
const cachedCodex = makeProvider(CODEX_DRIVER, {
193+
models: [
194+
builtIn,
195+
{
196+
slug: "removed-custom",
197+
name: "removed-custom",
198+
isCustom: true,
199+
capabilities: emptyCapabilities,
200+
},
201+
],
202+
});
203+
const fallbackCodex = makeProvider(CODEX_DRIVER, { models: [builtIn] });
204+
205+
assert.deepStrictEqual(
206+
hydrateCachedProvider({
207+
cachedProvider: cachedCodex,
208+
fallbackProvider: fallbackCodex,
209+
}).models,
210+
[builtIn],
211+
);
212+
});
213+
185214
it("ignores stale cached enabled state when the provider is now disabled", () => {
186215
const cachedCodex = makeProvider(CODEX_DRIVER, {
187216
checkedAt: "2026-04-10T12:00:00.000Z",

‎apps/server/src/provider/providerStatusCache.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ const mergeProviderModels = (
2121
cachedModels: ReadonlyArray<ServerProvider["models"][number]>,
2222
): ReadonlyArray<ServerProvider["models"][number]> => {
2323
const fallbackSlugs = new Set(fallbackModels.map((model) => model.slug));
24-
return [...fallbackModels, ...cachedModels.filter((model) => !fallbackSlugs.has(model.slug))];
24+
// The fallback snapshot is built from current settings and already carries
25+
// every custom model, so cached custom rows that are not in it were removed
26+
// while the cache was stale and must not come back.
27+
return [
28+
...fallbackModels,
29+
...cachedModels.filter((model) => !model.isCustom && !fallbackSlugs.has(model.slug)),
30+
];
2531
};
2632

2733
export const orderProviderSnapshots = (

‎apps/web/src/modelSelection.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,29 @@ describe("instance-scoped model selection", () => {
226226
]);
227227
});
228228

229+
it("drops server-reported custom rows that are no longer in settings", () => {
230+
const baseProvider = provider({
231+
instanceId: "claude_openrouter",
232+
models: ["claude-sonnet-4-6"],
233+
});
234+
const providers = [
235+
{
236+
...baseProvider,
237+
models: [
238+
...baseProvider.models,
239+
{ slug: "removed/custom", name: "removed/custom", isCustom: true, capabilities: {} },
240+
],
241+
},
242+
];
243+
const openrouter = deriveProviderInstanceEntries(providers)[0]!;
244+
245+
expect(
246+
getAppModelOptionsForInstance(settingsWithProviderInstances(), openrouter).map(
247+
(option) => option.slug,
248+
),
249+
).toEqual(["claude-sonnet-4-6", "openai/gpt-5.5"]);
250+
});
251+
229252
it("applies persisted per-instance model ordering", () => {
230253
const providers = [
231254
provider({

‎apps/web/src/modelSelection.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ export function getAppModelOptions(
175175
selectedModel?: string | null,
176176
): AppModelOption[] {
177177
const rawModels = getProviderModels(providers, provider);
178-
const options: AppModelOption[] = rawModels.map(toAppModelOption);
178+
// Server-reported custom rows mirror settings and can lag a removal, so
179+
// only built-ins are taken from the snapshot; custom rows are rebuilt from
180+
// settings below.
181+
const options: AppModelOption[] = rawModels
182+
.filter((model) => !model.isCustom)
183+
.map(toAppModelOption);
179184
const seen = new Set(options.map((option) => option.slug));
180185
const builtInModelSlugs = new Set(
181186
Arr.filterMap(getProviderModels(providers, provider), (model) =>
@@ -221,14 +226,18 @@ export function getAppModelOptions(
221226
* when present, falling back to the legacy per-kind
222227
* `settings.providers[driverKind].customModels` bucket for default
223228
* instances only. This keeps two instances of the same kind from leaking
224-
* custom slugs into each other.
229+
* custom slugs into each other. Custom rows reported by the server are
230+
* ignored so a slug removed in Settings disappears without waiting for the
231+
* next provider probe.
225232
*/
226233
export function getAppModelOptionsForInstance(
227234
settings: UnifiedSettings,
228235
entry: ProviderInstanceEntry,
229236
selectedModel?: string | null,
230237
): AppModelOption[] {
231-
const options: AppModelOption[] = entry.models.map(toAppModelOption);
238+
const options: AppModelOption[] = entry.models
239+
.filter((model) => !model.isCustom)
240+
.map(toAppModelOption);
232241
const seen = new Set(options.map((option) => option.slug));
233242
const builtInModelSlugs = new Set(
234243
Arr.filterMap(entry.models, (model) =>

0 commit comments

Comments
 (0)