Repository navigation
perf(session): never shrink tool results the model has not seen - #420
Merged
Merged
Conversation
Spill, prune and shake kept "the last 4 tool messages" and shrank the rest. That window counted messages, not steps, so when the model read six files in parallel, the first two results were cut to a 400-char head with a pointer before the request that should have carried them. The model never saw those files and read them again: one wasted round trip plus a second copy of each file. The three passes now share `shrinkable_tool_indices`: all but the last four, and never a result after the latest assistant message (the batch that answers its calls and goes out with the next request). This also replaces three copies of the same index computation. Tests that queued tool results with no assistant turn between them now add one, since a real transcript always has the model's reply after the results it saw; `unseen_tool_batch_is_never_shrunk` covers the batch case. Co-Authored-By: Claude Opus 5.5 <[email protected]>
mrnasil
force-pushed
the
perf/spill-unseen-results
branch
from
November 7, 2026 13:18
1578d0a to
529dac0
Compare
This was referenced Nov 7, 2026
Merged
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.
Third of the token-efficiency PRs (after #418, #419).
Problem
spill_old_tool_results,prune_old_tool_resultsandshake_old_tool_resultskeep "the last 4 tool messages" and shrink the rest. That window counts messages, not steps. If the model reads six files in parallel, the first two results are cut to a 400-char head plus a pointer before the request that should carry them. The model never sees those files, so it reads them again: an extra round trip plus a second copy of each file in context.Change
All three passes now use one helper,
shrinkable_tool_indices. It selects every tool message except the last four, and never one that comes after the latest assistant message. Those are the results answering that assistant's calls, and they go out with the next request. This also replaces three copies of the same index computation.Tests
unseen_tool_batch_is_never_shrunk. One assistant step with six reads: spill, prune and shake all return 0 before the model replies. After the reply, the two oldest are spilled.whycodes-session --lib171 passed;whycodes-agent --lib764 passed.docs/internals/compaction.mdpass table is updated.🤖 Generated with Claude Code