{"record":{"id":"91ffeb89a4cd2939","repo":"jackwener/OpenCLI","slug":"gemini-model-discovery-returned-a-malformed-result","errorCode":null,"errorMessage":"Gemini model discovery returned a malformed result","messagePattern":"Gemini model discovery returned a malformed result","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/gemini/ask.js","lineNumber":39,"sourceCode":"}\nconst NO_RESPONSE_PREFIX = '[NO RESPONSE]';\n\n/**\n * Validate a --model value for gemini ask.\n * Throws ArgumentError for short aliases or invalid formats.\n */\nfunction unwrapBrowserBridgeEnvelope(value) {\n    if (value && typeof value === 'object' && !Array.isArray(value) && 'session' in value) {\n        if ('data' in value) return value.data;\n        throw new CommandExecutionError('Gemini model discovery returned a malformed Browser Bridge envelope');\n    }\n    return value;\n}\n\nfunction requireDiscoveredModels(value) {\n    const unwrapped = unwrapBrowserBridgeEnvelope(value);\n    if (!Array.isArray(unwrapped)) {\n        throw new CommandExecutionError('Gemini model discovery returned a malformed result');\n    }\n    for (const row of unwrapped) {\n        if (!row || typeof row.model !== 'string' || !Array.isArray(row.thinkingValues)) {\n            throw new CommandExecutionError('Gemini model discovery returned a malformed row');\n        }\n    }\n    return unwrapped;\n}\n\nfunction validateAskModelValue(value) {\n    if (!value) {\n        throw new ArgumentError(\n            '--model requires a canonical model id (e.g. \"2.5-flash\"). ' +\n            'Use \"opencli gemini models\" to list available values.'\n        );\n    }\n    // Reject short aliases like \"pro\", \"flash\", \"flash-lite\" that lack a version number.\n    if (!/\\d+\\.\\d+/.test(value)) {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gemini/ask.js#L21-L57","documentation":"requireDiscoveredModels in clis/gemini/ask.js checks that, after envelope unwrapping, model discovery yielded an array. If the unwrapped value is not an array, this CommandExecutionError is thrown. It ensures askCommand only proceeds with a well-formed list of discovered model rows.","triggerScenarios":"`opencli gemini ask` runs model discovery and receives `null`, `undefined`, an object, or a string after envelope unwrap — e.g. discovery found no models and the bridge returned null instead of [].","commonSituations":"Gemini UI rendered a variant page without the model list; bridge automation failed silently and returned an empty/None result; regional or A/B UI differences change discovery output type.","solutions":["Run `opencli gemini models` to verify discovery works on this account/session","Retry the ask command after the browser page fully loads","Pass `--model` explicitly with a canonical id (e.g. 2.5-flash) to bypass reliance on discovery output shape","Update opencli if Gemini's UI changed the discovery result shape"],"exampleFix":"null","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(discoveryResult)) {\n  console.warn('Model discovery did not yield a list; pass --model explicitly');\n}","typeGuard":"function isDiscoveredModelArray(value) {\n  return Array.isArray(value) && value.length > 0 &&\n    value.every(r => r && typeof r.model === 'string' && Array.isArray(r.thinkingValues));\n}","tryCatchPattern":"try {\n  const models = await geminiAsk(args);\n} catch (err) {\n  if (err.message.includes('malformed result')) {\n    // fall back to explicit model selection\n    return geminiAsk({ ...args, model: '2.5-flash' });\n  }\n  throw err;\n}","preventionTips":["Pass an explicit --model to reduce reliance on discovery","Verify discovery health with `opencli gemini models`","Retry after full page load","Keep the CLI in sync with Gemini UI changes"],"tags":["model-discovery","gemini","browser-automation"],"backgroundTag":"model-discovery-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}