{"record":{"id":"d039e5be13743ad0","repo":"mastra-ai/mastra","slug":"knowledgerecord-not-found-input-as-recordid","errorCode":null,"errorMessage":"KnowledgeRecord not found: ${(input as { recordId: string }).recordId}","messagePattern":"KnowledgeRecord not found: (.+?)\\)\\.recordId\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/memory/src/processors/observational-memory/subconscious/knowledge-write-tools.ts","lineNumber":100,"sourceCode":"          maxScope: options.maxScope,\n          resolutionScope: options.scope,\n          defaultScope: expandKnowledgeScope(options.scope, options.defaultScope),\n        });\n      },\n    }),\n    knowledge_remove: createTool({\n      id: 'knowledge_remove',\n      description: 'Soft-delete a visible record. Curators cannot restore or physically erase knowledge records.',\n      inputSchema: {\n        type: 'object',\n        properties: { recordId: { type: 'string', minLength: 1 } },\n        required: ['recordId'],\n        additionalProperties: false,\n      } satisfies JSONSchema7,\n      execute: async input => {\n        const store = await getStore(memory);\n        const record = await store.getKnowledge({ id: (input as { recordId: string }).recordId, includeDeleted: true });\n        if (!record) throw new Error(`KnowledgeRecord not found: ${(input as { recordId: string }).recordId}`);\n        requireVisible(record.scope, options, 'KnowledgeRecord');\n        return store.removeKnowledge({ id: record.id, deletedBy: CURATOR_IDENTITY });\n      },\n    }),\n    knowledge_update_node: createTool({\n      id: 'knowledge_update_node',\n      description:\n        'Update a visible node name or kind using optimistic concurrency. Provide at least one of name or kind.',\n      inputSchema: {\n        type: 'object',\n        properties: {\n          node: { type: 'string', minLength: 1 },\n          expectedVersion: { type: 'integer', minimum: 1 },\n          name: { type: 'string', minLength: 1 },\n          kind: { type: 'string', minLength: 1 },\n        },\n        required: ['node', 'expectedVersion'],\n        additionalProperties: false,","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/memory/src/processors/observational-memory/subconscious/knowledge-write-tools.ts#L82-L118","documentation":"knowledge_remove soft-deletes a knowledge record by ID. The handler loads the record with getKnowledge({ id, includeDeleted: true }) and throws this error when no record with that ID exists at all — even deleted records are found, so this strictly means the ID is unknown (wrong, typo'd, foreign tenant, or never created). The message embeds the requested recordId.","triggerScenarios":"Calling knowledge_remove with a recordId that does not exist in the knowledge store; cross-tenant IDs; fabricated IDs from LLM output.","commonSituations":"Agents guessing record IDs from memory/context summaries; records living in a different storage environment (dev vs prod); truncated or transformed IDs after passing through logs or prompts.","solutions":["Confirm the recordId by first reading/listing records (knowledge_read / knowledge_search) in the current scope.","Check you are pointed at the same storage environment where the record was created.","If the record was already physically purged, treat removal as a no-op rather than retrying.","Validate tenant coordinates so foreign-tenant IDs aren't passed in."],"exampleFix":"// before\nawait tools.knowledge_remove.execute({ recordId: 'rec_guess_123' }, ctx);\n// after\nconst rec = await tools.knowledge_read.execute({ id: 'rec_actual_123' }, ctx);\nif (rec.found) await tools.knowledge_remove.execute({ recordId: 'rec_actual_123' }, ctx);","handlingStrategy":"try-catch","validationCode":"const rec = await tools.knowledge_read.execute({ id: recordId }, ctx);\nif (!rec.found) {\n  console.warn(`Skipping removal: record ${recordId} does not exist in this scope.`);\n  return { removed: false };\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await curatorTools.knowledge_remove.execute({ recordId }, {} as any);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('KnowledgeRecord not found:')) {\n    return { removed: false, reason: 'not-found' }; // idempotent remove\n  }\n  throw e;\n}","preventionTips":["Look up the record via knowledge_read/knowledge_search before removing.","Treat remove as idempotent and ignore not-found for already-purged records.","Ensure the same storage environment is used for reads and writes.","Don't let the LLM guess record IDs; source them from prior tool results."],"tags":["knowledge-remove","entity-not-found","stale-reference","tool-input-validation"],"backgroundTag":"entity-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}