Skip to content

fix(schema): add missing CompletionTokensDetails.ReasoningTokens handling in ConcatMessages#886

Merged
shentongmartin merged 1 commit intocloudwego:mainfrom
jesse-engineer:fix/concat_messages_reasoning_tokens
Mar 15, 2026
Merged

fix(schema): add missing CompletionTokensDetails.ReasoningTokens handling in ConcatMessages#886
shentongmartin merged 1 commit intocloudwego:mainfrom
jesse-engineer:fix/concat_messages_reasoning_tokens

Conversation

@jesse-engineer
Copy link
Copy Markdown
Contributor

Summary

  • ConcatMessages merges TokenUsage fields (PromptTokens, CompletionTokens, TotalTokens, PromptTokenDetails.CachedTokens) when concatenating streamed messages, but omits CompletionTokensDetails.ReasoningTokens, causing reasoning token counts to be lost after stream concatenation.
  • This PR adds the missing CompletionTokensDetails.ReasoningTokens handling, using the same "keep the larger value" strategy as the other token fields.
  • Updated existing test case response_meta to cover ReasoningTokens.

Test plan

  • Updated TestConcatMessage/response_meta to include CompletionTokensDetails.ReasoningTokens in both input messages and expected output
  • All existing tests pass (go test ./schema/ -run TestConcatMessage -v)

Made with Cursor

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.77%. Comparing base (14e3696) to head (fe62457).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #886      +/-   ##
==========================================
- Coverage   81.80%   81.77%   -0.04%     
==========================================
  Files         146      146              
  Lines       16033    16035       +2     
==========================================
- Hits        13116    13112       -4     
- Misses       1969     1975       +6     
  Partials      948      948              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ling in ConcatMessages

ConcatMessages merges TokenUsage fields (PromptTokens, CompletionTokens,
TotalTokens, PromptTokenDetails.CachedTokens) but omits
CompletionTokensDetails.ReasoningTokens, causing reasoning token counts
to be lost when concatenating streamed messages.

Made-with: Cursor
@jesse-engineer jesse-engineer force-pushed the fix/concat_messages_reasoning_tokens branch from 8e58ba5 to fe62457 Compare March 15, 2026 12:48
@shentongmartin shentongmartin merged commit 2033c27 into cloudwego:main Mar 15, 2026
15 of 16 checks passed
shentongmartin pushed a commit that referenced this pull request Mar 17, 2026
…ling in ConcatMessages (#886)

ConcatMessages merges TokenUsage fields (PromptTokens, CompletionTokens,
TotalTokens, PromptTokenDetails.CachedTokens) but omits
CompletionTokensDetails.ReasoningTokens, causing reasoning token counts
to be lost when concatenating streamed messages.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants