{"record":{"id":"6280e96e9547abfe","repo":"farion1231/cc-switch","slug":"codex-current-login-provider-was-not-created","errorCode":null,"errorMessage":"Codex current-login provider was not created","messagePattern":"Codex current-login provider was not created","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/query/mutations.ts","lineNumber":70,"sourceCode":"          throw new Error(\"Claude Desktop official provider was not created\");\n        }\n        return officialProvider;\n      }\n\n      if (appId === \"codex\" && ensureCodexOfficialSeed) {\n        // The fixed seed is the one native \"Codex current login\" card.\n        // A managed account gets its own provider row so several accounts can\n        // coexist without replacing that native-login entry.\n        const managedAccountId = resolveManagedAccountId(\n          rest.meta,\n          \"codex_oauth\",\n        )?.trim();\n        if (!managedAccountId) {\n          await providersApi.ensureCodexOfficialProvider();\n          const providers = await providersApi.getAll(appId);\n          const nativeLoginProvider = providers[CODEX_OFFICIAL_PROVIDER_ID];\n          if (!nativeLoginProvider) {\n            throw new Error(\"Codex current-login provider was not created\");\n          }\n          return nativeLoginProvider;\n        }\n\n        const managedOfficialProvider: Provider = {\n          ...rest,\n          id: generateUUID(),\n          category: \"official\",\n          createdAt: Date.now(),\n        };\n        await providersApi.add(managedOfficialProvider, appId, addToLive);\n        return managedOfficialProvider;\n      }\n\n      if (appId === \"grokbuild\" && ensureGrokBuildOfficialSeed) {\n        await providersApi.ensureGrokBuildOfficialProvider();\n        const providers = await providersApi.getAll(appId);\n        const officialProvider = providers[GROKBUILD_OFFICIAL_PROVIDER_ID];","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/farion1231/cc-switch/blob/a2e22f330273a5b6ffa87cb8b82b624601bac562/src/lib/query/mutations.ts#L52-L88","documentation":"Thrown inside useAddProviderMutation's mutationFn on the Codex native-login path: when appId is 'codex', ensureCodexOfficialSeed is set, and no managed 'codex_oauth' account id can be resolved, the code calls ensureCodexOfficialProvider() and then expects providers[CODEX_OFFICIAL_PROVIDER_ID] to exist. Its absence means the official seed did not land - an invariant break, not a user-input error.","triggerScenarios":"mutateAsync({ appId: 'codex', providerInput: { ensureCodexOfficialSeed: true, meta without a codex_oauth managed id } }) where the ensure command no-ops or the subsequent getAll is missing the CODEX_OFFICIAL_PROVIDER_ID key.","commonSituations":"Fresh install where the Codex CLI auth/config file is missing so the seed cannot be written; backend version older than the frontend seed constant; race between ensure and the provider list read.","solutions":["Verify the Codex config/auth files the ensure command seeds from actually exist and are readable","Retry the mutation once to rule out a read-after-write race","Log the Object.keys() of getAll('codex') when the invariant fails to see what was actually returned"],"exampleFix":"// before\nawait providersApi.ensureCodexOfficialProvider();\nconst native = (await providersApi.getAll(appId))[CODEX_OFFICIAL_PROVIDER_ID];\nif (!native) throw new Error(\"Codex current-login provider was not created\");\n\n// after\nawait providersApi.ensureCodexOfficialProvider();\nlet native: Provider | undefined;\nfor (let i = 0; i < 3 && !native; i++) {\n  await new Promise((r) => setTimeout(r, 100 * (i + 1)));\n  native = (await providersApi.getAll(appId))[CODEX_OFFICIAL_PROVIDER_ID];\n}\nif (!native) throw new Error(\"Codex current-login provider was not created\");","handlingStrategy":"retry","validationCode":"// Skip the ensure path when the native-login card already exists\nconst existing = (await providersApi.getAll(\"codex\"))[CODEX_OFFICIAL_PROVIDER_ID];\nif (existing) {\n  return existing;\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await addProvider.mutateAsync(input);\n} catch (e) {\n  if (e instanceof Error && e.message === \"Codex current-login provider was not created\") {\n    await queryClient.invalidateQueries({ queryKey: providersKeys.all });\n    return await addProvider.mutateAsync(input); // one retry after cache refresh\n  }\n  throw e;\n}","preventionTips":["Verify the Codex CLI auth/config files exist before first-run seeding","Invalidate and re-read the provider query before declaring the seed failed","Treat this error as a backend invariant break, not a form validation issue"],"tags":["provider","seed","backend","codex","invariant"],"backgroundTag":null,"analyzedSha":"a2e22f330273a5b6ffa87cb8b82b624601bac562","analyzedAt":"2026-08-16T03:46:07.889Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}