{"record":{"id":"dbd9ad1629b82861","repo":"mastra-ai/mastra","slug":"experiment-not-found","errorCode":"EXPERIMENT_NOT_FOUND","errorMessage":"Experiment not found: ${experimentId}","messagePattern":"Experiment not found: (.+?)","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/datasets/dataset.ts","lineNumber":508,"sourceCode":"    });\n  }\n\n  /**\n   * Verify the experiment belongs to this dataset (and, by extension, to the\n   * handle's tenancy scope which was enforced when the handle was minted).\n   * Throws NOT_FOUND on missing or cross-dataset experiments so cross-tenant\n   * mutation via a valid scoped handle + a known foreign experimentId is\n   * rejected.\n   */\n  async #assertExperimentOwnership(experimentId: string): Promise<void> {\n    await this.#assertScope();\n    const experimentsStore = await this.#getExperimentsStore();\n    const experiment = await experimentsStore.getExperimentById({\n      id: experimentId,\n      filters: this.#scope,\n    });\n    if (!experiment || experiment.datasetId !== this.id) {\n      throw new MastraError({\n        id: 'EXPERIMENT_NOT_FOUND',\n        text: `Experiment not found: ${experimentId}`,\n        domain: 'STORAGE',\n        category: 'USER',\n      });\n    }\n  }\n\n  /**\n   * Get a specific experiment (run) by ID.\n   */\n  async getExperiment(args: { experimentId: string }) {\n    await this.#assertScope();\n    const experimentsStore = await this.#getExperimentsStore();\n    const experiment = await experimentsStore.getExperimentById({\n      id: args.experimentId,\n      filters: this.#scope,\n    });","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/datasets/dataset.ts#L490-L526","documentation":"Thrown by the internal #assertExperimentOwnership guard when getExperimentById returns no experiment, or the experiment's datasetId does not match this Dataset handle's id. This ensures a Dataset can only read/update/delete experiments that belong to it (and are within its scope).","triggerScenarios":"Calling listExperimentResults, updateExperimentResult, or deleteExperiment with an experimentId that does not exist, is scoped out by filters, or belongs to a different dataset.","commonSituations":"Copy-pasting an experiment id from another dataset; using an id from a different Mastra instance or storage backend; id typo; experiment was deleted; wrong scope/tenant on the Dataset handle.","solutions":["Verify the experimentId exists via the experiments store or listExperiments","Confirm the experiment belongs to this dataset (experiment.datasetId === dataset.id)","Re-obtain the Dataset handle for the correct dataset that owns the experiment","Check that the Dataset handle's scope filters match the environment that created the experiment"],"exampleFix":"// before\nawait wrongDataset.deleteExperiment({ experimentId: id });\n// after\nconst owningDataset = await mastra.getDataset(experiment.datasetId);\nawait owningDataset.deleteExperiment({ experimentId: id });","handlingStrategy":"try-catch","validationCode":"const experiment = await experimentsStore.getExperimentById({ id: experimentId, filters: scope });\nif (!experiment || experiment.datasetId !== dataset.id) throw new Error(`Experiment ${experimentId} not owned by dataset ${dataset.id}`);","typeGuard":"function isOwnedExperiment<T extends { datasetId: string }>(exp: T | undefined | null, datasetId: string): exp is T { return !!exp && exp.datasetId === datasetId; }","tryCatchPattern":"try {\n  await dataset.deleteExperiment({ experimentId });\n} catch (e) {\n  if (isMastraError(e) && e.id === 'EXPERIMENT_NOT_FOUND') {\n    console.warn(`Experiment ${experimentId} not found for this dataset; skipping`);\n  } else throw e;\n}","preventionTips":["Store experiment ids alongside the dataset id that created them","Look up valid ids via listExperiments instead of hardcoding","Keep the Dataset handle's scope consistent with the creating environment"],"tags":["storage","experiment","not-found","ownership"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}