UTF-8 character boundary handling bug causing CLI termination
Bug Description
Amazon Q CLI crashes with a UTF-8 character boundary error when processing Korean text during checkpoint saving.
Error Message
Message: byte index 60 is not a char boundary; it is inside '코' (bytes 59..62) of FindSelfVerificationAdapterTest 테스트 코드를 기존 코드와 동일한 스타일로 작성 Location: crates/chat-cli/src/cli/chat/checkpoint.rs:373
Expected Behavior
CLI should handle Korean and other multi-byte UTF-8 characters properly without crashing.
Actual Behavior
CLI terminates with a panic when attempting to slice a string at an invalid UTF-8 character boundary during checkpoint operations.
Steps to Reproduce
- Send a message containing Korean text
- Amazon Q starts generating a response
- CLI attempts to save a checkpoint
- UTF-8 character boundary error occurs at checkpoint.rs:373
- CLI terminates unexpectedly
Environment
- OS: macOS
- Amazon Q CLI version: [Your version]
Root Cause Analysis
The issue occurs because the Rust code is attempting to slice a string at byte index 60, which falls in the middle of the Korean character '코' (occupying bytes 59-62). This violates UTF-8 character boundaries and causes a panic.
Suggested Fix
The checkpoint saving logic should use character-aware string slicing methods that respect UTF-8 boundaries, such as:
- Using
char_indices()instead of byte indices - Implementing proper UTF-8 boundary checking before slicing
- Using safe string truncation methods
Impact
This bug prevents users from using Amazon Q CLI with Korean or other multi-byte character content, significantly limiting usability for non-English users.
Confirmed the issue
Just checked v1.18.1 vs main branch - you're spot on.
The Problem (v1.18.1)
let truncated = &s[..max_len]; // breaks on Korean chars
When Korean text hits 60 bytes, v1.18.1 tries to slice right through '코' (which spans bytes 59-62) → panic. Since Korean characters are 3 bytes each in UTF-8, any Korean text can trigger this issue when the 60-byte boundary falls in the middle of a character.
The Solution (main branch)
let truncated = truncate_safe(s, max_len);
The truncate_safe function in mod.rs properly handles UTF-8 boundaries using char_indices() instead of raw byte slicing.
Current Status
• v1.18.1: broken • main: fixed • next release: should include fix
Request
Can maintainers confirm this will be in the next release? And any ETA?
The bug is real and already solved in main.