Skip to content

fix(shell): use byte length for preview truncation#29382

Closed
SpencerJung wants to merge 2 commits into
anomalyco:devfrom
SpencerJung:fix/29291-shell-preview-byte-length
Closed

fix(shell): use byte length for preview truncation#29382
SpencerJung wants to merge 2 commits into
anomalyco:devfrom
SpencerJung:fix/29291-shell-preview-byte-length

Conversation

@SpencerJung
Copy link
Copy Markdown

Fixes #29291. The preview() function used text.length (UTF-16 code units) to check if output exceeds the metadata limit, but truncation should be based on byte length. This caused incorrect truncation for multi-byte characters like CJK, emoji, etc. Additionally, text.slice(-MAX_METADATA_LENGTH) could split a surrogate pair. Use Buffer.byteLength for the check and Buffer-based truncation that respects UTF-8 continuation bytes, matching the existing tail() function pattern.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential duplicates found:

  1. PR fix(shell): use byte length for preview truncation (fixes #29291) #29372 - fix(shell): use byte length for preview truncation (fixes #29291) - This appears to be addressing the same issue (shell tool preview truncation uses char length instead of byte length #29291) with the same fix approach.

  2. PR fix(shell): truncate metadata preview by bytes #29297 - fix(shell): truncate metadata preview by bytes - Related fix for metadata preview truncation using bytes.

  3. PR fix(shell): preview Unicode truncation uses byte length instead of char length #29288 - fix(shell): preview Unicode truncation uses byte length instead of char length - Addresses the same core issue of using byte length instead of character length for preview truncation.

These PRs are all targeting the same bug in shell preview truncation with multi-byte characters. PR #29372 appears to be the most direct duplicate as it fixes the exact same issue (#29291) with the same title.

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 26, 2026
@github-actions github-actions Bot closed this May 26, 2026
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.

shell tool preview truncation uses char length instead of byte length

1 participant