{"record":{"id":"1c9be6721450983c","repo":"jlcodes99/cockpit-tools","slug":"cpa-format-does-not-support-codex-agent-identity-a","errorCode":null,"errorMessage":"CPA format does not support Codex Agent Identity accounts","messagePattern":"CPA format does not support Codex Agent Identity accounts","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utils/codexExportFormats.ts","lineNumber":644,"sourceCode":"  if (format === 'auth_json') {\n    const payload = accounts.map(toOfficialAuthJson);\n    const normalizedPayload = payload.length === 1 ? payload[0] : payload;\n    return JSON.stringify(normalizedPayload, null, 2);\n  }\n\n  if (format === 'sub2api') {\n    const payload: Sub2apiBatchCreatePayload = {\n      exported_at: formatSub2apiExportedAt(),\n      proxies: [],\n      accounts: accounts.map(toSub2apiAccount),\n      type: 'sub2api-data',\n      version: 1,\n    };\n    return JSON.stringify(payload, null, 2);\n  }\n\n  if (accounts.some(hasAgentIdentity)) {\n    throw new Error('CPA format does not support Codex Agent Identity accounts');\n  }\n\n  const cpaPayload = accounts.map((account) => toPortableTokenStorage(account, options));\n  const normalizedPayload = cpaPayload.length === 1 ? cpaPayload[0] : cpaPayload;\n  return JSON.stringify(normalizedPayload, null, 2);\n}\n\nexport function buildCodexExportFileNameBase(\n  baseName: string,\n  format: CodexExportFormat,\n): string {\n  if (format === 'cockpit_tools') {\n    return baseName;\n  }\n  if (format === 'auth_json') {\n    return `${baseName}_auth`;\n  }\n  return `${baseName}_${format}`;","sourceCodeStart":626,"sourceCodeEnd":662,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/utils/codexExportFormats.ts#L626-L662","documentation":"The CPA (portable token storage) batch export throws this error when any account in the selection has an Agent Identity, because the CPA format cannot represent auth_mode='agentIdentity' credentials. The export fails fast instead of producing a lossy file.","triggerScenarios":"Calling the CPA export/serialize function with an accounts array where accounts.some(hasAgentIdentity) is true — mixing at least one Agent Identity account into a CPA batch export.","commonSituations":"Select-all export that includes agentIdentity accounts; batch migration to a tool that only supports token storage; users unaware CPA is limited to token-based accounts.","solutions":["Deselect Agent Identity accounts from the CPA export batch","Export Agent Identity accounts via a format that supports them (e.g. sub2api agentIdentity or official auth.json)","Split the export: CPA for token accounts, another format for agentIdentity accounts","Filter with hasAgentIdentity before invoking the CPA serializer"],"exampleFix":"// before\nconst json = exportCpa(accounts); // throws if any hasAgentIdentity\n// after\nconst supported = accounts.filter(a => !hasAgentIdentity(a));\nconst json = exportCpa(supported);","handlingStrategy":"validation","validationCode":"const unsupported = accounts.filter(hasAgentIdentity);\nif (unsupported.length) throw new Error(`${unsupported.length} agentIdentity account(s) unsupported in CPA`);","typeGuard":"function isCpaExportable(a: CodexAccount): boolean {\n  return !hasAgentIdentity(a);\n}","tryCatchPattern":"try {\n  const json = exportCpa(accounts);\n} catch (e) {\n  if ((e as Error).message.includes('CPA format does not support')) {\n    // split into CPA export + agentIdentity-capable export\n  }\n}","preventionTips":["Filter out hasAgentIdentity accounts before CPA export","Choose agentIdentity-capable formats for those accounts","Communicate per-format account support in the export UI"],"tags":["unsupported-format","export","agent-identity"],"backgroundTag":"unsupported-export-format","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"}