fix: exclude completion_tokens from compression trigger for reasoning models#12071
Closed
nightq wants to merge 1 commit into
Closed
fix: exclude completion_tokens from compression trigger for reasoning models#12071nightq wants to merge 1 commit into
nightq wants to merge 1 commit into
Conversation
…emature compression for reasoning models Fixes NousResearch#12026 Root cause: Compression trigger was summing prompt_tokens + completion_tokens, but completion_tokens for reasoning models includes internal thinking tokens that don't consume context window space. This caused premature compression when models like GLM-5.1, QwQ, etc. used ~42% of actual context. Fix: Use only prompt_tokens for compression trigger calculation.
Contributor
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.
Summary
Fixes premature context compression for reasoning models (GLM-5.1, QwQ, etc.) by excluding completion_tokens from the compression trigger calculation.
Root Cause
The compression trigger was summing to determine when to compress context. For reasoning models, includes internal thinking/reasoning tokens that are ephemeral output and don't consume context window space for the next API call.
This caused compression to fire when the model had only used ~42% of its actual context window, because reasoning tokens inflated the calculated token count past the 50% threshold.
Example:
Fix
Use only for the compression trigger. The prompt already represents actual context window consumption — it's what the provider charges for and what determines whether the next request will fit.
Impact
Test Plan
Closes #12026