fix(compaction): skip compression when it cannot reduce the token count - #354
Open
hashbender wants to merge 1 commit into
Open
fix(compaction): skip compression when it cannot reduce the token count#354hashbender wants to merge 1 commit into
hashbender wants to merge 1 commit into
Conversation
|
Review Complete Risk: 🟢 Low (5/100) — no findings · 88 LOC across 2 files PR #354 introduces tests for trajectory_compressor.py but does not modify the compressor itself. No issues found across correctness, performance, or training-data preservation lenses. Files Reviewed (2 files) |
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.
What does this PR do?
Skips trajectory compaction when it cannot actually reduce the token count.
compress_trajectory(and its async twin) replaced a compressible middle region with a summary without checking that the summary is smaller than what it replaces. When the region was already small, the "summary" was larger than the original, so the trajectory grew while being markedwas_compressed=True(observed: 406 → 465 tokens,tokens_saved = -59).The fix adds a net-savings guard: when the compressible region's token count is
<=the summary target, return the trajectory unchanged instead of expanding it. Applied to both the sync and async paths (sibling call path included).Related Issue
No separate issue filed; reproduces on current
main.Type of Change
Changes Made
trajectory_compressor.py— guard bothcompress_trajectoryandcompress_trajectory_async: skip compression whenregion_tokens <= summary_target_tokens, returning the trajectory unchanged.tests/test_trajectory_compressor.py— sync and async tests asserting a tiny compressible region is left unchanged (no token growth,was_compressednot set).How to Test
main: compressing a trajectory with a small compressible middle grows the token count yet reportswas_compressed=True.scripts/run_tests.sh tests/test_trajectory_compressor.py -q→ the added net-savings tests pass (34 passed). Note: 3 tests (*_omits_temperature, kimi/moonshot) fail identically on unmodifiedmain— they are unrelated to this change (temperature-omission for kimi models), not a regression from this PR.Checklist
Code
fix(compaction): ...)scripts/run_tests.sh tests/test_trajectory_compressor.py— the net-savings tests pass; the only failures are the 3 pre-existing*_omits_temperaturecases that also fail onmainDocumentation & Housekeeping
cli-config.yaml.example— N/ACONTRIBUTING.md/AGENTS.md— N/AMirror-of: NousResearch#56415
NousResearch#56415