jackwener/OpenCLI · error · CommandExecutionError

${pickerResult?.reason || 'Failed to open Gemini model picke

Error message

${pickerResult?.reason || 'Failed to open Gemini model picker for model discovery'}

What it means

This CommandExecutionError is thrown when the browser-bridge script that clicks Gemini's model picker button fails or reports not-ok. The library clicks the picker button inside gemini.google.com to enumerate selectable models; if the click throws, the bridge returns ok:false with a reason, or the envelope can't be unwrapped, this fallback message is used.

Source

Thrown at clis/gemini/ask.js:149

        // ── Model and thinking discovery (shared by both model and
        //    thinking selection) ──────────────────────────────────────
        let discoveredModels = null;
        if (hasModel || hasThinking) {
            await ensureGeminiPage(page);

            // Open the picker menu (click the model-picker button).
            const pickerRaw = await page.evaluate(`
              (() => {
                ${pickModelPickerScript()}
                const picker = findModelPicker();
                if (!picker) return { ok: false, reason: 'Gemini model picker button was not found' };
                try { picker.click(); } catch (_) { return { ok: false, reason: 'Failed to click Gemini model picker button' }; }
                return { ok: true };
              })()
            `);
            const pickerResult = unwrapBrowserBridgeEnvelope(pickerRaw);
            if (!pickerResult || typeof pickerResult !== 'object' || !pickerResult.ok) {
                throw new CommandExecutionError(
                    pickerResult?.reason || 'Failed to open Gemini model picker for model discovery'
                );
            }

            // Wait for React to render the menu.
            await page.wait(1.0);

            // Read model entries from the open menu.
            const raw = await page.evaluate(readMenuModelsScript());
            discoveredModels = requireDiscoveredModels(raw);

            // Close the menu. Thinking support is intentionally not copied from
            // the currently-visible UI into every model row: Gemini exposes
            // thinking controls for the current selection, not a reliable
            // per-model capability matrix.
            await page.evaluate(`(() => { try { document.body.click(); } catch (_) {} })()`);
        }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command after a page.reload() / fresh login so the model picker button is rendered before clicking
  2. Increase the wait before clicking the picker (e.g. page.wait(2.0)) to let React mount the button
  3. Update the picker-button selector in clis/gemini/ask.js to match the current Gemini Web DOM
  4. Check `opencli gemini login` status to ensure an authenticated, non-redirected session

Example fix

// before
await page.wait(1.0);
// after
await page.wait(3.0); // let React render the picker button before clicking
Defensive patterns

Strategy: retry

Validate before calling

const pickerRaw = await evalBridge(script);
const pickerResult = unwrapBrowserBridgeEnvelope(pickerRaw);
if (!pickerResult?.ok) { await page.wait(2.0); /* retry once before proceeding */ }

Type guard

function isPickerResultOk(r) { return !!r && typeof r === 'object' && r.ok === true; }

Try / catch

try {
  await runAskCommand();
} catch (e) {
  if (/model picker/i.test(e.message)) { await page.reload(); await page.wait(3); /* retry */ }
  else throw e;
}

Prevention

When it happens

Trigger: The injected picker.click() throws (element detached/not clickable), the bridge returns {ok:false, reason:'Failed to click Gemini model picker button'}, or pickerRaw fails unwrapBrowserBridgeEnvelope (null/non-object).

Common situations: Gemini Web UI changed so the picker button selector no longer matches; page not fully rendered before the click; slow network causing React not to mount the button; browser bridge/CDP hiccup or page navigation mid-automation.

Related errors


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