fix: use char-safe string truncation to prevent UTF-8 panic#76
Open
pluginmd wants to merge 1 commit intoRightNow-AI:mainfrom
Open
fix: use char-safe string truncation to prevent UTF-8 panic#76pluginmd wants to merge 1 commit intoRightNow-AI:mainfrom
pluginmd wants to merge 1 commit intoRightNow-AI:mainfrom
Conversation
`append_daily_memory_log` and session summary truncation used byte-level slicing (`&s[..500]`, `&t[..200]`) which panics on multi-byte UTF-8 characters (e.g. Vietnamese, CJK). Replace with `chars().take(N)` for safe truncation at character boundaries. Panic observed in production with Vietnamese text: byte index 500 is not a char boundary; it is inside 'ặ' (bytes 498..501) This crashed a tokio worker thread, silently killing the Telegram polling loop and making the bot unresponsive. 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
append_daily_memory_logused&trimmed[..500]which panics when byte 500 falls inside a multi-byte UTF-8 character&t[..200]with the same issuechars().take(N).collect()for safe character-boundary truncationRoot cause
Vietnamese/CJK text contains multi-byte UTF-8 characters (e.g.
ặ= 3 bytes). Rust panics on byte-level string slicing at non-char boundaries:Impact
The panic kills a tokio worker thread. If the Telegram polling task was running on that thread, the polling loop dies silently — the bot stops responding to messages while the container remains healthy.
Test plan
cargo build --workspace --libcompilesFrom https://openfang.vn team with love!
🤖 Generated with Claude Code