linshenkx/prompt-optimizer · error · Error
Model not found
Error message
Model not found
What it means
Thrown by updateExistingModel after passing the originalId check but finding that modelManager.getModel(form.value.originalId) returns undefined. The edit session is well-formed but the target model vanished from the registry between opening the form and saving it.
Source
Thrown at packages/ui/src/composables/model/useTextModelManager.ts:803
providerId: string,
modelId: string,
existingConfig?: TextModelConfig
) => resolveTextModelMetadata({
providerId,
modelId,
registry: textAdapterRegistry,
existingProviderMeta: existingConfig?.providerMeta,
existingModelMeta: existingConfig?.modelMeta
})
const updateExistingModel = async () => {
if (!form.value.originalId) {
throw new Error('Invalid edit session')
}
const existingConfig = await modelManager.getModel(form.value.originalId)
if (!existingConfig) {
throw new Error('Model not found')
}
const connectionConfig: TextConnectionConfig = {
baseURL: (form.value.connectionConfig.baseURL as string)?.trim() || existingConfig.connectionConfig?.baseURL,
...form.value.connectionConfig
}
if (form.value.displayMaskedKey) {
if (form.value.originalApiKey) {
connectionConfig.apiKey = form.value.originalApiKey
} else {
delete connectionConfig.apiKey
}
} else if (form.value.connectionConfig.apiKey) {
connectionConfig.apiKey = form.value.connectionConfig.apiKey
} else {
delete connectionConfig.apiKey
}View on GitHub (pinned to 3e677b1d9f)
Solutions
- Catch this error and offer to save as a new model instead of updating
- Refresh the models list when the edit window regains focus, warning if the target disappeared
- Compare editingModelId with the fresh list before save; if missing, prompt the user
- Ensure model ids are stable across persistence rounds (don't regenerate keys on load)
Example fix
// before
const existingConfig = await modelManager.getModel(form.value.originalId)
if (!existingConfig) throw new Error('Model not found')
// after
const existingConfig = await modelManager.getModel(form.value.originalId)
if (!existingConfig) {
form.value.originalId = undefined
return createNewModel() // degrade to create
} Defensive patterns
Strategy: fallback
Validate before calling
const stillThere = (await modelManager.getModel(form.value.originalId)) != null
if (!stillThere) { /* offer save-as-new or abort */ } Type guard
null
Try / catch
try { await updateExistingModel() } catch (e) { if (String(e?.message) === 'Model not found') { form.value.originalId = undefined; await saveForm() /* recreates */ } else throw e } Prevention
- Refresh models when the edit dialog regains focus
- Keep model ids stable across persistence loads
- Warn users when the edited model disappears from the live list
When it happens
Trigger: Saving an edit after the model was deleted elsewhere (another tab, another component, external config file edit). Also when the store was reloaded and the model id changed (regenerated key) or when persistence failed silently.
Common situations: Long-lived edit dialog over a model deleted in the meantime; concurrent edits from two windows; external modification of the models config file; id regeneration on app upgrade.
Related errors
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/b622c7b76c1a509a.
Report an issue: GitHub.