Repository navigation
Description
Describe the bug
The OpenTelemetry reference says:
To measure AI unit consumption, read
github.copilot.nano_aiufrom the rootinvoke_agentspan only. The attribute is also stamped on the childchatspans, so summing it across every span double-counts.
The root invoke_agent span's github.copilot.nano_aiu covers only the main agent's own chat spans. Subagent usage isn't included. Since #4224 was fixed, that usage is on the subagents' own nested invoke_agent spans and their chat spans. Following the docs therefore undercounts AI credits in every session that uses subagents.
Summing github.copilot.nano_aiu over all chat spans matches /usage exactly, and so does summing it over all invoke_agent spans, root and subagents.
The root's token totals have the same gap. gen_ai.usage.input_tokens and gen_ai.usage.output_tokens are documented as "Total input/output tokens (all turns)", but they leave out the subagents' tokens.
One Copilot CLI session: a claude-sonnet-5.5 session started two background subagents in parallel, one on gpt-6-luna and one on claude-haiku-5.5.
| Source | AI credits | Input tokens |
|---|---|---|
/usage |
11.88 (Sonnet 11.26, Haiku 0.38, Luna 0.24) | 276.4k |
Root invoke_agent spans (two turns) |
11.257 | 176,020 (Sonnet only) |
All chat spans |
11.879 | 276,373 |
All invoke_agent spans (roots + subagents) |
11.879 | 276,373 |
We saw the same thing on two other clients that use the same runtime. In each case the root's nano_aiu equals the sum of the main agent's own chat spans exactly, and every subagent is left out:
- Desktop app (runtime
1.0.115-7), two background subagents: root 21.449, allchatspans 22.846. - VS Code 1.149 Copilot harness (runtime
1.0.116), one synchronous subagent (gen_ai.transfer.mode=return_to_calleron thetaskspan): root 15.308, allchatspans 15.613.
Affected version
GitHub Copilot CLI 1.0.119. Also seen in runtime 1.0.115-7 (desktop app) and 1.0.116 (VS Code 1.149).
Steps to reproduce the behavior
COPILOT_OTEL_FILE_EXPORTER_PATH=otel.jsonl copilot, then/modeland pickclaude-sonnet-5.5.- Prompt:
Use the task tool to start two background subagents in parallel: one with model gpt-6-luna that creates a.txt with three lines about OpenTelemetry, and one with model claude-haiku-5.5 that creates b.txt with three lines about Grafana. - When both have finished, run
/usageand note the AI credits. - Sum
github.copilot.nano_aiu/ 1e9 inotel.jsonl:- over
invoke_agentspans with no parent: lower than/usage, missing the subagents. - over all
chatspans: equal to/usage.
- over
Expected behavior
One of these:
- The root
invoke_agentspan'sgithub.copilot.nano_aiuandgen_ai.usage.*include the usage of the subagents it started, as the docs imply. - Or the docs say to sum
github.copilot.nano_aiuover allinvoke_agentspans (root and subagents), or over allchatspans.
Additional context
- Related to OTel spans for subagent calls omit billing attributes (github.copilot.nano_aiu, github.copilot.cost), so external cost accounting undercounts actual billing #4224, which added billing attributes to subagent spans (fixed in 1.0.86). The docs still say to read only the root span.
- The gap is the subagents' share of the session, so it grows with subagent use. In the CLI session above it was 5%; in the app session it was 6%.
Activity