OTel: Subagent chat spans after write_agent lose gen_ai.usage.* attributes and report parent model name
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 48/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Ativa
- Stack de tecnologia
- python
- Domínio
- backend, observability
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 11.5k
- Forks
- 2k
- Merge médio
- 6h 34min
- PRs com merge (30d)
- 3
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de github/copilot-cli
-
area:plugins
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
github/copilot-cli#5567 ·
-
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 78/100
github/copilot-cli#5489 ·
-
Built-in functions.view returns no content for large files despite documenting automatic truncationAbertaarea:tools
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
github/copilot-cli#5476 ·
-
triage
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 74/100
github/copilot-cli#5377 ·
-
area:platform-windows area:tools
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 74/100
github/copilot-cli#5340 ·
Todas as issues de github/copilot-cli
Issues semelhantes
-
marketing
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
Mantenedores costumam responder em até 1 dia
-
Status: Triage Suggestion
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
GTNewHorizons/GT-New-Horizons-Modpack#27957 ·
Mantenedores costumam responder em até 1 dia
-
[Suggestion]: NoParrotAberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 92/100
collabnix/awesome-mcp-lists#515 ·
Mantenedores costumam responder em até 1 dia
-
Look-ahead bias via resample('1min').interpolate(method='time') in CCIStrategy and ReinforcedQuickieAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
documentation good first issue
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 90/100
Mantenedores costumam responder em até 1 dia