Repository navigation
fix(tools): snap truncation boundaries outside UTF-16 surrogate pairs (#1979) - #2029
Conversation
nc-review: comments — 2 important, 2 nits@dhruvil-codes — a few things worth a look, none blocking. The change adds a 🟠 important · The
The project rubric asks for a regression test with a bug fix, and this half of the diff currently has none. 🟠 important · PR #2004 ("fix: never split surrogate pairs in truncateToolResult", branch I could not read #2004's diff — it is not in the supplied corpus — so I cannot confirm it is byte-for-byte the same fix, and the implementations may differ (this PR composes the snap with the existing placeholder and token snaps; #2004's branch name suggests a standalone cleanup). Please compare against #2004 and coordinate rather than landing both. If the two are equivalent, one should close in favour of the other rather than merging both. ⚪ nit · This is now the third implementation of surrogate-safe cutting in the codebase, and the module name does not match its new role:
They are close enough that a future fix to one will not reach the others, and ⚪ nit · Two other tool-result caps still cut by raw UTF-16 index and can leave a lone surrogate, in the same way #1979 describes:
This is outside the scope #1979 asked for (it named only 🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with |
|
Thanks @nc-review!
|
|
Thanks @dhruvil-codes, merged! I merged main into the branch to get it over the line. The fetch_url part was already covered on main, so what landed is the surrogate-safe truncation in |
Description
Closes #1979
\ runcateToolResult\ and \etch_url\ sliced strings by UTF-16 index with a hard cut when no whitespace token was nearby, cutting UTF-16 surrogate pairs (such as emojis or other astral code points) in half and producing invalid lone surrogates in model context.
Changes