{"record":{"id":"687b48254080f4f9","repo":"mastra-ai/mastra","slug":"experiment-not-found-experimentidb","errorCode":null,"errorMessage":"Experiment not found: ${experimentIdB}","messagePattern":"Experiment not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/datasets/experiment/analytics/compare.ts","lineNumber":85,"sourceCode":"\n  if (!experimentsStore) {\n    throw new Error('ExperimentsStorage not configured.');\n  }\n  if (!scoresStore) {\n    throw new Error('ScoresStorage not configured.');\n  }\n\n  // 2. Load both experiments\n  const [experimentA, experimentB] = await Promise.all([\n    experimentsStore.getExperimentById({ id: experimentIdA }),\n    experimentsStore.getExperimentById({ id: experimentIdB }),\n  ]);\n\n  if (!experimentA) {\n    throw new Error(`Experiment not found: ${experimentIdA}`);\n  }\n  if (!experimentB) {\n    throw new Error(`Experiment not found: ${experimentIdB}`);\n  }\n\n  // 3. Check version mismatch\n  const versionMismatch = experimentA.datasetVersion !== experimentB.datasetVersion;\n  if (versionMismatch) {\n    warnings.push(\n      `Experiments have different dataset versions: ${experimentA.datasetVersion} vs ${experimentB.datasetVersion}`,\n    );\n  }\n\n  // 4. Load results for both experiments\n  const [resultsA, resultsB] = await Promise.all([\n    experimentsStore.listExperimentResults({ experimentId: experimentIdA, pagination: { page: 0, perPage: false } }),\n    experimentsStore.listExperimentResults({ experimentId: experimentIdB, pagination: { page: 0, perPage: false } }),\n  ]);\n\n  // 5. Load scores for both experiments\n  const [scoresA, scoresB] = await Promise.all([","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/datasets/experiment/analytics/compare.ts#L67-L103","documentation":"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.","triggerScenarios":"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).","commonSituations":"Comparing against a 'baseline' experiment ID hardcoded in config that was cleaned up; baseline recorded before a storage migration; baseline ID from another project.","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"],"exampleFix":"// before\nawait mastra.compareExperiments({ experimentA: idA, experimentB: config.baselineId });\n// after\nconst baseline = await experimentsStore.getExperimentById({ id: config.baselineId });\nif (!baseline) throw new Error(`Baseline experiment ${config.baselineId} not found; re-run it first`);","handlingStrategy":"validation","validationCode":"const b = await experimentsStore.getExperimentById({ id: experimentIdB });\nif (!b) throw new Error(`Experiment B (baseline) not found: ${experimentIdB}`);","typeGuard":"function isExperiment(e: unknown): e is NonNullable<Awaited<ReturnType<typeof experimentsStore.getExperimentById>>> {\n  return !!e && typeof e === 'object' && 'id' in e;\n}","tryCatchPattern":"try {\n  await mastra.compareExperiments({ experimentA, experimentB });\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Experiment not found')) {\n    // recreate baseline experiment, then retry\n  } else throw err;\n}","preventionTips":["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"],"tags":["storage","experiment","not-found","user-input"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}