{"record":{"id":"fe3d5177239ce2a2","repo":"mastra-ai/mastra","slug":"record","errorCode":null,"errorMessage":"record","messagePattern":"record","errorType":"exception","errorClass":"KnowledgeNotFoundError","httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/knowledge/inmemory.ts","lineNumber":418,"sourceCode":"    this.#recordActivity('record-deleted', 'record', id, record.scope, record.sourceThreadId);\n    this.#enqueue('record', id, 'delete', updated.deletedAt.toISOString(), record.scope);\n    return cloneRecord(updated);\n  }\n\n  async restoreKnowledge({ id }: { id: string }): Promise<KnowledgeRecord> {\n    const record = this.#db.knowledgeRecords.get(id);\n    if (!record) throw new KnowledgeNotFoundError('record', id);\n    if (!record.deletedAt) return cloneRecord(record);\n    const updated = { ...record, deletedAt: undefined, deletedBy: undefined };\n    this.#db.knowledgeRecords.set(id, updated);\n    this.#recordActivity('record-restored', 'record', id, record.scope, record.sourceThreadId);\n    this.#enqueue('record', id, 'upsert', createKnowledgeUlid(), record.scope);\n    return cloneRecord(updated);\n  }\n\n  async rescopeKnowledge({ id, scope }: { id: string; scope: KnowledgeScope }): Promise<KnowledgeRecord> {\n    const record = this.#db.knowledgeRecords.get(id);\n    if (!record) throw new KnowledgeNotFoundError('record', id);\n    const canonical = canonicalizeKnowledgeScope(scope);\n    assertKnowledgeScopeWithinCeiling(canonical, record.maxScope);\n    const updated = { ...record, scope: canonical };\n    this.#db.knowledgeRecords.set(id, updated);\n    this.#recordActivity('record-rescoped', 'record', id, canonical, record.sourceThreadId);\n    if (knowledgeScopeKey(record.scope) !== knowledgeScopeKey(canonical)) {\n      this.#enqueue('record', id, 'delete', createKnowledgeUlid(), record.scope);\n    }\n    if (!record.deletedAt) {\n      this.#enqueue('record', id, 'upsert', createKnowledgeUlid(), canonical);\n    }\n    return cloneRecord(updated);\n  }\n\n  async raiseKnowledgeCeiling({\n    id,\n    maxScope,\n  }: {","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/knowledge/inmemory.ts#L400-L436","documentation":"rescopeKnowledge() throws KnowledgeNotFoundError('record', id) when the given record ID does not exist, before canonicalizing the new scope. It then verifies the requested scope fits within the record's maxScope ceiling. Note this error surfaces the record ID through KnowledgeNotFoundError even though the raw message reads 'record'.","triggerScenarios":"Calling rescopeKnowledge({ id, scope }) with an ID that was never created, an ID from another instance/environment, or an ID captured before the store was reinitialized; rescoping records loaded from a stale list snapshot.","commonSituations":"Bulk rescope jobs built from cached IDs across process restarts; multi-tenant code pointing at the wrong store; ID copy/paste between dev and prod data.","solutions":["Fetch fresh record IDs (listKnowledge) immediately before rescoping in bulk jobs.","Wrap rescopes in error handling that logs and skips missing records rather than aborting the batch.","Verify the storage instance/tenant context matches where the record was created.","Persist records durably (a storage adapter) if IDs must survive restarts."],"exampleFix":"// before\nfor (const id of cachedIds) await storage.rescopeKnowledge({ id, scope });\n// after\nfor (const id of cachedIds) {\n  try { await storage.rescopeKnowledge({ id, scope }); }\n  catch (e) { if (!(e instanceof KnowledgeNotFoundError)) throw e; }\n}","handlingStrategy":"validation","validationCode":"const records = await storage.listKnowledge({});\nconst target = records.records.find(r => r.id === id);\nif (!target) throw new SkipRescope(`record ${id} not found`);\nif (!isKnowledgeScopeWithinCeiling(newScope, target.maxScope)) throw new SkipRescope('scope exceeds ceiling');","typeGuard":null,"tryCatchPattern":"try {\n  await storage.rescopeKnowledge({ id, scope });\n} catch (e) {\n  if (e instanceof KnowledgeNotFoundError) { skipped.push(id); return; }\n  throw e;\n}","preventionTips":["Build bulk rescope batches from a fresh listKnowledge call.","Check the new scope fits the record's maxScope before calling.","Verify tenant/store context matches the records' origin.","Use durable storage adapters if record IDs must outlive the process."],"tags":["knowledge","not-found","scope","rescope"],"backgroundTag":"entity-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}