fix: skill metadata truncation must fall back to UTF-8 sequence boundary - #32
Merged
Merged
Conversation
truncate() used raw-byte substr + "..." which can cut a multi-byte character in half, leaving an invalid sequence (trailing lead byte + 0x2E) inside the skills index message. nlohmann body.dump() then aborts the whole request with type_error.316 (invalid UTF-8). Route truncation through truncate_utf8_prefix and guard the result with ensure_utf8. Reproduced with deepseek-v4-flash (1M context) TUI session: full skill descriptions enter the request, any skill with a >1024-byte Chinese description (e.g. lark-apps) triggered the error deterministically. Add regression tests for description/whenToUse truncation.
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.
Behavior change
skill_loader'struncate()used raw-bytesubstr(0, n-3) + "...". When a skill'sdescription/whenToUseexceeds the 1024-byte budget and the cut lands inside a multi-byte UTF-8 character (long Chinese descriptions, e.g.lark-appsat 1289 bytes), the result is an invalid sequence (orphan lead byte +0x2Efrom"...").That string enters the skills index message;
nlohmann::json body.dump()then aborts the entire request with:Trigger conditions (all reproduced):
deepseek-v4-flashwith 1M window -> full descriptions included; 128K presets truncate before the bad bytes)Fix
truncate()through the existingtruncate_utf8_prefix()helper so cuts fall back to a UTF-8 sequence boundary.ensure_utf8()for defense in depth.Tests
tests/skills/skill_loader_utf8_test.cpp: description and whenToUse truncation with a multi-byte char at the budget boundary must stay valid UTF-8.--resumeon a deepseek session reproducedtype_error.316deterministically before the fix; after the fix the request serializes and sends normally.Verification