{"record":{"id":"224bded9c831d2b2","repo":"mastra-ai/mastra","slug":"this-name-entity-with-id-id-not-found","errorCode":null,"errorMessage":"${this.name}: entity with id ${id} not found","messagePattern":"(.+?): entity with id (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/filesystem-versioned.ts","lineNumber":502,"sourceCode":"  async getById(id: string): Promise<TEntity | null> {\n    this.hydrate();\n    return this.entities.has(id) ? structuredClone(this.entities.get(id)!) : null;\n  }\n\n  async createEntity(id: string, entity: TEntity): Promise<TEntity> {\n    this.hydrate();\n    if (this.entities.has(id)) {\n      throw new Error(`${this.name}: entity with id ${id} already exists`);\n    }\n    this.entities.set(id, structuredClone(entity));\n    return structuredClone(entity);\n  }\n\n  async updateEntity(id: string, updates: Record<string, unknown>): Promise<TEntity> {\n    this.hydrate();\n    const existing = this.entities.get(id);\n    if (!existing) {\n      throw new Error(`${this.name}: entity with id ${id} not found`);\n    }\n\n    const updated = { ...existing } as Record<string, unknown>;\n\n    for (const [key, value] of Object.entries(updates)) {\n      if (key === 'id') continue;\n      if (value === undefined) continue;\n\n      if (key === 'metadata' && typeof value === 'object' && value !== null) {\n        updated['metadata'] = {\n          ...((updated['metadata'] as Record<string, unknown> | undefined) ?? {}),\n          ...(value as Record<string, unknown>),\n        };\n      } else {\n        updated[key] = value;\n      }\n    }\n    updated['updatedAt'] = new Date();","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/filesystem-versioned.ts#L484-L520","documentation":"updateEntity hydrates state and looks up the entity by id; if it is absent the update is rejected with this error rather than silently no-oping. Only the 'id' key and whitelisted fields are later merged, so the store requires an existing record as the merge base.","triggerScenarios":"Calling store.update('entities', id, updates) (delegating to updateEntity) where no entity with that id exists; updating an id that was deleted on disk before hydration; a typo'd or stale id captured from an older list result.","commonSituations":"Editing a record that another user/process deleted; frontend holding a stale id after a delete; test fixtures referencing ids that were never seeded.","solutions":["Verify the entity exists with get() before calling update, or catch the error and create the entity instead.","Refresh the id from a fresh list/get call to rule out a stale or deleted record.","Fix the id (check casing/typos) against the storage directory contents."],"exampleFix":"// before\nawait store.update('agents', id, { name: 'new-name' });\n// after\nconst existing = await store.get('agents', id);\nif (!existing) throw new Error(`Agent ${id} no longer exists`);\nawait store.update('agents', id, { name: 'new-name' });","handlingStrategy":"try-catch","validationCode":"const existing = await store.get('entities', id);\nif (!existing) throw new Error(`Cannot update: entity ${id} not found`);","typeGuard":null,"tryCatchPattern":"try {\n  await store.update('entities', id, updates);\n} catch (e) {\n  if (String(e.message).includes('not found')) {\n    // handle deleted/stale record: recreate or surface to user\n  } else throw e;\n}","preventionTips":["Re-fetch the entity right before updating to avoid stale-id updates.","Handle concurrent deletes in UI code (refresh lists after mutations).","Validate id casing/format before issuing the update."],"tags":["storage","not-found","filesystem"],"backgroundTag":"entity-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}