Skip to content

fix(terminal): preserve Unicode boundaries when truncating output - #1186

Merged
Olga Lavrichenko (OLavrik) merged 3 commits into
JetBrains:mainfrom
Afloat16:fix/terminal-unicode-truncation-20261103
Nov 5, 2026
Merged

Olga Lavrichenko (OLavrik) merged 3 commits into
JetBrains:mainfrom
Afloat16:fix/terminal-unicode-truncation-20261103

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Problem

When pending terminal output exceeds its ceiling, slicing by UTF-16 code units can retain the low half of a surrogate pair. The next delivered batch then starts with a replacement character. This also occurs while the connection is backpressured.

Approach

If the truncation boundary bisects a high/low surrogate pair, move it forward by one code unit. The retained output still fits the configured ceiling and preserves complete pairs that already fit.

Changes

Add normal, exact-boundary and backpressure regression cases. Document the UTF-16 ceiling and whole-character truncation in the terminal specification.

Screenshots

Not applicable — no frontend changes.

Validation

  • Before the fix: 2 regression tests failed on main.
  • Targeted source suite: 11 tests passed using Node and Vitest 4.1.11 with bun:test aliased to Vitest; test assertions and production source were unchanged by the runner.
  • Test file: packages/server/src/terminal/outputBatcher.test.ts.
  • Biome 2.5.0 check of changed TypeScript files and git diff --check: passed.
  • Bun aborts at process startup in this environment. The complete Bun lint/typecheck/test gates and no-agent E2E suite could not run.

Checklist

  • Fast gates pass: bun run lint, bun run typecheck, bun run test
  • E2E suite passes for app-affecting changes (bun run e2e, or bun run e2e:full when touching agent behavior)
  • Before/after screenshots are included for frontend changes, or marked not applicable
  • Relevant SPEC.md / top-level specs updated to reflect any boundary, contract, or behavior change
  • I have read the Contributing guide and agree to the Code of Conduct

@jetbrains-air jetbrains-air Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved — ready to merge.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Nice catch on the orphaned low surrogate, and the backpressure test is a good touch.

…ual edge distance, since wheeling to the bottom-most Submit row can legitimately re-attach follow.

@jetbrains-air jetbrains-air Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved — ready to merge.

@Afloat16

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the E2E follow-up. I checked 9f683b6 against the approved 843c8f2: the only additional change is your follow-state assertion adjustment in e2e/ask-user-question.spec.ts. The terminal implementation, regression tests, and specification are unchanged.

The CI run for the current head is awaiting maintainer approval, and the required CI passed status is still Expected. Could you approve that run so the current revision can complete its checks?

@jetbrains-air jetbrains-air Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved — ready to merge.

@OLavrik
Olga Lavrichenko (OLavrik) added this pull request to the merge queue Nov 5, 2026
Merged via the queue into JetBrains:main with commit 91aeac1 Nov 5, 2026
11 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.

2 participants