{"record":{"id":"531f51ceb71c0d42","repo":"mastra-ai/mastra","slug":"resource-id-is-required-for-recall","errorCode":null,"errorMessage":"Resource ID is required for recall","messagePattern":"Resource ID is required for recall","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/memory/src/tools/om-tools.ts","lineNumber":1389,"sourceCode":"\n      if (explicitThreadId === 'current' && !currentThreadId) {\n        throw new Error('Could not resolve current thread.');\n      }\n\n      // Search mode\n      if (mode === 'search') {\n        // Schema validation rejects mode=\"search\" when search is disabled, but\n        // validation is skipped for resumed runs and builder-validated input —\n        // a stale search call on those paths would otherwise reach\n        // Memory.searchMessages and throw. Return guidance instead.\n        if (!searchEnabled) {\n          return { results: SEARCH_NOT_CONFIGURED_MESSAGE, count: 0 };\n        }\n        if (!query) {\n          throw new Error('query is required for mode=\"search\"');\n        }\n        if (!resourceId) {\n          throw new Error('Resource ID is required for recall');\n        }\n        return searchMessagesForResource({\n          memory,\n          resourceId,\n          currentThreadId: currentThreadId || undefined,\n          query,\n          topK: limit ?? 10,\n          before,\n          after,\n          threadScope: !isResourceScope ? currentThreadId || undefined : resolvedExplicitThreadId || undefined,\n        });\n      }\n\n      // Thread listing mode\n      if (mode === 'threads') {\n        const requestedCurrentThread = explicitThreadId === 'current';\n\n        // Thread scope: return current thread info only","sourceCodeStart":1371,"sourceCodeEnd":1407,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/tools/om-tools.ts#L1371-L1407","documentation":"The memory recall tool's search mode requires a resourceId to scope the semantic search to a specific resource (user). Mastra throws this when mode=\"search\" is invoked without a resourceId in the tool context. The library cannot safely search messages without knowing which resource's data to search.","triggerScenarios":"Calling the om-memory tool with mode=\"search\" and a non-empty query, but context.resourceId is undefined or an empty string (e.g. agent invoked without resourceId in its memory options, or caller omitted it in the tool's run context).","commonSituations":"Agents constructed without passing resourceId to Memory or the agent's memory options; standalone agents where the caller forgot to supply resourceId in the execution context; multi-tenant apps where the resourceId is set later in the request lifecycle than the tool call.","solutions":["Pass a resourceId when creating the Memory instance or when invoking the agent (e.g. agent.stream(..., { resourceId: 'user-123' })).","If calling the tool directly, include resourceId in the tool context object.","Verify the resourceId isn't an empty string or being read from an unset env/config variable before the call."],"exampleFix":"// before\nawait agent.stream('what did I say about cats?');\n// after\nawait agent.stream('what did I say about cats?', { resourceId: 'user-123', threadId: 'thread-abc' });","handlingStrategy":"validation","validationCode":"if (!resourceId || typeof resourceId !== 'string' || resourceId.length === 0) {\n  throw new Error('resourceId must be provided before calling memory search');\n}","typeGuard":"function hasResourceId(ctx: unknown): ctx is { resourceId: string } {\n  return typeof (ctx as any)?.resourceId === 'string' && (ctx as any).resourceId.length > 0;\n}","tryCatchPattern":"try {\n  await agent.stream(query, { resourceId, threadId });\n} catch (err) {\n  if (err instanceof Error && err.message === 'Resource ID is required for recall') {\n    // re-init with resourceId or prompt user to authenticate\n  }\n  throw err;\n}","preventionTips":["Always pass resourceId in agent.stream/generate options when memory is enabled.","Add an app-level assertion for resourceId before any memory-backed agent call.","Centralize agent invocation in a helper that enforces resourceId/threadId."],"tags":["memory","missing-argument","validation"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}