{"record":{"id":"dcf32c4ba3679361","repo":"mastra-ai/mastra","slug":"memory-instance-is-required-for-recall","errorCode":null,"errorMessage":"Memory instance is required for recall","messagePattern":"Memory instance is required for recall","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/memory/src/tools/om-tools.ts","lineNumber":791,"sourceCode":"  resourceId?: string;\n  cursor: string;\n  partIndex: number;\n  charOffset?: number;\n  threadScope?: string;\n  maxTokens?: number;\n}): Promise<{\n  text: string;\n  messageId: string;\n  partIndex: number;\n  role: string;\n  type: string;\n  truncated: boolean;\n  charOffset: number;\n  nextCharOffset?: number;\n  note?: string;\n}> {\n  if (!memory || typeof memory.getMemoryStore !== 'function') {\n    throw new Error('Memory instance is required for recall');\n  }\n\n  if (!threadId) {\n    throw new Error('Thread ID is required for recall');\n  }\n\n  const resolved = await resolveCursorMessage(memory, cursor, {\n    resourceId,\n    threadScope,\n    enforceThreadScope: false,\n  });\n\n  if ('hint' in resolved) {\n    throw new Error(resolved.hint);\n  }\n\n  const allParts = formatMessageParts(resolved, 'high');\n","sourceCodeStart":773,"sourceCodeEnd":809,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/tools/om-tools.ts#L773-L809","documentation":"The high-detail recall reader validates its `memory` argument structurally: it must exist and expose `getMemoryStore()` (duck-typing a Mastra Memory instance). Throwing here prevents a confusing deep TypeError later when the function tries to hit the storage layer. It indicates the caller wired the om tool without a real Memory instance.","triggerScenarios":"Passing null/undefined as memory; passing the wrong object (e.g. a storage adapter, a config object, or an agent) instead of a Memory instance; destructuring/mis-ordered arguments in a custom tool execute; memory created lazily and still undefined at call time.","commonSituations":"Tool registered before Memory initialization (async setup not awaited); refactoring changed the argument shape; unit test omitted the memory mock; DI container in mastra/ not providing memory to the tool factory.","solutions":["Pass an actual `new Memory({ ... })` (or equivalent Mastra Memory) instance into the tool/function.","Check the call site for swapped/missing arguments — memory is the first parameter.","Ensure any async Memory construction is awaited before the tool executes.","In tests, provide a Memory stub implementing getMemoryStore() and recall()."],"exampleFix":"// before\nconst tool = createOmRecallTool({ memory: undefined });\n// after\nimport { Memory } from '@mastra/core/memory';\nconst memory = new Memory({ store: libsqlStore });\nconst tool = createOmRecallTool({ memory });","handlingStrategy":"type-guard","validationCode":"function isRecallMemory(m: unknown): m is RecallMemory {\n  return !!m && typeof m === 'object' && typeof (m as any).getMemoryStore === 'function' && typeof (m as any).recall === 'function';\n}\nif (!isRecallMemory(memory)) throw new TypeError('Pass a Mastra Memory instance to the recall tool.');","typeGuard":"const isMemory = (m: unknown): m is RecallMemory =>\n  !!m && typeof (m as RecallMemory).getMemoryStore === 'function';","tryCatchPattern":"try {\n  return await recallDetail({ memory, threadId, cursor, partIndex });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Memory instance is required')) {\n    throw new Error('Tool misconfigured: attach a Memory instance when registering the om recall tool.');\n  }\n  throw e;\n}","preventionTips":["Construct Memory once at startup and share it via DI/config, not per-call literals.","Typecheck tool factories so the memory parameter cannot be optional.","Await async memory initialization before registering tools."],"tags":["validation","memory","configuration","dependency-injection"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}