{"record":{"id":"d591ba39592b1817","repo":"mastra-ai/mastra","slug":"memory-error-resource-scoped-working-memory-is-en","errorCode":null,"errorMessage":"Memory error: Resource-scoped working memory is enabled but no resourceId was provided. Either provide a resourceId or explicitly set workingMemory.scope to 'thread'.","messagePattern":"Memory error: Resource-scoped working memory is enabled but no resourceId was provided\\. Either provide a resourceId or explicitly set workingMemory\\.scope to 'thread'\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/memory/src/index.ts","lineNumber":1017,"sourceCode":"    if (!config.workingMemory?.enabled) {\n      throw new Error('Working memory is not enabled for this memory instance');\n    }\n\n    const span = this.createMemorySpan(\n      'update',\n      observabilityContext,\n      { threadId, resourceId },\n      {\n        workingMemoryEnabled: true,\n      },\n    );\n\n    try {\n      const scope = config.workingMemory.scope || 'resource';\n\n      // Guard: If resource-scoped working memory is enabled but no resourceId is provided, throw an error\n      if (scope === 'resource' && !resourceId) {\n        throw new Error(\n          `Memory error: Resource-scoped working memory is enabled but no resourceId was provided. ` +\n            `Either provide a resourceId or explicitly set workingMemory.scope to 'thread'.`,\n        );\n      }\n\n      // Use mutex to prevent race conditions when multiple concurrent calls update the same resource/thread\n      const mutexKey = scope === 'resource' ? `resource-${resourceId}` : `thread-${threadId}`;\n      const mutex = this.updateWorkingMemoryMutexes.has(mutexKey)\n        ? this.updateWorkingMemoryMutexes.get(mutexKey)!\n        : new Mutex();\n      this.updateWorkingMemoryMutexes.set(mutexKey, mutex);\n      const release = await mutex.acquire();\n\n      try {\n        const memoryStore = await this.getMemoryStore();\n        if (scope === 'resource' && resourceId) {\n          await memoryStore.updateResource({\n            resourceId,","sourceCodeStart":999,"sourceCodeEnd":1035,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/index.ts#L999-L1035","documentation":"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'.","triggerScenarios":"memory.updateWorkingMemory({ threadId, workingMemory }) with workingMemory scope 'resource' (explicit or default) and no resourceId.","commonSituations":"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.","solutions":["Pass resourceId to updateWorkingMemory","Set workingMemory: { scope: 'thread' } in the Memory options so only threadId is required","Ensure agent tool call data includes resourceId (thread.resourceId)"],"exampleFix":"// before\nawait memory.updateWorkingMemory({ threadId, workingMemory: 'User likes jazz' });\n// after\nawait memory.updateWorkingMemory({ threadId, resourceId, workingMemory: 'User likes jazz' });\n// or: new Memory({ options: { workingMemory: { enabled: true, scope: 'thread' } } })","handlingStrategy":"validation","validationCode":"if ((config.workingMemory?.scope ?? 'resource') === 'resource' && !resourceId) {\n  throw new Error('resourceId required for resource-scoped working memory');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await memory.updateWorkingMemory({ threadId, resourceId, workingMemory });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Resource-scoped working memory is enabled but no resourceId')) {\n    // supply resourceId or switch scope to 'thread'\n  } else throw e;\n}","preventionTips":["Treat resourceId as mandatory for working memory unless scope is 'thread'","Thread resourceId through agent tool contexts","Set scope explicitly rather than relying on the default"],"tags":["memory","working-memory","validation"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}