Repository navigation
fix(analytics): truncate display strings on UTF-8 char boundaries - #2789
Merged
Merged
Conversation
rtk gain --history panicked with "byte index 22 is not a char boundary" when a tracked command contained non-ASCII text (Cyrillic, CJK, emoji). The same byte-slicing pattern existed in the --failures display (top commands, recent failures, timestamp prefix) and in the session id column of rtk session, all reproduced as real panics. Replace the ad-hoc byte-based truncations with the shared char-safe core::utils::truncate() helper, and use .get(..n).unwrap_or() for the timestamp and session id prefix slices so they fall back to the full string instead of panicking. Output is byte-identical to the previous behavior for pure-ASCII data. Fixes #2787
KuSh
approved these changes
Jul 3, 2026
Merged
This was referenced Sep 5, 2026
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.
Fixes #2787
Problem
rtk gain --historypanicked when a tracked command contained non-ASCII text (Cyrillic, CJK, emoji):Root cause
Display code in
src/analytics/truncated strings with raw byte slicing (s.len() > Nthen&s[..M]), which panics when the cut lands inside a multi-byte UTF-8 character. These were hand-inlined byte-based copies of the char-safecore::utils::truncate()helper that the rest of the codebase already uses. This is the 5th recurrence of this defect class (previous fixes: da486bf tee, c5ec92f git, 533894a json, #2751 parser); an audit of all string-slice sites insrc/confirmed the remaining unsafe ones were all insrc/analytics/.Every fixed site was first reproduced as a real panic against the pre-fix binary with crafted data:
gain.rshistory commandbyte index 22 is not a char boundarygain.rsfailures top commandsbyte index 47 is not a char boundarygain.rsfailures recent commandsbyte index 37 is not a char boundarygain.rsfailures timestamp prefixbyte index 16 is not a char boundarysession_cmd.rssession id prefixbyte index 8 is not a char boundaryFix
core::utils::truncate()(chars-based, existing helper, no new dependency)..get(..n).unwrap_or(full)for the timestamp and session id prefix slices: valid prefix when the boundary is clean, full string instead of a panic otherwise.Verification
rtk ls -la "D:\...Ародинамический..."tracked, thenrtk gain --history) now renders correctly with exit 0.RTK_DB_PATHdatabases and a sandboxedCLAUDE_CONFIG_DIR).gain --history,gain --failuresandsession, with every truncation branch exercised (ellipsis present in compared output).cargo fmt --all --check,cargo clippy --all-targets(zero warnings),cargo test --all(2371 passed).Checklist
src/core/utils.rs)CAP_*applies to filter output lists; the 10-row display limits here are pre-existing SQLLIMIT 10, unchanged)rtk gain --history,rtk gain --failures,rtk sessioninspectedFollow-up candidate (out of scope here): enable
clippy::string_slicerepo-wide to prevent this defect class permanently; it requires#[allow]annotations on the ~20 verified-safe slice sites.