mastra-ai/mastra · error · Error
Experiment not found: ${experimentIdB}
Error message
Experiment not found: ${experimentIdB} What it means
compareExperiments fetches both experiments by ID; this error means the SECOND experiment (experimentIdB) was not found in the experiments store. Identical semantics to the experimentIdA variant but reported for the B argument.
Source
Thrown at packages/core/src/datasets/experiment/analytics/compare.ts:85
if (!experimentsStore) {
throw new Error('ExperimentsStorage not configured.');
}
if (!scoresStore) {
throw new Error('ScoresStorage not configured.');
}
// 2. Load both experiments
const [experimentA, experimentB] = await Promise.all([
experimentsStore.getExperimentById({ id: experimentIdA }),
experimentsStore.getExperimentById({ id: experimentIdB }),
]);
if (!experimentA) {
throw new Error(`Experiment not found: ${experimentIdA}`);
}
if (!experimentB) {
throw new Error(`Experiment not found: ${experimentIdB}`);
}
// 3. Check version mismatch
const versionMismatch = experimentA.datasetVersion !== experimentB.datasetVersion;
if (versionMismatch) {
warnings.push(
`Experiments have different dataset versions: ${experimentA.datasetVersion} vs ${experimentB.datasetVersion}`,
);
}
// 4. Load results for both experiments
const [resultsA, resultsB] = await Promise.all([
experimentsStore.listExperimentResults({ experimentId: experimentIdA, pagination: { page: 0, perPage: false } }),
experimentsStore.listExperimentResults({ experimentId: experimentIdB, pagination: { page: 0, perPage: false } }),
]);
// 5. Load scores for both experiments
const [scoresA, scoresB] = await Promise.all([View on GitHub (pinned to 75dd419e61)
Solutions
- Verify experimentIdB exists with experimentsStore.getExperimentById({ id: experimentIdB }) before comparing
- Re-run the baseline experiment to obtain a fresh ID if it was deleted
- Ensure both IDs come from the same Mastra storage instance/environment
- Fix typos or truncated IDs in the comparison call
Example fix
// before
await mastra.compareExperiments({ experimentA: idA, experimentB: config.baselineId });
// after
const baseline = await experimentsStore.getExperimentById({ id: config.baselineId });
if (!baseline) throw new Error(`Baseline experiment ${config.baselineId} not found; re-run it first`); Defensive patterns
Strategy: validation
Validate before calling
const b = await experimentsStore.getExperimentById({ id: experimentIdB });
if (!b) throw new Error(`Experiment B (baseline) not found: ${experimentIdB}`); Type guard
function isExperiment(e: unknown): e is NonNullable<Awaited<ReturnType<typeof experimentsStore.getExperimentById>>> {
return !!e && typeof e === 'object' && 'id' in e;
} Try / catch
try {
await mastra.compareExperiments({ experimentA, experimentB });
} catch (err) {
if (err instanceof Error && err.message.startsWith('Experiment not found')) {
// recreate baseline experiment, then retry
} else throw err;
} Prevention
- Resolve the baseline experiment ID dynamically (e.g. latest baseline query) instead of hardcoding
- Verify baseline existence before every comparison
- Keep baseline and candidate experiments in the same storage backend
- Clean up comparisons when retention deletes experiments
When it happens
Trigger: Calling compareExperiments with a valid experimentA but an experimentB ID that does not exist (deleted, wrong environment, typo, or written to a different storage backend).
Common situations: Comparing against a 'baseline' experiment ID hardcoded in config that was cleaned up; baseline recorded before a storage migration; baseline ID from another project.
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
- Experiment not found: ${experimentIdA}
- EXPERIMENT_NOT_FOUND
- EXPERIMENT_TARGET_NOT_FOUND
- DATASET_NOT_FOUND
- Dataset not found: ${args.id}
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/687b48254080f4f9.
Report an issue: GitHub.