Skip to content

fix(compression): keep the tail of a truncated lite tool result - #18138

Merged
diegosouzapw merged 4 commits into
cheaper-inference:release/v3.8.53from
DarknessKiller:fix/lite-tool-result-tail-upstream
Oct 29, 2026
Merged

diegosouzapw merged 4 commits into
cheaper-inference:release/v3.8.53from
DarknessKiller:fix/lite-tool-result-tail-upstream

Conversation

@DarknessKiller

@DarknessKiller DarknessKiller commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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):

tool result in out after lite
95-line numbered file read 5873 chars / 95 lines 2013 chars / 35 lines (cut after line 33)
rg output, 108 matches 9116 chars 2008 chars, 24 matches left

Everything the agent was about to edit is in the 60 dropped lines, and the model rebuilds them from memory instead.

Fix

truncateToolText now 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

  • new tests/unit/compression/lite.test.ts case: 95 line-addressed lines, first and last line must survive, elision marker present. Fails before the fix with last 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.ts and its test. No config, no env var, no default cap change.

DarknessKiller and others added 3 commits October 26, 2026 01:46
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
diegosouzapw merged commit bcc7404 into cheaper-inference:release/v3.8.53 Oct 29, 2026
32 of 41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants