Skip to content

fix(context): avoid 100 percent threshold at minimum context length#24076

Open
soynchux wants to merge 1 commit into
NousResearch:mainfrom
soynchux:fix/context-compression-64k-threshold
Open

fix(context): avoid 100 percent threshold at minimum context length#24076
soynchux wants to merge 1 commit into
NousResearch:mainfrom
soynchux:fix/context-compression-64k-threshold

Conversation

@soynchux

Copy link
Copy Markdown
Contributor

Summary

Fix context compression threshold calculation for minimum-context models.

Previously, ContextCompressor always applied the 64K floor directly to
threshold_tokens. On models with a 64K context window, that could raise the
effective trigger to 100% of the window, so auto-compression would not fire
until the context was already exhausted.

This change keeps the historical 64K floor for larger context windows, but
falls back to the configured percentage when the floor would otherwise consume
the entire minimum context window.

Closes #14690.

What changed

  • Added a shared _compute_threshold_tokens() helper in ContextCompressor
  • Applied the same threshold logic in both __init__() and update_model()
  • Added regression coverage for:
    • 64K models using the percentage threshold
    • exact trigger behavior at 32K for the default 50% threshold
    • model updates preserving the corrected threshold behavior

Why this is safe

  • Larger context windows keep the existing 64K floor behavior
  • The behavior change is limited to the broken minimum-context case
  • Existing threshold-related feasibility tests still pass

Tests

  • uv run --group dev pytest tests/agent/test_context_compressor.py -k "threshold or minimum_context_window or update_model_preserves" -n 0
  • uv run --group dev pytest tests/run_agent/test_compression_feasibility.py tests/run_agent/test_compressor_fallback_update.py -k "threshold or exact_threshold_boundary_no_warning or just_below_threshold_auto_corrects" -n 0

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder labels May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Context auto-compression never triggers when context_length == MINIMUM_CONTEXT_LENGTH (64000)

2 participants