{"record":{"id":"e25560206f99ca2f","repo":"mastra-ai/mastra","slug":"current-thread-is-required-when-browsing-by-cursor","errorCode":null,"errorMessage":"Current thread is required when browsing by cursor","messagePattern":"Current thread is required when browsing by cursor","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/memory/src/tools/om-tools.ts","lineNumber":1485,"sourceCode":"        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        }\n\n        const resolved = await resolveCursorMessage(memory, cursor!, { resourceId });\n        if ('hint' in resolved) {\n          return {\n            messages: resolved.hint,\n            count: 0,\n            cursor: cursor!,\n            page: page ?? 1,\n            limit: Math.min(limit ?? 20, 20),\n            detail: detail ?? 'low',\n            hasNextPage: false,\n            hasPrevPage: false,\n            truncated: false,\n            tokenOffset: 0,\n          };\n        }\n","sourceCodeStart":1467,"sourceCodeEnd":1503,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/tools/om-tools.ts#L1467-L1503","documentation":"When browsing messages by cursor (message ID) without a resolved threadId, non-resource-scoped memory has no way to locate the thread containing the cursor — it is limited to the current thread. Mastra throws because a current thread is mandatory in that path.","triggerScenarios":"mode=\"messages\" with a cursor but no threadId and no currentThreadId, while resource scope is disabled (so cursor-based thread resolution via resolveCursorMessage isn't used).","commonSituations":"Paginating history via cursor in a standalone script with no active agent thread; cursor continuation calls that drop threadId between pages.","solutions":["Pass threadId along with the cursor in the tool context.","Enable resource scope so the cursor can be resolved across threads via resolveCursorMessage.","Maintain the currentThreadId in the run context (invoke within an agent run that has a thread)."],"exampleFix":"// before\nawait recallTool.execute({ context: { mode: 'messages', cursor: 'msg-42' } });\n// after\nawait recallTool.execute({ context: { mode: 'messages', cursor: 'msg-42', threadId: 'thread-abc' } });","handlingStrategy":"validation","validationCode":"if (cursor && !threadId && !currentThreadId) {\n  throw new Error('threadId or an active thread is required when paginating with a cursor');\n}","typeGuard":"function cursorCallIsValid(a: { cursor?: string; threadId?: string; currentThreadId?: string }): boolean {\n  return !a.cursor || Boolean(a.threadId || a.currentThreadId);\n}","tryCatchPattern":"try {\n  return await recall({ mode: 'messages', cursor, threadId });\n} catch (err) {\n  if (err instanceof Error && err.message === 'Current thread is required when browsing by cursor') {\n    return recall({ mode: 'messages', threadId: knownThreadId, cursor });\n  }\n  throw err;\n}","preventionTips":["Carry threadId through every page of cursor pagination.","Enable resource scope if you need cursor resolution across threads.","Avoid raw cursors in scripts without thread context."],"tags":["memory","pagination","missing-argument"],"backgroundTag":"missing-required-parameter","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}