{"record":{"id":"3b10aab9370708ed","repo":"jackwener/OpenCLI","slug":"gemini-generation-probe-returned-a-malformed-resul","errorCode":null,"errorMessage":"Gemini generation probe returned a malformed result","messagePattern":"Gemini generation probe returned a malformed result","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/gemini/utils.js","lineNumber":2383,"sourceCode":"    const urls = requireGeminiArrayResult(result, 'Gemini image detection');\n    if (!urls.every((url) => typeof url === 'string')) {\n        throw new CommandExecutionError('Gemini image detection returned a malformed result');\n    }\n    return urls;\n}\n/** Cheap generation probe: the snapshot read walks the whole transcript. */\nexport async function isGeminiGenerating(page) {\n    let result;\n    try {\n        result = await page.evaluate(`(() => ${isGeneratingExpression()})()`);\n    }\n    catch (error) {\n        const message = error instanceof Error ? error.message : String(error);\n        throw new CommandExecutionError('Gemini generation probe failed', message);\n    }\n    const value = unwrapGeminiEvaluateResult(result, 'Gemini generation probe');\n    if (typeof value !== 'boolean') {\n        throw new CommandExecutionError('Gemini generation probe returned a malformed result');\n    }\n    return value;\n}\nexport async function waitForGeminiImages(page, beforeUrls, timeoutSeconds) {\n    const beforeSet = new Set(beforeUrls);\n    const pollIntervalSeconds = 3;\n    const maxPolls = Math.max(1, Math.ceil(timeoutSeconds / pollIntervalSeconds));\n    let lastUrls = [];\n    let stableCount = 0;\n    let stillGenerating = false;\n    for (let index = 0; index < maxPolls; index += 1) {\n        await page.wait(index === 0 ? 2 : pollIntervalSeconds);\n        // The text waits already gate on this signal; without it the image wait\n        // can settle on whatever is on screen mid-generation (#2245). An\n        // unreadable probe keeps the last known state so the deadline still\n        // reports the right typed error.\n        const generating = await isGeminiGenerating(page);\n        if (generating !== null)","sourceCodeStart":2365,"sourceCodeEnd":2401,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gemini/utils.js#L2365-L2401","documentation":"Thrown by isGeminiGenerating when the generation probe evaluates successfully but unwrapGeminiEvaluateResult yields a value that is not a boolean. The probe must return true/false for 'is the model generating'; any other shape (undefined, object, string) is rejected so callers can trust the flag.","triggerScenarios":"The in-page isGeneratingExpression returns undefined (selector for the generating indicator not found and no fallback), or returns an object/serialized wrapper because the evaluate layer unwraps results differently than expected — typically after a Gemini DOM change to the generating spinner/stop-button area.","commonSituations":"Gemini redesign replacing the spinner element the probe checks; probe running on a page state (empty chat, error screen) with no indicator at all; evaluate proxy layer wrapping the boolean; stale cached script version in the page.","solutions":["Log the raw probe value and update isGeneratingExpression to match the current generating-indicator DOM (return false as default when absent).","Retry the probe once — a mid-render state can transiently yield undefined.","Use readGeminiSnapshot's isGenerating (validated boolean) as an alternative probe.","Catch CommandExecutionError around isGeminiGenerating in polling loops and treat unknown states as 'still waiting'."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isBoolean(v) { return typeof v === 'boolean'; }","tryCatchPattern":"let generating = null;\ntry {\n  generating = await isGeminiGenerating(page);\n} catch (e) {\n  if (String(e.message).includes('malformed result')) generating = null; // unknown state\n  else throw e;\n}\nif (generating !== false) { /* keep waiting */ }","preventionTips":["Probe only on a loaded conversation page (not blank/error screens).","Default the in-page expression to `false` when the indicator is absent.","Update the generating-indicator selector after Gemini redesigns.","Treat unknown probe states as 'still generating' rather than false."],"tags":["gemini","type-mismatch","page-evaluate","polling"],"backgroundTag":"schema-validation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}