Repository navigation
fix(hooks): keep truncation from splitting a surrogate pair - #1598
Conversation
subagent-stop, post-tool-failure, task-completed, session-end and truncateCaptureOutput, which post-tool-use applies to tool output, cut captured text with slice(0, n). An emoji at the limit was split, and the hook sent a lone high surrogate. The cut now goes through truncateText, which steps back one unit when it would land inside a pair, as stop.ts and the server-side truncation already do. Text within the limit is unchanged. Signed-off-by: Dmitrii Zhukov <dmitry0983@gmail.com>
|
@dmazhukov is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
| Layer / File(s) | Summary |
|---|---|
Surrogate-safe truncation and hook capture src/hooks/_capture-filter.ts, src/hooks/post-tool-failure.ts, src/hooks/session-end.ts, src/hooks/subagent-stop.ts, src/hooks/task-completed.ts, plugin/scripts/*.mjs |
Truncation paths use helpers that avoid leaving a lone high surrogate at the boundary. Existing truncation limits and suffix behavior remain unchanged. |
Boundary and hook-level tests test/capture-filter.test.ts, test/hook-truncation.test.ts |
Tests cover text within the limit, fitting surrogate pairs, and pairs that truncation would split across the supported hooks. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers: rohitg00
Merge Risk: 
Low · previous review f0d3d
-
The normal test command can fail on supported older Node 20 versions. Use a URL-based directory lookup before merging, or explicitly accept that compatibility gap.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
Issue
#1597requires pair-safe truncation at the five hook sites and unchanged text within the limit. The source hooks usetruncateTextforsubagent-stopat 4000,post-tool-failureat 4000,task-completedat 2000,session-endat 8000, andtruncateCaptureOutput. The generatedplugin/scripts/*.mjsfiles include the same behavior. Unit and integration tests cover unchanged text, boundary-fitting pairs, split pairs, and all listed hooks.
Full details: Out of Scope Changes check
-
Explanation
The changes stay within issue
#1597. They add the shared truncation helper, update the five requested hook paths and generated scripts, and add focused unit and integration tests. No changes target the excludedintegrations/, opencode plugin, or server-side truncation paths.
-
-
Finishing Touches
-
Fix failing CI checks
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- 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.
CodeRabbit Verify
- Run CodeRabbit Verify to test the changes in this pull request.
Hook truncation no longer splits a surrogate pair:
subagent-stop,post-tool-failure,task-completed,session-endandtruncateCaptureOutput(used bypost-tool-use) cut through a newtruncateText, which steps back one unit when the cut would land between the two halves of a pair. Fixes #1597..slice(0, n)counts UTF-16 units, so an emoji at the limit left a lone high surrogate in the observation. Text within the limit is sent unchanged. After this, every length cut insrc/hooksis pair-safe;stop.tsalready was.Overlaps the PR for #1596 in
subagent-stop.ts: whichever lands second resolves one hunk and rebuildsplugin/scripts/subagent-stop.mjs.Not covered: the same cut in
integrations/and the opencode plugin, and server-side cuts such as the sessionfirstPrompt.Summary by CodeRabbit
Bug Fixes
Tests