OTel: Subagent chat spans after write_agent lose gen_ai.usage.* attributes and report parent model name
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- backend, observability
Direzione di ricerca
Start by tracing how OpenTelemetry spans are created for background subagent turns and how write_agent resumes or steers them; the issue does not name relevant files or tests. Compare span context and model selection with usage-record correlation before and after write_agent. Done means resumed subagent chat spans retain their own invoke_agent parent, model name, and token usage attributes across follow-up turns.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
When a background subagent is launched via task(..., mode: "background", model: "<subagent-model>"), its initial OpenTelemetry spans export normally under an invoke_agent <agent_type> child span with the subagent's gen_ai.request.model and gen_ai.usage.{input_tokens,output_tokens} attributes populated.
However, as soon as the parent session sends a message to that background subagent via write_agent (either waking an idle subagent for a multi-turn follow-up or steering a running subagent), all subsequent OTel chat spans produced by the subagent exhibit two telemetry regressions:
- Wrong model and parent span attribution: Once the initial
invoke_agent <agent_type>span closes, no newinvoke_agentspan is opened for thewrite_agentturn. Subsequent subagentchatandexecute_toolspans attach directly to the parent session's span, and the subagent'schatspans are namedchat <parent-model>withgen_ai.request.model = "<parent-model>"instead of<subagent-model>(even thoughgen_ai.input.messages/gen_ai.output.messageson those spans belong to the subagent). - Missing token usage attributes (
gen_ai.usage.*): Althoughevents.jsonlstill writes completesession.usage_recordentries for the subagent (usage.accounting.sourceSessionId = "<subagent-session-id>",usage.model = "<subagent-model>",inputTokens,outputTokens,cacheReadTokens), the OTel exporter fails to attach usage metrics to those post-write_agentchatspans —gen_ai.usage.input_tokensandgen_ai.usage.output_tokensare completely absent on every subsequent subagentchatspan. Downstream OTel collectors / Prometheusspanmetricspipelines therefore drop 100% of subagent token consumption afterwrite_agent.
Affected version
1.0.115-7 (GitHub Copilot App / copilot-agent)
Steps to reproduce the behavior
- Enable OpenTelemetry trace export (
OTEL_EXPORTER_OTLP_ENDPOINT/ OTLP receiver such as Grafana Alloy + Tempo). - Start a parent session running
<parent-model>(e.g.gemini-4-neon). - Have the parent launch a background subagent running a different
<subagent-model>(e.g.task(agent_type: "general-purpose", mode: "background", model: "gemini-4-hydrogen", ...)). - Observe in Tempo that initial subagent LLM calls appear under
invoke_agent general-purposeaschat gemini-4-hydrogenwithgen_ai.request.model = "gemini-4-hydrogen"andgen_ai.usage.input_tokens/gen_ai.usage.output_tokenspopulated. - Have the parent send a follow-up or steering message via
write_agent(agent_id: "<subagent-id>", message: "...")(reproduces both when the subagent isidlebetween turns and whenrunning). - Inspect the newly exported OTel
chatspans for the subagent's subsequent turns in Tempo:- Span name is
chat gemini-4-neon(gen_ai.request.model = "gemini-4-neon") instead ofgemini-4-hydrogen. gen_ai.usage.input_tokensandgen_ai.usage.output_tokensare missing (null), whileevents.jsonland localassistant_usage_eventsstill record the subagent'sgemini-4-hydrogentoken usage normally.
- Span name is
Expected behavior
After write_agent wakes or steers a background subagent:
- Subsequent subagent turns should be scoped under a subagent
invoke_agentspan (preserving trace hierarchy) and report the subagent's actualgen_ai.request.model(chat <subagent-model>). session.usage_recordevents forsourceSessionId = "<subagent-session-id>"should continue binding to the corresponding subagentchatspans sogen_ai.usage.input_tokens,gen_ai.usage.output_tokens, and cache token attributes remain populated across multi-turnwrite_agentinteractions.
Additional context
- Surface: GitHub Copilot App (
service.name = "github-copilot-app",otel.scope.name = "github.copilot",otel.scope.version = "1.0.115-7") - OS / Arch: macOS (ARM64)
- Root-cause clue from
events.jsonlvs Tempo: Afterwrite_agent, subagentassistant.turn_startevents still reference the originalparentToolCallIdfrom the initialtaskcall (whoseinvoke_agentspan has already closed), whilesession.usage_recordcarriesusage.accounting.sourceSessionId = "<subagent-native-session-id>"andassistant.messagecarriesapiCallId. The OTel span tracker appears to fall back to the parent session's active span/model context and misses the usage-record correlation for subagent turns resumed viawrite_agent.
- Lingua principale
- Python
- Stelle
- 11.5k
- Fork
- 2k
- Merge medio
- 6h 34m
- PR unite (30g)
- 3
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi 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.
Altre issue di github/copilot-cli
-
area:plugins
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
github/copilot-cli#5567 ·
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
github/copilot-cli#5489 ·
-
Built-in functions.view returns no content for large files despite documenting automatic truncationApertaarea:tools
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
github/copilot-cli#5476 ·
-
triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 74/100
github/copilot-cli#5377 ·
-
area:platform-windows area:tools
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 74/100
github/copilot-cli#5340 ·
Tutte le issue di github/copilot-cli
Issue simili
-
fidelity
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
backlog
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
sagemathinc/sagebrush#3434 ·
I maintainer di solito rispondono entro 1 giorno
-
marketing
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
documentation good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
wuisabel-gif/MemWhale#576 ·
I maintainer di solito rispondono entro 1 giorno
-
Status: Triage Suggestion
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
GTNewHorizons/GT-New-Horizons-Modpack#27957 ·
I maintainer di solito rispondono entro 1 giorno