{"record":{"id":"0a8dd6e7d3d50e5f","repo":"mastra-ai/mastra","slug":"target-not-found-targettype-targetid","errorCode":null,"errorMessage":"Target not found: ${targetType}/${targetId}","messagePattern":"Target not found: (.+?)/(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/datasets/experiment/index.ts","lineNumber":335,"sourceCode":"            signal: itemSignal,\n          });\n          return { output: result, error: null, traceId: null };\n        } catch (err: unknown) {\n          return {\n            output: null,\n            error: {\n              message: err instanceof Error ? err.message : String(err),\n              stack: err instanceof Error ? err.stack : undefined,\n            },\n            traceId: null,\n          };\n        }\n      };\n    } else if (targetType && targetId) {\n      // Registry-based target path (existing)\n      const resolved = await resolveTarget(mastra, targetType, targetId, agentVersion);\n      if (!resolved) {\n        throw new Error(`Target not found: ${targetType}/${targetId}`);\n      }\n      const { target } = resolved;\n      execFn = (item, itemSignal) => {\n        // Merge global request context with per-item request context (item takes precedence)\n        const mergedRequestContext =\n          globalRequestContext || item.requestContext ? { ...globalRequestContext, ...item.requestContext } : undefined;\n        return executeTarget(target, targetType, item, {\n          signal: itemSignal,\n          requestContext: mergedRequestContext,\n          experimentId,\n          versions,\n          toolMocks: targetType === 'agent' ? item.toolMocks : undefined,\n          unmockedToolPolicy:\n            targetType === 'agent' ? (item.unmockedToolPolicy ?? config.unmockedToolPolicy ?? 'allow') : undefined,\n        });\n      };\n    } else {\n      throw new Error('No task: provide targetType+targetId or task');","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/datasets/experiment/index.ts#L317-L353","documentation":"When an experiment specifies a registry-based task via targetType+targetId, runExperiment resolves the target through resolveTarget against the Mastra instance's registry (agents, tools, workflows, scorers). If resolution returns null/undefined, this Error is thrown: no registered object matches that type/ID (or the requested agentVersion).","triggerScenarios":"Calling runExperiment with targetType 'agent' (or 'tool'/'workflow'/'scorer') and a targetId that is not registered on the Mastra instance, or with an agentVersion that does not exist for the named agent.","commonSituations":"Renaming an agent without updating experiment configs; registering the target on a different Mastra instance than the one running the experiment; referencing an old agentVersion after redeploying; typo in the target ID.","solutions":["Verify the target is registered: check mastra.getAgent(targetId)/equivalent before running the experiment","Correct the targetId (or rename it back) to match the registered key","Omit or fix agentVersion so it matches a version that exists for the target","Ensure runExperiment is called on the Mastra instance that actually registers the target"],"exampleFix":"// before\nawait runExperiment({ targetType: 'agent', targetId: 'support-agent-v2', ... });\n// after\nif (!mastra.getAgent('support-agent-v2')) throw new Error('agent not registered');\nawait runExperiment({ targetType: 'agent', targetId: 'support-agent-v2', ... });","handlingStrategy":"validation","validationCode":"if (!mastra.getAgent(targetId) && !mastra.getTool(targetId) && !mastra.getWorkflow(targetId)) {\n  throw new Error(`Target ${targetType}/${targetId} not registered on this Mastra instance`);\n}","typeGuard":"function isRegisteredTarget(mastra: Mastra, t: { targetType: string; targetId: string }): boolean {\n  switch (t.targetType) {\n    case 'agent': return !!mastra.getAgent(t.targetId);\n    case 'tool': return !!mastra.getTool(t.targetId);\n    case 'workflow': return !!mastra.getWorkflow(t.targetId);\n    default: return false;\n  }\n}","tryCatchPattern":"try {\n  await runExperiment(config);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Target not found')) {\n    console.error(`Register target or fix ID: ${err.message}`);\n  } else throw err;\n}","preventionTips":["Verify target registration at service startup","Keep experiment configs in sync with agent/tool registry names (single source of constants)","Pin agentVersion only when you know it exists","Call runExperiment on the same Mastra instance that registers the targets"],"tags":["configuration","registry","not-found","experiment"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}