Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): re-seed a model selection the provider has moved on from

s31teg924129e1ffe6
diff --git a/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.spec.tsx b/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.spec.tsx
index bcc227a877..551947bb81 100644
--- a/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.spec.tsx
@@ -109,6 +109,23 @@ describe("ModelSelection", () => {
expect(onChange).toHaveBeenCalledWith([fresh, gone]);
});
+ it("re-seeds the recommended models when the listing carries none of the stored selection", async () => {
+ // A subscription catalog that moved on wholesale (Claude Code after a model generation):
+ // every stored id is gone, and keeping them would leave the chat picker on models the
+ // provider refuses while the new ones sit unticked.
+ const stored: LlmModelInfo[] = [
+ { id: "old-a", name: "Old A" },
+ { id: "old-b", name: "Old B" }
+ ];
+ const onChange = vi.fn();
+
+ await renderSelection({
+ query: { provider: "claude-agent" }, selected: stored, onChange, autoSelectDefaults: false
+ });
+ expect(onChange).toHaveBeenCalledOnce();
+ expect(onChange).toHaveBeenCalledWith([MODELS[0], MODELS[2]]);
+ });
+
it("leaves an empty selection untouched when auto-select is off", async () => {
// A provider deliberately emptied to "hide all" — reopening its editor
// must not silently re-populate it (see shouldSeedDefaultModels).
diff --git a/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.tsx b/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.tsx
index cb8267cdad..7359498663 100644
--- a/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.tsx
+++ b/apps/client/src/widgets/type_widgets/options/llm/ModelSelection.tsx
@@ -53,7 +53,13 @@ export default function ModelSelection({ query, timeoutMs, selected, onChange, a
if (!active) return;
setModels(fetched);
setLoading(false);
- if (autoSelectDefaults && selected.length === 0 && fetched.length > 0) {
+ const seedFresh = autoSelectDefaults && selected.length === 0;
+ // A stored selection the listing no longer carries any part of is one the provider
+ // has moved on from, so it is seeded again as for a new provider: the old ids are
+ // ones the provider now refuses, so keeping them would offer nothing usable.
+ const seedSuperseded = selected.length > 0
+ && !selected.some(model => fetched.some(f => f.id === model.id));
+ if ((seedFresh || seedSuperseded) && fetched.length > 0) {
onChange(defaultSelectedModels(fetched));
return;
}