{"record":{"id":"0def71142e40f70a","repo":"mastra-ai/mastra","slug":"failed-to-observe-workflow-stream-response-stat","errorCode":null,"errorMessage":"Failed to observe workflow stream: ${response.statusText}","messagePattern":"Failed to observe workflow stream: (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"client-sdks/client-js/src/resources/run.ts","lineNumber":281,"sourceCode":"   * for await (const event of stream) {\n   *   console.log('Received:', event);\n   * }\n   * ```\n   */\n  async observe(params?: { offset?: number }): Promise<globalThis.ReadableStream<StreamVNextChunkType>> {\n    const searchParams = new URLSearchParams();\n    searchParams.set('runId', this.runId);\n    if (params?.offset !== undefined) {\n      searchParams.set('offset', String(params.offset));\n    }\n\n    const response: Response = await this.request(`/workflows/${this.workflowId}/observe?${searchParams.toString()}`, {\n      method: 'POST',\n      stream: true,\n    });\n\n    if (!response.ok) {\n      throw new Error(`Failed to observe workflow stream: ${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   * Observes workflow stream for a workflow run\n   * @deprecated Use `observe()` instead for better control over replay position\n   * @returns Promise containing the workflow execution results\n   */\n  async observeStream() {\n    return this.observe();\n  }","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/client-sdks/client-js/src/resources/run.ts#L263-L299","documentation":"Thrown by Run.observe() (used by observeStream) when the POST to /workflows/:id/observe returns a non-OK HTTP status. Observation attaches to an existing run's event stream, so failure typically means the run cannot be observed on the server.","triggerScenarios":"Calling run.observeStream() for a run ID that does not exist, has finished and been pruned, or when the server errors while setting up the observation stream (client-sdks/client-js/src/resources/run.ts:281).","commonSituations":"Observing a run after server restart lost in-memory state; wrong workflowId/runId; server 500 during stream setup.","solutions":["Verify the run ID is active or recently completed and the workflowId matches.","Check server logs for the HTTP error detail; statusText alone may be vague.","Re-create/restart the run if its state was lost (e.g. after a dev server reload).","Handle 404 by falling back to fetching run status via non-streaming endpoints."],"exampleFix":"// before\nconst observed = await run.observeStream();\n\n// after\ntry {\n  const observed = await run.observeStream();\n} catch (e) {\n  console.error('Cannot observe run:', e.message);\n  const status = await run.status(); // fallback to polling\n}","handlingStrategy":"try-catch","validationCode":"const runs = await client.getWorkflowRuns(workflowId);\nif (!runs.runs.some(r => r.runId === runId)) throw new Error(`Run ${runId} not found on ${workflowId}`);","typeGuard":"function runExists(runs: { runs: { runId: string }[] }, runId: string): boolean {\n  return runs.runs.some(r => r.runId === runId);\n}","tryCatchPattern":"try {\n  const stream = await run.observeStream();\n} catch (e) {\n  if (/Failed to observe/.test(e.message)) {\n    console.error('Observation rejected:', e.message);\n    const status = await run.status(); // polling fallback\n  } else throw e;\n}","preventionTips":["Only observe runs that exist and are recent","Expect run state loss after dev server reloads","Provide polling fallback for long-running observers","Correlate statusText with server logs"],"tags":["network","streaming","workflow"],"backgroundTag":"http-error-response","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}