P2 Context Compression Infinite Loop — Aux Model Too Small (#53008)
Executive Summary
When the auxiliary compression model has a context window smaller than the main model's compression threshold, check_compression_model_feasibility() auto-lowers the session threshold to the aux model's context size. This creates an infinite compression loop when the session's actual token count exceeds the aux model's capacity — compression triggers every turn, is near-zero effective, and the threshold never recovers. Three distinct design flaws identified with a clean fix roadmap.
The Chain Reaction
- Main model: deepseek-v4-pro (1M context), threshold 0.5 → 500K tokens
- Aux model: Qwen2.5-7B (131K context)
check_compression_model_feasibility()sees 131K < 500K → lowers threshold to 131K- Session reaches ~205K tokens > 131K threshold → compression triggers every turn
- Aux model (131K context) cannot process 205K of input → compression near-zero effective: 245→243 messages, 205K→204K tokens
- After compression: ~204K > 131K threshold → next turn triggers again → infinite loop
Log Evidence
Three Design Flaws
| Flaw | Location | Detail |
|---|---|---|
| 1. Single-direction threshold | check_compression_model_feasibility() | threshold_tokens lowered but never restored — no mechanism to raise it back when conditions change |
| 2. No effectiveness check | 3-pass loop in turn_context.py | Only checks message count reduction, not actual token reduction. 245→243 messages passes the check even though 205K→204K is meaningless |
| 3. No main-model fallback | Compression pipeline | When aux model fails, there's no fallback to use the main model (1M context) for compression — even though the main model could handle it trivially |
Impact Assessment
| Dimension | Severity | Detail |
|---|---|---|
| Token Cost | HIGH | Compression runs every turn consuming tokens with near-zero benefit — 16+ wasted compression cycles per session |
| Performance | HIGH | Every turn triggers an expensive aux-model call that does nothing — adds latency with no gain |
| Configuration | HIGH | Silent misconfiguration — user doesn't know aux model is too small until they notice the compression spam |
| Fix Complexity | MODERATE | 3 changes: 80% safety margin on auto-lower, 10% minimum reduction check, main-model fallback |
Proposed Fix (3 Changes)
- 80% safety margin on threshold auto-lower: When aux model context is smaller than threshold, lower to
aux_context * 0.8instead ofaux_context— prevents the threshold from sitting right at the aux model's limit - Effectiveness verification with 10% reduction minimum: Check actual token reduction, not just message count. If compression reduces tokens by <10%, skip it and log a warning
- Main-model fallback: When aux model is too small (<50% of session tokens), fall back to using the main model for compression — the main model has the context capacity
Workaround: Set compression.threshold: 0.10 (100K for 1M models) so Qwen2.5-7B at 131K exceeds it → no auto-lower triggered.
Source Evidence
- GitHub Issue: #53008 — Context Compression Infinite Loop
- Opened: June 26, 2026
- Reporter: @xiaoou-hermes
- Labels: P2, bug, comp/agent, type/bug
- Hermes: v0.17.0 | OS: Ubuntu 24.04 | Python: 3.11.15
📋 https://hermes-agent.reviews/hermes-context-compression-infinite-loop-53008.html
Tracked by hermes-agent.reviews — June 26, 2026