{"record":{"id":"32fdfd821c6e162f","repo":"farion1231/cc-switch","slug":"grok-build-official-provider-was-not-created","errorCode":null,"errorMessage":"Grok Build official provider was not created","messagePattern":"Grok Build official provider was not created","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/query/mutations.ts","lineNumber":90,"sourceCode":"          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];\n        if (!officialProvider) {\n          throw new Error(\"Grok Build official provider was not created\");\n        }\n        return officialProvider;\n      }\n\n      let id: string;\n\n      if (\n        appId === \"opencode\" ||\n        appId === \"openclaw\" ||\n        appId === \"hermes\" ||\n        appId === \"pi\"\n      ) {\n        if (\n          providerInput.category === \"omo\" ||\n          providerInput.category === \"omo-slim\"\n        ) {\n          const prefix = providerInput.category === \"omo\" ? \"omo\" : \"omo-slim\";\n          id = `${prefix}-${generateUUID()}`;","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/farion1231/cc-switch/blob/a2e22f330273a5b6ffa87cb8b82b624601bac562/src/lib/query/mutations.ts#L72-L108","documentation":"Thrown inside useAddProviderMutation's mutationFn when appId is 'grokbuild' with ensureGrokBuildOfficialSeed set: ensureGrokBuildOfficialProvider() runs, then providers[GROKBUILD_OFFICIAL_PROVIDER_ID] must exist. Its absence means the Grok Build official seed was not created or not returned - an invariant break, not a user-input error.","triggerScenarios":"mutateAsync({ appId: 'grokbuild', providerInput: { ensureGrokBuildOfficialSeed: true, ... } }) where the ensure command no-ops or getAll('grokbuild') lacks the GROKBUILD_OFFICIAL_PROVIDER_ID key.","commonSituations":"First-run seeding on a fresh data dir; backend not yet supporting the grokbuild seed; race between the ensure write and the provider list read.","solutions":["Check the ensureGrokBuildOfficialProvider backend command logs for a silent early return","Retry the mutation once to clear a transient race","Confirm getAll('grokbuild') contains the GROKBUILD_OFFICIAL_PROVIDER_ID key after a manual ensure"],"exampleFix":"// before\nawait providersApi.ensureGrokBuildOfficialProvider();\nconst official = (await providersApi.getAll(appId))[GROKBUILD_OFFICIAL_PROVIDER_ID];\nif (!official) throw new Error(\"Grok Build official provider was not created\");\n\n// after\nawait providersApi.ensureGrokBuildOfficialProvider();\nlet official: Provider | undefined;\nfor (let i = 0; i < 3 && !official; i++) {\n  await new Promise((r) => setTimeout(r, 100 * (i + 1)));\n  official = (await providersApi.getAll(appId))[GROKBUILD_OFFICIAL_PROVIDER_ID];\n}\nif (!official) throw new Error(\"Grok Build official provider was not created\");","handlingStrategy":"retry","validationCode":"// Skip the ensure path when the official provider already exists\nconst existing = (await providersApi.getAll(\"grokbuild\"))[GROKBUILD_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 === \"Grok Build official 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":["Check for the official provider before invoking the ensure seed path","Log the returned provider map keys when the invariant fails","Confirm the backend build actually supports the grokbuild seed command"],"tags":["provider","seed","backend","grok","invariant"],"backgroundTag":null,"analyzedSha":"a2e22f330273a5b6ffa87cb8b82b624601bac562","analyzedAt":"2026-08-16T03:46:07.889Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}