different-ai/openwork · error

Invalid cloud provider sync response.

Error message

Invalid cloud provider sync response.

What it means

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).

Source

Thrown at apps/app/src/app/lib/openwork-server.ts:70

  cloudProviderId: string;
  providerId: string;
  name: string;
  /** Machine-readable skip reason, e.g. "missing_credentials". */
  reason: string;
};

export type OpenworkCloudProviderSyncStatus = {
  hasSession: boolean;
  lastRun: { at: string | number; status: OpenworkCloudProviderSyncRun["status"]; message?: string } | null;
  providers: CloudImportedProvider[];
  /** A managed engine reload is still owed: materialized providers are not served yet. */
  reloadPending: boolean;
  /** Den-granted providers the server sync skipped, each with a reason. */
  skippedProviders: OpenworkCloudProviderSyncSkippedProvider[];
};

function parseCloudProviderSyncRun(value: unknown): OpenworkCloudProviderSyncRun {
  if (!value || typeof value !== "object" || !("status" in value)) throw new Error("Invalid cloud provider sync response.");
  const status = value.status;
  if (status !== "applied" && status !== "noop" && status !== "failed" && status !== "no_session") {
    throw new Error("Invalid cloud provider sync status.");
  }
  const message = "message" in value && typeof value.message === "string" ? value.message : undefined;
  return { status, message };
}

function parseCloudImportedProvider(value: unknown): CloudImportedProvider | null {
  if (!value || typeof value !== "object") return null;
  if (
    !("cloudProviderId" in value) || typeof value.cloudProviderId !== "string" ||
    !("providerId" in value) || typeof value.providerId !== "string" ||
    !("sourceProviderId" in value) || typeof value.sourceProviderId !== "string" ||
    !("name" in value) || typeof value.name !== "string" ||
    !("modelIds" in value) || !Array.isArray(value.modelIds) || !value.modelIds.every((item) => typeof item === "string")
  ) return null;
  return {

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Log the raw response body and status code before parsing to see what was actually returned.
  2. Confirm the client is pointed at the correct Den server URL and is authenticated.
  3. Check the server API version for schema changes to the sync run response and update the parser/contract.

Example fix

// before: silent parse failure
const run = parseCloudProviderSyncRun(await res.json());
// after: validate content-type/status first
if (!res.ok) throw new Error(`Provider sync failed: ${res.status} ${await res.text()}`);
const run = parseCloudProviderSyncRun(await res.json());
Defensive patterns

Strategy: type-guard

Validate before calling

const body = await res.json();
const isSyncRun = (v: unknown): v is { status: string } =>
  !!v && typeof v === "object" && "status" in v && typeof (v as { status: unknown }).status === "string";
if (!isSyncRun(body)) throw new Error(`Unexpected provider sync payload: ${JSON.stringify(body).slice(0, 200)}`);

Type guard

function isSyncRunPayload(v: unknown): v is { status: unknown; message?: unknown } {
  return typeof v === "object" && v !== null && "status" in v;
}

Try / catch

try {
  const run = await client.cloud.providerSync.run();
} catch (err) {
  if (err instanceof Error && err.message.includes("Invalid cloud provider sync response")) {
    // payload shape wrong: re-check auth and base URL, log body
    await reauthenticateIfExpired();
  } else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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`.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/33d197b9acb9c16c. Report an issue: GitHub.