mastra-ai/mastra · error

sendStateSignal requires Mastra memory

Error message

sendStateSignal requires Mastra memory

What it means

sendStateSignal() throws this when agent.getMemory() returns no memory instance. State signals are persisted through Mastra memory, so without a configured Memory the signal has nowhere to live and the runtime refuses to proceed.

Source

Thrown at packages/core/src/agent/thread-stream-runtime.ts:2716

  }

  async sendStateSignal<OUTPUT = unknown>(
    agent: Agent<any, any, any, any>,
    stateInput: AgentStateSignalInput,
    target: SendAgentStateSignalOptions<OUTPUT>,
    pubsub?: PubSub,
  ): Promise<SendAgentStateSignalResult<OUTPUT>> {
    if (!target.resourceId || !target.threadId) {
      throw new Error('resourceId and threadId are required to send a state signal');
    }
    const resourceId = target.resourceId;
    const threadId = target.threadId;

    const requestContext = target.ifIdle?.streamOptions?.requestContext;
    const memoryContext = parseMemoryRequestContext(requestContext);
    const memory = await agent.getMemory({ requestContext });
    if (!memory) {
      throw new Error('sendStateSignal requires Mastra memory');
    }

    const loadedThread = (await memory.getThreadById({ threadId })) ?? memoryContext?.thread;
    if (!loadedThread) {
      throw new Error(`sendStateSignal could not load thread ${threadId}`);
    }

    const thread = {
      ...loadedThread,
      id: threadId,
      resourceId: loadedThread.resourceId ?? resourceId,
      createdAt: loadedThread.createdAt ?? new Date(),
      updatedAt: loadedThread.updatedAt ?? new Date(),
      metadata: loadedThread.metadata,
    };

    const applied = await applyStateSignal({
      input: stateInput,

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Configure memory on the Agent: new Agent({ name, instructions, model, memory: new Memory({ storage, ... }) }).
  2. Verify agent.getMemory({ requestContext }) resolves non-undefined in your setup (check DI/env wiring).
  3. If the agent is intentionally stateless, use direct generate/stream instead of sendStateSignal.

Example fix

// before
const agent = new Agent({ name: 'a', instructions: '...', model });
await runtime.sendStateSignal(agent, state, target); // throws
// after
const agent = new Agent({ name: 'a', instructions: '...', model, memory: new Memory({ storage }) });
await runtime.sendStateSignal(agent, state, target);
Defensive patterns

Strategy: validation

Validate before calling

const memory = await agent.getMemory({ requestContext });
if (!memory) throw new Error('Agent has no memory; cannot sendStateSignal');

Type guard

function hasMemory(a: Agent): a is Agent & { getMemory(): Promise<Memory> } {
  return Boolean(a.getMemory);
} // plus an async check: (await a.getMemory({})) != null

Try / catch

try {
  return await runtime.sendStateSignal(agent, state, target);
} catch (e) {
  if (e instanceof Error && e.message === 'sendStateSignal requires Mastra memory') {
    // configure Memory on the agent or use a non-memory path
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling sendStateSignal on an Agent constructed without a memory option (or whose memory factory resolves to undefined), even though resourceId/threadId were provided.

Common situations: Agent created for a stateless use case (no memory configured) later reused for signal-based workflows; memory passed via DI/environment config that failed to resolve; copy-pasting an agent definition without the memory block.

Related errors


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