Conversation
Collaborator
|
Thanks for identifying a real boundary-condition bug. Current main still has the three unsafe CLI display slices in Problems
Suggested changes
Automated hermes-sweeper review. |
Collaborator
|
Salvaged onto current |
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
Collaborator
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.
Bug
agent/display.pytruncates tool previews with the idiomtext[:max_len - 3] + "..."in four places, but only one of them guards against a small
max_len._truncate_preview(the canonical helper) does it correctly:The three siblings omit that guard:
max_len/limitcome from_tool_preview_max_len, which is set straight fromthe user''s
display.tool_preview_lengthconfig viaset_tool_preview_max_len()(only clamped to
>= 0). So a user can settool_preview_length: 1(or2/3),and then for any preview longer than the limit:
max_len = 3?text[:0] + "..."?"..."(3 chars for a limit of 3 - over budget)max_len = 2?text[:-1] + "..."? drops the last character and appends...,producing output longer than the configured limit (e.g.
"hello"?"hell...")_pathwithlimit = 2?p[-(-1):]=p[1:]? drops the first character andprepends
...- same corruption from the other end.So a small
tool_preview_lengthsilently mangles previews instead of shorteningthem - the opposite of what the setting is for. The author already fixed this in
_truncate_preview; the siblings were missed.Fix
build_tool_preview()and_trunc()now route through_truncate_preview,reusing its guard (and removing the duplicated slice logic - DRY).
_path()truncates from the front (keeps the tail), so it can''t reuse_truncate_preview; it gets the samelimit <= 3guard inline.Behavior is unchanged for normal
tool_preview_lengthvalues (0 = unlimited, orany value > 3); only the previously-corrupting 1-3 range is corrected.
Verification
_truncate_previewguard on currentmain._tool_preview_max_lenis user-settable to 1-3 viadisplay.tool_preview_length(set_tool_preview_max_lenclamps only to>= 0).tool_preview(checked before opening).