fix(hooks): prevent UTF-16 surrogate pair splitting in RatingCapture#882
Open
rikitikitavi2012-debug wants to merge 1 commit intodanielmiessler:mainfrom
Conversation
Fix crash where String.prototype.slice splits UTF-16 surrogate pairs (like emojis) causing corrupted JSON output. Added a `safeSlice` utility function that checks if the boundary lands on a high surrogate and gracefully drops the incomplete pair. Replaced all truncation slice calls with `safeSlice` across releases. Also added tests to verify correct emoji truncation logic. Co-authored-by: rikitikitavi2012-debug <240362902+rikitikitavi2012-debug@users.noreply.github.com>
Author
|
This fixes the issue reported in #874 — adds a safeSlice() helper to prevent splitting UTF-16 surrogate pairs when truncating hook output. |
Author
|
Friendly ping — this PR has been open for a few days without review. Happy to address any feedback or make changes if needed. Let me know if there's anything blocking the merge. |
virtualian
added a commit
to virtualian/pai
that referenced
this pull request
Mar 9, 2026
Add safeSlice() helper that checks for high surrogates at truncation boundaries before slicing. Replaces 6 bare .slice(0, N) calls that could produce orphaned surrogates and corrupt ratings.jsonl entries when emoji land at exact cut points. Upstream: danielmiessler/Personal_AI_Infrastructure#882 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
virtualian
added a commit
to virtualian/pai
that referenced
this pull request
Mar 9, 2026
…ISC/effort alignment (#66) * fix: prevent UTF-16 surrogate pair splitting in RatingCapture (#65) Add safeSlice() helper that checks for high surrogates at truncation boundaries before slicing. Replaces 6 bare .slice(0, N) calls that could produce orphaned surrogates and corrupt ratings.jsonl entries when emoji land at exact cut points. Upstream: danielmiessler/Personal_AI_Infrastructure#882 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: align SKILL.md ISC system-of-record with Algorithm PRD design (#65) Change ISC system-of-record from Claude Code task system (TaskCreate) to PRD.md checkboxes, matching how the Algorithm actually writes and tracks criteria. Upstream: danielmiessler/Personal_AI_Infrastructure#891 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: harmonize SKILL.md effort budgets and ISC minimums with Algorithm (#65) Remove Instant and Fast tiers that don't align with Algorithm operation. Consolidate to 5 tiers (Standard–Comprehensive) with realistic ISC ranges instead of inflated minimums (was Deep=128, now 40-80). Upstream: danielmiessler/Personal_AI_Infrastructure#890 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
safeSlice()function that detects high surrogates (0xD800–0xDBFF) at cut boundary and drops incomplete pairs.slice(0, N)calls inRatingCapture.hook.tsacross v3.0 and v4.0.0 releasesratings.jsonlentries when emoji appear near truncation boundaryFixes #874
Context
.slice(0, 500)operates on UTF-16 code units. When the cut lands between a surrogate pair (emoji, CJK supplementary), it produces an orphaned high surrogate → invalid JSON → statusline LEARNING section breaks.Test plan
safeSlice("test 🗣️".repeat(200), 500)truncates without orphaned surrogatesratings.jsonlremains valid JSON after truncation with emoji content🤖 Submitted by Navi, PAI agent of Ivan (@rikitikitavi2012-debug)
Generated with Claude Code + Jules