{"record":{"id":"c79eb285cb0e7a91","repo":"jackwener/OpenCLI","slug":"model-wanted-is-ambiguous-in-trae-cn-model-me","errorCode":null,"errorMessage":"Model \"${wanted}\" is ambiguous in Trae CN model menu: ${containsMatches.map(item => item.Model).join(', ')}","messagePattern":"Model \"(.+?)\" is ambiguous in Trae CN model menu: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/trae-cn/utils.js","lineNumber":724,"sourceCode":"    'The prompt was injected and submit was triggered, but no new user turn containing that prompt appeared.',\n  );\n}\n\nexport async function selectTraeModel(page, name) {\n  const wanted = ensurePrompt(name);\n  const wantedKey = normalizeModelLabel(wanted);\n  let models = await page.evaluate(listOpenModelItemsScript());\n  if (!models || models.length === 0) {\n    await page.click(TRAE_CN_MODEL_TRIGGER_SELECTOR);\n    await page.wait(0.8);\n    models = await page.evaluate(listOpenModelItemsScript());\n  }\n  const exactMatch = models.find((item) => normalizeModelLabel(item.Model) === wantedKey);\n  const containsMatches = exactMatch\n    ? []\n    : models.filter((item) => normalizeModelLabel(item.Model).includes(wantedKey));\n  if (!exactMatch && containsMatches.length > 1) {\n    throw new ArgumentError(\n      `Model \"${wanted}\" is ambiguous in Trae CN model menu: ${containsMatches.map(item => item.Model).join(', ')}`,\n    );\n  }\n  const match = exactMatch || containsMatches[0];\n  if (!match) {\n    throw new ArgumentError(`Model \"${wanted}\" not found in Trae CN model menu`);\n  }\n  await page.click(TRAE_CN_MODEL_ITEM_SELECTOR, { nth: match.Index });\n  await page.wait(0.8);\n  const info = await page.evaluate(inspectTraeShellScript());\n  const selectedLabel = info.model || '';\n  const selectedKey = normalizeModelLabel(selectedLabel);\n  const matchKey = normalizeModelLabel(match.Model);\n  if (!selectedKey || (selectedKey !== matchKey && selectedKey !== wantedKey)) {\n    throw new CommandExecutionError(\n      `Trae CN model switch did not verify the requested model: requested \"${wanted}\", current \"${selectedLabel || 'unknown'}\"`,\n      'Open the Trae CN model menu and verify the requested model is selectable, then retry.',\n    );","sourceCodeStart":706,"sourceCodeEnd":742,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trae-cn/utils.js#L706-L742","documentation":"selectTraeModel matches the requested model name against the model menu using normalized labels. When there is no exact match but multiple fuzzy (substring) matches exist, the choice is ambiguous and the library throws this ArgumentError listing all candidates so you can disambiguate.","triggerScenarios":"Passing a partial name that matches several menu entries, e.g. 'gpt' matching 'gpt-4o' and 'gpt-4o-mini', or a common prefix like 'deepseek'.","commonSituations":"Users typing shorthand model names, or menu containing multiple variants/families of the same model line.","solutions":["Use the full exact model name as shown in the Trae CN menu","Pick one of the listed ambiguous candidates verbatim","Check the model menu contents first with a read/inspect command"],"exampleFix":"// before\nselectTraeModel(page, 'deepseek')\n// after\nselectTraeModel(page, 'deepseek-r1')","handlingStrategy":"validation","validationCode":"const models = await page.evaluate(listModelsScript());\nconst wantedKey = normalizeModelLabel(wanted);\nconst matches = models.filter(m => normalizeModelLabel(m.Model).includes(wantedKey));\nif (!matches.some(m => normalizeModelLabel(m.Model) === wantedKey) && matches.length > 1)\n  throw new Error(`Ambiguous model \"${wanted}\": ${matches.map(m=>m.Model).join(', ')}`);","typeGuard":"const isUnambiguousModel = (models, wanted) => {\n  const key = normalizeModelLabel(wanted);\n  return models.some(m => normalizeModelLabel(m.Model) === key) ||\n    models.filter(m => normalizeModelLabel(m.Model).includes(key)).length === 1;\n};","tryCatchPattern":"try { await selectTraeModel(page, name); } catch (e) { if (/is ambiguous/.test(e.message)) { console.error(e.message + '\\nPass the full model name'); process.exitCode = 2; } else throw e; }","preventionTips":["Always use the exact label from the model menu","Pre-fetch the model list and validate names before selecting","Avoid generic prefixes like 'gpt' or 'deepseek'"],"tags":["automation","ambiguity","argument-validation"],"backgroundTag":"ambiguous-model-name","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}