fix: bound conversation compaction budgets - #772
Draft
KevinXia69 wants to merge 1 commit into
Draft
Conversation
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
Why
The existing ratio-only calculations scale every compaction dimension with the model context window. For a configured 983,616-token window, they produce roughly:
The summary request can exceed provider output limits and make compaction disproportionately expensive. This change keeps the existing rolling-summary architecture while bounding those costs. With the current default 4,096-token generation limit, the same model now uses a 131,072-token history plan, a 4,096-token summary cap, and a 78,643-token recent verbatim tail. That leaves meaningful headroom before the next compaction instead of triggering it again after only a small amount of new history.
The history budget remains a soft planning target: the newest non-empty message is still preserved if that single message exceeds the target.
Testing
pytest tests/services/session/test_context_builder.py tests/services/config/test_context_window_detection.py tests/services/model_selection/test_llm_selection.py tests/services/session/test_turn_runtime.py(88 passed)pre-commit run --files deeptutor/services/session/context_builder.py tests/services/session/test_context_builder.py