Skip to content

fix(compression): break infinite loop when aux model context < session size (#53008) - #53235

Closed
Christopher-Schulze wants to merge 1 commit into
NousResearch:mainfrom
Christopher-Schulze:fix/53008-compression-infinite-loop
Closed

fix(compression): break infinite loop when aux model context < session size (#53008)#53235
Christopher-Schulze wants to merge 1 commit into
NousResearch:mainfrom
Christopher-Schulze:fix/53008-compression-infinite-loop

Conversation

@Christopher-Schulze

@Christopher-Schulze Christopher-Schulze commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #53008. When Hermes uses an auxiliary compression model with a smaller context window than the main model, compression could repeatedly re-trigger without producing enough headroom.

Root cause

  • Feasibility correction set the compression threshold to 100% of the auxiliary model context, leaving no room for the summary and protected conversation tail.
  • Once the actual middle window exceeded the auxiliary context, summary generation still selected the undersized auxiliary runtime.

Fix

  1. Auto-corrected thresholds now use 80% of auxiliary context, clamped to MINIMUM_CONTEXT_LENGTH.
  2. compress() compares the actual middle window with auxiliary context. Oversized windows use the main runtime for that pass, then restore the configured auxiliary model in finally.
  3. The fallback passes the main provider, model, endpoint, API key, and API mode explicitly, so call_llm(task="compression") cannot re-select the auxiliary task configuration.
  4. The overflow warning is emitted once per session and reset on both session reset and natural session end.

Current main already contains provider-token anti-thrash verification. This rebase deliberately removes the PR's older threshold-escape implementation instead of duplicating that upstream behavior.

Verification

  • scripts/check.sh --project hermes-agent --worktree worktrees/hermes-agent/53008: PASS
  • Locked dependency sync, uv lock --check, and full ruff check .: PASS
  • Changed tests: 32/32 PASS
  • Focused compression integration set: 47/47 PASS
  • Exact-base proof on 7b5ba2054721dde998ed47fd4a0f031955278e99: 6 regression failures on base, all pass on this branch
  • git diff --check origin/main: PASS

Full-project ty remains advisory and hits its existing upstream panic in tools/checkpoint_manager.py; the blocking project gates pass.

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jun 26, 2026
@Christopher-Schulze
Christopher-Schulze force-pushed the fix/53008-compression-infinite-loop branch 3 times, most recently from ba0353c to 64e9348 Compare July 1, 2026 13:01
@Christopher-Schulze
Christopher-Schulze force-pushed the fix/53008-compression-infinite-loop branch from 64e9348 to d3fc655 Compare July 12, 2026 11:53
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused compression investigation and regression coverage.

This is an automated hermes-sweeper review. Current main already provides the requested infinite-loop guarantee:

  • agent/context_compressor.py:1199 judges each completed compaction using provider-reported prompt usage and records an ineffective attempt when it remains above the trigger.
  • agent/context_compressor.py:1305 stops automatic compaction after two ineffective attempts rather than retrying indefinitely.
  • tests/agent/test_compaction_anti_thrash.py:130 covers the rough-preflight/real-usage sequence that could otherwise reopen the loop.
  • The load-bearing implementation is 7f9485707d0183af0c9f04e1153e1ec9bd98aa68 (fix(compaction): judge the anti-thrash verdict on real usage, not in should_compress), verified as present in current main.

@teknium1 teknium1 closed this Jul 15, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists sweeper:implemented-on-main Sweeper: behavior already present on current main sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Context Compression Infinite Loop

3 participants