{"record":{"id":"0e572b398832a124","repo":"mastra-ai/mastra","slug":"observational-memory-record-not-found-input-id","errorCode":null,"errorMessage":"Observational memory record not found: ${input.id}","messagePattern":"Observational memory record not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/memory/inmemory.ts","lineNumber":1256,"sourceCode":"  async clearObservationalMemory(threadId: string | null, resourceId: string): Promise<void> {\n    const key = this.getObservationalMemoryKey(threadId, resourceId);\n    this.db.observationalMemory.delete(key);\n  }\n\n  async setPendingMessageTokens(id: string, tokenCount: number): Promise<void> {\n    const record = this.findObservationalMemoryRecordById(id);\n    if (!record) {\n      throw new Error(`Observational memory record not found: ${id}`);\n    }\n\n    record.pendingMessageTokens = tokenCount;\n    record.updatedAt = new Date();\n  }\n\n  async updateObservationalMemoryConfig(input: UpdateObservationalMemoryConfigInput): Promise<void> {\n    const record = this.findObservationalMemoryRecordById(input.id);\n    if (!record) {\n      throw new Error(`Observational memory record not found: ${input.id}`);\n    }\n\n    record.config = this.deepMergeConfig(record.config as Record<string, unknown>, input.config);\n    record.updatedAt = new Date();\n  }\n\n  /**\n   * Helper to find an observational memory record by ID across all keys\n   */\n  private findObservationalMemoryRecordById(id: string): ObservationalMemoryRecord | null {\n    for (const records of this.db.observationalMemory.values()) {\n      const record = records.find(r => r.id === id);\n      if (record) return record;\n    }\n    return null;\n  }\n}\n","sourceCodeStart":1238,"sourceCodeEnd":1274,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/memory/inmemory.ts#L1238-L1274","documentation":"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.","triggerScenarios":"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.","commonSituations":"Config-update code paths running after memory was cleared; reusing ids saved before a server restart.","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."],"exampleFix":"// before\nawait memory.updateObservationalMemoryConfig({ id: staleId, config: newConfig });\n// after\nconst record = await memory.getLatestObservationalMemoryRecord(threadId, resourceId);\nif (record) await memory.updateObservationalMemoryConfig({ id: record.id, config: newConfig });","handlingStrategy":"try-catch","validationCode":"const record = await memory.getLatestObservationalMemoryRecord(threadId, resourceId);\nif (!record) throw new Error(`Cannot update observational memory config: record missing for ${threadId}/${resourceId}`);","typeGuard":"function isLiveRecord(r: ObservationalMemoryRecord | undefined): r is ObservationalMemoryRecord {\n  return r !== undefined;\n}","tryCatchPattern":"try {\n  await memory.updateObservationalMemoryConfig({ id, config });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Observational memory record not found')) {\n    // initialize the record with the desired config instead\n  } else throw e;\n}","preventionTips":["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."],"tags":["memory","in-memory-storage","configuration"],"backgroundTag":"record-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}