mastra-ai/mastra · error

Memory error: Resource-scoped working memory is enabled but

Error message

Memory error: Resource-scoped working memory is enabled but no resourceId was provided. Either provide a resourceId or explicitly set workingMemory.scope to 'thread'.

What it means

When working memory scope is 'resource' (the default), updateWorkingMemory needs a resourceId to key the working memory. If resourceId is missing, the guard throws with guidance to supply one or scope to 'thread'.

Source

Thrown at packages/memory/src/index.ts:1017

    if (!config.workingMemory?.enabled) {
      throw new Error('Working memory is not enabled for this memory instance');
    }

    const span = this.createMemorySpan(
      'update',
      observabilityContext,
      { threadId, resourceId },
      {
        workingMemoryEnabled: true,
      },
    );

    try {
      const scope = config.workingMemory.scope || 'resource';

      // Guard: If resource-scoped working memory is enabled but no resourceId is provided, throw an error
      if (scope === 'resource' && !resourceId) {
        throw new Error(
          `Memory error: Resource-scoped working memory is enabled but no resourceId was provided. ` +
            `Either provide a resourceId or explicitly set workingMemory.scope to 'thread'.`,
        );
      }

      // Use mutex to prevent race conditions when multiple concurrent calls update the same resource/thread
      const mutexKey = scope === 'resource' ? `resource-${resourceId}` : `thread-${threadId}`;
      const mutex = this.updateWorkingMemoryMutexes.has(mutexKey)
        ? this.updateWorkingMemoryMutexes.get(mutexKey)!
        : new Mutex();
      this.updateWorkingMemoryMutexes.set(mutexKey, mutex);
      const release = await mutex.acquire();

      try {
        const memoryStore = await this.getMemoryStore();
        if (scope === 'resource' && resourceId) {
          await memoryStore.updateResource({
            resourceId,

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Pass resourceId to updateWorkingMemory
  2. Set workingMemory: { scope: 'thread' } in the Memory options so only threadId is required
  3. Ensure agent tool call data includes resourceId (thread.resourceId)

Example fix

// before
await memory.updateWorkingMemory({ threadId, workingMemory: 'User likes jazz' });
// after
await memory.updateWorkingMemory({ threadId, resourceId, workingMemory: 'User likes jazz' });
// or: new Memory({ options: { workingMemory: { enabled: true, scope: 'thread' } } })
Defensive patterns

Strategy: validation

Validate before calling

if ((config.workingMemory?.scope ?? 'resource') === 'resource' && !resourceId) {
  throw new Error('resourceId required for resource-scoped working memory');
}

Try / catch

try {
  await memory.updateWorkingMemory({ threadId, resourceId, workingMemory });
} catch (e) {
  if (e instanceof Error && e.message.includes('Resource-scoped working memory is enabled but no resourceId')) {
    // supply resourceId or switch scope to 'thread'
  } else throw e;
}

Prevention

When it happens

Trigger: memory.updateWorkingMemory({ threadId, workingMemory }) with workingMemory scope 'resource' (explicit or default) and no resourceId.

Common situations: Thread-scoped integrations after upgrading Mastra where the default scope changed to 'resource'; call sites that only track threadId; agent tool calls not forwarding resourceId.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


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