Repository navigation
Backlog
Labels
area:agentsSub-agents, fleet, autopilot, plan mode, background agents, and custom agents
Description
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.
Metadata
Metadata
Assignees
Labels
area:agentsSub-agents, fleet, autopilot, plan mode, background agents, and custom agents
Activity
tcx4c70 commentedon Nov 30, 2026
Additional reproduction path (without
write_agent): parallelbackgroundsubagentsFurther testing shows the underlying issue is broader than
write_agentalone — any new top-level turn in the parent session while amode: "background"subagent is still running triggers the exact same telemetry regression:<parent-model>, e.g.gemini-4-neon) dispatches twomode: "background"subagents in parallel in the same turn — Subagent A (gpt-6.2-sol, fast) and Subagent B (grok-4.7, slower).chatspans under their respectiveinvoke_agentspans with accurategen_ai.request.modelandgen_ai.usage.{input_tokens,output_tokens}.<system_notification>to the parent session, starting a new parent turn (e.g. callingread_agenton Subagent A) and opening a new parent trace.invoke_agentspan.chat <parent-model>(gen_ai.request.model = "<parent-model>") withgen_ai.usage.input_tokensandgen_ai.usage.output_tokensmissing (null), even thoughevents.jsonlcontinues recording completesession.usage_recordevents for Subagent B.This suggests the OTel span tracker ties subagent
invoke_agentspan lifetimes and usage-record routing to the single parent interaction turn that spawned them, rather than maintaining independent per-sourceSessionIdsubagent span state across parent turn boundaries.