Skip to content

fix(conversation): count a message's reasoning once in the token estimate - #1594

Merged
edenreich merged 1 commit into
mainfrom
fix/issue-1591
Oct 20, 2026
Merged

edenreich merged 1 commit into
mainfrom
fix/issue-1591

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Resolves #1591

Summary

EstimateMessageTokens added both Reasoning and ReasoningContent, but buildAssistantMessage and BuildAgentMessagesFromEntries store the same string in both fields. Every reasoning token was counted twice wherever the estimate is used: the compaction trigger, the rollover gate and the status bar's context figure. On the run in #1586 the reasoning through the first compaction was 240k chars, so this was about 60k phantom tokens of the gap to the provider's prompt_tokens.

Changes

  • reasoningOf picks the message's reasoning once, Reasoning first, ReasoningContent as the fallback, and the estimate counts that.
  • TestEstimateMessageTokensCountsReasoningOnce pins that a message with both fields set estimates the same as one with a single field.

no docs ticket: internal bug fix.

…mate

The agent stores the same reasoning text in both Reasoning and
ReasoningContent, and the estimate added both, so every reasoning token
counted twice in the compaction trigger, the rollover gate and the
status bar. On the run in #1586 that was about 60k phantom tokens.
@edenreich
edenreich requested a review from a team as a code owner October 20, 2026 20:36
@github-project-automation github-project-automation Bot moved this to Todo in 2026 Oct 20, 2026
@edenreich edenreich moved this from Todo to QA in 2026 Oct 20, 2026
@edenreich
edenreich merged commit adff866 into main Oct 20, 2026
1 check passed
@edenreich
edenreich deleted the fix/issue-1591 branch October 20, 2026 20:53
@edenreich edenreich moved this from QA to Done in 2026 Oct 20, 2026
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.234.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] Token estimate counts reasoning twice

1 participant