Repository navigation
fix(compression): keep the tail of a truncated lite tool result - #18138
Merged
diegosouzapw merged 4 commits intoOct 29, 2026
Conversation
… truncation comment
The tail start was rounded back to the previous newline, so a long last line pushed the output past maxToolLength (30 lines x 1000 chars gave 2410 chars for a 2000 cap, 11 x 20000 gave 21410). Search forward for the first line that begins inside the tail budget and fall back to the head-only cut when none fits. Count lines with a bounded indexOf loop instead of splitting the whole payload, and add cap tests for short and long lines. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
diegosouzapw
merged commit Oct 29, 2026
bcc7404
into
cheaper-inference:release/v3.8.53
32 of 41 checks passed
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.
Problem
Lite's tool-result cap keeps only the head and throws the rest away, with no way for the model to know what the dropped region contained beyond a single marker. Any consumer that addresses content by line - an anchored edit tool, a line-numbered grep, a diff - then looks up a line that is no longer in the context.
Measured with the current defaults (
maxToolLength= 2000):rgoutput, 108 matchesEverything the agent was about to edit is in the 60 dropped lines, and the model rebuilds them from memory instead.
Fix
truncateToolTextnow keeps the tail too for multi-line content: ~70% of the budget from the head, ~30% from the end, both on line boundaries, with an honest... [N lines elided] ...marker in the middle. The existing...[truncated]marker stays at the end, so every current consumer and test contract is unchanged.Single-line content keeps the #8169 word-boundary cut (no tail slice, nothing to align).
Same fixture after the fix: 2057 chars - head through line 33,
... [61 lines elided] ..., tail through the last line.Tests
tests/unit/compression/lite.test.tscase: 95 line-addressed lines, first and last line must survive, elision marker present. Fails before the fix withlast line must survive the cut.tests/unit/compression/lite.test.ts+tests/unit/8169-lite-word-boundary-truncation.test.ts+tests/unit/compression/lite-current-turn.test.ts-> 43 pass.tests/unit/chatcore-compression-integration.test.ts+tests/integration/chatcore-compression-integration.test.ts-> pass.tests/unit/compression/*.test.ts(full dir) -> 1944 pass.Scope
Only
open-sse/services/compression/lite.tsand its test. No config, no env var, no default cap change.