feat: Token budget aware fresh tail#236
Open
Bikkies wants to merge 1 commit intoMartian-Engineering:mainfrom
Open
feat: Token budget aware fresh tail#236Bikkies wants to merge 1 commit intoMartian-Engineering:mainfrom
Bikkies wants to merge 1 commit intoMartian-Engineering:mainfrom
Conversation
faa57b9 to
8891a7e
Compare
Author
|
2 tests fail because they use token budgets small enough that the fresh tail exceeds the compaction threshold which is the scenario this PR addresses. |
- Fixed two failing tests by disabling token-budget tail for those specific cases so they test stock compaction behavior - Added companion tests that verify the token-budget tail feature works as expected Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
8891a7e to
155b7bd
Compare
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.
This basically just adds a way for us to force compact older messages when we actually reach the configured compaction threshold, instead of the blunt "keep last 64 messages no matter what" behaviour that could lead to overflows when using models with lower context lengths. Now we TRY to keep the last 64 (or whatever you configure) messages, but if they really don't fit, we gotta compact.
freshTailCountprotects the last N messages from compaction regardless of size. With the default of 64, a handful of large tool results in the tail can exceed the context window and there's no way to compact them out, even when context is about to overflow.This is common in agentic workflows where tool results vary wildly in size. One message might be 50 tokens and the next one might be 30k.
This adds a token-count cap to the fresh tail using the existing
contextThresholdconfig. Walks backward from the newest message, accumulating tokens. Once the budget (contextThreshold * contextWindow) is hit, older messages lose protection and become compactable regardless of how many you try to protect withfreshTailCount