Skip to content

rtk gain --history panics on non-ASCII (CJK) filenames in command history #2318

Closed

Description

@blackshixin-rgb

Bug Description

rtk gain --history panics when a recorded command contains CJK (Chinese/Japanese/Korean) characters in filenames. The truncation logic in gain.rs:250 uses a byte index that falls in the middle of a multi-byte UTF-8 character.

Steps to Reproduce

  1. Run any rtk command that includes CJK filenames, e.g.:
    rtk ls -la 停止小工具.command 启动小工具.command 内存监视.app
  2. Then run:
    rtk gain --history

Error Output

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

The display truncation at gain.rs:250 appears to use a fixed byte offset (likely &s[..22]) instead of a character-boundary-aware truncation. For ASCII this works fine, but CJK characters are 3 bytes each in UTF-8, so byte index 22 lands in the middle of '工' (U+5DE5, bytes 20..23).

Suggested Fix

Use s.char_indices() or s.floor_char_boundary(max_len) (stable since Rust 1.82) to find the nearest valid character boundary before truncating.

Environment

  • rtk version: 0.42.3
  • OS: macOS 15.5 (Darwin 25.5.0), arm64
  • Locale: zh_CN.UTF-8

Activity

  1. pszymkowiak commented on Jun 8, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 97%

    Summary

    Panic in gain.rs:250 when command history contains CJK filenames due to byte-index string slicing; fix by using char-boundary-aware truncation.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/analytics/gain.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  2. Yohjisakamoto commented on Jul 22, 2026

    @Yohjisakamoto

    This CJK history-analysis failure reinforces why end-to-end agent outcomes matter more than compressed text alone: DeepSWE found Tura cuts coding-agent rounds by 89% and total token cost by 80%; would you evaluate the methodology? https://turaai.net/docs#benchmark-current-test-set-record

  3. KuSh commented on Sep 5, 2026

    @KuSh
    Collaborator

    This panic is fixed: PR #2789 replaced the byte-index truncation in gain's history view with character-safe truncation, shipped in v0.44.0. The same crash is tracked on #2954, and your CJK repro no longer panics on current builds. If you still see it on 0.44.0 or newer, please comment on #2954 and we will reopen.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions