Compare
Sorry, something went wrong.
No results found
feat: count sub-agent tokens from subagent.completed events
Parse subagent.completed events in session-state JSONL to capture
sub-agent token usage for sessions without shutdown. This recovers
~13.3M previously uncounted tokens across 3 sessions on this machine.
Key changes:
- Add subagent_rows to CopilotFileDetails for cache persistence
- Parse subagent.completed events (model + totalTokens) in copilot.rs
- Prevent double-counting: clear seg_subagent on shutdown (modelMetrics
already includes sub-agent usage), only trailing segment tokens added
- Include subagent_rows in OTel merge delta base to prevent double-count
with OTel chat spans that also contain sub-agent calls
- Bump STATS_CACHE_VERSION 5→6 to invalidate old caches
- Add 4 unit tests: no-shutdown counting, shutdown no-double-count,
null-field skip, OTel merge no-double-count
新增解析 subagent.completed 事件,捕获无 shutdown 会话的子 agent token。
关键改动:
- CopilotFileDetails 新增 subagent_rows 字段
- 解析 subagent.completed 的 model 和 totalTokens
- 防重复计数:shutdown 时清零 seg_subagent(modelMetrics 已含子 agent)
- OTel 合并时将 subagent_rows 纳入 delta 基准,防止与 chat span 重复
- 缓存版本 5→6
- 新增 4 个单元测试
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>