Skip to content

Fix auto compression for tool-heavy sessions#36626

Open
franksong2702 wants to merge 1 commit into
NousResearch:mainfrom
franksong2702:franksong2702/fix-auto-compression-tool-heavy-streams
Open

Fix auto compression for tool-heavy sessions#36626
franksong2702 wants to merge 1 commit into
NousResearch:mainfrom
franksong2702:franksong2702/fix-auto-compression-tool-heavy-streams

Conversation

@franksong2702
Copy link
Copy Markdown

Summary

Long single-turn, tool-heavy sessions could repeatedly auto-compress without materially reducing context. Completed tool results in the protected tail could remain large, internal context-compaction markers could be treated like real user anchors, and repeated no-op compression could continue until the provider rejected the oversized context.

This PR makes auto compression fail explicitly when it is exhausted and demotes completed tool results to concise evidence summaries, including completed tool results at the current tail before the next LLM call.

Changes

  • Demotes completed tool result bodies to concise evidence summaries even when they sit in the current protected tail.
  • Keeps provider-legal assistant/tool pairing while replacing only completed raw tool bodies.
  • Skips context-compaction reference markers when finding the latest real user tail anchor.
  • Tracks repeated ineffective compression attempts and marks them as compression_exhausted.
  • Returns an explicit failed/partial/compression_exhausted result during preflight when compression leaves messages/tokens effectively unchanged.
  • Adds regression tests for tool-heavy tail summarization, marker-anchor handling, ineffective compression exhaustion, and preflight no-op exhaustion.

Verification

  • python -m pytest tests/test_auto_compression_tool_heavy_tail.py tests/run_agent/test_1630_context_overflow_loop.py tests/run_agent/test_compression_trigger_excludes_reasoning.py tests/test_ctx_halving_fix.py tests/run_agent/test_compression_persistence.py tests/run_agent/test_compressor_fallback_update.py tests/run_agent/test_compression_boundary.py -q
  • git diff --check

Related

Risks / Follow-ups

  • The branch is currently behind upstream main by one commit; no rebase was performed before publishing to avoid changing the already-validated branch state.
  • Tool result summarization is intentionally limited to completed role=tool messages; running tools have no result row to summarize.

Model Used

AI-assisted implementation with OpenAI GPT-5 Codex in a local coding workflow. The assistant inspected repository code, wrote regression tests, implemented the fix, and ran the verification commands above.

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 P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants