Skip to content

fix: improve context compression quality — higher limits, tool tracking, degradation warning#6395

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-b0a4b31e
Apr 9, 2026
Merged

fix: improve context compression quality — higher limits, tool tracking, degradation warning#6395
teknium1 merged 2 commits into
mainfrom
hermes/hermes-b0a4b31e

Conversation

@teknium1

@teknium1 teknium1 commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

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:

Content type Before After
Message body 3,000 chars (2000+800) 6,000 chars (4000+1500)
Tool call arguments 500 chars (400 head) 1,500 chars (1200 head)

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:

## Tools & Patterns
[Which tools were used, how they were used effectively, and any
tool-specific discoveries. Accumulate across compactions.]

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:

⚠️  Session compressed 3 times — accuracy may degrade. Consider /new to start fresh.

compression_count was 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 = 1 on the MagicMock in test_flag_reset_on_compression — the new degradation warning reads this attribute as an int, but the existing mock returned a MagicMock object.

Test plan

  • 36 compressor tests pass
  • 23 context pressure tests pass (including the fixed one)
  • py_compile clean on both files

Ref #499

SHL0MS and others added 2 commits April 8, 2026 20:17
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants