Skip to content

fix(core): preserve unicode in grep previews - #42356

Merged
kitlangton merged 1 commit into
devfrom
unicode-preview
Aug 13, 2026
Merged

fix(core): preserve unicode in grep previews#42356
kitlangton merged 1 commit into
devfrom
unicode-preview

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

What

Prevent oversized Ripgrep line previews from persisting half of a Unicode character. A malformed preview could display as and poison subsequent provider requests.

Before / After

Before

A grep match longer than 2,000 JavaScript string units could place an emoji across the preview boundary. slice(0, 2_000) retained only the emoji's first UTF-16 code unit, which JSON serialized as an unpaired \ud83d. The TUI displayed a replacement character, and OpenAI rejected later requests with HTTP 400 because the request body was not valid Unicode JSON.

After

When the preview cutoff lands after the first half of a Unicode character, Ripgrep drops that incomplete code unit before appending the truncation marker. Persisted tool output remains valid Unicode and can be submitted to providers.

How

  • packages/core/src/ripgrep.ts: remove a trailing unmatched high-surrogate code unit from truncated line previews.
  • packages/core/test/ripgrep.test.ts: cover an emoji crossing the exact 2,000-unit preview boundary.

Scope

This fixes the producer that created the malformed durable tool output. It does not add a provider-request sanitizer or rewrite existing session history.

Testing

  • bun run test test/ripgrep.test.ts from packages/core: 3 passed
  • bun typecheck from packages/core: passed
  • Push hook workspace typecheck: 30 packages passed
  • End-to-end A/B replay against OpenAI:
    • original exported history containing one unpaired \ud83d: HTTP 400 Invalid body: failed to parse JSON value
    • identical history with only that unpaired code unit removed: normal assistant response

@kitlangton
kitlangton enabled auto-merge (squash) August 13, 2026 16:34
@kitlangton
kitlangton merged commit 6c035e1 into dev Aug 13, 2026
11 checks passed
@kitlangton
kitlangton deleted the unicode-preview branch August 13, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant