mastra-ai/mastra · error · MastraError

AGENT_SEND_STREAM_RESUME_MISSING_TARGET

AGENT_SEND_STREAM_RESUME_MISSING_TARGET

Error message

sendStreamResume() requires threadId, resourceId, and runId.

What it means

A synchronous input-validation error from Agent.sendStreamResume(): the call is missing one or more of the required identifiers threadId, resourceId, or runId needed to locate the suspended stream run to resume. It is thrown before any storage lookup occurs.

Source

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

  ): Promise<MastraModelOutput<OUTPUT>> {
    // Route standalone `new Agent({ durable: true })` calls through the
    // durable execution path.
    const durable = await this.#getStandaloneDurable();
    if (durable) {
      return durable.approveToolCall(options) as Promise<MastraModelOutput<OUTPUT>>;
    }

    // @ts-expect-error - the types here are wrong
    return this.resumeStream({ approved: true }, options);
  }

  async sendStreamResume<OUTPUT = undefined>(
    options: SendAgentStreamResumeOptions<OUTPUT>,
  ): Promise<SendAgentStreamResumeResult> {
    const { threadId, resourceId, runId, toolCallId, resumeData, streamOptions } = options;

    if (!threadId || !resourceId || !runId) {
      throw new MastraError({
        id: 'AGENT_SEND_STREAM_RESUME_MISSING_TARGET',
        domain: ErrorDomain.AGENT,
        category: ErrorCategory.USER,
        text: 'sendStreamResume() requires threadId, resourceId, and runId.',
        details: { threadId, resourceId, runId, agentName: this.name },
      });
    }

    const pubsub = this.getPubSub();
    const hasLocalRun = agentThreadStreamRuntime.hasThreadRun(runId, pubsub);
    let resumableRun = agentThreadStreamRuntime.getResumableThreadRun(
      { threadId, resourceId, runId, toolCallId },
      pubsub,
    );

    if (!resumableRun && !hasLocalRun) {
      // The thread runtime only tracks runs seen by this process. Recover the
      // explicitly targeted run from snapshot storage after a restart or when

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Ensure threadId, resourceId, and runId are all provided in the options object
  2. Verify the values are non-empty strings, not undefined from destructuring
  3. Check that runId was captured from the original stream before suspension
  4. Log the options object before the call to identify which field is missing

Example fix

// before
await agent.sendStreamResume({ threadId, resourceId }); // runId missing
// after
if (!runId) throw new Error('runId is required to resume');
await agent.sendStreamResume({ threadId, resourceId, runId, toolCallId, resumeData });
Defensive patterns

Strategy: validation

Validate before calling

function canResume(o: { threadId?: string; resourceId?: string; runId?: string }): boolean {
  return Boolean(o.threadId && o.resourceId && o.runId);
}

Type guard

function isResumeTarget(o: Partial<{ threadId: string; resourceId: string; runId: string }>): o is { threadId: string; resourceId: string; runId: string } {
  return typeof o.threadId === 'string' && o.threadId.length > 0
    && typeof o.resourceId === 'string' && o.resourceId.length > 0
    && typeof o.runId === 'string' && o.runId.length > 0;
}

Try / catch

try {
  await agent.sendStreamResume({ threadId, resourceId, runId });
} catch (e) {
  if (e instanceof MastraError && e.id === 'AGENT_SEND_STREAM_RESUME_MISSING_TARGET') {
    logger.warn('resume aborted: missing identifiers', e.details);
    return; // don't retry; fix the inputs
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling agent.sendStreamResume({ threadId?: ..., resourceId?: ..., runId?: ... }) where any of threadId, resourceId, or runId is undefined/null/empty string.

Common situations: Destructuring resume parameters from a request handler where query/body fields are missing, forgetting to persist runId when the stream was suspended, UI passing partial resume options.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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