{"record":{"id":"742d11e1c371cda6","repo":"moeru-ai/airi","slug":"failed-to-update-provider-config","errorCode":null,"errorMessage":"Failed to update provider config","messagePattern":"Failed to update provider config","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/stage-ui/src/services/inference-service-providers.ts","lineNumber":198,"sourceCode":"\n  async function patchConfigRemote(\n    client: InferenceServiceProvidersRemoteClient,\n    providerId: string,\n    config: Record<string, unknown>,\n    status: ProviderValidationStatus,\n    options?: InferenceServiceProviderServiceOptions,\n  ): Promise<InferenceServiceProvider> {\n    options?.abortSignal?.throwIfAborted()\n    const res = await client.api.v1.providers[':id'].$patch({\n      param: { id: providerId },\n      json: {\n        config,\n        validated: status === 'configured',\n        validationBypassed: status === 'bypassed',\n      },\n    }, requestOptions(options))\n    if (!res.ok)\n      throw new Error('Failed to update provider config')\n\n    const item = await res.json()\n    options?.abortSignal?.throwIfAborted()\n    return normalize(item)\n  }\n\n  return {\n    buildLocal,\n    fetchRemote,\n    createRemote,\n    deleteRemote,\n    patchConfigRemote,\n  }\n}\n\nexport const inferenceServiceProvidersService = createInferenceServiceProvidersService()\n","sourceCodeStart":180,"sourceCodeEnd":215,"githubUrl":"https://github.com/moeru-ai/airi/blob/0616eabd5ba89c7bcef0eb1da84694b9c285c573/packages/stage-ui/src/services/inference-service-providers.ts#L180-L215","documentation":"Thrown by patchConfigRemote when PATCH /api/v1/providers/:id returns non-2xx. The body sends the new config plus validated/validationBypassed derived from the requested status, and the server re-validates: unknown provider id, schema-invalid config, or a validated request whose config cannot be validated all fail here. The res.ok check hides the concrete status.","triggerScenarios":"Patching config for a provider id that was deleted server-side (404); submitting config that fails server-side schema validation; marking status 'configured' (validated: true) while the config lacks working credentials so server-side validation rejects; auth expired (401).","commonSituations":"Editing a provider in settings while it is removed in another window; version skew where the server expects different config keys; pasting a truncated API key that fails validation.","solutions":["Check the HTTP status and response body for the validation message.","Refetch providers and confirm the id still exists before patching.","Fix the config payload to satisfy the provider definition's schema (correct keys, complete credentials).","If validation cannot pass yet, save with 'bypassed' status instead of 'configured'.","Re-authenticate if 401/403."],"exampleFix":"// before\nawait providersService.patchConfigRemote(client, providerId, newConfig, 'configured')\n\n// after - validate before sending and bypass when credentials are incomplete\nconst definition = getDefinedProvider(provider.definitionId)\nif (!definition)\n  throw new Error('Unknown provider definition')\n\nconst status = credentialsComplete(newConfig) ? 'configured' : 'bypassed'\nawait providersService.patchConfigRemote(client, providerId, newConfig, status)","handlingStrategy":"validation","validationCode":"import { getDefinedProvider } from '../libs/providers/providers'\n\nconst definition = getDefinedProvider(provider.definitionId)\nif (!definition)\n  throw new Error('Unknown provider definition')\n// only claim 'configured' when the config is complete; otherwise 'bypassed'\nconst status = isConfigComplete(definition, nextConfig) ? 'configured' : 'bypassed'\nawait providersService.patchConfigRemote(client, providerId, nextConfig, status, { abortSignal })","typeGuard":null,"tryCatchPattern":"try {\n  const updated = await providersService.patchConfigRemote(client, providerId, config, status, { abortSignal })\n}\ncatch (error) {\n  // config rejected server-side: keep local state unchanged, show fields to fix\n  toast.error(errorMessageFrom(error) ?? 'Failed to update provider config')\n}","preventionTips":["Validate config against the provider definition's schema client-side before patching.","Refetch providers and confirm the id exists when edits may have raced a deletion.","Map server validation messages onto the specific config fields that failed.","Do not send validated: true for configs that have never passed validation."],"tags":["http","api-client","providers","validation","config"],"backgroundTag":"http-error-status","analyzedSha":"0616eabd5ba89c7bcef0eb1da84694b9c285c573","analyzedAt":"2026-08-18T17:29:58.153Z","contentChangedAt":"2026-08-18T17:29:58.153Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}