fix: improve context compression quality — higher limits, tool tracking, degradation warning#6395
Merged
Conversation
…king, degradation warning Three targeted improvements to the compression system: 1. Replace hardcoded truncation limits with named class constants (_CONTENT_MAX=6000, _CONTENT_HEAD=4000, _CONTENT_TAIL=1500, _TOOL_ARGS_MAX=1500, _TOOL_ARGS_HEAD=1200). Previous limits (3000/500) heavily truncated the summarizer's input — a 200-line edit got cut to 3000 chars before the summarizer ever saw it. 2. Add '## Tools & Patterns' section to both compression prompt templates (first-pass and iterative). Preserves working tool invocations, preferred flags, and tool-specific discoveries across compaction boundaries. 3. Warn users on 2nd+ compression: 'Session compressed N times — accuracy may degrade. Consider /new to start fresh.' Ref #499
The new degradation warning reads compression_count as an int, but the existing test's MagicMock returns a MagicMock object for that attribute, causing '>=' comparison to fail.
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
Salvage of PR #4156 by @SHL0MS (cherry-picked onto current main) with one test fix.
Three targeted improvements to context compression quality, addressing the most impactful issues from #499.
1. Higher serializer truncation limits (3K → 6K)
The summarizer model was working from heavily truncated data. Magic numbers replaced with named class constants:
These only affect input to the auxiliary summarizer model — no impact on the main model's context or prompt cache.
2. "Tools & Patterns" section in compression prompts
Both prompt templates (first-pass and iterative-update) now include:
Preserves HOW tools were used effectively across compaction boundaries — the agent often re-discovers effective flag combos after compression.
3. Degradation warning after repeated compressions
After 2+ compressions:
compression_countwas tracked internally but never surfaced to the user. Uses_vprint(force=True)— purely user-facing, does NOT inject into the message stream or affect prompt caching.Follow-up fix
Set
compression_count = 1on the MagicMock intest_flag_reset_on_compression— the new degradation warning reads this attribute as an int, but the existing mock returned a MagicMock object.Test plan
py_compileclean on both filesRef #499