mastra-ai/mastra · error · Error
KnowledgeRecord not found: ${(input as { recordId: string })
Error message
KnowledgeRecord not found: ${(input as { recordId: string }).recordId} What it means
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.
Source
Thrown at packages/memory/src/processors/observational-memory/subconscious/knowledge-write-tools.ts:100
maxScope: options.maxScope,
resolutionScope: options.scope,
defaultScope: expandKnowledgeScope(options.scope, options.defaultScope),
});
},
}),
knowledge_remove: createTool({
id: 'knowledge_remove',
description: 'Soft-delete a visible record. Curators cannot restore or physically erase knowledge records.',
inputSchema: {
type: 'object',
properties: { recordId: { type: 'string', minLength: 1 } },
required: ['recordId'],
additionalProperties: false,
} satisfies JSONSchema7,
execute: async input => {
const store = await getStore(memory);
const record = await store.getKnowledge({ id: (input as { recordId: string }).recordId, includeDeleted: true });
if (!record) throw new Error(`KnowledgeRecord not found: ${(input as { recordId: string }).recordId}`);
requireVisible(record.scope, options, 'KnowledgeRecord');
return store.removeKnowledge({ id: record.id, deletedBy: CURATOR_IDENTITY });
},
}),
knowledge_update_node: createTool({
id: 'knowledge_update_node',
description:
'Update a visible node name or kind using optimistic concurrency. Provide at least one of name or kind.',
inputSchema: {
type: 'object',
properties: {
node: { type: 'string', minLength: 1 },
expectedVersion: { type: 'integer', minimum: 1 },
name: { type: 'string', minLength: 1 },
kind: { type: 'string', minLength: 1 },
},
required: ['node', 'expectedVersion'],
additionalProperties: false,View on GitHub (pinned to 75dd419e61)
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.
Example fix
// before
await tools.knowledge_remove.execute({ recordId: 'rec_guess_123' }, ctx);
// after
const rec = await tools.knowledge_read.execute({ id: 'rec_actual_123' }, ctx);
if (rec.found) await tools.knowledge_remove.execute({ recordId: 'rec_actual_123' }, ctx); Defensive patterns
Strategy: try-catch
Validate before calling
const rec = await tools.knowledge_read.execute({ id: recordId }, ctx);
if (!rec.found) {
console.warn(`Skipping removal: record ${recordId} does not exist in this scope.`);
return { removed: false };
} Try / catch
try {
return await curatorTools.knowledge_remove.execute({ recordId }, {} as any);
} catch (e) {
if (e instanceof Error && e.message.startsWith('KnowledgeRecord not found:')) {
return { removed: false, reason: 'not-found' }; // idempotent remove
}
throw e;
} Prevention
- 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.
When it happens
Trigger: Calling knowledge_remove with a recordId that does not exist in the knowledge store; cross-tenant IDs; fabricated IDs from LLM output.
Common situations: 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.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Knowledge node not found: ${value.node}
- Plugin tool "${toolName}" is no longer available
- Cannot favorite: ${entityType} with id ${entityId} does not
- SandboxNotReadyError: sandbox with id '${this.id}' is not re
- knowledge_read requires id or name.
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/d039e5be13743ad0.
Report an issue: GitHub.