different-ai/openwork · error

Organization context response was incomplete.

Error message

Organization context response was incomplete.

What it means

loadOrgContext throws this when the response is ok (HTTP 200) but parseOrgContextPayload returns null/falsy — i.e., the server returned a 2xx body that does not match the expected organization-context shape. This is a response-schema/contract mismatch, not an HTTP failure.

Source

Thrown at ee/apps/den-web/app/(den)/dashboard/_providers/org-dashboard-provider.tsx:191

  async function loadOrgContext(organizationId: string, refreshRoles: boolean) {
    const path = refreshRoles ? "/v1/org?refreshRoles=true" : "/v1/org";
    const { response, payload } = await requestJson(
      path,
      { method: "GET", headers: { [ORG_SCOPE_HEADER]: organizationId } },
      12000,
    );
    if (!response.ok) {
      if (response.status === 404) {
        throw new OrganizationNotFoundError(getErrorMessage(payload, `Failed to load organization (${response.status}).`));
      }

      throw new Error(getErrorMessage(payload, `Failed to load organization (${response.status}).`));
    }

    const parsed = parseOrgContextPayload(payload);
    if (!parsed) {
      throw new Error("Organization context response was incomplete.");
    }

    return parsed;
  }

  async function restoreDisplayedOrganization() {
    const displayedOrgId = orgContext?.organization.id;
    if (!displayedOrgId) {
      return;
    }

    setRequestOrgScope(displayedOrgId);
    await setActiveOrganization({ organizationId: displayedOrgId });
    setOrgDirectory((current) => current.map((entry) => ({ ...entry, isActive: entry.id === displayedOrgId })));
  }

  async function refreshOrgData() {
    if (!user) {

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Log the raw payload at parse time to see what the 200 body actually contains.
  2. Align den-web and den-api versions — deploy both together so the /v1/org schema matches parseOrgContextPayload.
  3. Check the reverse proxy for body-rewriting rules, auth redirects converted to 200, or HTML error pages.
  4. Make parseOrgContextPayload validate with Zod (or similar) so the failure pinpoints the missing field.
  5. Retry once before throwing; transient truncation via proxy is a common cause.

Example fix

// before
const parsed = parseOrgContextPayload(payload);
if (!parsed) throw new Error("Organization context response was incomplete.");
// after
const parsed = OrgContextSchema.safeParse(payload);
if (!parsed.success) {
  throw new Error(`Organization context response was incomplete: ${parsed.error.issues.map(i => i.path.join('.')).join(',')}`);
}
Defensive patterns

Strategy: type-guard

Validate before calling

// validate the 200 body before use
const parsed = OrgContextSchema.safeParse(payload);
if (!parsed.success) throw new Error(`Incomplete org context: ${parsed.error.message}`);

Type guard

function isOrgContext(p: unknown): p is { organization: { id: string; slug: string }; role: string } {
  const o = p as { organization?: { id?: unknown; slug?: unknown }; role?: unknown } | null;
  return !!o && typeof o.organization === "object" && typeof o.organization?.id === "string" && typeof o.organization?.slug === "string" && typeof o.role === "string";
}

Try / catch

try {
  await loadOrgContext(orgId, false);
} catch (err) {
  if (String(err.message).startsWith("Organization context response was incomplete")) {
    await refreshOrgData(); // resync rather than crash the dashboard
  } else throw err;
}

Prevention

When it happens

Trigger: den-api deployed with an older/newer /v1/org payload shape than the den-web parser expects; proxy or middleware returning an empty or HTML body with 200 (e.g., a login page injected by a captive portal or misconfigured SSO gateway); truncated responses.

Common situations: Version skew between den-web and den-api after a partial deploy; reverse proxy serving a cached or rewritten 200 response; single-org-mode server returning a minimal payload missing expected fields.

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