{"record":{"id":"c14d692d75fde89c","repo":"jlcodes99/cockpit-tools","slug":"codex-store","errorCode":null,"errorMessage":"[Codex Store] 自动恢复接管失败:","messagePattern":"\\[Codex Store\\] 自动恢复接管失败:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/stores/useCodexAccountStore.ts","lineNumber":216,"sourceCode":"      const currentAccount = await codexService.getCurrentCodexAccount();\n      if (requestId !== fetchCodexCurrentAccountSeq) {\n        return;\n      }\n      set({ currentAccount });\n      persistCodexCurrentAccountCache(currentAccount);\n    } catch (e) {\n      if (requestId !== fetchCodexCurrentAccountSeq) {\n        return;\n      }\n      console.error('获取当前 Codex 账号失败:', e);\n    }\n  },\n\n  restoreActiveTakeoverIfNeeded: async () => {\n    try {\n      await codexService.restoreCodexActiveTakeoverIfEnabled();\n    } catch (e) {\n      console.warn('[Codex Store] 自动恢复接管失败:', e);\n    }\n  },\n\n  applyAccountSnapshot: (account: CodexAccount) => {\n    if (!account?.id) return;\n\n    // 授权/切号返回的账号是后端刚落盘的权威快照，先写入内存和 localStorage，\n    // 同时使旧的异步回读失效，避免旧结果把刚更新的状态覆盖回去。\n    invalidateCodexFetchRequests();\n    set((state) => {\n      const nextAccounts = mergeCodexAccountIntoList(state.accounts, account);\n      const nextCurrentAccount =\n        state.currentAccount?.id === account.id ? account : state.currentAccount;\n      persistCodexAccountsCache(nextAccounts);\n      persistCodexCurrentAccountCache(nextCurrentAccount);\n      return {\n        accounts: nextAccounts,\n        currentAccount: nextCurrentAccount,","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/stores/useCodexAccountStore.ts#L198-L234","documentation":"In useCodexAccountStore, the restoreActiveTakeoverIfNeeded action calls codexService.restoreCodexActiveTakeoverIfEnabled() on startup to re-attach the previously active Codex account takeover (proxy/session hijacking of the CLI config). Any exception thrown by the Tauri backend or service layer is caught and only logged as a warning, so app startup is never blocked — but the active takeover silently fails to be restored.","triggerScenarios":"App startup or store initialization when restoreCodexActiveTakeoverIfEnabled() throws: Tauri IPC invoke fails, the backend cannot read/write Codex config.toml, or no enabled takeover record exists but the backend treats that as an error.","commonSituations":"Codex CLI config file missing or permissions-restricted, stale takeover state pointing at a removed account, Tauri backend command renamed/panicking after an update, or the app started before the Codex home directory existed.","solutions":["Inspect the logged error object `e` in the console to see the underlying Tauri/backend cause (file permission, missing config, IPC failure).","Verify the Codex config file path exists and is writable by the app (check permissions / antivirus lock).","Clear stale takeover state in the backend store so restore starts from a clean slate, then re-enable takeover manually.","If it persists after an app update, confirm the Tauri command name restore_codex_active_takeover_if_enabled still matches the frontend invoke call."],"exampleFix":"// before\ntry {\n  await codexService.restoreCodexActiveTakeoverIfEnabled();\n} catch (e) {\n  console.warn('[Codex Store] 自动恢复接管失败:', e);\n}\n// after\ntry {\n  await codexService.restoreCodexActiveTakeoverIfEnabled();\n} catch (e) {\n  console.warn('[Codex Store] 自动恢复接管失败:', e);\n  get().refreshAccounts?.(); // resync so UI reflects that takeover is NOT active\n}","handlingStrategy":"try-catch","validationCode":"// before restoring, check state availability\nconst enabled = await codexService.isCodexTakeoverEnabled?.();\nif (!enabled) return; // nothing to restore\n","typeGuard":"function isTakeoverResult(v: unknown): v is { restored: boolean } {\n  return !!v && typeof v === 'object' && 'restored' in v;\n}\n","tryCatchPattern":"try {\n  await codexService.restoreCodexActiveTakeoverIfEnabled();\n} catch (e) {\n  console.warn('[Codex Store] 自动恢复接管失败:', e);\n  // mark takeover state as inactive in UI so users can re-enable manually\n}","preventionTips":["Ensure the Codex config directory exists and is writable before app startup restore","Clean up stale takeover records when an account is deleted","Surface restore failure in the UI instead of only console.warn so users know to re-enable takeover"],"tags":["tauri","ipc","codex","startup","state-restore"],"backgroundTag":"tauri-invoke-failed","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"}