{"record":{"id":"7e0a10c62d919321","repo":"jackwener/OpenCLI","slug":"codex-model-switch-to-selected-was-not-verifi","errorCode":null,"errorMessage":"Codex model switch to \"${selected}\" was not verified.","messagePattern":"Codex model switch to \"(.+?)\" was not verified\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/codex/model.js","lineNumber":257,"sourceCode":"            await page.wait(0.25);\n            const reread = unwrapEvaluateResult(await page.evaluate(`(function() {\n        const re = new RegExp(${patternJson});\n        const composers = Array.from(document.querySelectorAll('[contenteditable=\"true\"]')).filter((el) => el.offsetParent);\n        const last = composers[composers.length - 1];\n        if (!last) return '';\n        let root = last;\n        for (let i = 0; i < 5; i++) root = root.parentElement || root;\n        const btns = Array.from(root.querySelectorAll('button')).filter((b) => b.offsetParent);\n        const match = btns.find((b) => re.test((b.textContent || '').trim()));\n        return match ? (match.textContent || '').trim() : '';\n      })()`));\n            if (modelSelectionVerified(reread, selected)) {\n                verified = reread;\n                break;\n            }\n        }\n        if (!verified) {\n            throw new CommandExecutionError(\n                `Codex model switch to \"${selected}\" was not verified.`,\n                'The model menu click may have failed or the model selector text may have drifted.',\n            );\n        }\n        return [{ Status: 'switched', Model: verified }];\n    },\n});\n","sourceCodeStart":239,"sourceCodeEnd":265,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/codex/model.js#L239-L265","documentation":"After dispatching the menu-item click, the command polls up to 20 times (5s) re-reading the composer toolbar button and verifying via `modelSelectionVerified` that the visible text now reflects the chosen model/reasoning. This CommandExecutionError is thrown when verification never passes, meaning the click may have been swallowed, the menu selection didn't apply, or the selector text drifted so the re-read never sees the new value.","triggerScenarios":"Running `opencli codex model <name>` where the synthetic click on the menu item didn't register (menu intercepted the event, item disabled), the model switched but the toolbar text renders differently than expected (reasoning suffix, truncation), or the 5-second verify window expired before the UI updated.","commonSituations":"Codex UI updates changing the toolbar button's rendered text; slow machines where the switch takes >5s; menus requiring native trusted events that synthetic PointerEvent/MouseEvent sequences don't satisfy; the chosen option actually failed to apply (server rejected the switch).","solutions":["Re-run the command; transient click loss is the most common cause.","After switching, verify manually with `opencli codex model` (no args) to read the active model — the switch may have applied despite failed verification.","If it reproduces, the model selector text likely drifted in a Codex update (see the 'model selector text may have drifted' detail) — update opencli/MODEL_BTN_TEXT_RE.","Increase the verify attempts/window in model.js if your environment is slow, and ensure no other window overlays the Codex menu during the switch."],"exampleFix":"// before\nopencli codex model \"gpt-5.5\"          // throws: switch not verified\n// after\nopencli codex model \"gpt-5.5\" || true\nopencli codex model                     # read active model to confirm\n# in automation: retry the switch up to N times before giving up","handlingStrategy":"retry","validationCode":"// confirm the switch applied after invoking\nconst out = await run('opencli codex model'); // read-only\nconst active = parseActiveModel(out);\nif (!active.toLowerCase().includes(wanted.toLowerCase())) {\n  throw new Error('Switch did not take effect; retry');\n}","typeGuard":"function switchVerified(activeText, chosen) {\n  const n = s => String(s||'').toLowerCase().replace(/\\bgpt[-\\s]*/g,'').replace(/\\s+/g,' ').trim();\n  return n(activeText) === n(chosen);\n}","tryCatchPattern":"try {\n  await switchModel(name);\n} catch (err) {\n  if (err instanceof CommandExecutionError && /was not verified/.test(err.message)) {\n    // click may have been swallowed — retry the switch, then read-only verify\n    await sleep(1000);\n    return switchModel(name);\n  }\n  throw err;\n}","preventionTips":["Retry the switch once; transient click loss is common","Follow every switch with a read-only `codex model` to confirm the active value","Allow extra time on slow machines (5s verify window may be tight)","Keep opencli/MODEL_BTN_TEXT_RE updated after Codex toolbar UI changes"],"tags":["verification-failed","browser-automation","codex","model-selection"],"backgroundTag":"ui-state-verification-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}