{"record":{"id":"ba6242271077bf59","repo":"jlcodes99/cockpit-tools","slug":"provider-store-cachekey","errorCode":null,"errorMessage":"[Provider Store] 忽略异常空当前账号，保留本地缓存: ${cacheKey}","messagePattern":"\\[Provider Store\\] 忽略异常空当前账号，保留本地缓存: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/stores/createProviderAccountStore.ts","lineNumber":227,"sourceCode":"        const currentAccountId = normalizeCurrentAccountId(get().currentAccountId, accounts);\n        set({ currentAccountId });\n        persistCurrentAccountId(currentAccountId);\n        return currentAccountId;\n      }\n\n      try {\n        const resolvedAccountId = await options.resolveCurrentAccountId();\n        if (requestId !== fetchCurrentAccountSeq) {\n          return get().currentAccountId;\n        }\n        if (\n          !resolvedAccountId &&\n          get().currentAccountId &&\n          accounts.length > 0 &&\n          !acceptEmptyCurrentAccountId &&\n          !allowNextEmptyCurrentAccountId\n        ) {\n          console.warn(\n            `[Provider Store] 忽略异常空当前账号，保留本地缓存: ${cacheKey}`,\n          );\n          return get().currentAccountId;\n        }\n        allowNextEmptyCurrentAccountId = false;\n        const currentAccountId = normalizeCurrentAccountId(resolvedAccountId, accounts);\n        set({ currentAccountId });\n        persistCurrentAccountId(currentAccountId);\n        return currentAccountId;\n      } catch (error) {\n        if (requestId !== fetchCurrentAccountSeq) {\n          return get().currentAccountId;\n        }\n        console.error(`[Provider Store] Failed to resolve current account for ${cacheKey}:`, error);\n        const currentAccountId = normalizeCurrentAccountId(get().currentAccountId, accounts);\n        set({ currentAccountId });\n        persistCurrentAccountId(currentAccountId);\n        return currentAccountId;","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/stores/createProviderAccountStore.ts#L209-L245","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Usually safe to ignore — the store intentionally preserved the cached current account.","Refresh accounts again; if the backend consistently returns empty, fix the backend resolver for that provider.","If the cache is genuinely stale, clear it deliberately via the store's reset/logout flow so the empty result is accepted.","If your integration intentionally clears current account, call the API path that sets allowNextEmptyCurrentAccountId/acceptEmptyCurrentAccountId first.","Check for provider API version changes affecting the current-account field."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const next = await resolveCurrentAccountId();\nconst shouldAcceptEmpty =\n  next != null ||\n  acceptEmptyCurrentAccountId ||\n  allowNextEmptyCurrentAccountId ||\n  get().accounts.length === 0;\nif (!shouldAcceptEmpty) {\n  console.warn(`[Provider Store] ignoring anomalous empty current account: ${cacheKey}`);\n  return get().currentAccountId;\n}","typeGuard":"function hasResolvedCurrent(v: unknown): v is { currentAccountId: string } {\n  return typeof v === 'object' && v !== null &&\n    typeof (v as { currentAccountId?: unknown }).currentAccountId === 'string' &&\n    (v as { currentAccountId: string }).currentAccountId.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Only bypass the guard via the documented allowNextEmptyCurrentAccountId/acceptEmptyCurrentAccountId flags during deliberate resets.","Verify backend current-account resolvers return ids consistent with the accounts list.","Refresh accounts after provider API upgrades to catch contract drift early."],"tags":["state-management","zustand","cache","accounts"],"backgroundTag":"empty-current-account-guard","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"}