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

  1. Main model: deepseek-v4-pro (1M context), threshold 0.5 → 500K tokens
  2. Aux model: Qwen2.5-7B (131K context)
  3. check_compression_model_feasibility() sees 131K < 500K → lowers threshold to 131K
  4. Session reaches ~205K tokens > 131K threshold → compression triggers every turn
  5. Aux model (131K context) cannot process 205K of input → compression near-zero effective: 245→243 messages, 205K→204K tokens
  6. After compression: ~204K > 131K threshold → next turn triggers again → infinite loop

Log Evidence

Compression Log
⚠️ Session compressed 12 times — accuracy may degrade. ⚠️ Session compressed 16 times — accuracy may degrade. ⚠️ Session compressed 20 times — accuracy may degrade. [Each "compression" reduces 245→243 messages, 205K→204K tokens — effectively useless]

Three Design Flaws

FlawLocationDetail
1. Single-direction thresholdcheck_compression_model_feasibility()threshold_tokens lowered but never restored — no mechanism to raise it back when conditions change
2. No effectiveness check3-pass loop in turn_context.pyOnly checks message count reduction, not actual token reduction. 245→243 messages passes the check even though 205K→204K is meaningless
3. No main-model fallbackCompression pipelineWhen 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

DimensionSeverityDetail
Token CostHIGHCompression runs every turn consuming tokens with near-zero benefit — 16+ wasted compression cycles per session
PerformanceHIGHEvery turn triggers an expensive aux-model call that does nothing — adds latency with no gain
ConfigurationHIGHSilent misconfiguration — user doesn't know aux model is too small until they notice the compression spam
Fix ComplexityMODERATE3 changes: 80% safety margin on auto-lower, 10% minimum reduction check, main-model fallback

Proposed Fix (3 Changes)

  1. 80% safety margin on threshold auto-lower: When aux model context is smaller than threshold, lower to aux_context * 0.8 instead of aux_context — prevents the threshold from sitting right at the aux model's limit
  2. 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
  3. 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

📋 https://hermes-agent.reviews/hermes-context-compression-infinite-loop-53008.html
Tracked by hermes-agent.reviews — June 26, 2026