Avoid reporting subagent token usage to the context window widget#3515
Open
bharatvansh wants to merge 1 commit intomicrosoft:mainfrom
Open
Avoid reporting subagent token usage to the context window widget#3515bharatvansh wants to merge 1 commit intomicrosoft:mainfrom
bharatvansh wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Avoid reporting token usage from subagent requests to the context window widget. Add unit tests covering subagent vs regular usage reporting.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents subagent token usage from being reported to the context window widget in the chat input, ensuring users only see token usage from the parent request.
Changes:
- Added
shouldReportUsageToContextWidget()method that returns false whensubAgentInvocationIdis set - Gated the
stream.usage(...)call to only report usage for non-subagent requests - Added comprehensive unit tests verifying usage reporting behavior for both regular and subagent requests
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/extension/intents/node/toolCallingLoop.ts |
Added private helper method to check if usage should be reported and updated the usage reporting condition to exclude subagent requests |
src/extension/intents/test/node/toolCallingLoopUsage.spec.ts |
New test file with comprehensive tests for usage reporting behavior in regular vs subagent contexts |
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.
Summary
When a request is executed in a subagent context (i.e.
request.subAgentInvocationIdis set), we should not report token usage to the context window widget in the chat input. The widget should reflect only the parent request’s usage; otherwise subagent/tool traffic can inflate what the user sees.Changes
stream.usage(...)reporting inToolCallingLoopso it only runs for non-subagent requests.Why
Subagents may run additional model calls and tool loops. Reporting their usage to the parent request’s context widget misrepresents the request’s actual context usage and can confuse users.
Testing
npm run test:unit -- src/extension/intents/test/node/toolCallingLoopUsage.spec.tsNotes
This change only affects usage reporting for the context window widget and does not change server requests or token accounting elsewhere.