mastra-ai/mastra · error · HTTPException

Failed to create observe stream

Error message

Failed to create observe stream

What it means

Thrown with HTTP 500 when `_run.observeStreamLegacy()` returns an object without a `stream`. The internal legacy observe stream could not be created for the run, so the route cannot combine cached history with a live stream.

Source

Thrown at packages/server/src/server/handlers/workflows.ts:1436

      if (!run) {
        throw new HTTPException(404, { message: 'Workflow run not found' });
      }

      await validateRunOwnership(run, effectiveResourceId);

      const _run = await workflow.createRun({ runId, resourceId: run.resourceId });
      const serverCache = mastra.getServerCache();
      if (!serverCache) {
        throw new HTTPException(500, { message: 'Server cache not found' });
      }

      // Get cached chunks and create replay stream
      const cachedRunChunks = (await serverCache.listFromTo(runId, 0)) as StreamEvent[];
      const result = _run.observeStreamLegacy();

      if (!result.stream) {
        throw new HTTPException(500, { message: 'Failed to create observe stream' });
      }

      return createReplayStream<StreamEvent>({
        history: cachedRunChunks,
        liveSource: result.stream,
      });
    } catch (error) {
      return handleError(error, 'Error observing workflow stream');
    }
  },
});

// ============================================================================
// Worker Step Execution Endpoint
// Used by standalone OrchestrationWorker instances with HttpRemoteStrategy.
// ============================================================================

// `workflowId` and `runId` are taken from path params (single source of

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Align @mastra/core, @mastra/server, and client package versions (same release line) and reinstall
  2. Retry the observation; if persistent, use the current stream endpoint instead of the legacy one
  3. Capture server logs and file an issue with the run state if the stream is consistently missing

Example fix

// before
"@mastra/core": "^0.10.0", "@mastra/server": "^0.11.0"
// after
"@mastra/core": "0.11.2", "@mastra/server": "0.11.2"
Defensive patterns

Strategy: retry

Validate before calling

const obs = run.observeStreamLegacy?.(); if (!obs?.stream) throw new Error('observeStreamLegacy returned no stream');

Type guard

const hasStream = (r: unknown): r is { stream: ReadableStream } => !!r && 'stream' in (r as any) && (r as any).stream != null;

Try / catch

try { await observe(workflowId, runId); } catch (e) { if (isHttpException(e, 500) && /observe stream/i.test(e.message)) await retryWithBackoff(() => observe(workflowId, runId), 2); else throw e; }

Prevention

When it happens

Trigger: Calling observeStreamLegacy on a run whose runtime state does not support legacy observation; internal/core version mismatch between @mastra/server and @mastra/core causing the API to behave unexpectedly.

Common situations: Mixed versions of @mastra/core and @mastra/server in a monorepo or lockfile drift; observing runs created by a much older/newer core version; unusual run states after cancellation or failure.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/4bd6b4713409994e. Report an issue: GitHub.