{"record":{"id":"6f156e63e13ccd9e","repo":"mastra-ai/mastra","slug":"experiment-not-found-experimentida","errorCode":null,"errorMessage":"Experiment not found: ${experimentIdA}","messagePattern":"Experiment not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/datasets/experiment/analytics/compare.ts","lineNumber":82,"sourceCode":"\n  const experimentsStore = await storage.getStore('experiments');\n  const scoresStore = await storage.getStore('scores');\n\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  ]);","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/datasets/experiment/analytics/compare.ts#L64-L100","documentation":"compareExperiments fetches both experiments by ID before comparing their scores. This error means the first experiment (experimentIdA) does not exist in the experiments store — getExperimentById returned undefined. It is thrown as a plain Error so the caller can distinguish a bad ID from a comparison failure.","triggerScenarios":"Calling compareExperiments({ experimentA, experimentB }) (or the equivalent options object) where the first experiment ID was deleted, never created, or belongs to a different storage backend than the one wired into the Mastra instance.","commonSituations":"Using an experiment ID from a dev database in a prod environment; an experiment removed by a cleanup/retention job; a typo'd or truncated UUID; storage class swapped (e.g. InMemory store restarted, wiping experiments) between run and compare.","solutions":["Log/verify experimentIdA exists via experimentsStore.getExperimentById({ id: experimentIdA }) before comparing","Check you are connected to the same Mastra storage instance that recorded the experiment","Re-run the experiment if it was deleted, and compare using the new ID","Confirm the ID string has no whitespace/truncation (copy full UUID)"],"exampleFix":"// before\nawait mastra.compareExperiments({ experimentA: staleId, experimentB: idB });\n// after\nconst a = await experimentsStore.getExperimentById({ id: staleId });\nif (!a) throw new Error(`Experiment ${staleId} missing; re-run experiment first`);\nawait mastra.compareExperiments({ experimentA: staleId, experimentB: idB });","handlingStrategy":"validation","validationCode":"const a = await experimentsStore.getExperimentById({ id: experimentIdA });\nif (!a) throw new Error(`Experiment A not found: ${experimentIdA}`);","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    // re-run or re-create the missing experiment\n  } else throw err;\n}","preventionTips":["Store experiment IDs centrally (config/DB) right after creation","Pre-check both experiment IDs before comparing","Pin the storage instance used for experiments per environment","Never hardcode experiment IDs across environments"],"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-30T03:17:51.788Z"}