linshenkx/prompt-optimizer · error · Error
modelManager.modelIdGenerateFailed
Error message
modelManager.modelIdGenerateFailed
What it means
createNewModel generates a unique model key by trying candidates derived from the model id/name; if every candidate collides with an existing model key, modelKey stays empty and it throws modelManager.modelIdGenerateFailed. The slug/candidate generator plus a uniqueness loop could not produce a free id.
Source
Thrown at packages/ui/src/composables/model/useTextModelManager.ts:864
}
const createNewModel = async () => {
// Auto-generate a stable internal id for the config.
// Text models use the id as the storage key and runtime selector.
const providerId = form.value.providerId || 'custom'
// Extremely unlikely, but avoid collisions with built-in keys or existing custom configs.
let modelKey = ''
for (let attempt = 0; attempt < 5; attempt++) {
const candidate = generateTextModelId(providerId, attempt)
const existingModel = await modelManager.getModel(candidate)
if (!existingModel && !isDefaultModel(candidate)) {
modelKey = candidate
break
}
}
if (!modelKey) {
throw new Error(t('modelManager.modelIdGenerateFailed'))
}
const { providerMeta, modelMeta } = resolveFormMetadata(
form.value.providerId,
form.value.defaultModel || form.value.modelId
)
const connectionConfig: TextConnectionConfig = {
...form.value.connectionConfig
}
if (form.value.displayMaskedKey && form.value.originalApiKey) {
connectionConfig.apiKey = form.value.originalApiKey
}
normalizeConnectionCustomHeaders(connectionConfig)
const newConfig = {
id: modelKey,
name: form.value.name,View on GitHub (pinned to 3e677b1d9f)
Solutions
- Rename the model id / provider+model combination so it is unique
- Increase or fix the candidate suffix loop (ensure it appends -1, -2, ... and has a sane bound)
- Sanitize before generating: if the cleaned base id is empty, reject early with a clear validation message
- Delete duplicate same-named models that are no longer needed
Example fix
// before
if (!modelKey) {
throw new Error(t('modelManager.modelIdGenerateFailed'))
}
// after
if (!modelKey) {
const fallback = `${sanitizedBase || 'model'}-${Date.now().toString(36)}`
modelKey = fallback
} Defensive patterns
Strategy: validation
Validate before calling
const base = sanitizeModelId(form.value.modelId)
if (!base) { /* require a valid model id before save */ }
const taken = new Set(models.value.map((m) => m.id))
if (taken.has(base) && !isEdit) { /* pick a different name */ } Type guard
const isValidModelKey = (k: unknown): k is string => typeof k === 'string' && /^[a-z0-9][a-z0-9-_]*$/i.test(k)
Try / catch
try { await createNewModel() } catch (e) { if (/modelIdGenerateFailed/.test(String(e?.message))) { form.value.modelId = `${form.value.modelId}-${Date.now().toString(36)}`; await createNewModel() } else throw e } Prevention
- Use unique, descriptive model ids
- Sanitize ids early and reject empty results
- Bound and verify the collision-retry loop
When it happens
Trigger: Creating a model whose id candidates all already exist (e.g. many duplicates named the same so candidate-1..N are exhausted), or the candidate sanitizer stripping the id to an empty string so no valid key is produced. Typically requires many same-named models or an id made entirely of invalid characters.
Common situations: Bulk import creating dozens of identically named models; model id containing only whitespace/symbols that sanitize to ''; a loop bug where candidates are never incremented; hitting an artificial cap on collision retries.
Related errors
AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27).
Data as JSON: /api/errors/5b8c6bc377d237b0.
Report an issue: GitHub.