Skip to content

[BUG] Token estimate counts reasoning twice #1591

Closed

Description

@edenreich

Summary

EstimateMessageTokens (internal/conversation/tokenizer.go) adds both msg.Reasoning and msg.ReasoningContent, but the agent stores the same string in both fields: buildAssistantMessage in internal/agent/loop/agent_streaming.go and BuildAgentMessagesFromEntries in internal/conversation/domain/agent_messages.go set both to one value. Every reasoning token is counted twice in the compaction trigger, the rollover gate and the status bar's context estimate. Split out of #1586.

Steps to Reproduce

  1. Build an assistant sdk.Message with Reasoning and ReasoningContent both pointing at the same 4000-char string.
  2. Call TokenizerService.EstimateMessageTokens on it.

Expected Behavior

About 1000 tokens for the reasoning.

Actual Behavior

About 2000. On the run in #1586, 240k chars of reasoning through the first compaction added ~60k phantom tokens to the estimate.

Activity

  1. added
    bug
    on Oct 20, 2026
  2. added theissue type on Oct 20, 2026
  3. moved this from Todo to QA in 2026on Oct 20, 2026
  4. moved this from QA to Done in 2026on Oct 20, 2026
  5. inference-gateway-releaser commented on Oct 20, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.234.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugreleased

    Type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions