rtk-ai / rtk-ai/rtk

`rtk read <file>` exits 1 with no output on a non-UTF-8 file, while `--head-lines`/`--tail-lines` on the same file are byte-exact

Open
#4,065 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:cli bug good first issue priority:medium
Dominant language
Rust
Stars
81.1k
Forks
5.1k
Avg merge
4d 11h
Merged PRs (30d)
40

Description

A plain read of a file that isn't valid UTF-8 exits 1 and prints nothing:

$ printf 'line one\nline two has a latin-1 byte: \xe9\nline three\n' > /tmp/nonutf8.log
$ rtk read /tmp/nonutf8.log
cat: /tmp/nonutf8.log: invalid utf-8 sequence of 1 bytes from index 38
$ echo $?
1

Same file, same binary, with a line window:

$ rtk read --head-lines 3 /tmp/nonutf8.log | cmp - /tmp/nonutf8.log && echo identical
identical

run() takes the byte path only when byte_line_window() returns Some, and that needs head_lines or tail_lines. A plain read has neither, falls through to String::from_utf8, and dies. The byte path is already byte-exact, it just isn't reachable without a window.

The hook decides which path a command lands on:

rewritten to result
cat frtk read f exit 1, no output
head -2 frtk read f --head-lines 2 works
tail -1 frtk read f --tail-lines 1 works

So cat on a log with one Latin-1 byte in it hands the agent an empty result, while head on the same file is fine. An empty result reads like an empty file.

CONTRIBUTING's Never Block rule covers this case: fall back to raw output instead of erroring out.

PR #1019 fixed it in April with a narrow gate (unfiltered, no window, no -n). A maintainer confirmed the bug on 2026-05-18 and asked for a rebase, the author rebased, and the branch then sat unreviewed until the stale bot closed it on 2026-09-14. I'll send a fresh PR against current develop.

  • develop @ d402152, macOS 26.6.2 arm64
  • also on 0.49.0 from brew, where the message reads stream did not contain valid UTF-8

Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the command's run() path and inspect byte_line_window(), which currently selects the byte-exact path only for head or tail windows. Reproduce the plain read and windowed read commands with the non-UTF-8 sample, then verify that the unfiltered plain read follows the raw-output fallback described by CONTRIBUTING's Never Block rule and preserves the file bytes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.