jackwener/OpenCLI · error · CommandExecutionError

Click on model option failed.

Error message

Click on model option failed.

What it means

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.

Source

Thrown at clis/trae-solo/model.js:117

                // to JS dispatch on the nth visible option.
                const fallbackClicked = await page.evaluate(`(function(i) {
          const opts = Array.from(document.querySelectorAll('.core-model-select-model-item[role="option"]'))
            .filter((el) => el.offsetParent);
          const target = opts[i];
          if (!target) return false;
          const r = target.getBoundingClientRect();
          const init = { bubbles: true, cancelable: true, button: 0, buttons: 1,
            clientX: Math.round(r.left + r.width / 2),
            clientY: Math.round(r.top + r.height / 2) };
          target.dispatchEvent(new PointerEvent('pointerdown', { ...init, pointerType: 'mouse' }));
          target.dispatchEvent(new MouseEvent('mousedown', init));
          target.dispatchEvent(new PointerEvent('pointerup', { ...init, pointerType: 'mouse' }));
          target.dispatchEvent(new MouseEvent('mouseup', init));
          target.dispatchEvent(new MouseEvent('click', init));
          return true;
        })(${idx})`);
                if (!fallbackClicked) {
                    throw new CommandExecutionError('Click on model option failed.', `model=${chosenLabel}`);
                }
            }
            await page.wait(0.6);
            const after = await readCurrentModel(page);
            if (!after || !after.toLowerCase().includes(name)) {
                throw new CommandExecutionError(
                    `Model click did not verify selected model "${chosenLabel}".`,
                    after ? `current=${after}` : 'model trigger was unreadable after click',
                );
            }
            return [{ Status: 'switched', Model: after }];
        }

        // Just read the current.
        return [{ Status: 'Active', Model: current }];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the command — transient menu closing is the most common cause.
  2. Ensure no background task/re-render is in flight in Trae before switching models (wait for the current operation to finish).
  3. Use `--list` first to confirm the menu opens reliably, then switch immediately after.
  4. If persistent, verify the `.core-model-select-model-item[role="option"]` selector still matches in the current Trae build and update selectors.
  5. Increase page.wait tolerance or re-open the trigger and retry the click.

Example fix

// before
await cli('trae-solo', 'model', 'gpt-4o'); // flaky menu
// after
for (let i = 0; i < 3; i++) {
  try { await cli('trae-solo', 'model', 'gpt-4o'); break; }
  catch (e) { if (!/Click on model option failed/.test(e.message) || i === 2) throw e;
    await new Promise(r => setTimeout(r, 1000)); }
}
Defensive patterns

Strategy: retry

Validate before calling

const opts = await cli('trae-solo', 'model', { list: true });
if (!opts.length) throw new Error('Model menu not opening — abort before switch');

Try / catch

try {
  await cli('trae-solo', 'model', name);
} catch (e) {
  if (/Click on model option failed/.test(e.message)) {
    await sleep(1000); // let any re-render settle, then retry once
    await cli('trae-solo', 'model', name);
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/7bb2c0882fcbae0f. Report an issue: GitHub.