OTel spans for subagent calls omit billing attributes (github.copilot.nano_aiu, github.copilot.cost), so external cost accounting undercounts actual billing
Nessuno ha ancora preso questa issue.
- Lingua principale
- Shell
- Stelle
- 11.2k
- Fork
- 1.9k
- Merge medio
- 14h 16m
- PR unite (30g)
- 6
Descrizione
Describe the bug
When a session delegates work to subagents (the task tool / custom agents), the OTel spans for those subagent model calls omit all billing attributes. The subagent calls consume real AI credits (per the cumulative session display — see #4207, which notes session usage "including usage by the main agent, subagents, and background operations"), but that consumption is invisible to OpenTelemetry, so any external cost accounting built on the documented OTel telemetry (copilot help monitoring) systematically undercounts actual billing.
Main-agent chat spans carry the full billing envelope:
github.copilot.nano_aiugithub.copilot.costgithub.copilot.initiator(user/agent)github.copilot.interaction_id/github.copilot.turn_id
Subagent model calls emit spans with correct gen_ai.* semconv attributes (gen_ai.operation.name, gen_ai.request.model, gen_ai.usage.input_tokens / output_tokens / cache_read.input_tokens / cache_creation.input_tokens) but carry none of the github.copilot.* billing attributes — no nano_aiu, no cost, not even initiator or an interaction id. This holds at every level:
- The subagent's child
chatspans: no billing attributes. - The subagent's own nested
invoke_agentspan (which does carrygen_ai.agent.nameand rolled-up token counts): no billing attributes. - The session root
invoke_agentspan'sgithub.copilot.nano_aiurollup equals the sum of the main-agentchatspans'nano_aiuexactly — i.e. the subagent spend is not folded in anywhere.
Observed within a single trace from one session (models are our configured custom-agent models; the same holds for built-in task delegation):
| Span | Model | gen_ai.usage.input_tokens |
nano_aiu |
cost |
|---|---|---|---|---|
root invoke_agent |
claude-fable-5 | 1,963,612 | 506,956,900,000 | 13 |
main-agent chat × 13 |
claude-fable-5 | … | present on every one; sums to exactly 506,956,900,000 | 1 each |
nested invoke_agent (custom agent A) |
claude-haiku-4.5 | 296,978 | absent | absent |
nested invoke_agent (custom agent B) |
gpt-5.6-terra | 155,061 | absent | absent |
subagent chat spans |
claude-haiku-4.5 / gpt-5.6-terra | 124K–321K each | absent | absent |
In our sessions the unreported subagent calls account for roughly 10–15% of estimated session cost (rate-card priced from the token counts, which are reported).
Affected version
GitHub Copilot CLI 1.0.73
Steps to reproduce the behavior
- Enable OTel export (
COPILOT_OTEL_ENABLEDwith an OTLP endpoint, orCOPILOT_OTEL_FILE_EXPORTER_PATH). - Run an interactive session and issue a prompt that delegates to a subagent — e.g. a custom agent configured with a different model, or anything that triggers the
tasktool. - Inspect the exported spans for the session trace.
- Main-agent
chatspans carrygithub.copilot.nano_aiu/github.copilot.cost; the subagentinvoke_agentandchatspans carry token usage but no billing attributes, and the root rollup excludes them.
Expected behavior
Subagent model calls should carry the same billing attributes as main-agent calls (github.copilot.nano_aiu, github.copilot.cost), so that OTel-based cost accounting matches what is actually billed. Alternatively, if this is intentional (subagent calls genuinely bill zero credits), it would be great to have that documented in copilot help billing / the monitoring docs — though the cumulative session credit display suggests they are billed.
Additional context
- OS: Windows 11, x86_64, Windows Terminal / PowerShell (also reproduced from sessions on the same version exporting via OTLP to an OpenTelemetry Collector).
- Related issues: #4207 (per-subagent credit breakdown in
/usage— confirms subagent usage is part of session credit consumption), #1582 (/usageundercounts quota consumption; suspects background operations), #2068 (background compaction consumes a premium request), #4107 (verifiednano_aiumatches the interactive footer exactly for main-agent sessions — the mismatch reported here only appears once subagents are involved), #3778 (OTel cost metric feature request). - Happy to provide sanitized span exports (main-agent vs subagent, same trace) on request.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la telemetria di Copilot CLI documentata da copilot help monitoring, quindi riproduci il problema usando lo strumento task o un agente personalizzato con l’esportazione OTel abilitata. Confronta gli span chat dell’agente principale con gli span invoke_agent e chat del subagente, incluso il session root rollup. L’attività è completata quando gli attributi di fatturazione e l’utilizzo del subagente sono rappresentati in modo coerente, oppure quando il comportamento di fatturazione è documentato se quelle chiamate sono intenzionalmente gratuite.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- github
- Ambito
- cli, observability
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100