ai icon indicating copy to clipboard operation
ai copied to clipboard

WorkflowAgent run has no root span: each model call becomes its own agent root in the trace

Open robertyates opened this issue 1 month ago • 4 comments

Description

A durable WorkflowAgent run has no span that covers the whole run. With registerTelemetry(new OpenTelemetry()), every model call of one agent.stream() arrives as its own root: ai.workflowAgent.stream <model> (an invoke_agent span) with a step and a chat span under it. The calls share a trace ID, but nothing sits above them, so the run's input (the prompt) and output (the final text) are on no span. Trace viewers that name and summarise a trace from its root span (Arize, Phoenix, Langfuse) show one model call instead of the run.

A plain streamText or ToolLoopAgent in the same process produces one invoke_agent span for the whole run, with every model call and tool call under it.

This is a separate gap from #23608 (tool calls send no telemetry) but has the same cause. WorkflowAgent sends the run's start and end (telemetryDispatcher.onStart and onEnd in workflow-agent.ts) from the workflow body, where registered integrations are not visible, so both are no-ops. #22378 made each model step send its own start and end, which is why each call now appears as its own run.

Versions: @ai-sdk/[email protected] (also checked against main), [email protected], @ai-sdk/[email protected], [email protected].

Reproduction

The workflow from #23608, or any WorkflowAgent run that makes two model calls (a tool call, then text), with an OpenTelemetry integration registered globally:

  • Expected: one invoke_agent root span for the run, with the prompt as input and the final text as output, and both model calls (and the tool call, once #23608 is fixed) under it.
  • Actual: two ai.workflowAgent.stream root spans, one per model call, with no parent.

Notes

  • Steps of a durable run can execute in different processes, so no in-memory span can stay open for the run. One option: derive the run span's ID from the run ID, parent each model step's spans to it, and send the run span itself from a step when the run ends (or when it suspends, for example on a tool approval).
  • We work around it by sending our own root span from the step that ends each turn and reparenting the turn's top-level spans to it in our exporter.

robertyates avatar Oct 20 '26 16:10 robertyates

Identify issue type

Identified as Bug
Confidence: High

Rationale

This is a concrete telemetry failure in existing WorkflowAgent behavior: run-level tracing is missing and model calls are incorrectly represented as independent roots.

Evidence

  • A durable WorkflowAgent run emits each model call as a separate root span instead of one span covering the full run.
  • The run-level telemetry start and end events reportedly execute where registered integrations are unavailable, making them no-ops.
  • The behavior loses run-level prompt/output telemetry and differs from streamText and ToolLoopAgent behavior.

ai-sdk-factory[bot] avatar Oct 20 '26 16:10 ai-sdk-factory[bot]

Bug discovery clarification

@robertyates, how did you discover this bug? Did you encounter it while using the AI SDK in production, find it while auditing or reviewing AI SDK source code, or discover it another way? Please describe the original discovery context.

The report documents observed tracing behavior and subsequent source-code investigation, but it does not establish whether the bug was originally discovered in production, during an AI SDK code audit, or in local testing. The original author has not clarified the discovery source.

ai-sdk-factory[bot] avatar Oct 20 '26 16:10 ai-sdk-factory[bot]

We found it in production. Our chat agent runs on WorkflowAgent, and we moved its tracing to registerTelemetry(new OpenTelemetry()) exporting to Arize once #22378 shipped. The traces that came back had blank Input and Output and were named after a single model call: each turn arrived as one ai.workflowAgent.stream root per model call, with nothing above them. We then read workflow-agent.ts to find out why, and saw the run's onStart / onEnd dispatched from the workflow body.

We've worked around it on our side by sending our own root span from the step that ends each turn and reparenting the turn's top-level spans to it in our exporter. That's the code we'd like to delete once this is fixed.

robertyates avatar Oct 21 '26 12:10 robertyates

:rocket: Published in:

Package Version
ai 7.0.162 github npm
@ai-sdk/alibaba 2.0.82 github npm
@ai-sdk/amazon-bedrock 5.0.132 github npm
@ai-sdk/angular 3.0.162 github npm
@ai-sdk/anthropic 4.0.96 github npm
@ai-sdk/anthropic-aws 2.0.89 github npm
@ai-sdk/assemblyai 3.0.74 github npm
@ai-sdk/azure 4.0.116 github npm
@ai-sdk/baseten 2.1.62 github npm
@ai-sdk/black-forest-labs 2.0.76 github npm
@ai-sdk/bytedance 2.0.77 github npm
@ai-sdk/cartesia 3.0.69 github npm
@ai-sdk/cerebras 3.0.84 github npm
@ai-sdk/code-mode 1.0.119 github npm
@ai-sdk/cohere 4.0.75 github npm
@ai-sdk/deepgram 3.1.45 github npm
@ai-sdk/deepinfra 3.0.84 github npm
@ai-sdk/deepseek 3.0.79 github npm
@ai-sdk/devtools 1.0.65 github npm
@ai-sdk/elevenlabs 3.0.79 github npm
@ai-sdk/fal 3.0.75 github npm
@ai-sdk/fireworks 3.0.87 github npm
@ai-sdk/fish-audio 3.0.52 github npm
@ai-sdk/gateway 4.0.135 github npm
@ai-sdk/gladia 3.0.74 github npm
@ai-sdk/gmicloud 3.0.55 github npm
@ai-sdk/google 4.0.111 github npm
@ai-sdk/google-vertex 5.0.131 github npm
@ai-sdk/groq 4.0.76 github npm
@ai-sdk/harness 1.0.173 github npm
@ai-sdk/harness-acp 1.0.113 github npm
@ai-sdk/harness-claude-code 1.0.177 github npm
@ai-sdk/harness-cline 1.0.101 github npm
@ai-sdk/harness-codex 1.0.175 github npm
@ai-sdk/harness-cursor 1.0.88 github npm
@ai-sdk/harness-deepagents 1.0.173 github npm
@ai-sdk/harness-fx 1.0.89 github npm
@ai-sdk/harness-github-copilot 1.0.70 github npm
@ai-sdk/harness-grok-build 1.0.112 github npm
@ai-sdk/harness-opencode 1.0.176 github npm
@ai-sdk/harness-pi 1.0.176 github npm
@ai-sdk/heygen 3.0.16 github npm
@ai-sdk/huggingface 2.0.84 github npm
@ai-sdk/hume 3.0.74 github npm
@ai-sdk/klingai 4.0.76 github npm
@ai-sdk/langchain 3.0.162 github npm
@ai-sdk/llamaindex 3.0.162 github npm
@ai-sdk/luma 3.0.75 github npm
@ai-sdk/mcp 2.0.90 github npm
@ai-sdk/minimax 3.0.73 github npm
@ai-sdk/mistral 4.0.79 github npm
@ai-sdk/moonshotai 3.0.84 github npm
@ai-sdk/open-responses 2.0.79 github npm
@ai-sdk/openai 4.0.108 github npm
@ai-sdk/openai-compatible 3.0.84 github npm
@ai-sdk/otel 1.0.162 github npm
@ai-sdk/parallel 3.0.2 github npm
@ai-sdk/perplexity 5.0.26 github npm
@ai-sdk/policy-opa 1.0.162 github npm
@ai-sdk/prodia 2.0.75 github npm
@ai-sdk/provider-utils 5.0.74 github npm
@ai-sdk/quiverai 2.0.75 github npm
@ai-sdk/react 4.0.166 github npm
@ai-sdk/replicate 3.0.75 github npm
@ai-sdk/revai 3.0.74 github npm
@ai-sdk/rsc 3.0.162 github npm
@ai-sdk/sandbox-just-bash 1.0.173 github npm
@ai-sdk/sandbox-vercel 1.0.173 github npm
@ai-sdk/svelte 5.0.162 github npm
@ai-sdk/togetherai 3.0.85 github npm
@ai-sdk/tool-bash 1.0.16 github npm
@ai-sdk/tool-web-fetch 1.0.12 github npm
@ai-sdk/topaz 3.0.21 github npm
@ai-sdk/tui 1.0.163 github npm
@ai-sdk/typesafe-ai 3.0.33 github npm
@ai-sdk/valibot 3.0.74 github npm
@ai-sdk/voyage 2.0.74 github npm
@ai-sdk/vue 4.0.162 github npm
@ai-sdk/workflow 2.0.94 github npm
@ai-sdk/workflow-harness 1.0.173 github npm
@ai-sdk/xai 5.0.38 github npm
@ai-sdk/zai 3.0.46 github npm

github-actions[bot] avatar Nov 03 '26 01:11 github-actions[bot]