{"record":{"id":"7bb2c0882fcbae0f","repo":"jackwener/OpenCLI","slug":"click-on-model-option-failed","errorCode":null,"errorMessage":"Click on model option failed.","messagePattern":"Click on model option failed\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/trae-solo/model.js","lineNumber":117,"sourceCode":"                // to JS dispatch on the nth visible option.\n                const fallbackClicked = await page.evaluate(`(function(i) {\n          const opts = Array.from(document.querySelectorAll('.core-model-select-model-item[role=\"option\"]'))\n            .filter((el) => el.offsetParent);\n          const target = opts[i];\n          if (!target) return false;\n          const r = target.getBoundingClientRect();\n          const init = { bubbles: true, cancelable: true, button: 0, buttons: 1,\n            clientX: Math.round(r.left + r.width / 2),\n            clientY: Math.round(r.top + r.height / 2) };\n          target.dispatchEvent(new PointerEvent('pointerdown', { ...init, pointerType: 'mouse' }));\n          target.dispatchEvent(new MouseEvent('mousedown', init));\n          target.dispatchEvent(new PointerEvent('pointerup', { ...init, pointerType: 'mouse' }));\n          target.dispatchEvent(new MouseEvent('mouseup', init));\n          target.dispatchEvent(new MouseEvent('click', init));\n          return true;\n        })(${idx})`);\n                if (!fallbackClicked) {\n                    throw new CommandExecutionError('Click on model option failed.', `model=${chosenLabel}`);\n                }\n            }\n            await page.wait(0.6);\n            const after = await readCurrentModel(page);\n            if (!after || !after.toLowerCase().includes(name)) {\n                throw new CommandExecutionError(\n                    `Model click did not verify selected model \"${chosenLabel}\".`,\n                    after ? `current=${after}` : 'model trigger was unreadable after click',\n                );\n            }\n            return [{ Status: 'switched', Model: after }];\n        }\n\n        // Just read the current.\n        return [{ Status: 'Active', Model: current }];\n    },\n});\n","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trae-solo/model.js#L99-L135","documentation":"Thrown when both click strategies for the chosen model option fail: the real CDP-backed `page.click` on the nth-of-type selector threw, AND the JavaScript fallback (dispatching synthetic pointer/mouse events on the nth visible option) returned false because no visible option existed at that index. It indicates the model menu closed, re-rendered, or the DOM changed between enumeration and clicking.","triggerScenarios":"The dropdown closes between stage 1 enumeration and stage 2 click (e.g. a re-render or focus change); the option list shrank so `opts[idx]` is undefined in the fallback; the page navigated; or a Trae UI update changed the option element structure so page.click times out on the selector.","commonSituations":"Slow/heavily loaded Trae windows where menus animate in and out; clicking while an AI task is running causes re-renders; flaky remote/desktop sessions delaying input events; Trae version upgrades altering the `.core-model-select-model-item` DOM.","solutions":["Retry the command — transient menu closing is the most common cause.","Ensure no background task/re-render is in flight in Trae before switching models (wait for the current operation to finish).","Use `--list` first to confirm the menu opens reliably, then switch immediately after.","If persistent, verify the `.core-model-select-model-item[role=\"option\"]` selector still matches in the current Trae build and update selectors.","Increase page.wait tolerance or re-open the trigger and retry the click."],"exampleFix":"// before\nawait cli('trae-solo', 'model', 'gpt-4o'); // flaky menu\n// after\nfor (let i = 0; i < 3; i++) {\n  try { await cli('trae-solo', 'model', 'gpt-4o'); break; }\n  catch (e) { if (!/Click on model option failed/.test(e.message) || i === 2) throw e;\n    await new Promise(r => setTimeout(r, 1000)); }\n}","handlingStrategy":"retry","validationCode":"const opts = await cli('trae-solo', 'model', { list: true });\nif (!opts.length) throw new Error('Model menu not opening — abort before switch');","typeGuard":null,"tryCatchPattern":"try {\n  await cli('trae-solo', 'model', name);\n} catch (e) {\n  if (/Click on model option failed/.test(e.message)) {\n    await sleep(1000); // let any re-render settle, then retry once\n    await cli('trae-solo', 'model', name);\n  } else throw e;\n}","preventionTips":["Avoid switching models while an AI task is streaming (causes re-renders).","Retry once with a short delay — menu flakiness is usually transient.","Keep the Trae window focused/visible during UI automation.","Pin a known-good Trae version in automation environments."],"tags":["ui-automation","click-failure","trae","flaky"],"backgroundTag":"ui-click-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}