jlcodes99/cockpit-tools · warning

刷新 Codex 账号资料失败:

Error message

刷新 Codex 账号资料失败:

What it means

This warning is emitted by useCodexAccountStore's background profile-sync path. When refreshing a Codex account's profile (fetching fresh identity/plan info from the Codex backend via the service layer) fails, the store keeps the old cached profile, logs this warning with the account id, and releases the per-account in-flight lock (CODEX_PROFILE_SYNC_IN_FLIGHT) in the finally block so future syncs can retry.

Source

Thrown at src/stores/useCodexAccountStore.ts:447

        set((state) => {
          const nextAccounts = state.accounts.map((item) =>
            item.id === updatedAccount.id ? { ...item, ...updatedAccount } : item,
          );
          const nextCurrentAccount =
            state.currentAccount?.id === updatedAccount.id
              ? { ...state.currentAccount, ...updatedAccount }
              : state.currentAccount;

          persistCodexAccountsCache(nextAccounts);
          persistCodexCurrentAccountCache(nextCurrentAccount);

          return {
            accounts: nextAccounts,
            currentAccount: nextCurrentAccount,
          };
        });
      } catch (e) {
        console.warn('刷新 Codex 账号资料失败:', account.id, e);
      } finally {
        CODEX_PROFILE_SYNC_IN_FLIGHT.delete(account.id);
      }
    }
  },

  importFromLocal: async () => {
    const account = await codexService.importCodexFromLocal();
    await get().fetchAccounts();
    await emitAccountsChanged({
      platformId: 'codex',
      reason: 'import',
    });
    return account;
  },

  importFromJson: async (jsonContent: string) => {
    const accounts = await codexService.importCodexFromJson(jsonContent);

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Read the third logged argument `e` for the underlying cause (401/403, network error, etc.).
  2. Re-authenticate the affected Codex account (log out/in) to refresh the token.
  3. Check network/proxy connectivity to the Codex backend from the desktop app.
  4. If the account no longer exists, remove it from the store so sync stops retrying.

Example fix

// before
} catch (e) {
  console.warn('刷新 Codex 账号资料失败:', account.id, e);
}
// after
} catch (e) {
  if (isAuthError(e)) {
    markAccountNeedsRelogin(account.id);
  }
  console.warn('刷新 Codex 账号资料失败:', account.id, e);
}
Defensive patterns

Strategy: retry

Validate before calling

// skip sync when offline or no auth token
if (!navigator.onLine) return;
if (!account.hasCredentials) return;

Type guard

function hasProfileSyncTarget(a: CodexAccount | undefined): a is CodexAccount & { id: string } {
  return !!a && typeof a.id === 'string' && a.id.length > 0;
}

Try / catch

try {
  await refreshCodexProfile(account.id);
} catch (e) {
  console.warn('刷新 Codex 账号资料失败:', account.id, e);
  scheduleProfileRetry(account.id, { backoffMs: 30_000 }); // bounded retry
}

Prevention

When it happens

Trigger: A per-account profile sync runs (typically on an interval or on account switch) and the underlying service call throws: network failure, expired Codex auth token, account removed remotely, or the backend command returning an error.

Common situations: Codex OAuth/session token expired, offline or behind a proxy blocking api.openai.com, account deleted/revoked while the app still lists it, or rate limiting on the Codex endpoint.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/2eff429647f5c305. Report an issue: GitHub.