jlcodes99/cockpit-tools · error
codex.localAccess.noEligibleAccountsSelected
codex.localAccess.noEligibleAccountsSelected
Error message
所选账号不在当前环境中,或不符合 API 服务条件。请先在当前环境导入可用 Codex 账号后再添加。
What it means
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`.
Source
Thrown at src/pages/useCodexAccountsLocalAccessController.tsx:1006
localAccessState,
],
);
const handleAddLocalAccessAccount = useCallback(
async (accountId: string) => {
if (addingLocalAccessAccountId) return;
setAddingLocalAccessAccountId(accountId);
try {
const result =
await codexLocalAccessService.appendCodexLocalAccessAccounts([
accountId,
]);
setLocalAccessState(result.state);
const accountAdded = Boolean(
result.state.collection?.accountIds.includes(accountId),
);
if (!accountAdded) {
throw new Error(
t(
"codex.localAccess.noEligibleAccountsSelected",
"所选账号不在当前环境中,或不符合 API 服务条件。请先在当前环境导入可用 Codex 账号后再添加。",
),
);
}
await ensureLocalAccessEntryVisible();
window.dispatchEvent(new Event("codex-local-access-state-updated"));
setMessage({
text: t("codex.localAccess.saveSuccess", "API 服务集合已更新"),
});
} catch (error) {
console.error("Failed to add account to API service:", error);
setMessage({
text: t("messages.actionFailed", {
action: t("codex.localAccess.entryAction", "添加至 API 服务"),
error: String(error).replace(/^Error:\s*/, ""),
}),View on GitHub (pinned to 1ed8b77992)
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.
Example fix
// before
await addAccountToLocalAccess(accountId);
// after
if (canAddCodexAccountToLocalAccess(account, restrictFreeAccounts)) {
await addAccountToLocalAccess(accountId);
} else {
setMessage({ text: t("codex.localAccess.accountIneligible"), tone: "warning" });
} Defensive patterns
Strategy: validation
Validate before calling
const eligible = accountId != null &&
accounts.some((a) => a.id === accountId) &&
canAddCodexAccountToLocalAccess(account, restrictFreeAccounts);
if (!eligible) throw new Error(t("codex.localAccess.noEligibleAccountsSelected")); Type guard
function isSelectedAccountInEnvironment(accountId: string, state: LocalAccessState): boolean {
return state.collection?.accountIds.includes(accountId) ?? false;
} Try / catch
try {
await addAccountToLocalAccess(accountId);
} catch (err) {
if (err instanceof Error && err.message.includes("noEligibleAccountsSelected")) {
promptSwitchEnvironment();
} else { throw err; }
} Prevention
- Clear multi-selections when the environment changes.
- Check `canAddCodexAccountToLocalAccess` before invoking add.
- Keep the account list freshly synced so IDs match the current environment.
When it happens
Trigger: 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`.
Common situations: 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.
Related errors
- message
- codex.localAccess.testUnavailable
- messages.rawLineNoRefreshToken(item.lineNumber)
- messages.rawLineMultipleRefreshTokens(item.lineNumber)
- PROVIDER_NAME_REQUIRED
AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05).
Data as JSON: /api/errors/bb694dec2303c342.
Report an issue: GitHub.