{"record":{"id":"bb694dec2303c342","repo":"jlcodes99/cockpit-tools","slug":"codex-localaccess-noeligibleaccountsselected-bb694d","errorCode":"codex.localAccess.noEligibleAccountsSelected","errorMessage":"所选账号不在当前环境中，或不符合 API 服务条件。请先在当前环境导入可用 Codex 账号后再添加。","messagePattern":"所选账号不在当前环境中，或不符合 API 服务条件。请先在当前环境导入可用 Codex 账号后再添加。","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pages/useCodexAccountsLocalAccessController.tsx","lineNumber":1006,"sourceCode":"        localAccessState,\n      ],\n    );\n  \n    const handleAddLocalAccessAccount = useCallback(\n      async (accountId: string) => {\n        if (addingLocalAccessAccountId) return;\n        setAddingLocalAccessAccountId(accountId);\n        try {\n          const result =\n            await codexLocalAccessService.appendCodexLocalAccessAccounts([\n              accountId,\n            ]);\n          setLocalAccessState(result.state);\n          const accountAdded = Boolean(\n            result.state.collection?.accountIds.includes(accountId),\n          );\n          if (!accountAdded) {\n            throw new Error(\n              t(\n                \"codex.localAccess.noEligibleAccountsSelected\",\n                \"所选账号不在当前环境中，或不符合 API 服务条件。请先在当前环境导入可用 Codex 账号后再添加。\",\n              ),\n            );\n          }\n          await ensureLocalAccessEntryVisible();\n          window.dispatchEvent(new Event(\"codex-local-access-state-updated\"));\n          setMessage({\n            text: t(\"codex.localAccess.saveSuccess\", \"API 服务集合已更新\"),\n          });\n        } catch (error) {\n          console.error(\"Failed to add account to API service:\", error);\n          setMessage({\n            text: t(\"messages.actionFailed\", {\n              action: t(\"codex.localAccess.entryAction\", \"添加至 API 服务\"),\n              error: String(error).replace(/^Error:\\s*/, \"\"),\n            }),","sourceCodeStart":988,"sourceCodeEnd":1024,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/pages/useCodexAccountsLocalAccessController.tsx#L988-L1024","documentation":"Thrown when adding a Codex account to local (API service) access completes but the account ID does not appear in the resulting `state.collection.accountIds`. The controller treats that as \"the selected account is not in the current environment or not eligible for API service\" and raises the localized error `codex.localAccess.noEligibleAccountsSelected`.","triggerScenarios":"Calling the add-account flow in `useCodexAccountsLocalAccessController` (around line 1006) with an `accountId` that, after the backend add operation and `setLocalAccessState(result.state)`, is not present in `result.state.collection?.accountIds`.","commonSituations":"The user selected an account from a different environment/profile than the active one; the account is a free/restricted account that fails eligibility checks; the collection was regenerated server-side and silently dropped the account.","solutions":["Switch to the environment the account belongs to (or import the account into the current environment) before adding it.","Verify the account is eligible for API service (not a restricted/free account blocked by `restrictFreeAccounts`).","Refresh the account list and retry, confirming `accountId` matches an entry in the current environment's accounts.","Check `filterCodexLocalAccessAccountIds` / `canAddCodexAccountToLocalAccess` in src/utils/codexLocalAccessAccounts.ts to see which eligibility rule rejected the account."],"exampleFix":"// before\nawait addAccountToLocalAccess(accountId);\n// after\nif (canAddCodexAccountToLocalAccess(account, restrictFreeAccounts)) {\n  await addAccountToLocalAccess(accountId);\n} else {\n  setMessage({ text: t(\"codex.localAccess.accountIneligible\"), tone: \"warning\" });\n}","handlingStrategy":"validation","validationCode":"const eligible = accountId != null &&\n  accounts.some((a) => a.id === accountId) &&\n  canAddCodexAccountToLocalAccess(account, restrictFreeAccounts);\nif (!eligible) throw new Error(t(\"codex.localAccess.noEligibleAccountsSelected\"));","typeGuard":"function isSelectedAccountInEnvironment(accountId: string, state: LocalAccessState): boolean {\n  return state.collection?.accountIds.includes(accountId) ?? false;\n}","tryCatchPattern":"try {\n  await addAccountToLocalAccess(accountId);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"noEligibleAccountsSelected\")) {\n    promptSwitchEnvironment();\n  } else { throw err; }\n}","preventionTips":["Clear multi-selections when the environment changes.","Check `canAddCodexAccountToLocalAccess` before invoking add.","Keep the account list freshly synced so IDs match the current environment."],"tags":["codex","local-access","eligibility","account-selection"],"backgroundTag":"no-eligible-accounts-selected","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"}