{"record":{"id":"3868ece0cf2fbdd5","repo":"mastra-ai/mastra","slug":"cannot-update-working-memory-scope-id-is-requi","errorCode":null,"errorMessage":"Cannot update working memory: ${scope} ID is required","messagePattern":"Cannot update working memory: (.+?) ID is required","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/memory/mock.ts","lineNumber":403,"sourceCode":"    memoryConfig,\n  }: {\n    threadId: string;\n    resourceId?: string;\n    workingMemory: string;\n    memoryConfig?: MemoryConfigInternal;\n  }) {\n    const mergedConfig = this.getMergedThreadConfig(memoryConfig);\n    const workingMemoryConfig = mergedConfig.workingMemory;\n\n    if (!workingMemoryConfig?.enabled) {\n      return;\n    }\n\n    const scope = workingMemoryConfig.scope || 'resource';\n    const id = scope === 'resource' ? resourceId : threadId;\n\n    if (!id) {\n      throw new Error(`Cannot update working memory: ${scope} ID is required`);\n    }\n\n    const memoryStorage = await this.getMemoryStore();\n    await memoryStorage.updateResource({\n      resourceId: id,\n      workingMemory,\n    });\n  }\n\n  async __experimental_updateWorkingMemoryVNext({\n    threadId,\n    resourceId,\n    workingMemory,\n    searchString: _searchString,\n    memoryConfig,\n  }: {\n    threadId: string;\n    resourceId?: string;","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/memory/mock.ts#L385-L421","documentation":"updateWorkingMemory resolves which identifier to use based on workingMemoryConfig.scope: 'resource' uses resourceId, 'thread' uses threadId. If the relevant ID is missing, the update cannot proceed and this error is thrown. It is the public-API guard equivalent of errors 1440/1441, raised inside updateWorkingMemory itself.","triggerScenarios":"Calling memory.updateWorkingMemory with scope 'resource' (default) and no resourceId, or with workingMemory explicitly configured as { scope: 'thread' } and no threadId.","commonSituations":"Upgrading Mastra versions where the default scope changed from thread to resource; forgetting to pass threadId in thread-scoped setups; tests calling updateWorkingMemory directly with only workingMemory content.","solutions":["For thread-scoped memory, pass threadId: memory.updateWorkingMemory({ threadId, workingMemory })","For resource-scoped (default) memory, pass resourceId: memory.updateWorkingMemory({ resourceId, workingMemory })","Check your Memory configuration: if options.workingMemory.scope is 'thread', ensure every call site supplies a threadId","Derive the missing ID before the call (e.g. resolve resourceId from the current user/session)"],"exampleFix":"// before (thread-scoped config)\nawait memory.updateWorkingMemory({ workingMemory: 'Prefers dark mode' });\n// after\nawait memory.updateWorkingMemory({ threadId, workingMemory: 'Prefers dark mode' });","handlingStrategy":"validation","validationCode":"function assertWorkingMemoryArgs(\n  cfg: { scope?: 'thread' | 'resource' } | undefined,\n  ids: { threadId?: string; resourceId?: string },\n) {\n  const scope = cfg?.scope ?? 'resource';\n  const id = scope === 'resource' ? ids.resourceId : ids.threadId;\n  if (!id) throw new Error(`Cannot update working memory: ${scope} ID is required`);\n}","typeGuard":"const hasScopeId = (\n  scope: 'thread' | 'resource',\n  ids: { threadId?: string; resourceId?: string },\n): boolean => typeof (scope === 'resource' ? ids.resourceId : ids.threadId) === 'string';","tryCatchPattern":"try {\n  await memory.updateWorkingMemory(args);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Cannot update working memory')) {\n    const scope = workingMemoryConfig?.scope ?? 'resource';\n    const id = scope === 'resource' ? await resolveResourceId() : await resolveThreadId();\n    await memory.updateWorkingMemory({ ...args, ...(scope === 'resource' ? { resourceId: id } : { threadId: id }) });\n  } else throw err;\n}","preventionTips":["Match your call-site arguments to the configured scope: thread scope needs threadId, resource scope needs resourceId","Read your Memory constructor options to confirm workingMemory.scope before writing update calls","Wrap updateWorkingMemory in a helper that resolves IDs from the current session automatically","Add unit tests that call updateWorkingMemory with the exact scope your app configures","When upgrading versions, re-verify the default scope and your ID-passing patterns"],"tags":["memory","working-memory","missing-argument","validation"],"backgroundTag":"missing-required-identifier","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}