jackwener/OpenCLI · error · CommandExecutionError

Gemini model discovery returned a malformed row

Error message

Gemini model discovery returned a malformed row

What it means

requireDiscoveredModels in clis/gemini/ask.js validates each row of the discovered model list: every row must be a truthy object with a string `model` and an array `thinkingValues`. Any row failing this shape triggers this CommandExecutionError, preventing malformed rows from reaching the model picker or thinking-level logic.

Source

Thrown at clis/gemini/ask.js:43

 * Validate a --model value for gemini ask.
 * Throws ArgumentError for short aliases or invalid formats.
 */
function unwrapBrowserBridgeEnvelope(value) {
    if (value && typeof value === 'object' && !Array.isArray(value) && 'session' in value) {
        if ('data' in value) return value.data;
        throw new CommandExecutionError('Gemini model discovery returned a malformed Browser Bridge envelope');
    }
    return value;
}

function requireDiscoveredModels(value) {
    const unwrapped = unwrapBrowserBridgeEnvelope(value);
    if (!Array.isArray(unwrapped)) {
        throw new CommandExecutionError('Gemini model discovery returned a malformed result');
    }
    for (const row of unwrapped) {
        if (!row || typeof row.model !== 'string' || !Array.isArray(row.thinkingValues)) {
            throw new CommandExecutionError('Gemini model discovery returned a malformed row');
        }
    }
    return unwrapped;
}

function validateAskModelValue(value) {
    if (!value) {
        throw new ArgumentError(
            '--model requires a canonical model id (e.g. "2.5-flash"). ' +
            'Use "opencli gemini models" to list available values.'
        );
    }
    // Reject short aliases like "pro", "flash", "flash-lite" that lack a version number.
    if (!/\d+\.\d+/.test(value)) {
        throw new ArgumentError(
            '--model "' + value + '" is not accepted. ' +
            'Short aliases like "pro", "flash", or "flash-lite" are not supported. ' +
            'Use a canonical model id (e.g. "2.5-flash"). ' +

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the command after the page fully loads to rule out a partially rendered row
  2. Update opencli so the row extractor matches the current Gemini model-card markup
  3. As a workaround, pass an explicit `--model 2.5-flash` and valid `--thinking` value if your CLI version permits skipping discovery-dependent selection

Example fix

null
Defensive patterns

Strategy: type-guard

Validate before calling

for (const row of discovered) {
  if (!row || typeof row.model !== 'string' || !Array.isArray(row.thinkingValues)) {
    console.warn('Skipping malformed discovery row:', row);
  }
}

Type guard

function isValidModelRow(row) {
  return !!row && typeof row.model === 'string' && Array.isArray(row.thinkingValues);
}

Try / catch

try {
  const models = await geminiAsk(args);
} catch (err) {
  if (err.message.includes('malformed row')) {
    return geminiAsk({ ...args, model: '2.5-flash' }); // bypass picker
  }
  throw err;
}

Prevention

When it happens

Trigger: `opencli gemini ask` performs discovery and at least one element of the model array is null, a plain string, or an object missing `model`/`thinkingValues` (or with non-array `thinkingValues`).

Common situations: Gemini introduces a new model card variant the extraction script doesn't fully parse; partial page load leaves one row half-populated; UI A/B test changes row markup for a single model.

Understand the failure class

Related errors


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