{"record":{"id":"af260073bdd18ba5","repo":"mastra-ai/mastra","slug":"dataset-not-found-args-id-af2600","errorCode":null,"errorMessage":"Dataset not found: ${args.id}","messagePattern":"Dataset not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/storage/domains/datasets/inmemory.ts","lineNumber":141,"sourceCode":"  }\n\n  async getDatasetById({\n    id,\n    filters,\n  }: {\n    id: string;\n    filters?: DatasetTenancyFilters;\n  }): Promise<DatasetRecord | null> {\n    const record = this.db.datasets.get(id);\n    if (!record) return null;\n    if (!matchesTenancy(record, filters)) return null;\n    return toDatasetRecord(record);\n  }\n\n  protected async _doUpdateDataset(args: UpdateDatasetInput): Promise<DatasetRecord> {\n    const existing = this.db.datasets.get(args.id);\n    if (!existing) {\n      throw new Error(`Dataset not found: ${args.id}`);\n    }\n\n    const updated = {\n      ...existing,\n      name: args.name ?? existing.name,\n      description: args.description ?? existing.description,\n      metadata: args.metadata ?? existing.metadata,\n      inputSchema: args.inputSchema !== undefined ? args.inputSchema : existing.inputSchema,\n      groundTruthSchema: args.groundTruthSchema !== undefined ? args.groundTruthSchema : existing.groundTruthSchema,\n      requestContextSchema:\n        args.requestContextSchema !== undefined ? args.requestContextSchema : existing.requestContextSchema,\n      tags: args.tags !== undefined ? args.tags : existing.tags,\n      targetType: args.targetType !== undefined ? args.targetType : existing.targetType,\n      targetIds: args.targetIds !== undefined ? args.targetIds : existing.targetIds,\n      scorerIds: args.scorerIds !== undefined ? args.scorerIds : existing.scorerIds,\n      // Tenancy and candidate identity are immutable after creation.\n      updatedAt: new Date(),\n    } as DatasetRecord;","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/storage/domains/datasets/inmemory.ts#L123-L159","documentation":"InMemory storage's _doUpdateDataset() looks up args.id in its in-memory datasets map and throws this plain Error when absent. The public updateDataset() in the base class performs the same lookup first, so this subclass throw is a race-condition backstop (dataset deleted between the base check and the mutation).","triggerScenarios":"updateDataset({id}) on an InMemory store where the dataset was never created or was deleted concurrently after the base-class existence check.","commonSituations":"Updating a dataset in a fresh server process whose in-memory DB was not repopulated (InMemory storage does not persist across restarts), updating a dataset that another concurrent call deleted.","solutions":["Verify the dataset exists with getDatasetById({id}) before updateDataset, creating it if needed.","Remember InMemory storage resets on process restart — switch to a persistent adapter (libsql/postgres/etc.) if datasets must survive restarts.","Seed datasets deterministically at startup if your app assumes they exist.","Catch the error and recreate the dataset from config when running against ephemeral storage."],"exampleFix":"// before\nawait storage.datasets.updateDataset({ id: 'ds', name: 'New Name' });\n// after\nif (!(await storage.datasets.getDatasetById({ id: 'ds' }))) {\n  await storage.datasets.createDataset({ id: 'ds', name: 'New Name' });\n} else {\n  await storage.datasets.updateDataset({ id: 'ds', name: 'New Name' });\n}","handlingStrategy":"try-catch","validationCode":"if (!(await storage.datasets.getDatasetById({ id }))) {\n  await storage.datasets.createDataset({ id, name });\n}","typeGuard":"function isInMemoryStorage(storage: unknown): boolean {\n  return storage?.constructor?.name === 'InMemoryStorage';\n}","tryCatchPattern":"try {\n  await storage.datasets.updateDataset({ id, name });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Dataset not found:')) {\n    await storage.datasets.createDataset({ id, name });\n  } else throw e;\n}","preventionTips":["Seed required datasets at startup when using InMemory storage.","Remember InMemory state is lost on restart — prefer persistent adapters for durable datasets.","Handle concurrent updates/deletes of the same dataset id."],"tags":["storage","datasets","in-memory","not-found"],"backgroundTag":"dataset-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}