mastra-ai/mastra · error · Error

Dataset not found: ${args.id}

Error message

Dataset not found: ${args.id}

What it means

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).

Source

Thrown at packages/core/src/storage/domains/datasets/inmemory.ts:141

  }

  async getDatasetById({
    id,
    filters,
  }: {
    id: string;
    filters?: DatasetTenancyFilters;
  }): Promise<DatasetRecord | null> {
    const record = this.db.datasets.get(id);
    if (!record) return null;
    if (!matchesTenancy(record, filters)) return null;
    return toDatasetRecord(record);
  }

  protected async _doUpdateDataset(args: UpdateDatasetInput): Promise<DatasetRecord> {
    const existing = this.db.datasets.get(args.id);
    if (!existing) {
      throw new Error(`Dataset not found: ${args.id}`);
    }

    const updated = {
      ...existing,
      name: args.name ?? existing.name,
      description: args.description ?? existing.description,
      metadata: args.metadata ?? existing.metadata,
      inputSchema: args.inputSchema !== undefined ? args.inputSchema : existing.inputSchema,
      groundTruthSchema: args.groundTruthSchema !== undefined ? args.groundTruthSchema : existing.groundTruthSchema,
      requestContextSchema:
        args.requestContextSchema !== undefined ? args.requestContextSchema : existing.requestContextSchema,
      tags: args.tags !== undefined ? args.tags : existing.tags,
      targetType: args.targetType !== undefined ? args.targetType : existing.targetType,
      targetIds: args.targetIds !== undefined ? args.targetIds : existing.targetIds,
      scorerIds: args.scorerIds !== undefined ? args.scorerIds : existing.scorerIds,
      // Tenancy and candidate identity are immutable after creation.
      updatedAt: new Date(),
    } as DatasetRecord;

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Verify the dataset exists with getDatasetById({id}) before updateDataset, creating it if needed.
  2. Remember InMemory storage resets on process restart — switch to a persistent adapter (libsql/postgres/etc.) if datasets must survive restarts.
  3. Seed datasets deterministically at startup if your app assumes they exist.
  4. Catch the error and recreate the dataset from config when running against ephemeral storage.

Example fix

// before
await storage.datasets.updateDataset({ id: 'ds', name: 'New Name' });
// after
if (!(await storage.datasets.getDatasetById({ id: 'ds' }))) {
  await storage.datasets.createDataset({ id: 'ds', name: 'New Name' });
} else {
  await storage.datasets.updateDataset({ id: 'ds', name: 'New Name' });
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!(await storage.datasets.getDatasetById({ id }))) {
  await storage.datasets.createDataset({ id, name });
}

Type guard

function isInMemoryStorage(storage: unknown): boolean {
  return storage?.constructor?.name === 'InMemoryStorage';
}

Try / catch

try {
  await storage.datasets.updateDataset({ id, name });
} catch (e) {
  if (e instanceof Error && e.message.startsWith('Dataset not found:')) {
    await storage.datasets.createDataset({ id, name });
  } else throw e;
}

Prevention

When it happens

Trigger: updateDataset({id}) on an InMemory store where the dataset was never created or was deleted concurrently after the base-class existence check.

Common situations: 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.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/af260073bdd18ba5. Report an issue: GitHub.