Avoid reporting subagent token usage to the context window widget#3515
Conversation
Avoid reporting token usage from subagent requests to the context window widget. Add unit tests covering subagent vs regular usage reporting.
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 |
|
@bharatvansh Can you updaet and resync with main to unsitck the test? I don't know why GitHub isn't showing me the button to do just that |
Head branch was pushed to by a user without write access
|
Hi @lramos15 , I've resynced with main and fixed the toolCallingLoopUsage test failures. The CI are green now. You can take another look and re-enable auto-merge. Thanks! |
|
@lramos15 Happy to address any remaining feedback. is there anything blocking this from merging? |
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.