Skip to content

.NET: Preserve GitHub Copilot reasoning token usage - #9773

Open
ZedingZhang (ZedingZhang) wants to merge 1 commit into
microsoft:mainfrom
ZedingZhang:fix/copilot-reasoning-token-usage
Open

ZedingZhang (ZedingZhang) wants to merge 1 commit into
microsoft:mainfrom
ZedingZhang:fix/copilot-reasoning-token-usage

Conversation

@ZedingZhang

@ZedingZhang ZedingZhang (ZedingZhang) commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Motivation & Context

The Copilot SDK reports reasoning-token counts in AssistantUsageEvent, but GitHubCopilotAgent drops them when constructing UsageDetails.

Description & Review Guide

  • What are the major changes? Copy AssistantUsageData.ReasoningTokens into the existing UsageDetails.ReasoningTokenCount property. Add four offline regression cases for a positive count, zero, a missing counter, and missing usage data.
  • What is the impact of these changes? Reported reasoning-token counts survive conversion. Input, output, cached-input, and total token counts keep their current values. This adds no public API or dependency.
  • What do you want reviewers to focus on? Nullable counter preservation and the unchanged total. The regression control fails for positive and zero counts before the fix; both missing-data cases pass. Verified with SDK 10.0.401 on macOS arm64: full solution build (0 warnings/errors); all 32 unit-test projects on .NET 10 (9,865 passed, 74 skipped, 0 failed); and scoped dotnet format --verify-no-changes for both changed projects. The unit-test run used an English locale and Python 3.12 for unrelated locale-sensitive/Python subprocess tests. Copilot alone has 51 passed and 2 platform/privilege skips.

Related Issue

Related to #9684, reasoning-token item only. The broader issue remains open.

N/A - trivial change: this corrects an unambiguous dropped counter by copying an existing SDK property into its existing usage counterpart. It requires no API, representation, or execution-policy decision. No competing open PR for this mapping was found. The issue does not currently carry maintainer implementation approval, so this submission relies on the trivial-change exception.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: OpenAI Codex assisted with issue analysis, implementation, regression tests, and this PR description. Codex executed the reported build, test, and formatting commands. I reviewed all submitted content and take responsibility for it.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

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.

🟢 Approval recommended

The narrow, null-safe mapping preserves zero and missing values, leaves totals unchanged, and has focused regression coverage with no identified defects.

No open issues 🎉

What changed in this PR

Preserves reasoning-token usage reported by the Copilot SDK in the .NET agent adapter, addressing the reasoning-token portion of #9684 without changing other token counts.

Changes:

  • Maps the nullable SDK reasoning-token count to UsageDetails.ReasoningTokenCount.
  • Adds four regression cases covering positive, zero, missing-counter, and missing-data values while verifying existing counts remain unchanged.
File Description
dotnet/​tests/​Microsoft.Agents.AI.GitHub.Copilot.UnitTests/​GitHubCopilotAgentTests.cs Adds reasoning-token preservation regression tests.
dotnet/​src/​Microsoft.Agents.AI.GitHub.Copilot/​GitHubCopilotAgent.cs Copies reasoning-token usage into response usage details.

Review effort: Balanced

This branch was previously deployed

1 inactive deployment
github-app-auth — d1f962a5 Deployed Oct 27, 2026 by ZedingZhang via add_label #26353
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants