.NET: Preserve cached and reasoning token counts in Foundry Hosting - #8334
Open
Manjunath Janardhan (manjunathshiva) wants to merge 1 commit into
Open
Conversation
Manjunath Janardhan (manjunathshiva)
deployed
to
github-app-auth
September 12, 2026 17:30 — with
GitHub Actions
Active
Manjunath Janardhan (manjunathshiva)
deployed
to
github-app-auth
September 12, 2026 17:30 — with
GitHub Actions
Active
Manjunath Janardhan (manjunathshiva)
deployed
to
github-app-auth
September 12, 2026 17:30 — with
GitHub Actions
Active
Manjunath Janardhan (manjunathshiva)
deployed
to
github-app-auth
September 12, 2026 17:30 — with
GitHub Actions
Active
Copilot started reviewing on behalf of
Manjunath Janardhan (manjunathshiva)
September 12, 2026 17:30
View session
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation correctly preserves compatibility and is comprehensively covered by regression tests.
Pull request overview
Fixes #6823 by preserving provider-reported cached-input and reasoning-token counts in Foundry Hosting.
Changes:
- Prefer dedicated usage counters while retaining legacy dictionary fallbacks.
- Add regression coverage for precedence, explicit zeroes, fallback, and terminal-event accumulation.
File summaries
| File | Description |
|---|---|
dotnet/src/Microsoft.Agents.AI.Foundry.Hosting/OutputConverter.cs |
Corrects usage-counter conversion and fallback behavior. |
dotnet/tests/Microsoft.Agents.AI.Foundry.Hosting.UnitTests/OutputConverterTests.cs |
Covers counter representations, precedence, and accumulation. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced (auto)
Note
Copilot is running an experiment and ran this review at Balanced.
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Manjunath Janardhan (manjunathshiva)
marked this pull request as ready for review
September 12, 2026 17:32
Manjunath Janardhan (manjunathshiva)
deployed
to
github-app-auth
September 12, 2026 17:32 — with
GitHub Actions
Active
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
Foundry Hosting reports cached input and reasoning tokens as zero when providers populate the dedicated
UsageDetailsproperties. For example,CachedInputTokenCount = 34304andReasoningTokenCount = 128become zero in the completed response, while input/output/total counts remain correct.Description & Review Guide
CachedInputTokenCountandReasoningTokenCountfirst, falling back to each existingAdditionalCountskey only when the dedicated property is absent. Add nine regression cases covering missing values, explicit zero, conflicting and mixed representations, and accumulation into completed and failed responses.Verified with .NET SDK 10.0.401 on macOS arm64: seven regression cases failed before the fix; all nine pass afterward. All 473 Foundry Hosting tests pass. The full solution builds with zero warnings/errors; the enabled .NET 10 Debug unit suite passes 7,322 tests with 65 skipped and no failures, preserving the solution's existing Feature Registry Debug exclusion. Formatting checks pass. Reproduction uses the actual in-process converter; no live Azure/model calls were required.
Related Issue
Fixes #6823
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.