OTel: Subagent chat spans after write_agent lose gen_ai.usage.* attributes and report parent model name
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 48/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- python
- 領域
- backend, observability
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- Python
- 星號
- 11.5k
- 分支
- 2k
- 平均合併
- 6 小時 34 分鐘
- 30 天內合併 PR
- 3
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
github/copilot-cli 的其他 Issue
-
area:plugins
難度 2/5 1-3 小時 新手友好度 75/100
github/copilot-cli#5567 ·
-
難度 1/5 1-3 小時 新手友好度 78/100
github/copilot-cli#5489 ·
-
Built-in functions.view returns no content for large files despite documenting automatic truncation未關閉area:tools
難度 2/5 1-3 小時 新手友好度 72/100
github/copilot-cli#5476 ·
-
triage
難度 1/5 1 小時以內 新手友好度 74/100
github/copilot-cli#5377 ·
-
area:platform-windows area:tools
難度 1/5 1 小時以內 新手友好度 74/100
github/copilot-cli#5340 ·
查看 github/copilot-cli 的全部 Issue
相似的 Issue
-
fidelity
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
-
backlog
難度 2/5 1-3 小時 新手友好度 72/100
sagemathinc/sagebrush#3434 ·
維護者通常 1 天內回覆
-
marketing
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 1 天內回覆
-
documentation good first issue help wanted
難度 2/5 1-3 小時 新手友好度 78/100
wuisabel-gif/MemWhale#576 ·
維護者通常 1 天內回覆
-
Status: Triage Suggestion
難度 2/5 1-3 小時 新手友好度 68/100
GTNewHorizons/GT-New-Horizons-Modpack#27957 ·
維護者通常 1 天內回覆