Repository navigation
fix(display): handle small max_len values in build_tool_preview() - #9477
Closed
kagura-chen wants to merge 1 commit into
Closed
kagura-chen wants to merge 1 commit into
kagura-chen wants to merge 1 commit into
Conversation
When max_len < 4, the truncation logic `preview[:max_len - 3] + '...'` produces a negative slice index, resulting in output that exceeds max_len. For max_len < 4, hard-truncate to max_len without ellipsis since there is no room for even one character plus '...'. Also fixes the existing test assertion that incorrectly allowed len(result) <= 43 instead of <= 40 for max_len=40. Fixes NousResearch#9439
kagura-chen
force-pushed
the
fix/build-tool-preview-max-len
branch
from
April 15, 2026 00:07
1cffe16 to
ec39c05
Compare
Author
|
CI note: The |
Author
|
Closing to reduce PR backlog. The fix is still valid — happy to reopen or resubmit if there's interest. Thanks! |
teknium1
pushed a commit
that referenced
this pull request
Sep 12, 2026
`build_tool_preview()`'s generic-key fallback and the cute-message helpers still truncated with a bare `text[:max_len - 3] + "..."`; for max_len 1-3 the slice goes negative and returns almost the whole string (27 chars for max_len=1). `_truncate_preview` already had the guard, so the two code paths disagreed. One truncation helper (`_tail_trunc`) with the guard, used everywhere; the head-truncating `_cute_path` gets the same clamp. Salvage of PR #48483 by @HeLLGURD (current-code fix); the earliest reports and patches were #9464 (@LarHope), #9477 (@kagura-agent) and #9497. Co-authored-by: LarHope <12761142+LarHope@users.noreply.github.com> Fixes #9439
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
build_tool_preview()inagent/display.pybreaks itsmax_lencontract whenmax_len < 4. The truncation logic:produces a negative slice index for
max_lenvalues of 1, 2, or 3, resulting in output that exceeds the specifiedmax_len.For example, with
max_len=1andpreview="hello":preview[1-3]→preview[-2]→"lo"+"..."→"lo..."(length 5, violates max_len=1)Fix
When
max_len < 4, hard-truncate tomax_lenwithout ellipsis, since there is no room for even one character plus"...". Formax_len >= 4, the existing ellipsis logic works correctly.Also fixes an incorrect existing test assertion that allowed
len(result) <= 43instead of<= 40formax_len=40.Tests
Added 7 new test cases covering:
max_len=0(unlimited — no truncation)max_len=1, 2, 3(small values — hard truncate, no ellipsis)max_len=4(first value where ellipsis fits)All 31 display tests pass. Full test suite shows no regressions.
Fixes #9439