different-ai/openwork · error

The snapshot response was invalid.

Error message

The snapshot response was invalid.

What it means

useWorkflowSnapshots GETs /v1/workflows/{id}/snapshots?limit=100 and requires the payload to be an object whose 'items' is an array; otherwise it throws 'The snapshot response was invalid.' Each item is then validated with workflowArtifactSnapshotSchema.parse.

Source

Thrown at ee/apps/den-web/app/(den)/dashboard/_components/workflow-data.tsx:59

      );
      if (typeof payload !== "object" || payload === null || !("script" in payload)) throw new Error("The Workflow response was invalid.");
      return workflowDetailSchema.parse(payload.script);
    },
    enabled: Boolean(configObjectId),
  });
}

export function useWorkflowSnapshots(configObjectId: string) {
  return useQuery({
    queryKey: keys.snapshots(configObjectId),
    queryFn: async () => {
      const payload = await checkedRequest(
        `/v1/workflows/${encodeURIComponent(configObjectId)}/snapshots?limit=100`,
        { method: "GET" },
        "Failed to load snapshots",
      );
      if (typeof payload !== "object" || payload === null || !("items" in payload) || !Array.isArray(payload.items)) {
        throw new Error("The snapshot response was invalid.");
      }
      return payload.items.map((item) => workflowArtifactSnapshotSchema.parse(item));
    },
    enabled: Boolean(configObjectId),
  });
}

function useLifecycleMutation<TInput, TResult>(input: {
  configObjectId: string;
  mutation: (value: TInput) => Promise<TResult>;
}) {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: input.mutation,
    onSettled: async () => {
      await queryClient.invalidateQueries({ queryKey: ["workflow", input.configObjectId] });
      await queryClient.invalidateQueries({ queryKey: ["plugins"] });
      await queryClient.invalidateQueries({ queryKey: ["automations"] });

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Log the response body to see the actual shape vs expected {items: []}.
  2. Update the client check/parser to match the current API contract, or fix the server to return {items: [...]}.
  3. Verify the workflow id exists (a 404 leaking as a 200-shaped body indicates proxy interference).
  4. If Zod throws on individual items after this check, the items shape changed — update workflowArtifactSnapshotSchema.

Example fix

// before
if (typeof payload !== "object" || payload === null || !("items" in payload) || !Array.isArray(payload.items)) {
  throw new Error("The snapshot response was invalid.");
}
// after
const items = (payload as {items?: unknown} | null)?.items;
if (!Array.isArray(items)) {
  console.error("snapshots payload:", payload);
  throw new Error("The snapshot response was invalid.");
}
return items.map((item) => workflowArtifactSnapshotSchema.parse(item));
Defensive patterns

Strategy: type-guard

Validate before calling

function hasItemsArray(v: unknown): v is { items: unknown[] } {
  return isRecord(v) && Array.isArray(v.items);
}

Type guard

function isSnapshotList(v: unknown): v is { items: WorkflowArtifactSnapshot[] } {
  return isRecord(v) && Array.isArray(v.items) && v.items.every((i) => isRecord(i) && typeof i.id === "string");
}

Try / catch

try {
  const snapshots = await snapshotsQuery.refetch();
} catch (e) {
  if (e instanceof Error && e.message === "The snapshot response was invalid.") {
    console.error("snapshots body shape mismatch");
    // render empty state and log payload for contract debugging
  } else throw e;
}

Prevention

When it happens

Trigger: Snapshots endpoint returns ok but body lacks an items array (e.g. {error: ...} with 200, null body, or items as an object), so the Array.isArray check fails.

Common situations: API contract change renaming/relocating items; gateway returning an empty JSON body on 200; workflow id valid but snapshots feature disabled server-side returning a bare object.

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/bf4eb49be1a3e945. Report an issue: GitHub.