{"record":{"id":"08cd0b8a8de1e606","repo":"mastra-ai/mastra","slug":"experiment-target-not-found-08cd0b","errorCode":"EXPERIMENT_TARGET_NOT_FOUND","errorMessage":"Target not found: ${experiment.targetType} \"${experiment.targetId}\"","messagePattern":"Target not found: (.+?) \"(.+?)\"","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/datasets/experiment/item.ts","lineNumber":89,"sourceCode":"  const attempt = args.attempt ?? 0;\n\n  if (experiment.targetType === null || experiment.targetId === null) {\n    throw new MastraError({\n      id: 'EXPERIMENT_HAS_NO_TARGET',\n      text: `Experiment ${experiment.id} has no target; results must be ingested via submitExperimentResult`,\n      domain: 'STORAGE',\n      category: 'USER',\n    });\n  }\n\n  const resolved = await resolveTarget(\n    mastra,\n    experiment.targetType,\n    experiment.targetId,\n    experiment.agentVersion ?? undefined,\n  );\n  if (!resolved) {\n    throw new MastraError({\n      id: 'EXPERIMENT_TARGET_NOT_FOUND',\n      text: `Target not found: ${experiment.targetType} \"${experiment.targetId}\"`,\n      domain: 'STORAGE',\n      category: 'USER',\n    });\n  }\n\n  // Scorer precedence: experiment scorerIds → item scorerIds → dataset scorerIds → none.\n  let scorers: MastraScorer<any, any, any, any>[] = [];\n  let scorerConfigError: ExecutionResult['error'] = null;\n  if (experiment.scorerIds != null) {\n    scorers = resolveScorers(mastra, [...new Set(experiment.scorerIds)]);\n  } else if (item.scorerIds !== undefined) {\n    const resolution = await createItemScorerResolver(mastra)(item.scorerIds);\n    scorers = resolution.scorers;\n    if (resolution.missingIds.length > 0) {\n      scorerConfigError = {\n        code: EXPERIMENT_ITEM_SCORER_NOT_FOUND,","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/datasets/experiment/item.ts#L71-L107","documentation":"After resolving the experiment's target (agent or workflow by type and id, optionally at a specific agentVersion), executeExperimentItem throws EXPERIMENT_TARGET_NOT_FOUND if nothing was resolved. The experiment record points at a target that no longer exists or isn't registered on the Mastra instance.","triggerScenarios":"experiment.targetId references an agent/workflow that was deleted or renamed; running against a different Mastra instance that doesn't register that agent; experiment.agentVersion pins a version that is gone; typo in targetId when creating the experiment.","commonSituations":"Renaming agents while old experiment runs still reference the old id; environment drift between dev/staging where agents differ; cleaning up agents with active experiments; rollback removing a pinned agentVersion.","solutions":["Verify the agent/workflow id in experiment.targetId exists on the Mastra instance you're executing against.","Re-create the experiment against an existing target, or update the experiment record's targetId.","If using agentVersion, ensure that version still exists or clear agentVersion to use the current one.","Register the missing agent/workflow in this environment's Mastra instance before running."],"exampleFix":"// before\nconst experiment = await datasets.experiments.create({ targetType: 'agent', targetId: 'support-agent-v1', ... });\n// after — verify target exists first\nconst agent = mastra.getAgent('support-agent-v1');\nif (!agent) throw new Error('Agent support-agent-v1 not registered');\nconst experiment = await datasets.experiments.create({ targetType: 'agent', targetId: 'support-agent-v1', ... });","handlingStrategy":"validation","validationCode":"const agent = mastra.getAgent(experiment.targetId);\nif (!agent) throw new Error(`Target agent \"${experiment.targetId}\" is not registered in this Mastra instance`);","typeGuard":"function targetExists(mastra: Mastra, e: { targetType: string; targetId: string }): boolean {\n  return e.targetType === 'agent'\n    ? !!mastra.getAgent(e.targetId)\n    : !!mastra.getWorkflow(e.targetId);\n}","tryCatchPattern":"try {\n  await runExperimentItem({ mastra, experiment, item });\n} catch (err) {\n  if (err?.id === 'EXPERIMENT_TARGET_NOT_FOUND') {\n    logger.error(`Experiment ${experiment.id} references missing target ${experiment.targetId}`);\n    return markRunFailed(runId, err);\n  }\n  throw err;\n}","preventionTips":["Resolve the target from the same Mastra instance used for execution.","Avoid renaming/deleting agents with active experiments; check references first.","If pinning agentVersion, confirm the version exists before creating experiments.","Keep target ids consistent across environments via config, not literals."],"tags":["experiments","configuration","not-found"],"backgroundTag":"target-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}