Repository navigation
Python: Sum streamed GitHubCopilotAgent usage across model calls - #10088
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit intoNov 6, 2026
Conversation
Each ASSISTANT_USAGE event carries the usage of a single model call, but the streaming handler emitted it with merge_mode="replace", so core kept only the last call. Emit it with merge_mode="append" so the calls are summed, matching the non-streaming path.
Dineshsuriya D (droideronline)
temporarily deployed
to
github-app-auth
November 4, 2026 08:42 — with
GitHub Actions
Inactive
Dineshsuriya D (droideronline)
temporarily deployed
to
github-app-auth
November 4, 2026 08:42 — with
GitHub Actions
Inactive
Dineshsuriya D (droideronline)
marked this pull request as ready for review
November 4, 2026 08:44
Dineshsuriya D (droideronline)
temporarily deployed
to
github-app-auth
November 4, 2026 08:44 — with
GitHub Actions
Inactive
Member
|
/review |
Contributor
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: No findings
Scope: full PR (1 commit(s)): 1d421d17a1d4
Model: gpt-5.6-sol
Overview
The PR changes streamed ASSISTANT_USAGE updates from replacement to additive merging so core aggregation sums per-model-call deltas, matching the existing non-streaming path. Core's usage merge contract handles missing and invalid counters, while the added regression and existing streaming and non-streaming tests exercise the intended behavior. No Critical, High, or Medium PR-introduced defect was established.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Nov 6, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
A streamed
GitHubCopilotAgentrun that makes several model calls (for example model call, tool call, model call) reports only the usage of the last call. Earlier calls are dropped, so the finalusage_detailsundercounts the run. Anything that records or limits usage from streamed Copilot runs sees only a fraction of the real tokens. The non-streaming path already sums correctly.Description & Review Guide
Each
ASSISTANT_USAGEevent carries the usage of one model call, not a cumulative total. The streaming handler emitted it withmerge_mode="replace", which core treats as "overwrite the running value" (Content._add_usage_content). Each event therefore overwrote the previous one.ASSISTANT_USAGEhandler now emits usage withmerge_mode="append", so core sums the per-call usage withadd_usage_details. A regression test streams three usage events (100/10, 200/20, 300/30) and asserts the final response reports 600/60 (660 total). The test fails onmainwith 300/30.appendis the right choice versus accumulating a running total in the adapter and emitting it withreplace. I choseappendbecause the events are per-call deltas and it is the smaller change.Related Issue
Fixes #10087
AI Assistance
AI assistance details: implementation, tests, and this PR description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.