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

Abierto
#5,622 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
Python
Estrellas
11.5k
Forks
2k
Merge medio
6 h 34 min
PR fusionados (30 d)
3

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de github/copilot-cli

Todos los issues de github/copilot-cli

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.