Skip to content

fix(compression): skip empty summary windows#60579

Closed
HOYALIM wants to merge 1 commit into
NousResearch:mainfrom
HOYALIM:codex/skip-empty-compression-window
Closed

fix(compression): skip empty summary windows#60579
HOYALIM wants to merge 1 commit into
NousResearch:mainfrom
HOYALIM:codex/skip-empty-compression-window

Conversation

@HOYALIM

@HOYALIM HOYALIM commented Jul 8, 2026

Copy link
Copy Markdown

Problem

Fixes #59496. After the latest persisted handoff summary is removed from the compression window, the remaining window can be empty. The compressor still proceeded to _generate_summary([]), spending one auxiliary model request and then surfacing the empty-window failure path.

Solution

After rehydrating _previous_summary from the latest handoff, return early when there are no new turns left to summarize. The early return mirrors the existing no-compressible-window path: it records an ineffective compression attempt, sets savings to 0%, and avoids the model call.

Validation

  • scripts/run_tests.sh tests/agent/test_context_compressor_summary_continuity.py -q
  • scripts/run_tests.sh tests/agent/test_context_compressor.py tests/agent/test_context_compressor_cross_session_guard.py tests/agent/test_preflight_compression_gate.py tests/agent/test_context_compressor_summary_continuity.py -q
  • .venv/bin/ruff check agent/context_compressor.py tests/agent/test_context_compressor_summary_continuity.py
  • git diff --check
  • uv lock --check

Impact

For the affected boundary case, _generate_summary calls drop from 1 to 0. That avoids one auxiliary context-engine request, its prompt tokens, and its latency for each no-new-turn compression trigger.

Notes

ty check agent/context_compressor.py tests/agent/test_context_compressor_summary_continuity.py still reports existing annotations/type issues in agent/context_compressor.py around nullable defaults and call_llm(**call_kwargs); this patch does not add new ty diagnostics.

Signed-off-by: Ho Lim <subhoya@gmail.com>
Copilot AI review requested due to automatic review settings July 8, 2026 00:03

Copilot AI 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.

Pull request overview

This PR fixes an edge case in the context compression pipeline where, after rehydrating _previous_summary from a persisted handoff summary, the adjusted compression slice can become empty but the compressor still called _generate_summary([]), wasting an auxiliary model request and triggering the “summary generation failed → abort” path.

Changes:

  • Add an early-return guard in ContextCompressor.compress() to treat a post-handoff-adjustment empty turns_to_summarize window as a no-op (record ineffective attempt, 0% savings, skip model call).
  • Add a regression test ensuring the compressor does not call _generate_summary when the handoff summary sits at the end of the compression window, and that state counters are updated accordingly.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
agent/context_compressor.py Adds a no-op guard after handoff summary rehydration to avoid calling the summarizer with an empty window.
tests/agent/test_context_compressor_summary_continuity.py Adds coverage for the “handoff at window end → no new turns” boundary condition and asserts no model call occurs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@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 sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state P3 Low — cosmetic, nice to have duplicate This issue or pull request already exists labels Jul 8, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #59526 — diff-verified: this PR inserts the identical if not turns_to_summarize: early-return guard in context_compressor.compress() (same _ineffective_compression_count/_last_compression_savings_pct = 0.0/return messages), differing only in log-message wording. Both Closes #59496. #59526 is the earlier, open, canonical PR; the extra regression test here doesn't change the mechanism. (Sibling #59737 is the same fix, also linked to #59526.)

@HOYALIM

HOYALIM commented Jul 8, 2026

Copy link
Copy Markdown
Author

@HOYALIM Closing this as a duplicate of #59526, which was opened earlier for #59496 and carries the same guard plus regression coverage. Next step is to track #59526 as the canonical fix.

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

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have 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.

[Bug]: Context compression calls context engine with empty window after summary boundary adjustment

3 participants