mastra-ai/mastra · error · Error
Observational memory record not found: ${input.id}
Error message
Observational memory record not found: ${input.id} What it means
updateObservationalMemoryConfig deep-merges a new config into an existing observational memory record's config, and throws this error when the record identified by input.id does not exist in the in-memory store. This ensures configuration changes are only applied to live records rather than silently dropped.
Source
Thrown at packages/core/src/storage/domains/memory/inmemory.ts:1256
async clearObservationalMemory(threadId: string | null, resourceId: string): Promise<void> {
const key = this.getObservationalMemoryKey(threadId, resourceId);
this.db.observationalMemory.delete(key);
}
async setPendingMessageTokens(id: string, tokenCount: number): Promise<void> {
const record = this.findObservationalMemoryRecordById(id);
if (!record) {
throw new Error(`Observational memory record not found: ${id}`);
}
record.pendingMessageTokens = tokenCount;
record.updatedAt = new Date();
}
async updateObservationalMemoryConfig(input: UpdateObservationalMemoryConfigInput): Promise<void> {
const record = this.findObservationalMemoryRecordById(input.id);
if (!record) {
throw new Error(`Observational memory record not found: ${input.id}`);
}
record.config = this.deepMergeConfig(record.config as Record<string, unknown>, input.config);
record.updatedAt = new Date();
}
/**
* Helper to find an observational memory record by ID across all keys
*/
private findObservationalMemoryRecordById(id: string): ObservationalMemoryRecord | null {
for (const records of this.db.observationalMemory.values()) {
const record = records.find(r => r.id === id);
if (record) return record;
}
return null;
}
}
View on GitHub (pinned to 75dd419e61)
Solutions
- Resolve the current record id from the thread/resource before updating config.
- Ensure clearObservationalMemory is not invoked before the config update completes.
- Persist observational memory config with a durable storage provider.
- Catch the error and re-create/initialize the record with the desired config.
Example fix
// before
await memory.updateObservationalMemoryConfig({ id: staleId, config: newConfig });
// after
const record = await memory.getLatestObservationalMemoryRecord(threadId, resourceId);
if (record) await memory.updateObservationalMemoryConfig({ id: record.id, config: newConfig }); Defensive patterns
Strategy: try-catch
Validate before calling
const record = await memory.getLatestObservationalMemoryRecord(threadId, resourceId);
if (!record) throw new Error(`Cannot update observational memory config: record missing for ${threadId}/${resourceId}`); Type guard
function isLiveRecord(r: ObservationalMemoryRecord | undefined): r is ObservationalMemoryRecord {
return r !== undefined;
} Try / catch
try {
await memory.updateObservationalMemoryConfig({ id, config });
} catch (e) {
if (e instanceof Error && e.message.startsWith('Observational memory record not found')) {
// initialize the record with the desired config instead
} else throw e;
} Prevention
- Update config on a freshly fetched record.
- Don't clear observational memory before config updates complete.
- Persist config in durable storage when settings must survive restarts.
- Centralize config updates so stale ids aren't reused.
When it happens
Trigger: Calling updateObservationalMemoryConfig({ id, config }) with a stale/unknown id — after clearObservationalMemory, a process restart of in-memory storage, or an id from another storage backend.
Common situations: Config-update code paths running after memory was cleared; reusing ids saved before a server restart.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- sendStateSignal requires Mastra memory
- Storage is not configured on this AgentController
- Storage does not have a memory domain configured
- Memory is not configured on this AgentController
- Dynamic memory factory returned empty value
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/0e572b398832a124.
Report an issue: GitHub.