Skip to content

Fix: Auto-compression never fires in pure chat (no tool calls) path [#65959] - #66175

Closed
rajv2er wants to merge 1 commit into
NousResearch:mainfrom
rajv2er:fix/auto-compression-didnt-fire-65959
Closed

Fix: Auto-compression never fires in pure chat (no tool calls) path [#65959]#66175
rajv2er wants to merge 1 commit into
NousResearch:mainfrom
rajv2er:fix/auto-compression-didnt-fire-65959

Conversation

@rajv2er

@rajv2er rajv2er commented Jul 17, 2026

Copy link
Copy Markdown

Summary

Fixes #65959 — Auto-compression did not fire after long TUI session crossed threshold.

Root Cause

In agent/conversation_loop.py, the post-response should_compress() check (lines ~4956-4965) only existed in the tool-call branch (if assistant_message.tool_calls:). When the model returned a final text response with no tool calls, execution jumped to the else branch and skipped the compression check entirely, breaking out of the loop.

A pure-chat TUI session (user text → assistant text, no read_file, search_files, etc.) could grow past the ~200k token threshold with zero conversation_compression records persisted — exactly as reported for session 20260716_112216_60220c.

Fix

Added the identical compression logic to the no-tool-calls branch (after line 4982), mirroring the tool-call path:

  • Uses real last_prompt_tokens when available
  • Falls back to rough estimate including tool schemas
  • Respects compression_enabled flag and cooldown guards via should_compress()

Testing

  • Syntax clean (python3 -m py_compile)
  • All 32 core compression tests pass (test_compress_focus.py, test_compressed_summary_metadata.py, test_compression_concurrent_fork.py)
  • Logic is a verbatim mirror of the existing proven tool-call compression site

Notes

  • Minimal, targeted change (23 lines added)
  • No behavior change for tool-call turns
  • Closes the gap that let pure-chat sessions bypass auto-compression indefinitely

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cron Cron scheduler and job management tool/mcp MCP client and OAuth area/auth Authentication, OAuth, credential pools duplicate This issue or pull request already exists labels Jul 17, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #65993 — the live diff is byte-identical: both wrap cron-only MCP discovery with suppress_interactive_oauth to prevent the expired-token browser callback hang.

Addresses NousResearch#65959 — long TUI sessions with only text responses never
triggered auto-compression because the post-response should_compress()
check only existed in the tool-call branch. Added identical logic to the
no-tool-calls else branch.
@rajv2er
rajv2er force-pushed the fix/auto-compression-didnt-fire-65959 branch from 7c21460 to 925f18d Compare July 17, 2026 09:01

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Summary

Verdict: Approved

Fix extends post-response compression check to the pure-chat (no tool calls) path. The previous compression trigger only fired inside the tool-call branch, so long chat sessions without tool use could exceed the compression threshold unnoticed. Clear mirroring of the existing tool-call compression path. No security concerns.


Reviewed by Hermes Agent

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for investigating the pure-chat compression report.

This is an automated hermes-sweeper review. Current main already provides the issue's required guarantee: compression is evaluated on the full accumulated history before the next model call.

  • agent/conversation_loop.py:610-634 calls build_turn_context() before the API loop.
  • agent/turn_context.py:414-499 estimates the complete request, applies should_compress(), and invokes _compress_context() before issuing the model request.
  • tests/run_agent/test_413_compression.py:592-642 covers oversized user/assistant history with a text-only final response and asserts that preflight compression ran.
  • The preflight trigger shipped in aacc6bb0a8117940b2f9279b07bf9124fb7cfe09 (v2026.6.19).

The lone discussion comment references unrelated cron/MCP work in #65993; the actual diff for this PR was inspected separately.

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

Labels

area/auth Authentication, OAuth, credential pools comp/cron Cron scheduler and job management duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists sweeper:implemented-on-main Sweeper: behavior already present on current main tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-compression did not fire after long TUI session crossed threshold

4 participants