{"record":{"id":"4d978cecd36d3cfc","repo":"jackwener/OpenCLI","slug":"gemini-generation-probe-failed","errorCode":null,"errorMessage":"Gemini generation probe failed","messagePattern":"Gemini generation probe failed","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/gemini/utils.js","lineNumber":2379,"sourceCode":"      }\n      return urls;\n    })()\n  `);\n    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","sourceCodeStart":2361,"sourceCodeEnd":2397,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gemini/utils.js#L2361-L2397","documentation":"Thrown by isGeminiGenerating when page.evaluate of the isGeneratingExpression script itself throws (navigation, detached execution context, script syntax/runtime error). The original browser error message is preserved as the second argument of CommandExecutionError, and the wrapper normalizes it for callers of the generation probe.","triggerScenarios":"Polling isGeminiGenerating while the page navigates to a new conversation URL (execution context destroyed), the tab crashed/closed, or the in-page expression throws at runtime because expected DOM nodes are absent and the expression doesn't guard them.","commonSituations":"Race between submission and Gemini's client-side navigation; slow/unstable network causing context loss; headless browser killed mid-poll; Gemini deploying an update mid-session that breaks the probe expression.","solutions":["Retry the probe — navigation-timing races are transient and a re-poll usually succeeds.","Read the wrapped cause (second arg / error.cause) to identify the underlying evaluate failure.","Ensure the page isn't navigating during polling; wait for URL stability before probing.","Add null/DOM guards inside isGeneratingExpression so missing nodes return false instead of throwing.","Re-create the page/browser if the execution context is permanently gone (tab closed)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let generating = false;\ntry {\n  generating = await isGeminiGenerating(page);\n} catch (e) {\n  const cause = e.cause || e.message;\n  if (String(cause).includes('probe failed')) { await page.wait(1); generating = await isGeminiGenerating(page); }\n  else throw e;\n}","preventionTips":["Avoid probing during client-side navigation; wait for URL stability.","Add null guards inside isGeneratingExpression for missing DOM nodes.","Keep the browser/tab alive for the duration of polling loops.","Inspect e.cause for the underlying evaluate error when debugging."],"tags":["gemini","page-evaluate","polling","execution-context"],"backgroundTag":"execution-context-destroyed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}