Skip to content

fix(agent-runtime): bound Bash progress by UTF-16 length without splitting surrogate pairs - #1939

Merged
vastsa merged 2 commits into
vastsa:mainfrom
xpeng5278-web:fix/bash-progress-utf16
Oct 28, 2026
Merged

vastsa merged 2 commits into
vastsa:mainfrom
xpeng5278-web:fix/bash-progress-utf16

Conversation

@xpeng5278-web

Copy link
Copy Markdown
Contributor

Fixes #1938

What

appendToolProgress now spends the head and tail budgets in UTF-16 code units, the same unit as the MAX_TOOL_PROGRESS_CHARS check. Two small helpers take a prefix and a suffix by code units and leave out a code point that would not fit, so a surrogate pair is never split. The 60/40 head/tail split and the marker are unchanged.

Why

The budget was counted in code points while the cap is checked in code units, so supplementary-plane output (emoji etc.) was "truncated" to about twice the cap: "😀".repeat(40_000) came out at 131,036 code units against a 65,536 cap.

How tested

  • runtime.test.ts, via the existing Bash tools.output fixture: emoji over the cap stays ≤ 65,536 with no lone surrogates; a cut landing on a surrogate pair keeps it whole; ASCII over the cap is unchanged (exactly the cap, same marker position); under-cap output is appended as-is. The two supplementary-plane cases fail on unmodified main.
  • packages/agent-runtime: full vitest 106 files / 1495 tests pass; tsc --noEmit clean; pnpm lint:biome and scripts/check-architecture.mjs pass.

Scope

appendToolProgress in runtime.ts and tests. No constant or caller changes.

xpeng5278-web and others added 2 commits October 27, 2026 09:39
…tting surrogate pairs

The cap was measured in UTF-16 code units, then the slice kept that many
code points. Emoji and other supplementary-plane characters are two units
each, so truncated Bash progress stayed about twice the cap and every later
chunk was cut again from that oversized string.

Spend the same head/tail budget in code units and drop a code point that
does not fit, so a surrogate pair is never split.
@vastsa
vastsa merged commit eb740b1 into vastsa:main Oct 28, 2026
5 of 6 checks passed

This branch was previously deployed

1 inactive deployment
Preview — d45f54c5 Deployed Oct 28, 2026 by vercel[bot]
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] Bash progress truncation counts code points against a UTF-16 cap, so emoji-heavy output stays at ~2× the limit

2 participants