{"record":{"id":"1189b047266a3c29","repo":"mastra-ai/mastra","slug":"memory-instance-cannot-verify-thread-access-for-re","errorCode":null,"errorMessage":"Memory instance cannot verify thread access for recall","messagePattern":"Memory instance cannot verify thread access for recall","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/memory/src/tools/om-tools.ts","lineNumber":1468,"sourceCode":"        throw new Error(\n          isResourceScope\n            ? 'No active thread context and no cursor or threadId was provided for mode=\"messages\". Pass a threadId (use mode=\"threads\" to discover thread IDs) or a message ID as cursor.'\n            : 'No active thread context for mode=\"messages\". This tool is limited to the current thread and no current thread could be resolved.',\n        );\n      }\n\n      let targetThreadId: string | undefined;\n      let threadScope: string | undefined;\n\n      if (!isResourceScope) {\n        targetThreadId = currentThreadId;\n        threadScope = currentThreadId || undefined;\n      } else if (hasResolvedThreadId) {\n        if (!resourceId) {\n          throw new Error('Resource ID is required for recall');\n        }\n        if (!memory.getThreadById) {\n          throw new Error('Memory instance cannot verify thread access for recall');\n        }\n\n        const thread = await memory.getThreadById({ threadId: resolvedThreadId! });\n        if (!thread || thread.resourceId !== resourceId) {\n          throw new Error('Thread does not belong to the active resource');\n        }\n\n        targetThreadId = thread.id;\n        threadScope = thread.id;\n      } else {\n        targetThreadId = currentThreadId;\n        threadScope = currentThreadId || undefined;\n      }\n\n      if (hasCursor && !hasResolvedThreadId && !currentThreadId) {\n        if (!isResourceScope) {\n          throw new Error('Current thread is required when browsing by cursor');\n        }","sourceCodeStart":1450,"sourceCodeEnd":1486,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/tools/om-tools.ts#L1450-L1486","documentation":"Thread-access verification in resource-scoped recall requires the Memory instance to implement getThreadById. When the provided memory object lacks this method, Mastra throws rather than skipping the ownership check, because silently skipping would allow cross-resource reads.","triggerScenarios":"Passing a custom or partial Memory-like object (e.g. a stub, mock, or older memory class) as context.memory that does not define getThreadById, while mode=\"messages\" resolves an explicit threadId in resource scope.","commonSituations":"Dependency/version mismatch where the injected memory implementation predates getThreadById; test doubles missing the method; wrapping Memory in a proxy that drops methods.","solutions":["Use a full Mastra Memory instance (or upgrade @mastra/memory to a version that implements getThreadById).","If using a custom storage/memory adapter, implement getThreadById({ threadId }).","Update test mocks to include getThreadById."],"exampleFix":"// before\nconst memory = { query: async () => ({}) } as any;\n// after\nimport { Memory } from '@mastra/memory';\nconst memory = new Memory({ storage, options: { ... } });","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isFullMemory(m: unknown): m is Memory & { getThreadById: NonNullable<Memory['getThreadById']> } {\n  return typeof (m as any)?.getThreadById === 'function';\n}","tryCatchPattern":"if (!isFullMemory(memoryOrContext)) {\n  throw new Error('Provided memory does not implement getThreadById; use a full Memory instance');\n}","preventionTips":["Use the official Memory class from @mastra/memory, not hand-rolled stubs.","Keep @mastra/core and @mastra/memory versions in sync.","Make test mocks implement the full Memory surface (or use the real class with in-memory storage)."],"tags":["memory","api-mismatch","configuration"],"backgroundTag":"missing-method-on-dependency","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}