{"record":{"id":"777c408ff71cd40f","repo":"jackwener/OpenCLI","slug":"selectedmodelid-gemini-model-selection-read-bac","errorCode":null,"errorMessage":"selectedModelId ? `Gemini model selection read-back returned \"${selectedModelId}\", expected \"${modelId}\"` : `Gemini model selection did not expose selected model \"${modelId}\" after click`","messagePattern":"selectedModelId \\? `Gemini model selection read-back returned \"(.+?)\", expected \"(.+?)\"` : `Gemini model selection did not expose selected model \"(.+?)\" after click`","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/gemini/utils.js","lineNumber":2747,"sourceCode":"        );\n    }\n\n    // Wait for React to render the menu.\n    await page.wait(0.8);\n\n    // Find and click the matching menu item.\n    const raw = await page.evaluate(selectModelInMenuScript(modelId));\n    const result = unwrapGeminiEvaluateResult(raw, 'Gemini model selection');\n    if (!result || !result.ok) {\n        throw new CommandExecutionError(\n            result?.reason || 'Failed to select Gemini model \"' + modelId + '\"'\n        );\n    }\n\n    await page.wait(0.5);\n    const selectedModelId = await getCurrentGeminiModel(page);\n    if (selectedModelId !== modelId) {\n        throw new CommandExecutionError(\n            selectedModelId\n                ? `Gemini model selection read-back returned \"${selectedModelId}\", expected \"${modelId}\"`\n                : `Gemini model selection did not expose selected model \"${modelId}\" after click`\n        );\n    }\n}\n","sourceCodeStart":2729,"sourceCodeEnd":2754,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gemini/utils.js#L2729-L2754","documentation":"CommandExecutionError thrown after a model click when reading back the current model (getCurrentGeminiModel) does not equal the requested modelId — either a different model is reported or no model is exposed at all. This is a post-action verification step to guarantee the selection took effect.","triggerScenarios":"At clis/gemini/utils.js:2747 the click succeeded but the UI state read-back returned a mismatched selectedModelId, or returned nothing within the wait window (0.5s).","commonSituations":"UI state not yet updated at read time; selection silently reverted; ambiguous model names resolving to a different entry; Gemini UI lag.","solutions":["Re-run the selection command","Increase tolerance for UI lag (retry after a short wait)","Use the exact canonical model id from the picker listing"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// verify the requested id is canonical before selecting\nconst available = await listGeminiModels(page);\nif (!available.includes(modelId)) {\n  throw new Error(`'${modelId}' not offered; closest: ${available.filter(m => m.includes(modelId.slice(0,10)))}`);\n}","typeGuard":"function matchesRequested(selected: string | null, modelId: string): boolean {\n  return typeof selected === 'string' && selected.trim() === modelId;\n}","tryCatchPattern":"try {\n  await selectGeminiModel(page, modelId);\n} catch (err) {\n  if (err.message.includes('read-back')) {\n    const current = await getCurrentGeminiModel(page);\n    console.error(`Selection mismatch: got ${current}, wanted ${modelId}; retrying...`);\n  }\n  throw err;\n}","preventionTips":["Wait slightly longer between click and read-back if the UI is slow","Compare against canonical ids, not display labels","Re-run selection when read-back mismatches instead of proceeding"],"tags":["browser-automation","state-mismatch","gemini"],"backgroundTag":"state-readback-mismatch","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}