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

Ouverte
#5,622 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
48/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
python

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.
Langage dominant
Python
Étoiles
11.5k
Forks
2k
Merge moyen
6 h 34 min
PR mergées (30 j)
3

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de github/copilot-cli

Toutes les issues de github/copilot-cli

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.