{"record":{"id":"0b2631ca7b397128","repo":"different-ai/openwork","slug":"update-mcp-connection-response-was-incomplete","errorCode":null,"errorMessage":"Update MCP connection response was incomplete.","messagePattern":"Update MCP connection response was incomplete\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/mcp-connections-data.tsx","lineNumber":796,"sourceCode":"  const queryClient = useQueryClient();\n  const { orgId, runReauthableAction } = useOrgDashboard();\n\n  return useMutation({\n    mutationFn: async (input: UpdateMcpConnectionInput): Promise<UpdatedMcpConnection> => {\n      let updated: UpdatedMcpConnection | null = null;\n      await runReauthableAction(\"update-mcp-connection\", async () => {\n        const { connectionId, ...body } = input;\n        const { response, payload } = await requestJson(\n          `/v1/mcp-connections/${encodeURIComponent(connectionId)}`,\n          { method: \"PUT\", headers: getOrgScopeHeaders(requireOrgId(orgId)), body: JSON.stringify(body) },\n          30000,\n        );\n        if (!response.ok) {\n          throw getRequestError(payload, response, `Failed to update MCP connection (${response.status}).`);\n        }\n        updated = payload as UpdatedMcpConnection;\n      });\n      if (!updated) throw new Error(\"Update MCP connection response was incomplete.\");\n      return updated;\n    },\n    onSuccess: () => {\n      queryClient.invalidateQueries({ queryKey: mcpConnectionQueryKeys.all });\n    },\n  });\n}\n\nexport function useReviewMcpIssuer() {\n  const queryClient = useQueryClient();\n  const { orgId, runReauthableAction } = useOrgDashboard();\n\n  return useMutation({\n    mutationFn: async (input: {\n      connectionId: string;\n      action: \"preview\" | \"confirm\";\n      expectedUpdatedAt?: string;\n      authorizationServerIssuer?: string;","sourceCodeStart":778,"sourceCodeEnd":814,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/mcp-connections-data.tsx#L778-L814","documentation":"The updateMcpConnection mutation in den-web always defines `updated` via a runReauthableAction callback that assigns the parsed response payload. If the callback body completes without assigning (e.g. the mutation helper swallowed the network call or an empty payload path left the variable undefined), this guard throws instead of returning a partially-typed object. It exists so the mutation never returns `null`/`undefined` typed as UpdatedMcpConnection.","triggerScenarios":"mutateAsync on the update MCP connection mutation resolves but `updated` is still undefined: the runReauthableAction callback returned early, the response payload was never assigned (e.g. re-auth flow re-invoked the callback without reaching the assignment), or payload assignment was skipped after a silent auth retry.","commonSituations":"Session token expired mid-mutation so the reauth wrapper retried without re-running the body; a refactored callback introduced a code path that returns before `updated = payload ...`; API returns 2xx with empty body while code expected a JSON object.","solutions":["Log the payload inside the runReauthableAction callback to confirm the server response actually arrived and was assigned","Verify the reauth wrapper (runReauthableAction) actually re-executes the callback on re-auth instead of resolving without it","Check the update endpoint returns a JSON body on success, not 204/empty","Re-test after re-signing-in to rule out a stale-token retry path"],"exampleFix":"// before\nupdated = payload as UpdatedMcpConnection;\n});\nif (!updated) throw new Error(\"Update MCP connection response was incomplete.\");\n// after\nupdated = payload as UpdatedMcpConnection;\n});\nif (!updated) {\n  throw new Error(`Update MCP connection ${connectionId} returned no payload (status ${response.status}).`);\n}","handlingStrategy":"try-catch","validationCode":"const canUpdate = typeof connectionId === 'string' && connectionId.length > 0 && typeof patch === 'object';","typeGuard":"function isUpdatedMcpConnection(v: unknown): v is UpdatedMcpConnection {\n  return isRecord(v) && typeof (v as Record<string, unknown>).id === 'string';\n}","tryCatchPattern":"try {\n  await updateConnection.mutateAsync({ connectionId, patch });\n} catch (e) {\n  showToast({ variant: 'error', title: 'Could not update connection', description: e instanceof Error ? e.message : String(e) });\n}","preventionTips":["Validate connectionId and patch before mutating","Keep the reauth wrapper's contract: run callback once and throw on dismissed re-auth","Assert the update endpoint returns a JSON body on 2xx in an API test"],"tags":["react-query","mutation","api-response","null-guard"],"backgroundTag":"empty-api-response","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}