jlcodes99/cockpit-tools · warning

[Provider Store] 忽略异常空当前账号,保留本地缓存: ${cacheKey}

Error message

[Provider Store] 忽略异常空当前账号,保留本地缓存: ${cacheKey}

What it means

A protective console.warn in createProviderAccountStore (shared by Claude/Codebuddy/Cursor/Copilot/Grok account stores). When resolving the current account, if the service returned no account id but the store already has a cached currentAccountId and a non-empty local account list — and no explicit empty-accept flag was set — the store treats the empty result as anomalous and keeps the cached currentAccountId instead of clearing it.

Source

Thrown at src/stores/createProviderAccountStore.ts:227

        const currentAccountId = normalizeCurrentAccountId(get().currentAccountId, accounts);
        set({ currentAccountId });
        persistCurrentAccountId(currentAccountId);
        return currentAccountId;
      }

      try {
        const resolvedAccountId = await options.resolveCurrentAccountId();
        if (requestId !== fetchCurrentAccountSeq) {
          return get().currentAccountId;
        }
        if (
          !resolvedAccountId &&
          get().currentAccountId &&
          accounts.length > 0 &&
          !acceptEmptyCurrentAccountId &&
          !allowNextEmptyCurrentAccountId
        ) {
          console.warn(
            `[Provider Store] 忽略异常空当前账号,保留本地缓存: ${cacheKey}`,
          );
          return get().currentAccountId;
        }
        allowNextEmptyCurrentAccountId = false;
        const currentAccountId = normalizeCurrentAccountId(resolvedAccountId, accounts);
        set({ currentAccountId });
        persistCurrentAccountId(currentAccountId);
        return currentAccountId;
      } catch (error) {
        if (requestId !== fetchCurrentAccountSeq) {
          return get().currentAccountId;
        }
        console.error(`[Provider Store] Failed to resolve current account for ${cacheKey}:`, error);
        const currentAccountId = normalizeCurrentAccountId(get().currentAccountId, accounts);
        set({ currentAccountId });
        persistCurrentAccountId(currentAccountId);
        return currentAccountId;

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Usually safe to ignore — the store intentionally preserved the cached current account.
  2. Refresh accounts again; if the backend consistently returns empty, fix the backend resolver for that provider.
  3. If the cache is genuinely stale, clear it deliberately via the store's reset/logout flow so the empty result is accepted.
  4. If your integration intentionally clears current account, call the API path that sets allowNextEmptyCurrentAccountId/acceptEmptyCurrentAccountId first.
  5. Check for provider API version changes affecting the current-account field.
Defensive patterns

Strategy: validation

Validate before calling

const next = await resolveCurrentAccountId();
const shouldAcceptEmpty =
  next != null ||
  acceptEmptyCurrentAccountId ||
  allowNextEmptyCurrentAccountId ||
  get().accounts.length === 0;
if (!shouldAcceptEmpty) {
  console.warn(`[Provider Store] ignoring anomalous empty current account: ${cacheKey}`);
  return get().currentAccountId;
}

Type guard

function hasResolvedCurrent(v: unknown): v is { currentAccountId: string } {
  return typeof v === 'object' && v !== null &&
    typeof (v as { currentAccountId?: unknown }).currentAccountId === 'string' &&
    (v as { currentAccountId: string }).currentAccountId.length > 0;
}

Prevention

When it happens

Trigger: The backend resolve/get-current-account call returns null/empty while accounts.length > 0 and get().currentAccountId is set, with acceptEmptyCurrentAccountId and allowNextEmptyCurrentAccountId both false.

Common situations: Backend briefly returns an incomplete account payload (partial sync, service restart mid-request); API contract change where the current-account field was renamed/removed; a transient backend bug reporting zero current account despite existing accounts.

Related errors


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