mastra-ai/mastra · error · MastraError

AGENT_GENERATE_UNKNOWN_ERROR

AGENT_GENERATE_UNKNOWN_ERROR

Error message

An unknown error occurred while streaming

What it means

This is the fall-through case in Agent.generate(): #execute() returned a result whose status is neither 'success' nor 'failed' (an unexpected status), so Mastra throws a generic AGENT_GENERATE_UNKNOWN_ERROR because there is no original error to attach.

Source

Thrown at packages/core/src/agent/agent.ts:8045

      // Use agent's maxProcessorRetries as default, allow options to override
      maxProcessorRetries: mergedOptions.maxProcessorRetries ?? this.#maxProcessorRetries,
    } as unknown as InnerAgentExecutionOptions<any> & { _threadStreamPubSub?: PubSub };

    const result = await this.#execute(executeOptions);

    if (result.status !== 'success') {
      if (result.status === 'failed') {
        throw new MastraError(
          {
            id: 'AGENT_GENERATE_FAILED',
            domain: ErrorDomain.AGENT,
            category: ErrorCategory.USER,
          },
          // pass original error to preserve stack trace
          result.error,
        );
      }
      throw new MastraError({
        id: 'AGENT_GENERATE_UNKNOWN_ERROR',
        domain: ErrorDomain.AGENT,
        category: ErrorCategory.USER,
        text: 'An unknown error occurred while streaming',
      });
    }

    if (typeof result.result?.getFullOutput !== 'function') {
      throw new MastraError({
        id: 'AGENT_GENERATE_MALFORMED_RESULT',
        domain: ErrorDomain.AGENT,
        category: ErrorCategory.SYSTEM,
        text: 'Execution workflow produced a result without getFullOutput',
      });
    }

    const fullOutput = await result.result.getFullOutput();

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Update @mastra/core to the latest patch version — this indicates an unhandled internal status.
  2. Log the full result object just before the call (or enable debug logging) to capture the actual status.
  3. Report the issue with reproduction steps if it persists, including middleware/processor configuration.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await agent.generate(prompt);
} catch (e) {
  if (e instanceof MastraError && e.id === 'AGENT_GENERATE_UNKNOWN_ERROR') {
    logger.error('Unknown generate status — report bug with repro', { e });
  }
  throw e;
}

Prevention

When it happens

Trigger: agent.generate() where the internal execution result.status is an unrecognized value (not 'success' and not 'failed') — e.g. internal state machine produced 'suspended'/'aborted'-like status in a context where it shouldn't occur.

Common situations: Version drift between @mastra/core internals; workflow execution ending in an unexpected terminal state; bugs in custom middlewares/processors that short-circuit execution.

Related errors


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