mastra-ai/mastra · error · Error
Item not found: ${args.id}
Error message
Item not found: ${args.id} What it means
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.
Source
Thrown at packages/core/src/storage/domains/datasets/inmemory.ts:279
requestContext: args.requestContext,
metadata: args.metadata,
source: args.source,
createdAt: now,
updatedAt: now,
};
this.db.datasetItems.set(id, [row]);
// T3.11 — every mutation inserts exactly one dataset_version row
await this.createDatasetVersion(args.datasetId, newVersion);
return toDatasetItem(row);
}
protected async _doUpdateItem(args: UpdateDatasetItemInput): Promise<DatasetItem> {
const rows = this.db.datasetItems.get(args.id);
if (!rows || rows.length === 0) {
throw new Error(`Item not found: ${args.id}`);
}
const currentRow = rows.find(r => r.validTo === null && !r.isDeleted);
if (!currentRow) {
throw new Error(`Item not found: ${args.id}`);
}
if (currentRow.datasetId !== args.datasetId) {
throw new Error(`Item ${args.id} does not belong to dataset ${args.datasetId}`);
}
const dataset = this.db.datasets.get(args.datasetId);
if (!dataset) {
throw new Error(`Dataset not found: ${args.datasetId}`);
}
// Bump version (T3.26)
const newVersion = dataset.version + 1;
this.db.datasets.set(args.datasetId, { ...dataset, version: newVersion });View on GitHub (pinned to 75dd419e61)
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.
Example fix
// before
await storage.datasets.updateItem({ id: itemId, datasetId: 'ds', input: newInput });
// after
const item = await storage.datasets.getItemById({ id: itemId });
if (!item) throw new Error(`Item ${itemId} missing; add it before updating`);
await storage.datasets.updateItem({ id: itemId, datasetId: 'ds', input: newInput }); Defensive patterns
Strategy: validation
Validate before calling
const item = await storage.datasets.getItemById({ id: itemId });
if (!item) throw new Error(`Item '${itemId}' not found; cannot update`); Type guard
function itemExists(item: Awaited<ReturnType<typeof storage.datasets.getItemById>>): item is NonNullable<typeof item> {
return item !== null;
} Try / catch
try {
await storage.datasets.updateItem({ id: itemId, datasetId, input });
} catch (e) {
if (e instanceof Error && e.message.startsWith('Item not found:')) {
// re-add the item or surface 'stale item id' to the user
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Dataset not found: ${args.id}
- Dataset not found: ${args.datasetId}
- DATASET_NOT_FOUND
- Agent with id ${id} not found
- Dataset not found: ${args.id}
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/020bcea67b2b8ce1.
Report an issue: GitHub.