fix(compression): skip session rotation when compress returns message… - #50996
Closed
MorAlekss wants to merge 2 commits into
Closed
fix(compression): skip session rotation when compress returns message…#50996MorAlekss wants to merge 2 commits into
MorAlekss wants to merge 2 commits into
Conversation
…cking legitimate compression
Contributor
|
Thanks @MorAlekss — correct fix for the no-op-compress-triggers-rotation path. As of #52658 (#38763), Closing as superseded by the in-place default — the code was a correct fix for the behavior at the time. Credit preserved. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prevents session rotation when
compress()returns messages unchangeddue to a no-op early exit. Before this fix, a no-op compression could
trigger a full session rotation, archiving the conversation history
without any actual context reduction.
Root cause
compress_context()inagent/conversation_compression.pychecked_last_compress_abortedto detect failed compressions and skiprotation. However,
ContextCompressor.compress()has two additionalearly-exit paths that return messages unchanged without setting
_last_compress_aborted:compress_start >= compress_end— the entire transcriptfits within the tail budget, leaving no compressible window. This
path increments
_ineffective_compression_countto eventuallysuppress future compression attempts via the anti-thrashing guard,
but does not set
_last_compress_aborted.In both cases,
compress_context()proceeded past the_last_compress_abortedcheck with
len(compressed) == len(messages)and entered the sessionrotation path:
end_session()was called, a newsession_idwasassigned, and the conversation history was archived — all without any
actual compression having occurred.
Behavioral change
Before: a no-op compression caused a full session rotation, archiving
history and assigning a new session ID without reducing context size.
After: if
len(compressed) >= len(messages)aftercompress()returnsand
_last_compress_abortedis False, the rotation is skipped. Thelock is released and the original messages are returned unchanged, the
same way an explicit abort is handled.
What changed
agent/conversation_compression.py: added a guard after the_last_compress_abortedcheck. Ifcompress()returned as many ormore messages than the input, the function releases the lock and returns
without rotating the session.
tests/run_agent/test_infinite_compaction_loop.py: addedTestNoOpCompressionSkipsRotationwithtest_no_op_compression_does_not_rotate_session. The test wires a realsession DB mock, configures
compress()to return messages unchanged,and asserts that
end_session()is never called and the session IDremains unchanged.
What is NOT changed
_last_compress_abortedlogic unchanged_ineffective_compression_countanti-thrashing guard unchanged