You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
gain --history panics: 'end byte index is not a char boundary' with CJK/multi-byte command history #3733
rtk gain --history (and rtk discover) panics whenever recent command history contains multi-byte UTF-8 characters, e.g. a command like rtk proxy rg -n ≥? or any output containing 万.
thread 'main' panicked at src/analytics/gain.rs:250:54:
end byte index 22 is not a char boundary; it is inside '万' (bytes 20..23 of string)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Root cause
In src/analytics/gain.rs, the print_ascii_graph function slices a string by byte index:
let date_short = if date.len() >= 10{&date[5..10]}
When the source string contains multi-byte UTF-8 (CJK characters are 3 bytes), byte offset 10 can land in the middle of a character, which Rust rejects at runtime and panics.
The same file already contains a safe pattern in show_failures that avoids this exact problem:
let ts_short = &rec.timestamp[..rec.timestamp.floor_char_boundary(16)];
str::floor_char_boundary is stable since Rust 1.73, so it can be reused here.
How to reproduce
# any command in history containing CJK or multi-byte chars, then:
rtk gain --history
Suggested fix
Use floor_char_boundary instead of raw byte slicing in print_ascii_graph (and audit rtk discover for the same class of issue when it summarizes commands containing CJK):
let date_short = &date[..date.floor_char_boundary(10)];
Closing as a duplicate of #2954, which tracks the same problem and is now fixed (PR #2789, v0.44.0+). Please comment on #2954 or open a new issue with a fresh reproduction if you still see this on the latest version.
Activity
KuSh commentedon Sep 5, 2026
Closing as a duplicate of #2954, which tracks the same problem and is now fixed (PR #2789, v0.44.0+). Please comment on #2954 or open a new issue with a fresh reproduction if you still see this on the latest version.