Skip to content

fix: use truncate_str for UTF-8 safe string truncation#239

Open
slysian wants to merge 1 commit intoRightNow-AI:mainfrom
slysian:fix/utf8-string-truncation
Open

fix: use truncate_str for UTF-8 safe string truncation#239
slysian wants to merge 1 commit intoRightNow-AI:mainfrom
slysian:fix/utf8-string-truncation

Conversation

@slysian
Copy link

@slysian slysian commented Mar 3, 2026

Replace all &s[..s.len().min(N)] patterns with
openfang_types::truncate_str(s, N) to prevent panics when the byte index falls inside a multi-byte character (e.g. CJK / emoji).

The bug manifests as a thread panic in session.rs when the thinking content contains non-ASCII text and the 200-byte boundary lands mid-character.

Affected crates: openfang-memory, openfang-kernel, openfang-runtime.

Replace all `&s[..s.len().min(N)]` patterns with
`openfang_types::truncate_str(s, N)` to prevent panics when the byte
index falls inside a multi-byte character (e.g. CJK / emoji).

The bug manifests as a thread panic in session.rs when the thinking
content contains non-ASCII text and the 200-byte boundary lands
mid-character.

Affected crates: openfang-memory, openfang-kernel, openfang-runtime.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
egargale pushed a commit to egargale/openfang that referenced this pull request Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant