{"record":{"id":"97b486fa802f799d","repo":"mastra-ai/mastra","slug":"response-body-is-null-97b486","errorCode":null,"errorMessage":"Response body is null","messagePattern":"Response body is null","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"client-sdks/client-js/src/resources/run.ts","lineNumber":244,"sourceCode":"      method: 'POST',\n      body: {\n        inputData: params.inputData,\n        initialState: params.initialState,\n        requestContext,\n        tracingOptions: params.tracingOptions,\n        resourceId: params.resourceId,\n        perStep: params.perStep,\n        closeOnSuspend: params.closeOnSuspend,\n      },\n      stream: true,\n    });\n\n    if (!response.ok) {\n      throw new Error(`Failed to stream workflow: ${response.statusText}`);\n    }\n\n    if (!response.body) {\n      throw new Error('Response body is null');\n    }\n\n    // Pipe the response body through the transform stream\n    return response.body.pipeThrough(this.createChunkTransformStream());\n  }\n\n  /**\n   * Observe (reconnect to) an existing workflow stream.\n   * Use this to resume receiving events after a disconnection.\n   *\n   * @param params.offset - Optional position to resume from (0-based). If omitted, replays all events.\n   * @returns Promise containing a ReadableStream of workflow events\n   *\n   * @example\n   * ```typescript\n   * // Reconnect to a workflow stream from a specific position\n   * const stream = await run.observe({ offset: 42 });\n   *","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/client-sdks/client-js/src/resources/run.ts#L226-L262","documentation":"Thrown by Run.stream() when the workflow stream request succeeded (response.ok) but response.body is null, so there is no readable stream to pipe through the chunk transform. Indicates an empty or body-less response despite a success status.","triggerScenarios":"run.stream() returning 200 but with no body — proxies stripping the SSE payload, server aborting after headers, or a fetch implementation (mock/polyfill) without body support (client-sdks/client-js/src/resources/run.ts:244).","commonSituations":"Gateway buffering/terminating SSE connections; undici/fetch polyfills in unit tests; server killed mid-response.","solutions":["Disable response buffering for streaming endpoints on proxies/gateways.","Confirm server actually emits SSE data for the workflow run (curl -N).","Use a spec-compliant fetch (Node 18+ native fetch) in your environment/tests.","Retry the stream request if transient."],"exampleFix":"// before\nconst stream = await run.stream({ inputData });\nfor await (const chunk of stream) { ... }\n\n// after\ntry {\n  const stream = await run.stream({ inputData });\n  for await (const chunk of stream) { ... }\n} catch (e) {\n  if (e.message.includes('Response body is null')) console.error('Empty stream — check proxy/SSE config');\n  else throw e;\n}","handlingStrategy":"fallback","validationCode":"// before streaming, confirm infra supports SSE\nconst res = await fetch(`${baseUrl}/health`);\nif (!res.body) throw new Error('Fetch runtime does not expose response.body');","typeGuard":"function hasStreamBody(res: Response): res is Response & { body: ReadableStream } { return res.body !== null; }","tryCatchPattern":"try {\n  const stream = await run.stream({ inputData });\n  for await (const chunk of stream) handle(chunk);\n} catch (e) {\n  if (/Response body is null/.test(e.message)) {\n    await pollRunStatus(run); // fallback path\n  } else throw e;\n}","preventionTips":["Disable SSE buffering on proxies/load balancers","Test streaming paths with real HTTP, not body-less mocks","Use Node 18+ native fetch","Implement polling fallback for critical workflow monitoring"],"tags":["network","streaming","workflow"],"backgroundTag":"empty-response-body","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}