{"record":{"id":"e795cd67776e29e9","repo":"jlcodes99/cockpit-tools","slug":"codex-switchauth-reauthgenerationmissing","errorCode":"codex.switchAuth.reauthGenerationMissing","errorMessage":"codex.switchAuth.reauthGenerationMissing","messagePattern":"codex\\.switchAuth\\.reauthGenerationMissing","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pages/useCodexAccountsOAuthController.ts","lineNumber":1262,"sourceCode":"        if (reauthRetrySwitchAccountId && account?.id) {\n          setAddStatus(\"loading\");\n          setAddMessage(\n            t(\n              \"codex.switchAuth.switchingAfterReauth\",\n              \"授权成功，正在继续切换账号...\",\n            ),\n          );\n          try {\n            const refreshedAccount =\n              useCodexAccountStore\n                .getState()\n                .accounts.find((item) => item.id === account.id) || account;\n            const tokenGeneration = refreshedAccount.token_generation;\n            if (\n              typeof tokenGeneration !== \"number\" ||\n              !Number.isFinite(tokenGeneration)\n            ) {\n              throw new Error(t(\"codex.switchAuth.reauthGenerationMissing\"));\n            }\n            await useCodexAccountStore.getState().switchAccount(account.id, {\n              reauthTokenGeneration: tokenGeneration,\n              reconcileAfterSwitch: true,\n              launchAfterSwitch: reauthRetryLaunchAfterSwitch,\n            });\n          } catch (error) {\n            setAddStatus(\"error\");\n            setAddMessage(\n              t(\"codex.switchAuth.switchAfterReauthFailed\", {\n                defaultValue: \"授权已更新，但继续切换失败：{{error}}\",\n                error: String(error).replace(/^Error:\\s*/, \"\"),\n              }),\n            );\n            return;\n          }\n        }\n        if (reauthRetryInstanceId && account?.id) {","sourceCodeStart":1244,"sourceCodeEnd":1280,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/pages/useCodexAccountsOAuthController.ts#L1244-L1280","documentation":"Type guard in the continue-switch-after-reauth path: after OAuth re-auth succeeds, the refreshed account's token_generation is read from the account store; if it is not a number (undefined/null), the code cannot verify the credential generation and aborts the switch instead of using a stale token. The throw corresponds to the codex.switchAuth.reauthGenerationMissing key.","triggerScenarios":"Thrown at src/pages/useCodexAccountsOAuthController.ts:1262 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Wait for the account store to refresh so the new token_generation lands before continuing the switch","Re-run the re-auth flow if credentials were written without a generation bump","Inspect why the post-reauth account record lacks token_generation (backend write failure)"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}