{"record":{"id":"020bcea67b2b8ce1","repo":"mastra-ai/mastra","slug":"item-not-found-args-id","errorCode":null,"errorMessage":"Item not found: ${args.id}","messagePattern":"Item not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/datasets/inmemory.ts","lineNumber":279,"sourceCode":"      requestContext: args.requestContext,\n      metadata: args.metadata,\n      source: args.source,\n      createdAt: now,\n      updatedAt: now,\n    };\n\n    this.db.datasetItems.set(id, [row]);\n\n    // T3.11 — every mutation inserts exactly one dataset_version row\n    await this.createDatasetVersion(args.datasetId, newVersion);\n\n    return toDatasetItem(row);\n  }\n\n  protected async _doUpdateItem(args: UpdateDatasetItemInput): Promise<DatasetItem> {\n    const rows = this.db.datasetItems.get(args.id);\n    if (!rows || rows.length === 0) {\n      throw new Error(`Item not found: ${args.id}`);\n    }\n\n    const currentRow = rows.find(r => r.validTo === null && !r.isDeleted);\n    if (!currentRow) {\n      throw new Error(`Item not found: ${args.id}`);\n    }\n    if (currentRow.datasetId !== args.datasetId) {\n      throw new Error(`Item ${args.id} does not belong to dataset ${args.datasetId}`);\n    }\n\n    const dataset = this.db.datasets.get(args.datasetId);\n    if (!dataset) {\n      throw new Error(`Dataset not found: ${args.datasetId}`);\n    }\n\n    // Bump version (T3.26)\n    const newVersion = dataset.version + 1;\n    this.db.datasets.set(args.datasetId, { ...dataset, version: newVersion });","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/datasets/inmemory.ts#L261-L297","documentation":"InMemory _doUpdateItem() reads this.db.datasetItems.get(args.id) — the SCD-2 history list for the item — and throws this plain Error when there are no rows at all, i.e., no item with that id was ever inserted into this store.","triggerScenarios":"updateItem({id, datasetId, ...}) with an item id that does not exist in the in-memory store (never created, wrong id, or lost to a process restart).","commonSituations":"Updating items using ids from a previous run of an InMemory-backed server, copying ids from another storage backend, or a typo in the item id.","solutions":["Verify the item exists first with getItemById({id}); insert it via addItems if absent.","Use item ids returned from the add/batchInsert call, not hand-written or foreign ids.","Switch to persistent storage if items must survive restarts under InMemory storage.","Ensure you are connected to the same store the item was created in."],"exampleFix":"// before\nawait storage.datasets.updateItem({ id: itemId, datasetId: 'ds', input: newInput });\n// after\nconst item = await storage.datasets.getItemById({ id: itemId });\nif (!item) throw new Error(`Item ${itemId} missing; add it before updating`);\nawait storage.datasets.updateItem({ id: itemId, datasetId: 'ds', input: newInput });","handlingStrategy":"validation","validationCode":"const item = await storage.datasets.getItemById({ id: itemId });\nif (!item) throw new Error(`Item '${itemId}' not found; cannot update`);","typeGuard":"function itemExists(item: Awaited<ReturnType<typeof storage.datasets.getItemById>>): item is NonNullable<typeof item> {\n  return item !== null;\n}","tryCatchPattern":"try {\n  await storage.datasets.updateItem({ id: itemId, datasetId, input });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Item not found:')) {\n    // re-add the item or surface 'stale item id' to the user\n  } else throw e;\n}","preventionTips":["Only use item ids returned by addItems/batchInsertItems/listItems.","Re-fetch items after process restarts when using InMemory storage.","Confirm both processes operate on the same storage backend."],"tags":["storage","datasets","in-memory","not-found"],"backgroundTag":"item-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}