Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.

Avoid reporting subagent token usage to the context window widget - #3515

Merged
Logan Ramos (lramos15) merged 3 commits into
microsoft:mainfrom
RealSatellite:fix/subagent-usage-context-widget
Mar 6, 2026
Merged

Logan Ramos (lramos15) merged 3 commits into
microsoft:mainfrom
RealSatellite:fix/subagent-usage-context-widget

Conversation

@RealSatellite

Copy link
Copy Markdown
Contributor

Summary

When a request is executed in a subagent context (i.e. request.subAgentInvocationId is 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

  • Gate stream.usage(...) reporting in ToolCallingLoop so it only runs for non-subagent requests.
  • Add a unit test verifying:
    • regular requests report usage
    • subagent requests do not report usage

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.ts

Notes

This change only affects usage reporting for the context window widget and does not change server requests or token accounting elsewhere.

Avoid reporting token usage from subagent requests to the context window widget. Add unit tests covering subagent vs regular usage reporting.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 when subAgentInvocationId is 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

@rzhao271 Raymond Zhao (rzhao271) modified the milestones: February 2026, March 2026 Feb 27, 2026
@lramos15

Copy link
Copy Markdown
Member

@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

auto-merge was automatically disabled March 2, 2026 16:55

Head branch was pushed to by a user without write access

@RealSatellite

Copy link
Copy Markdown
Contributor Author

Hi Logan Ramos (@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!

@bpasero
Benjamin Pasero (bpasero) removed their request for review March 2, 2026 20:07
@joaomorenoalt João Moreno (joaomorenoalt) removed this from the March 2026 milestone Mar 3, 2026
@RealSatellite

Copy link
Copy Markdown
Contributor Author

Logan Ramos (@lramos15) Happy to address any remaining feedback. is there anything blocking this from merging?

@vs-code-engineering vs-code-engineering Bot added this to the 1.111.0 milestone Mar 6, 2026
@lramos15
Logan Ramos (lramos15) added this pull request to the merge queue Mar 6, 2026
Merged via the queue into microsoft:main with commit 2128b11 Mar 6, 2026
13 of 16 checks passed
@RealSatellite
Ayush (RealSatellite) deleted the fix/subagent-usage-context-widget branch March 6, 2026 20:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants