From 0cf4c978de9acce1b14ee630f24000af4eb1967d Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Wed, 15 Apr 2026 17:44:02 +0000 Subject: [PATCH] fix: clean up stale models from recentModels and validate current selection - Add modelExists helper to check if a model exists in providers - Filter recentModels to remove entries that no longer exist - Validate current model selection against available providers - Force sync from config if current model is invalid - Only update state when cleanup actually changes something --- frontend/src/stores/modelStore.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/frontend/src/stores/modelStore.ts b/frontend/src/stores/modelStore.ts index 34d1b7af..77026541 100644 --- a/frontend/src/stores/modelStore.ts +++ b/frontend/src/stores/modelStore.ts @@ -81,16 +81,25 @@ export const useModelStore = create()( const state = get() - if (!providers || !state.model) { + if (!providers) { get().syncFromConfig(configModel) return } - const modelExists = providers.some( - (p) => p.id === state.model!.providerID && p.models && state.model!.modelID in p.models - ) + const modelExists = (model: ModelSelection) => + providers.some( + (p) => p.id === model.providerID && p.models && model.modelID in p.models + ) - if (!modelExists) { + const currentModelExists = state.model ? modelExists(state.model) : false + + const cleanedRecentModels = state.recentModels.filter(modelExists) + + if (cleanedRecentModels.length !== state.recentModels.length) { + set({ recentModels: cleanedRecentModels }) + } + + if (!currentModelExists) { get().syncFromConfig(configModel, true) } },