{"record":{"id":"fbb848d7403ea151","repo":"mastra-ai/mastra","slug":"no-response-body-for-agent-controller-session-stre","errorCode":null,"errorMessage":"No response body for agent controller session stream","messagePattern":"No response body for agent controller session stream","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client-sdks/client-js/src/resources/agent-controller.ts","lineNumber":383,"sourceCode":"      if (reconnectTimer) {\n        clearTimeout(reconnectTimer);\n        reconnectTimer = undefined;\n      }\n      const resolve = delayResolve;\n      delayResolve = undefined;\n      resolve?.();\n    };\n\n    const delay = (ms: number) =>\n      new Promise<void>(resolve => {\n        delayResolve = resolve;\n        reconnectTimer = setTimeout(settleDelay, ms);\n      });\n\n    const requestStream = async (): Promise<Response> => {\n      const response = (await this.request(this.url(`${this.base()}/stream`), { stream: true })) as Response;\n      if (!response.body) {\n        throw new Error('No response body for agent controller session stream');\n      }\n      return response;\n    };\n\n    const streamEndedError = () => new Error('Agent controller session stream ended unexpectedly');\n\n    const findFrameSeparator = (text: string): { index: number; length: number } | null => {\n      const candidates = [\n        { index: text.indexOf('\\r\\n\\r\\n'), length: 4 },\n        { index: text.indexOf('\\n\\n'), length: 2 },\n        { index: text.indexOf('\\r\\r'), length: 2 },\n      ].filter(candidate => candidate.index !== -1);\n      if (candidates.length === 0) return null;\n      return candidates.reduce((earliest, candidate) => (candidate.index < earliest.index ? candidate : earliest));\n    };\n\n    type PumpResult =\n      | { kind: 'done' }","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/client-sdks/client-js/src/resources/agent-controller.ts#L365-L401","documentation":"In agent-controller.ts requestStream(), the client POSTs to the agent controller session /stream endpoint with stream:true and throws 'No response body for agent controller session stream' when response.body is missing, because the caller needs a ReadableStream to process the session stream. It is invoked by firstResponse and run, and the surrounding code also sets up reconnect handling for dropped streams.","triggerScenarios":"GET/POST to {base}/stream returns ok but no body: fetch mocks, buffering proxies, runtimes lacking streaming body support, or server error responses swallowed into a bodyless response.","commonSituations":"Testing the agent controller with mocked fetch lacking a body; reverse proxies or serverless platforms that don't pass through SSE/chunked streams; Node/runtime fetch polyfills without ReadableStream response bodies.","solutions":["Confirm the server streams the session endpoint (curl -N).","Fix fetch mocks to include a ReadableStream body with the expected encoded chunks.","Use a runtime with native streaming fetch support; avoid polyfills for this code path.","Check intermediary proxies/load balancers are not buffering or emptying streaming responses.","Rely on the existing reconnect logic: catch the error and let the controller retry the stream."],"exampleFix":"// before\nconst res = await fetch(url, { method: 'POST' }); // mock without body\n// after\nconst res = new Response(new ReadableStream({ start(c) { c.enqueue(encoder.encode('data: {...}\\n\\n')); c.close(); } }), { status: 200 });","handlingStrategy":"try-catch","validationCode":"const probe = await fetch(`${base}/stream`, { method: 'POST' });\nif (probe.ok && !probe.body) throw new Error('Controller /stream returns no body in this environment');","typeGuard":"function hasBody(res: Response): res is Response & { body: ReadableStream<Uint8Array> } { return res.body != null; }","tryCatchPattern":"try {\n  await controller.run(params);\n} catch (err) {\n  if ((err as Error).message.startsWith('No response body for agent controller session stream')) {\n    console.error('Session stream had no body; relying on controller reconnect');\n  }\n  throw err;\n}","preventionTips":["Test the session stream endpoint outside the app (curl -N)","Ensure infrastructure passes through streaming responses","Upgrade to runtimes with native streaming fetch","Keep reconnect/backoff logic enabled for stream drops"],"tags":["streaming","null","http","agent-controller"],"backgroundTag":"null-response-body","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}