{"record":{"id":"ea3e09792a5c3fa1","repo":"jlcodes99/cockpit-tools","slug":"provider-not-found","errorCode":"PROVIDER_NOT_FOUND","errorMessage":"PROVIDER_NOT_FOUND","messagePattern":"PROVIDER_NOT_FOUND","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/services/codexModelProviderService.ts","lineNumber":654,"sourceCode":"    sourceTag?: string | null;\n    modelCatalog?: string[] | null;\n    modelContextWindows?: Record<string, number> | null;\n    supportsVision?: boolean;\n    modelCapabilities?: Record<string, { supportsVision?: boolean }> | null;\n    visionRoutingModel?: string | null;\n    boundInstanceId?: string | null;\n    website?: string;\n    apiKeyUrl?: string;\n    wireApi?: CodexProviderWireApi | null;\n    supportsWebsockets?: boolean;\n    enableModePreference?: CodexProviderEnableModePreference | null;\n    integrationType?: 'sub2api' | 'new_api' | null;\n    boundOauthAccountId?: string | null;\n  },\n): Promise<CodexModelProvider> {\n  const providers = await ensureProvidersLoaded();\n  const provider = providers.find((item) => item.id === providerId);\n  if (!provider) throw new Error('PROVIDER_NOT_FOUND');\n\n  const nextName = patch.name === undefined ? provider.name : sanitizeName(patch.name);\n  const nextBaseUrl =\n    patch.baseUrl === undefined\n      ? provider.baseUrl\n      : normalizeBaseUrlForStore(patch.baseUrl);\n  const normalizedBaseUrl = normalizeCodexModelProviderBaseUrl(nextBaseUrl);\n  if (!nextName) throw new Error('PROVIDER_NAME_REQUIRED');\n  if (!normalizedBaseUrl) throw new Error('PROVIDER_BASE_URL_INVALID');\n\n  const duplicated = providers.find(\n    (item) =>\n      item.id !== providerId &&\n      normalizeCodexModelProviderBaseUrl(item.baseUrl) === normalizedBaseUrl,\n  );\n  if (duplicated) throw new Error('PROVIDER_BASE_URL_EXISTS');\n\n  provider.name = nextName;","sourceCodeStart":636,"sourceCodeEnd":672,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/services/codexModelProviderService.ts#L636-L672","documentation":"updateCodexModelProvider looks up the provider by providerId in the loaded provider store and throws PROVIDER_NOT_FOUND when no record matches. This means the id passed in does not reference any persisted Codex model provider. It is a lookup failure on a stale or wrong identifier, thrown before any patch fields are applied.","triggerScenarios":"Calling updateCodexModelProvider(providerId, patch) with an id that is not in the store: a deleted provider, a fabricated/typo'd id, an id from a different store file, or a caller (e.g. saveCodexModelProviderDetectedIntegrationType, handleProviderOauthBindingChange) holding a reference captured before the provider was removed.","commonSituations":"UI kept a provider selected after it was deleted in another window; automated scripts caching provider ids across store resets; passing an apiKey id or OAuth account id where a provider id is expected; environment with a fresh/empty providers store after reinstall.","solutions":["Enumerate providers (e.g. listCodexModelProviders) and confirm the providerId exists before updating; use the fresh id from that list.","Re-fetch the provider by name or baseUrl instead of relying on a cached id, then update using the returned id.","If the provider was intentionally deleted, skip the update or recreate the provider first with createCodexModelProvider.","Catch the error, check for 'PROVIDER_NOT_FOUND' in message, and refresh the UI provider list."],"exampleFix":"// before: stale id\nawait updateCodexModelProvider(staleId, { name: 'new-name' });\n// after: resolve a live id first\nconst providers = await listCodexModelProviders();\nconst target = providers.find((p) => p.id === staleId);\nif (!target) throw new Error('Provider no longer exists; refresh the list');\nawait updateCodexModelProvider(target.id, { name: 'new-name' });","handlingStrategy":"validation","validationCode":"const providers = await listCodexModelProviders();\nconst provider = providers.find((p) => p.id === providerId);\nif (!provider) throw new Error(`Provider ${providerId} not found; refresh and retry`);","typeGuard":"function providerExists(providers: { id: string }[], providerId: string): providers is [{ id: string }, ...{ id: string }[]] {\n  return providers.some((p) => p.id === providerId);\n}","tryCatchPattern":"try {\n  await updateCodexModelProvider(providerId, patch);\n} catch (e) {\n  if ((e as Error).message === 'PROVIDER_NOT_FOUND') {\n    await refreshProviderList(); // resync UI state\n  } else throw e;\n}","preventionTips":["Never cache provider ids across store resets or sessions; resolve by name/baseUrl when possible.","Refresh the provider list after any delete, including deletes from other windows.","Distinguish provider ids from apiKey ids / OAuth account ids in your types.","Handle deletes gracefully so UI actions on removed providers become no-ops."],"tags":["lookup","not-found","stale-reference"],"backgroundTag":"resource-not-found","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"}