{"record":{"id":"33d197b9acb9c16c","repo":"different-ai/openwork","slug":"invalid-cloud-provider-sync-response","errorCode":null,"errorMessage":"Invalid cloud provider sync response.","messagePattern":"Invalid cloud provider sync response\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/app/src/app/lib/openwork-server.ts","lineNumber":70,"sourceCode":"  cloudProviderId: string;\n  providerId: string;\n  name: string;\n  /** Machine-readable skip reason, e.g. \"missing_credentials\". */\n  reason: string;\n};\n\nexport type OpenworkCloudProviderSyncStatus = {\n  hasSession: boolean;\n  lastRun: { at: string | number; status: OpenworkCloudProviderSyncRun[\"status\"]; message?: string } | null;\n  providers: CloudImportedProvider[];\n  /** A managed engine reload is still owed: materialized providers are not served yet. */\n  reloadPending: boolean;\n  /** Den-granted providers the server sync skipped, each with a reason. */\n  skippedProviders: OpenworkCloudProviderSyncSkippedProvider[];\n};\n\nfunction parseCloudProviderSyncRun(value: unknown): OpenworkCloudProviderSyncRun {\n  if (!value || typeof value !== \"object\" || !(\"status\" in value)) throw new Error(\"Invalid cloud provider sync response.\");\n  const status = value.status;\n  if (status !== \"applied\" && status !== \"noop\" && status !== \"failed\" && status !== \"no_session\") {\n    throw new Error(\"Invalid cloud provider sync status.\");\n  }\n  const message = \"message\" in value && typeof value.message === \"string\" ? value.message : undefined;\n  return { status, message };\n}\n\nfunction parseCloudImportedProvider(value: unknown): CloudImportedProvider | null {\n  if (!value || typeof value !== \"object\") return null;\n  if (\n    !(\"cloudProviderId\" in value) || typeof value.cloudProviderId !== \"string\" ||\n    !(\"providerId\" in value) || typeof value.providerId !== \"string\" ||\n    !(\"sourceProviderId\" in value) || typeof value.sourceProviderId !== \"string\" ||\n    !(\"name\" in value) || typeof value.name !== \"string\" ||\n    !(\"modelIds\" in value) || !Array.isArray(value.modelIds) || !value.modelIds.every((item) => typeof item === \"string\")\n  ) return null;\n  return {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/app/lib/openwork-server.ts#L52-L88","documentation":"parseCloudProviderSyncRun validates the body of a cloud provider sync run response from the OpenWork Den server. Any body that is not an object or lacks a `status` field is rejected with this error, since the status discriminates the union of possible outcomes (applied/noop/failed/no_session).","triggerScenarios":"Calling the provider sync run endpoint on createOpenworkServerClient and the response body is null, an HTML/error page, a JSON array, or valid JSON missing `status` — e.g. auth failure returning a different payload shape.","commonSituations":"Hitting a proxy or captive portal that returns HTML with 200, wrong base URL pointing at a non-Den service, server version returning an older/newer schema, expired auth producing an error body without `status`.","solutions":["Log the raw response body and status code before parsing to see what was actually returned.","Confirm the client is pointed at the correct Den server URL and is authenticated.","Check the server API version for schema changes to the sync run response and update the parser/contract."],"exampleFix":"// before: silent parse failure\nconst run = parseCloudProviderSyncRun(await res.json());\n// after: validate content-type/status first\nif (!res.ok) throw new Error(`Provider sync failed: ${res.status} ${await res.text()}`);\nconst run = parseCloudProviderSyncRun(await res.json());","handlingStrategy":"type-guard","validationCode":"const body = await res.json();\nconst isSyncRun = (v: unknown): v is { status: string } =>\n  !!v && typeof v === \"object\" && \"status\" in v && typeof (v as { status: unknown }).status === \"string\";\nif (!isSyncRun(body)) throw new Error(`Unexpected provider sync payload: ${JSON.stringify(body).slice(0, 200)}`);","typeGuard":"function isSyncRunPayload(v: unknown): v is { status: unknown; message?: unknown } {\n  return typeof v === \"object\" && v !== null && \"status\" in v;\n}","tryCatchPattern":"try {\n  const run = await client.cloud.providerSync.run();\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"Invalid cloud provider sync response\")) {\n    // payload shape wrong: re-check auth and base URL, log body\n    await reauthenticateIfExpired();\n  } else throw err;\n}","preventionTips":["Check res.ok and content-type is application/json before parsing.","Re-authenticate when an error body arrives with HTTP 200.","Keep client parser contracts in sync with the Den server API version.","Log raw bodies on parse failure for postmortems."],"tags":["validation","api-response","cloud","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}