OTel: Subagent chat spans after write_agent lose gen_ai.usage.* attributes and report parent model name

Aberta
#5,622 1 comentário 0 reações 0 responsáveis Ver no GitHub

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

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

area:agents
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:

  1. Wrong model and parent span attribution: Once the initial invoke_agent <agent_type> span closes, no new invoke_agent span is opened for the write_agent turn. Subsequent subagent chat and execute_tool spans attach directly to the parent session's span, and the subagent's chat spans are named chat <parent-model> with gen_ai.request.model = "<parent-model>" instead of <subagent-model> (even though gen_ai.input.messages / gen_ai.output.messages on those spans belong to the subagent).
  2. Missing token usage attributes (gen_ai.usage.*): Although events.jsonl still writes complete session.usage_record entries 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_agent chat spans — gen_ai.usage.input_tokens and gen_ai.usage.output_tokens are completely absent on every subsequent subagent chat span. Downstream OTel collectors / Prometheus spanmetrics pipelines therefore drop 100% of subagent token consumption after write_agent.
Affected version

1.0.115-7 (GitHub Copilot App / copilot-agent)

Steps to reproduce the behavior
  1. Enable OpenTelemetry trace export (OTEL_EXPORTER_OTLP_ENDPOINT / OTLP receiver such as Grafana Alloy + Tempo).
  2. Start a parent session running <parent-model> (e.g. gemini-4-neon).
  3. 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", ...)).
  4. Observe in Tempo that initial subagent LLM calls appear under invoke_agent general-purpose as chat gemini-4-hydrogen with gen_ai.request.model = "gemini-4-hydrogen" and gen_ai.usage.input_tokens / gen_ai.usage.output_tokens populated.
  5. Have the parent send a follow-up or steering message via write_agent(agent_id: "<subagent-id>", message: "...") (reproduces both when the subagent is idle between turns and when running).
  6. Inspect the newly exported OTel chat spans for the subagent's subsequent turns in Tempo:
    • Span name is chat gemini-4-neon (gen_ai.request.model = "gemini-4-neon") instead of gemini-4-hydrogen.
    • gen_ai.usage.input_tokens and gen_ai.usage.output_tokens are missing (null), while events.jsonl and local assistant_usage_events still record the subagent's gemini-4-hydrogen token usage normally.
Expected behavior

After write_agent wakes or steers a background subagent:

  • Subsequent subagent turns should be scoped under a subagent invoke_agent span (preserving trace hierarchy) and report the subagent's actual gen_ai.request.model (chat <subagent-model>).
  • session.usage_record events for sourceSessionId = "<subagent-session-id>" should continue binding to the corresponding subagent chat spans so gen_ai.usage.input_tokens, gen_ai.usage.output_tokens, and cache token attributes remain populated across multi-turn write_agent interactions.
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.jsonl vs Tempo: After write_agent, subagent assistant.turn_start events still reference the original parentToolCallId from the initial task call (whose invoke_agent span has already closed), while session.usage_record carries usage.accounting.sourceSessionId = "<subagent-native-session-id>" and assistant.message carries apiCallId. 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 via write_agent.
Linguagem predominante
Python
Estrelas
11.5k
Forks
2k
Merge médio
6h 34min
PRs com merge (30d)
3

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de github/copilot-cli

Todas as issues de github/copilot-cli

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.