Skip to content

fix(compression): clamp recommended threshold to small-context floor (#67422) - #67450

Closed
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/67422-compression-threshold
Closed

fix(compression): clamp recommended threshold to small-context floor (#67422)#67450
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/67422-compression-threshold

Conversation

@webtecnica

Copy link
Copy Markdown
Contributor

Closes #67422

Problem

The auxiliary-compression feasibility warning can recommend a compression.threshold value below the small-context floor (75%). Models with context windows under 512K have their threshold raised by _effective_threshold_percent, so a recommended value like 0.73 gets raised back to 0.75 on the next session, causing the warning to repeat indefinitely.

Fix

The warning in check_compression_model_feasibility() now accounts for the same small-context floor used by ContextCompressor._effective_threshold_percent():

  • When the main model's context is below 512K and the aux model's capacity would suggest a threshold below 75%, the threshold recommendation is clamped to 75%.
  • When the aux model cannot even reach the 75% floor (i.e., aux_context < main_ctx * 0.75), the warning omits the threshold recommendation entirely and explains that a larger auxiliary compression model is required — since lowering the threshold wouldn't help.

Changes

  • agent/conversation_compression.py: Added small-context floor awareness to the warning recommendation in check_compression_model_feasibility().

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint area/compression Context compression and continuation sessions sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state needs-decision Awaiting maintainer decision before any implementation labels Jul 19, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related to #67431/#67444, not a duplicate: #67431 checks the full effective threshold contract, while this branch mixes a narrower warning-floor change with substantial unrelated compression and session-rotation work. Please split/rebase for review.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for identifying a real warning mismatch: current main emits a raw aux_context / main_ctx recommendation in agent/conversation_compression.py:312-353, while the built-in compressor applies a 75% floor at agent/context_compressor.py:1209-1223.

Problems

  • The new _threshold_below_floor test still compares against the raw context window. The actual persisted trigger is computed from the effective input budget, including max_tokens reservation, the 64K floor, and the degenerate-window rule (agent/context_compressor.py:1226-1265). This can suppress a threshold recommendation that would be viable after recomputation.
  • The diff also adds lock refresh, session-rotation checks, user-anchor rewriting, and immediate rotated-session persistence, although the stated fix is only warning guidance. It adds no tests despite these session-state changes.

Suggested changes

  • Split the warning change from the unrelated compression/session work.
  • Compute built-in-compressor viability through the same effective-percent and _compute_threshold_tokens() contract, and add real-compressor regressions for an output-reservation case plus external-engine passthrough.

Automated hermes-sweeper review.

_SMALL_CTX_THRESHOLD_PERCENT,
)
_min_floor_pct = int(_SMALL_CTX_THRESHOLD_PERCENT * 100)
_threshold_below_floor = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This raw aux_context / main_ctx gate does not match the trigger that a persisted setting will produce: _compute_threshold_tokens() uses the effective input window after max_tokens reservation plus the 64K and degenerate-window rules (agent/context_compressor.py:1226-1265). Recompute that token trigger before deciding that a 75% setting is non-viable.

return False


def _refresh_persisted_compression_guards(compressor: Any) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lock-guard refresh is unrelated to the threshold-warning fix and begins a large session-state change set in this PR. Please move it to a focused compression/session-rotation change so the warning correction can be evaluated independently.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 19, 2026
@teknium1

Copy link
Copy Markdown
Contributor

The warning-floor bug is fixed via #69332 (merged) — salvage of #67431, which mirrors the full trigger recomputation and was the earliest submission. Your omit-when-unreachable idea was directionally right and is credited in the merged PR body. The unrelated ~300 lines bundled here (rotation guards, user-anchor rewrite, breaker refresh) would need to be re-filed as separate focused PRs to be reviewable — happy to look at each on its own merits. Thanks!

@teknium1 teknium1 closed this Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/compression Context compression and continuation sessions comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint needs-decision Awaiting maintainer decision before any implementation P3 Low — cosmetic, nice to have sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades 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.

Compression warning can recommend a threshold below the small-context floor

3 participants