mastra-ai/mastra · error · Error

Experiment not found: ${input.id}

Error message

Experiment not found: ${input.id}

What it means

updateExperiment requires an existing experiment row; when input.id does not resolve in the in-memory experiments map it throws a plain Error. The store does not upsert — the experiment must have been created first.

Source

Thrown at packages/core/src/storage/domains/experiments/inmemory.ts:79

      totalItems: input.totalItems,
      succeededCount: 0,
      failedCount: 0,
      skippedCount: 0,
      organizationId: input.organizationId ?? null,
      projectId: input.projectId ?? null,
      startedAt: null,
      completedAt: null,
      createdAt: now,
      updatedAt: now,
    };
    this.db.experiments.set(experiment.id, structuredClone(experiment));
    return structuredClone(experiment);
  }

  async updateExperiment(input: UpdateExperimentInput): Promise<Experiment> {
    const existing = this.db.experiments.get(input.id);
    if (!existing) {
      throw new Error(`Experiment not found: ${input.id}`);
    }
    const updated: Experiment = {
      ...existing,
      status: input.status ?? existing.status,
      totalItems: input.totalItems ?? existing.totalItems,
      succeededCount: input.succeededCount ?? existing.succeededCount,
      failedCount: input.failedCount ?? existing.failedCount,
      skippedCount: input.skippedCount ?? existing.skippedCount,
      startedAt: input.startedAt ?? existing.startedAt,
      completedAt: input.completedAt ?? existing.completedAt,
      name: input.name ?? existing.name,
      description: input.description ?? existing.description,
      metadata: input.metadata ?? existing.metadata,
      updatedAt: new Date(),
    };
    this.db.experiments.set(input.id, structuredClone(updated));
    return structuredClone(updated);
  }

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Confirm the id came from createExperiment's return value and was not recreated since.
  2. Check the experiment still exists (listExperiment/get) before updating.
  3. Re-create the experiment if the store was restarted; in-memory storage is not durable.
  4. Ensure a single shared storage instance is injected everywhere (avoid duplicate module instantiation).

Example fix

// before
await storage.experiments.updateExperiment({ id: expId, status: 'running' });
// after
const exp = await storage.experiments.getExperiment({ id: expId });
if (!exp) throw new Error(`Experiment ${expId} vanished — recreate before updating`);
await storage.experiments.updateExperiment({ id: expId, status: 'running' });
Defensive patterns

Strategy: try-catch

Validate before calling

const exp = await storage.experiments.getExperiment({ id });
if (!exp) throw new Error(`Cannot update missing experiment ${id}`);

Type guard

null

Try / catch

try {
  await storage.experiments.updateExperiment({ id, status: 'completed' });
} catch (e) {
  if (String(e).startsWith('Experiment not found')) {
    // store restarted or id stale: recreate or surface to caller
  } else throw e;
}

Prevention

When it happens

Trigger: updateExperiment({ id, status/totalItems/... }) with an id that was never created, already deleted, or from a restarted store; typo'd or undefined experiment id.

Common situations: Experiment worker resuming after dev-server restart (in-memory data lost); two storage instances (e.g., different module imports) with divergent maps; reporting progress for an experiment whose creation failed.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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