jackwener/OpenCLI · error · CommandExecutionError
Gemini model discovery returned a malformed result
Error message
Gemini model discovery returned a malformed result
What it means
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.
Source
Thrown at clis/gemini/ask.js:39
}
const NO_RESPONSE_PREFIX = '[NO RESPONSE]';
/**
* 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)) {View on GitHub (pinned to 49907e53dc)
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
Example fix
null
Defensive patterns
Strategy: type-guard
Validate before calling
if (!Array.isArray(discoveryResult)) {
console.warn('Model discovery did not yield a list; pass --model explicitly');
} Type guard
function isDiscoveredModelArray(value) {
return Array.isArray(value) && value.length > 0 &&
value.every(r => r && typeof r.model === 'string' && Array.isArray(r.thinkingValues));
} Try / catch
try {
const models = await geminiAsk(args);
} catch (err) {
if (err.message.includes('malformed result')) {
// fall back to explicit model selection
return geminiAsk({ ...args, model: '2.5-flash' });
}
throw err;
} Prevention
- 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
When it happens
Trigger: `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 [].
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Gemini model discovery returned a malformed Browser Bridge e
- Gemini model discovery returned a malformed row
- ${pickerResult?.reason || 'Failed to open Gemini model picke
- Gemini model discovery returned no selectable models. Gemini
- Could not select thinking level '${thinkingValue}' in the Ge
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/91ffeb89a4cd2939.
Report an issue: GitHub.