fix(compressor): _prune_old_tool_results boundary direction - #16228
Closed
swithek wants to merge 1 commit into
Closed
fix(compressor): _prune_old_tool_results boundary direction#16228swithek wants to merge 1 commit into
swithek wants to merge 1 commit into
Conversation
swithek
force-pushed
the
fix/prune-tool-results-budget-floor-inversion
branch
from
April 27, 2026 07:02
05c6608 to
e0552a8
Compare
Contributor
Author
|
hey @alt-glitch @teknium1 @benbarclay bumping this as it's actively affecting us, recent tool output gets silently pruned on long runs and makes the whole thing unreliable |
Contributor
|
Salvaged via #19725 onto current main - your commit authorship was preserved. Thanks! |
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?
Fixes a count/index direction error in
_prune_old_tool_results. The function's docstring promises "the token budget takes priority and the message count acts as a hard minimum floor", but the linedid the opposite in index-space: when the budget walk reserved space for the whole transcript (
boundary == 0),max(0, len - min_protect)truncated protection back down tomin_protectmessages and rewrote every older tool result with a one-line summary. Long-context Claude / Gemini runs silently shed tens of thousands of tokens of recent tool output the budget had room for.The fix moves the calculation into count-space, where
maxreads naturally and matches the docstring's language. Behaviour is identical to the one-charactermax → minpatch on every input, but the next reader doesn't have to re-derive that "min of indices == max of counts" in their head.Related Issue
N/A
Type of Change
Changes Made
agent/context_compressor.py: replaceprune_boundary = max(...)(index-space) with a 3-line count-space form; comment explains the inversion so it can't drift back.tests/agent/test_context_compressor.py: addTestTokenBudgetTailProtection::test_generous_budget_protects_everything_floor_does_not_override- a generous-budget transcript with unique tool outputs (so dedup is a no-op) must producepruned == 0.How to Test
pruned == 40.git stash pop, re-run, it passes.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs