{"record":{"id":"a500b055cba608cd","repo":"mastra-ai/mastra","slug":"failed-to-stream-background-tasks-response-stat","errorCode":null,"errorMessage":"Failed to stream background tasks: ${response.statusText}","messagePattern":"Failed to stream background tasks: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client-sdks/client-js/src/client.ts","lineNumber":2354,"sourceCode":"    return this.request(`/background-tasks/${encodeURIComponent(backgroundTaskId)}`);\n  }\n\n  /**\n   * Opens an SSE stream of background task events (completed/failed).\n   * Returns a Response that can be consumed as a ReadableStream.\n   */\n  public async streamBackgroundTasks(params: StreamBackgroundTasksParams = {}) {\n    const searchParams = new URLSearchParams();\n    if (params.agentId) searchParams.set('agentId', params.agentId);\n    if (params.runId) searchParams.set('runId', params.runId);\n    if (params.threadId) searchParams.set('threadId', params.threadId);\n    if (params.resourceId) searchParams.set('resourceId', params.resourceId);\n    if (params.taskId) searchParams.set('taskId', params.taskId);\n    const qs = searchParams.toString();\n    const response: Response = await this.request(`/background-tasks/stream${qs ? `?${qs}` : ''}`, { stream: true });\n\n    if (!response.ok) {\n      throw new Error(`Failed to stream background tasks: ${response.statusText}`);\n    }\n\n    if (!response.body) {\n      throw new Error('Response body is null');\n    }\n\n    return response.body.pipeThrough(createSseJsonTransform());\n  }\n\n  /**\n   * Lists schedules — agent schedules and workflow schedules — with optional\n   * filtering by agentId, workflowId, or status. Agent schedules can\n   * additionally be filtered by threadId, resourceId, or name.\n   */\n  public listSchedules(params: ListSchedulesParams = {}): Promise<ListSchedulesResponse> {\n    const searchParams = new URLSearchParams();\n    if (params.agentId) searchParams.set('agentId', params.agentId);\n    if (params.workflowId) searchParams.set('workflowId', params.workflowId);","sourceCodeStart":2336,"sourceCodeEnd":2372,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/client-sdks/client-js/src/client.ts#L2336-L2372","documentation":"MastraClient streams background tasks via GET /background-tasks/stream. When the HTTP response is not ok (e.g. 401, 404, 500), the client throws this error carrying only response.statusText, so the underlying cause is a failed HTTP request to the background-task stream endpoint.","triggerScenarios":"Calling client.streamBackgroundTasks(...) (with optional resourceId/taskId search params) while the server returns a non-2xx status: auth failure, endpoint not available in the deployed server version, or server error opening the SSE stream.","commonSituations":"Mastra server not running or URL misconfigured; auth token expired; older server build without the /background-tasks/stream route (404).","solutions":["Log the full response status and inspect server logs; statusText alone omits the body, so retry with fetch to see the error payload.","Verify the server URL/base path and that the deployed Mastra server supports the background-tasks stream endpoint.","Fix authentication (valid API key/token) if the status is 401/403.","Retry with backoff if the status is 5xx (transient server error)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// precheck availability\nconst res = await fetch(`${baseUrl}/background-tasks/stream`, { method: 'HEAD' });\nif (!res.ok) throw new Error(`Background task streaming unavailable (HTTP ${res.status})`);","typeGuard":null,"tryCatchPattern":"try {\n  const stream = await client.streamBackgroundTasks(params);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Failed to stream background tasks:')) {\n    // inspect HTTP status via server logs or a manual request; handle 401/404/5xx\n  }\n  throw e;\n}","preventionTips":["Verify server URL and auth before opening streams.","Confirm the deployed server version supports /background-tasks/stream.","Retry with backoff on 5xx."],"tags":["network","streaming","http"],"backgroundTag":"http-request-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}