Skip to content

fix(agent): lower compression retry threshold from 5% to any positive reduction (#59587) - #59605

Open
webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/59587-compression-retry-gate
Open

webtecnica wants to merge 1 commit into
NousResearch:mainfrom
webtecnica:fix/59587-compression-retry-gate

Conversation

@webtecnica

Copy link
Copy Markdown
Contributor

Summary

The 413 payload-too-large and context-overflow handlers in conversation_loop.py both require ≥5% estimated token reduction before retrying after compression. A genuine 3–4% reduction may be exactly what is needed to fit within the provider's limit, and the current gate causes a terminal failure unnecessarily.

Root cause

The 5% threshold (original_tokens * 0.95) existed as a loop-progress guard, but max_compression_attempts = 3 (line 1087) already provides an absolute upper bound, making the percentage gate redundant.

Fix

Remove the * 0.95 multiplier on all three sites (lines 3369, 3592, 3595), accepting any positive token reduction. The new_tokens > 0 and new_tokens < original_tokens check prevents zero-estimate or failed compressions from triggering a retry with a broken message list.

The len(messages) < original_len branch (message-count reduction) was already unconditional and is unchanged.

Safety

  • max_compression_attempts = 3 bounds the retry loop absolutely
  • A zero/negative estimate cannot trigger a retry (new_tokens > 0 check)
  • Compression is monotonically destructive — it never makes messages larger

Changes

File Δ
agent/conversation_loop.py 3 lines changed (remove * 0.95 at lines 3369, 3592, 3595)

Tests

  • tests/run_agent/test_infinite_compaction_loop.py: 14/14 passed

Closes #59587

… reduction (NousResearch#59587)

The 413 payload-too-large and context-overflow handlers both require
≥5% estimated token reduction before retrying after a compression
attempt (original_tokens * 0.95 gate). A genuine 3–4% reduction
may be exactly what is needed to fit within the provider's limit, and
the current gate causes a terminal failure that sends the user to
/new or /compress unnecessarily.

The 5% threshold existed as a loop-progress guard, but
max_compression_attempts = 3 already provides an absolute upper
bound on iterations, making the percentage gate redundant: even
without it, at most 3 retries happen.

Fix: remove the * 0.95 multiplier on all three sites (lines 3369,
3592, 3595), accepting any positive token reduction. The
new_tokens > 0 and new_tokens < original_tokens check prevents
zero-estimate or failed compressions from triggering a retry with a
broken message list.

Implementation note: the len(messages) < original_len branch
(message-count reduction) was already unconditional and is unchanged.
Only the token-reduction path is relaxed.
@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 Jul 6, 2026
@teknium1 teknium1 added the sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform label Jul 10, 2026
@teknium1 teknium1 added the area/compression Context compression and continuation sessions label Jul 19, 2026

This branch has not been deployed

No deployments
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 P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform 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.

**Two affected sites** in agent/conversation_loop.py:

3 participants