{"record":{"id":"65a3e227844d69a4","repo":"mastra-ai/mastra","slug":"root-agent-span-has-no-output","errorCode":null,"errorMessage":"Root agent span has no output","messagePattern":"Root agent span has no output","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/evals/scoreTraces/utils.ts","lineNumber":274,"sourceCode":"\n  // Find the root agent run span\n  const rootAgentSpan = spanTree.rootSpans.find(span => span.spanType === 'agent_run') as SpanRecord | undefined;\n\n  if (!rootAgentSpan) {\n    throw new Error('No root agent_run span found in trace');\n  }\n\n  return { spanTree, rootAgentSpan };\n}\n\nexport function transformTraceToScorerInputAndOutput(trace: TraceRecord): {\n  input: ScorerRunInputForAgent;\n  output: ScorerRunOutputForAgent;\n} {\n  const { spanTree, rootAgentSpan } = prepareTraceForTransformation(trace);\n\n  if (!rootAgentSpan.output) {\n    throw new Error('Root agent span has no output');\n  }\n\n  // Build input\n  const primaryLLMSpan = findPrimaryLLMSpan(spanTree, rootAgentSpan);\n  const inputMessages = extractInputMessages(rootAgentSpan);\n  const systemMessages = extractSystemMessages(primaryLLMSpan);\n\n  // Extract remembered messages from LLM span (excluding current input)\n  const currentInputContent = inputMessages[0]?.content.content || '';\n  const rememberedMessages = extractRememberedMessages(primaryLLMSpan, currentInputContent);\n\n  const input = {\n    inputMessages,\n    rememberedMessages,\n    systemMessages,\n    taggedSystemMessages: {}, // Todo: Support tagged system messages\n  };\n","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/evals/scoreTraces/utils.ts#L256-L292","documentation":"transformTraceToScorerInputAndOutput throws this when the root agent_run span exists but has no `output`. The scorer output is derived directly from the root span's output payload, so scoring cannot proceed without it.","triggerScenarios":"Scoring a trace whose root agent span has output === null/undefined — e.g. the agent run was cancelled or errored before producing output, output persistence failed, or spans were trimmed before the run finished.","commonSituations":"Scoring aborted/failed agent runs; storage adapters dropping large output payloads; running scorers against in-flight traces before output is written.","solutions":["Only trigger scoring after the agent run completes successfully and output is persisted","Check the storage adapter persists span output payloads (including large ones)","Re-run the generation and score the new trace"],"exampleFix":"// before\nawait scoreTrace({ trace: runningTrace });\n// after\nawait agentRunPromise; // wait for completion with output\nawait scoreTrace({ trace: await getTrace(traceId) });","handlingStrategy":"validation","validationCode":"const { rootAgentSpan } = prepareTraceForTransformation(trace);\nif (!rootAgentSpan.output) throw new Error('Agent run incomplete: no output to score');","typeGuard":"function hasRootOutput(t: TraceRecord): boolean {\n  const root = buildSpanTree(t.spans).rootSpans.find(s => s.spanType === 'agent_run');\n  return !!root && root.output != null;\n}","tryCatchPattern":"try {\n  const { output } = transformTraceToScorerInputAndOutput(trace);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Root agent span has no output') {\n    logger.warn('Skipping scoring: agent run produced no output', { traceId: trace.traceId });\n  } else throw e;\n}","preventionTips":["Trigger scoring only after the agent run resolves successfully","Verify storage adapters persist span output payloads fully","Avoid scoring in-flight or cancelled runs","Re-run generations whose traces lack output"],"tags":["trace","missing-output","scoring"],"backgroundTag":"missing-span-output","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}