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
rtk gain --failures (-F) panics on non-ASCII command text at gain.rs:731 (sibling of #2318) #3232
rtk gain --failures / rtk gain -F panics when a recorded command string in the parse-failure log contains a multi-byte (CJK) character and the display truncation slices it mid-character. This is the --failures display path, distinct from the --history path tracked in #2318 (which is gain.rs:250); this one is gain.rs:731.
Steps to Reproduce
Have any command containing CJK text in the failure log (e.g. a grep/find over a vault with Chinese paths, or pip output containing CJK), then:
rtk gain -F # or: rtk gain --failures
Error Output
thread 'main' (8871270) panicked at src/analytics/gain.rs:731:50:
end byte index 37 is not a char boundary; it is inside '周' (bytes 35..38 of string)
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
(Different invocations land on different bytes/chars — e.g. earlier 跳 at byte boundary 21..24 — depending on which command string is being truncated.)
Root Cause
Same class as #2318: the truncation at gain.rs:731 uses a fixed byte index (&s[..n]) instead of a character-boundary-aware cut. CJK chars are 3 bytes in UTF-8, so a byte offset that is valid for ASCII lands mid-character.
Workaround
--format json renders the same data through a different code path and does not panic:
rtk gain -F --format json
rtk gain --history --format json
Suggested Fix
Use s.floor_char_boundary(max_len) (stable since Rust 1.82) or s.char_indices() before truncating — applies to both the :250 (--history) and :731 (--failures) sites.
rtk gain --failures panics on multi-byte (CJK) command text due to byte-index string slicing at gain.rs:731; fix with char-boundary-aware truncation (same fix pattern as #2318 for gain.rs:250).
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.
I initially investigated this issue with the intention of implementing a fix and opening a PR. However, after upgrading Homebrew to rtk 0.44.0, I could not reproduce the panic, so I dug into the repository history and performed a controlled before/after reproduction.
Investigation
PR #2789 (fix(analytics): truncate display strings on UTF-8 char boundaries) was merged into develop on July 3 and is included in the stable v0.44.0 tag. It replaces the byte-index truncation in both gain --history and gain --failures with the shared UTF-8-safe truncate() helper.
Exact reproduction against v0.42.3
I downloaded the official rtk-aarch64-apple-darwin.tar.gz asset for v0.42.3 and verified its SHA-256 against the release checksum:
Test environment: macOS arm64. I used an isolated RTK_DB_PATH, so no existing analytics data was involved.
I created a real temporary vault containing:
/tmp/aaaaaaaaaaaaaaaa/周报/记录.txt
Then ran the v0.42.3 binary with:
rtk grep -r test /tmp/aaaaaaaaaaaaaaaa/周报
The native grep fallback executed successfully and the command was recorded in the parse-failure log. The path length was chosen deliberately: in the recorded raw command, 周 occupies bytes 35..38, so the old 37-byte display slice lands inside the character.
Running:
rtk gain -F
with v0.42.3 reproduced the report exactly:
thread 'main' panicked at src/analytics/gain.rs:731:50:
end byte index 37 is not a char boundary; it is inside '周' (bytes 35..38 of string)
The process exited with code 134.
Same database with v0.44.0
Without changing or recreating the database entry, I ran the Homebrew v0.44.0 binary against the same database:
rtk gain -F
It completed with exit code 0 and displayed the CJK command correctly in both sections:
Top Commands (by frequency)
1x grep -r test /tmp/aaaaaaaaaaaaaaaa/周报
Recent Failures (last 10)
... [ok] grep -r test /tmp/aaaaaaaaaaaaaaaa/周报
Additional observation
Using the exact workaround syntax shown in the issue:
rtk gain -F --format json
still reached the text display path and panicked on the official v0.42.3 binary in this reproduction.
Conclusion
The bug is definitely present in v0.42.3, but the same deterministic reproduction is fixed in v0.44.0. A new PR appears unnecessary because #2789 already contains the relevant fix and it has shipped in v0.44.0. This issue can likely be closed as fixed, subject to maintainer confirmation. @pszymkowiak
This looks resolved on the current code (PR #2789 / v0.44.0), but it could not be fully reproduced here. Marking it resolved-pending-close: it will be closed in a while unless someone reports it still happening on the latest version.
Fixed by #2789, shipped in v0.44.0: both the --history and --failures display paths now truncate on character boundaries instead of byte indices. I reproduced your case by seeding a failure log entry with CJK text and running rtk gain -F on current code, it truncates cleanly and exits 0. Please reopen or comment if you still hit a panic on the latest version.
Activity
pszymkowiak commentedon Jul 27, 2026
🔍 Automated Triage
bughighSummary
rtk gain --failures panics on multi-byte (CJK) command text due to byte-index string slicing at gain.rs:731; fix with char-boundary-aware truncation (same fix pattern as #2318 for gain.rs:250).
📁 Relevant files
src/analytics/gain.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
msranjana commentedon Jul 27, 2026
Hi @pszymkowiak I would like to work on this issue. Please let me know if it's available for me to take. Thanks!
JJordan0C commentedon Jul 28, 2026
I initially investigated this issue with the intention of implementing a fix and opening a PR. However, after upgrading Homebrew to
rtk 0.44.0, I could not reproduce the panic, so I dug into the repository history and performed a controlled before/after reproduction.Investigation
PR #2789 (
fix(analytics): truncate display strings on UTF-8 char boundaries) was merged intodevelopon July 3 and is included in the stablev0.44.0tag. It replaces the byte-index truncation in bothgain --historyandgain --failureswith the shared UTF-8-safetruncate()helper.Exact reproduction against v0.42.3
I downloaded the official
rtk-aarch64-apple-darwin.tar.gzasset for v0.42.3 and verified its SHA-256 against the release checksum:Test environment: macOS arm64. I used an isolated
RTK_DB_PATH, so no existing analytics data was involved.I created a real temporary vault containing:
Then ran the v0.42.3 binary with:
rtk grep -r test /tmp/aaaaaaaaaaaaaaaa/周报The native
grepfallback executed successfully and the command was recorded in the parse-failure log. The path length was chosen deliberately: in the recorded raw command,周occupies bytes 35..38, so the old 37-byte display slice lands inside the character.Running:
with v0.42.3 reproduced the report exactly:
The process exited with code 134.
Same database with v0.44.0
Without changing or recreating the database entry, I ran the Homebrew v0.44.0 binary against the same database:
It completed with exit code 0 and displayed the CJK command correctly in both sections:
Additional observation
Using the exact workaround syntax shown in the issue:
still reached the text display path and panicked on the official v0.42.3 binary in this reproduction.
Conclusion
The bug is definitely present in v0.42.3, but the same deterministic reproduction is fixed in v0.44.0. A new PR appears unnecessary because #2789 already contains the relevant fix and it has shipped in v0.44.0. This issue can likely be closed as fixed, subject to maintainer confirmation. @pszymkowiak
KuSh commentedon Sep 5, 2026
This looks resolved on the current code (PR #2789 / v0.44.0), but it could not be fully reproduced here. Marking it resolved-pending-close: it will be closed in a while unless someone reports it still happening on the latest version.
KuSh commentedon Sep 13, 2026
Fixed by #2789, shipped in v0.44.0: both the --history and --failures display paths now truncate on character boundaries instead of byte indices. I reproduced your case by seeding a failure log entry with CJK text and running
rtk gain -Fon current code, it truncates cleanly and exits 0. Please reopen or comment if you still hit a panic on the latest version.