{"record":{"id":"ffe36520695f95bd","repo":"mastra-ai/mastra","slug":"no-thread-found-with-id-threadid","errorCode":null,"errorMessage":"No thread found with id ${threadId}","messagePattern":"No thread found with id (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/memory/src/index.ts","lineNumber":578,"sourceCode":"    return store;\n  }\n\n  async listMessagesByResourceId(args: StorageListMessagesByResourceIdInput): Promise<StorageListMessagesOutput> {\n    const memoryStore = await this.getMemoryStore();\n    return memoryStore.listMessagesByResourceId(args);\n  }\n\n  protected async validateThreadIsOwnedByResource(threadId: string, resourceId: string, config: MemoryConfigInternal) {\n    const resourceScope =\n      (typeof config?.semanticRecall === 'object' && config?.semanticRecall?.scope !== `thread`) ||\n      config.semanticRecall === true;\n\n    const thread = await this.getThreadById({ threadId });\n\n    // For resource-scoped semantic recall, we don't need to validate that the specific thread exists\n    // because we're searching across all threads for the resource\n    if (!thread && !resourceScope) {\n      throw new Error(`No thread found with id ${threadId}`);\n    }\n\n    // If thread exists, validate it belongs to the correct resource\n    if (thread && thread.resourceId !== resourceId) {\n      throw new Error(\n        `Thread with id ${threadId} is for resource with id ${thread.resourceId} but resource ${resourceId} was queried.`,\n      );\n    }\n  }\n\n  private createMemorySpan(\n    operationType: MemoryOperationAttributes['operationType'],\n    observabilityContext?: Partial<ObservabilityContext>,\n    input?: any,\n    attributes?: Partial<MemoryOperationAttributes>,\n  ) {\n    const currentSpan = observabilityContext?.tracingContext?.currentSpan;\n    if (!currentSpan) return undefined;","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/index.ts#L560-L596","documentation":"recall() validates that the given threadId exists when semantic recall is thread-scoped. If getThreadById returns no thread and resourceScope is not enabled, the error is thrown. It is a lookup failure: the thread id does not exist in storage.","triggerScenarios":"Calling memory.recall({ threadId, resourceId }) with a threadId that was never created or was deleted, while semanticRecall is scoped to 'thread' (or semanticRecall is false/undefined so resourceScope is false).","commonSituations":"Replaying an old conversation after the DB was reset; typos or stale thread ids passed from application state; threads deleted by retention/cleanup jobs.","solutions":["Check that the thread id exists via memory.getThreadById({ threadId }) before recall","Create the thread first (memory.createThread) or recall only for existing threads","Enable resource-scoped recall (semanticRecall: { scope: 'resource' }) so recall searches across the resource's threads instead of requiring the specific thread","Fix stale ids in application state (persist and reuse the id returned from createThread)"],"exampleFix":"// before\nawait memory.recall({ threadId: maybeThreadId, resourceId });\n// after\nconst thread = await memory.getThreadById({ threadId: maybeThreadId });\nif (!thread) throw new Error(`Thread ${maybeThreadId} does not exist`);\nawait memory.recall({ threadId: maybeThreadId, resourceId });","handlingStrategy":"try-catch","validationCode":"const thread = await memory.getThreadById({ threadId });\nif (!thread && !resourceScope) throw new Error(`Cannot recall: thread ${threadId} not found`);","typeGuard":null,"tryCatchPattern":"try {\n  await memory.recall({ threadId, resourceId });\n} catch (e) {\n  if (e instanceof Error && e.message.includes('No thread found with id')) {\n    // recreate thread or skip recall\n  } else throw e;\n}","preventionTips":["Persist thread ids returned from createThread instead of hardcoding","Check thread existence before recall in replay/batch jobs","Be aware of cleanup/retention jobs that may delete threads"],"tags":["memory","thread","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}