Skip to content

gain --history panics: 'end byte index is not a char boundary' with CJK/multi-byte command history #3733

Closed as duplicate

Description

@blackmochen

Summary

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)];

Environment

  • rtk 0.43.0
  • macOS arm64

Activity

  1. KuSh commented on Sep 5, 2026

    @KuSh
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions