Skip to content

fix(native-chat): keep tool previews from ending in half an emoji - #51217

Merged
nwparker merged 1 commit into
stablyai:mainfrom
SeungWoonSong:fix/native-chat-tool-preview-emoji-truncation
Nov 27, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
SeungWoonSong:fix/native-chat-tool-preview-emoji-truncation

Conversation

@SeungWoonSong

@SeungWoonSong SeungWoonSong commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When Orca shortens a long tool command or tool output to fit on screen, it could cut an emoji in half and show a broken � symbol right before the …. Now it stops just before the emoji, so the preview ends cleanly.

What Changed

  • Before: the shell command row, the settled single-command run header, and the clipped tool output preview cut text at a fixed UTF-16 offset. If an emoji (a surrogate pair) crossed that offset, the preview ended in a lone high surrogate, which renders as �….
  • After: those previews end after the last whole character and keep their ellipsis.
  • Mechanism: summarizeToolInput now cuts with the existing sliceAtCodeUnitLimit (it already backs off one code unit when the cut would split a pair). A new ellipsizeCodeUnits(value, limit) helper in src/shared/text/surrogate-safe-text-slice.ts (surrogate-safe cut + … only when the text was longer) replaces the hand-rolled ternaries in truncateToolDetail and boundedPreviewValue. The run header already uses the same command preview formatter, so it gets the fix too.

Why

JavaScript string offsets count UTF-16 code units, so a plain slice can split a surrogate pair. The repo already had a surrogate-safe slice for this. Reusing it keeps the preview limits in code units, so we don't need grapheme segmentation (Intl.Segmenter), which costs much more. A preview is at most one code unit shorter when an emoji sits on the boundary.

Linked Issue

Fixes #51215

Visual Proof

No screenshots were captured for this landing pass. The change only affects the last character of a truncated preview string, and the unit tests pin it exactly. The original PR checked it in the real renderer (synthetic Claude JSONL read through nativeChat.readSession and rendered at 1360 × 850 on Linux). The DOM text it captured shows the lone surrogate as \ud83d:

  • Shell command row tail: aaaaaaaa\ud83d… (80 code units) → aaaaaaaaa… (79 code units)
  • Settled single-command run header: echo aaaa…aaa\ud83d… (80) → echo aaaa…aaa… (79)
  • Tool output preview tail: 67890123\ud83d… (4001) → 567890123… (4000)

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

  • src/shared/native-chat/tools/native-chat-tool-summary.test.ts adds one case for summarizeToolInput and one for truncateToolDetail, each with an emoji across the cutoff. With the source reverted to main and the test file kept, both fail. With the fix, both pass.

  • vitest run src/shared/native-chat/tools/ src/shared/text/: 6 files, 22 tests passed (macOS).

  • CI static gates on the touched files pass: anti-slop oxlint, code-quality native plugins, ast-grep, the changed-code quality gate, and oxfmt.

  • Squashed onto current main with no conflicts. The changed lines are identical to the reviewed patch.

  • Platforms: macOS (unit tests). The original PR also ran a renderer check on Linux. This is pure string logic, so it doesn't depend on the platform.

Performance

None. The surrogate-safe cut reads one extra code unit at the boundary, so the cost stays O(1) whatever the input size. Microbenchmarks (Bun, 200k iterations, old slice vs new ellipsizeCodeUnits):

Input Old New
short command (no truncation) 16.7 ns 8.0 ns
205-char command, limit 79 29.2 ns 23.2 ns
100k-char output, limit 4000 11.2 ns 12.7 ns
emoji-heavy output, limit 4000 12.7 ns 14.6 ns

The results are within noise, with no extra calls, caching, IPC or I/O. Each row still makes the same number of calls, so there is no fan-out across chats or rows.

Risk

Level: Low

This only changes display strings. A preview can be one code unit shorter when an emoji sits on the cutoff. Full command and output text don't change. To back out, revert the commit.

Review

I checked that the shared helper keeps the existing limits and only adds the ellipsis when the text was cut. All three preview paths (command row, run header, output preview) now go through the same surrogate-safe cut.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Original fix by @SeungWoonSong in #51217. Their authorship is kept on the squashed commit.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Tool summary, detail, and bounded preview truncation now use ellipsizeCodeUnits. The helper avoids splitting a surrogate pair at the code-unit limit. Tests cover emoji at the truncation boundaries.

Severity of issue fixed: Low

Merge Risk: Minimal · up to 066cd

Tool previews will no longer end in half an emoji and will keep their ellipsis. The change is small and low risk, so it is ready to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: tool previews no longer end in a split emoji. It also names the affected area (native-chat) and uses the fix type. It matches the raw summary, the objectives, and the …
Description check Passed The description follows the repository template and fills most required sections. It explains the change, the cause, the linked issue (Fixes #51215), testing, performance, and risk. Visual Proof is in…
Linked Issues check Passed Command row, settled run header, and output preview truncation now stop before a split surrogate pair and keep the ellipsis. Whole-PR diff from merge base 6b68f10 to head 066cdae shows summa…
Out of Scope Changes check Passed All changed hunks serve issue #51215: three truncation sites in native-chat-tool-summary.ts, one internal helper ellipsizeCodeUnits in surrogate-safe-text-slice.ts, and two regression tests. No unrela…
Full details: Title check

Explanation

The title names the main change: tool previews no longer end in a split emoji. It also names the affected area (native-chat) and uses the fix type. It matches the raw summary, the objectives, and the linked issue #51215.

Full details: Description check

Explanation

The description follows the repository template and fills most required sections. It explains the change, the cause, the linked issue (Fixes #51215), testing, performance, and risk. Visual Proof is incomplete: the before and after screenshots are placeholders reading 'screenshot being attached', and the Checklist leaves the screenshot item unchecked. The Review section and AI Disclosure are filled in. The ELI5 section keeps the template comment, but it has real content.

Resolution

Attach the before and after screenshots or videos to the Visual Proof section, or replace the placeholders with the actual attachments. Then check the screenshot item in the Checklist.

Full details: Linked Issues check

Explanation

Command row, settled run header, and output preview truncation now stop before a split surrogate pair and keep the ellipsis. Whole-PR diff from merge base 6b68f10 to head 066cdae shows summarizeToolInput, truncateToolDetail, and boundedPreviewValue now use surrogate-safe cuts. Full values are unchanged. Run header call path was not directly inspected; its result relies on the stated shared-formatter reuse.

Full details: Out of Scope Changes check

Explanation

All changed hunks serve issue #51215: three truncation sites in native-chat-tool-summary.ts, one internal helper ellipsizeCodeUnits in surrogate-safe-text-slice.ts, and two regression tests. No unrelated behavior change appears in the whole-PR diff.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d4f40918-aaa2-4033-8413-146327f4fb05
Commits

Reviewing files that changed from the base of the PR and between 8fc5013 and 066cdae.

Files selected for processing: 1

  • src/shared/text/surrogate-safe-text-slice.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Command previews, the settled single-command run header and clipped tool
output cut strings at a fixed UTF-16 offset, so an emoji crossing the
cutoff left a lone high surrogate before the ellipsis. Route those cuts
through the existing surrogate-safe slice via a shared ellipsizeCodeUnits
helper.

Fixes stablyai#51215

Co-authored-by: Neil <[email protected]>
@nwparker
nwparker force-pushed the fix/native-chat-tool-preview-emoji-truncation branch from 8fc5013 to 066cdae Compare November 27, 2026 23:25
@nwparker
nwparker merged commit 6cc2603 into stablyai:main Nov 27, 2026
57 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.

[Bug]: Native chat tool previews can end in a broken emoji

2 participants