{"record":{"id":"6a9793576726ddff","repo":"mastra-ai/mastra","slug":"no-active-thread-context-and-no-cursor-or-threadid","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/memory/src/tools/om-tools.ts","lineNumber":1450,"sourceCode":"          currentThreadId: currentThreadId || '',\n          page: page ?? 0,\n          limit: limit ?? 20,\n          before,\n          after,\n        });\n      }\n\n      const usedDefaultThreadId = !explicitThreadId && !cursor && Boolean(currentThreadId);\n      const defaultThreadNote =\n        usedDefaultThreadId && isResourceScope ? `threadId wasn't passed so used default ${currentThreadId}.\\n\\n` : '';\n      // Reuse the shared `resolvedExplicitThreadId` ('current' -> currentThreadId) mapping,\n      // falling back to the current thread when no threadId or cursor was provided.\n      const resolvedThreadId = resolvedExplicitThreadId || (usedDefaultThreadId ? currentThreadId : undefined);\n      const hasResolvedThreadId = typeof resolvedThreadId === 'string' && resolvedThreadId.length > 0;\n      const hasCursor = typeof cursor === 'string' && cursor.length > 0;\n\n      if (!hasResolvedThreadId && !hasCursor) {\n        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');","sourceCodeStart":1432,"sourceCodeEnd":1468,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/tools/om-tools.ts#L1432-L1468","documentation":"For mode=\"messages\", Mastra needs a thread to read from: either an explicitly passed threadId, a cursor, or the agent's current thread. When none can be resolved (resource scope, no default thread), it throws with guidance to pass a threadId or message-ID cursor.","triggerScenarios":"mode=\"messages\" called with no threadId, no cursor, and no currentThreadId resolvable in the run context (usedDefaultThreadId with empty currentThreadId).","commonSituations":"Invoking the recall tool outside an agent run so no 'current thread' exists; agent run without threadId while the tool needs conversation history; asking 'show messages' before any conversation started.","solutions":["Pass an explicit threadId to the tool call (discover one with mode=\"threads\").","Provide a message ID as cursor to continue browsing from that point.","Invoke the tool within an agent run where threadId is supplied so currentThreadId resolves."],"exampleFix":"// before\nconst res = await recallTool.execute({ context: { mode: 'messages' } });\n// after\nconst res = await recallTool.execute({ context: { mode: 'messages', threadId: 'thread-abc' } });","handlingStrategy":"validation","validationCode":"const hasThread = typeof threadId === 'string' && threadId.length > 0;\nconst hasCursor = typeof cursor === 'string' && cursor.length > 0;\nif (!hasThread && !hasCursor && !currentThreadId) {\n  throw new Error('Provide threadId or cursor for mode=\"messages\"');\n}","typeGuard":"function canRecallMessages(args: { threadId?: string; cursor?: string; currentThreadId?: string }): boolean {\n  return Boolean(args.threadId || args.cursor || args.currentThreadId);\n}","tryCatchPattern":"try {\n  return await recall({ mode: 'messages', threadId });\n} catch (err) {\n  if (err instanceof Error && err.message.includes('No active thread context')) {\n    const threads = await recall({ mode: 'threads', resourceId });\n    return recall({ mode: 'messages', threadId: threads.threads[0]?.id });\n  }\n  throw err;\n}","preventionTips":["Pass threadId explicitly when calling recall tools outside an agent run.","Discover thread IDs with mode=\"threads\" first.","Ensure agent runs supply threadId so currentThreadId resolves."],"tags":["memory","missing-argument","threads"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}