Inflated savings metric, unreachable truncation log on Windows, and passthrough that doesn't pass through
Environment
- rtk 0.43.0
- Windows 11 (10.0.26200), Git Bash / MINGW64, bash 5.2.37
- Claude Code, hook:
PreToolUse→matcher: "Bash"→rtk hook claude
Filed together because all three surfaced in one session and are related to how failures are reported. Happy to split if you prefer.
1. rtk gain counts failed parses as savings
Two playwright test runs failed to parse and returned nothing usable:
[RTK:PASSTHROUGH] playwright parser: All parsing tiers failed
[full output: ~/AppData\Local\rtk\tee\1785452444_playwright.log]
Both appear in rtk gain as the highest-efficiency entries of the session:
9. rtk playwright test -... 1 221 92.9% 1.9s
10. rtk playwright test -... 1 221 92.9% 2.4s
Output that was never delivered is not savings — it is a command that had to be re-run, costing more than it saved. Counting discarded output inflates the headline number precisely when the tool is failing.
Suggestion: exclude runs whose parser failed from the savings aggregate, or report them in a separate "failed" bucket.
2. Truncation log path is unreachable on Windows
When output is truncated, rtk points at the full log:
+36 more in src/App.tsx [see remaining: tail -n +26 ~/AppData\Local\rtk\tee\1785452647_grep_0_src_App_tsx.log]
Two problems:
- The
~does not resolve to the Windows user profile under Git Bash. It expands toC:/SPB_Data/AppData/...and the file is not found:cat: C:/SPB_Data/AppData/Local/rtk/tee/....log: El sistema no puede encontrar la ruta especificada. (os error 3) - The path mixes separators:
~/AppData\Local\rtk\tee\...(forward slash then backslashes).
Net effect: the escape hatch to the full output cannot be opened, so truncation becomes unrecoverable in practice.
Suggestion: emit an absolute path with consistent separators for the shell in
use, or print $LOCALAPPDATA-based paths on Windows.
3. [RTK:PASSTHROUGH] does not pass anything through
When the parser fails, the label says PASSTHROUGH but the caller receives no command output — only the notice and the (unreachable, see #2) log path. If parsing fails, the useful behaviour is to emit the raw output unmodified.
Combined with #2, a parser failure means the output is simply lost.
Context
Measured over one long session: 119 commands, 14.7K tokens saved (39.4% by
rtk's own accounting) against ~525K message tokens — about 2.8%. Against that,
five or six lost round-trips from the failures above. rtk read (50-98%) and
rtk ls (55-70%) were consistently good; the problems were concentrated in
test runners and grep.
wshm · Automated triage by AI
🔍 Automated Triage
| 🐛 Category | bug |
| 🟠 Priority | high |
| 🎯 Confidence | 85% |
Summary
Three related bugs in one session: failed parses counted as savings in rtk gain, truncation log paths unreachable/malformed on Windows Git Bash, and PASSTHROUGH mode losing output entirely on parser failure — bundle for triage, may need splitting into separate fixes.
📁 Relevant files
src/gain.rs
Triaged automatically by wshm · This is an automated analysis, not a human review.
I'd like to work on the Windows-facing parts of this (unreachable truncation log path + related passthrough/savings accounting). Opening a PR from a fresh branch off develop.
Apologies for the earlier comment — I see #3344 already covers all three parts of this issue. Yielding so we don't duplicate work.
Adding a case for part 1 of this issue with a different mechanism than the failed-parse one, in case it helps pin the root cause.
Here the command succeeds and parses fine. The inflation comes from the baseline: track() compares the filtered output against the whole file, not against what the user's original command would have printed.
$ seq 1 5000 > seq5000.txt
$ rtk read seq5000.txt --head-lines 5
1
2
3
4
5
$ rtk gain
Total commands: 1
Input tokens: 6.0K
Output tokens: 3
Tokens saved: 6.0K (99.9%)
The user's command was head -n 5 seq5000.txt, which emits the same 10 bytes. Real saving: zero. Reported: 99.9%.
This matters more after #3941, which makes --head-lines byte-identical to native head. Under develop's head -N → --max-lines N mapping the output was at least smaller than head's, so the figure was overstated rather than invented; once the window is faithful, the entire reported saving for this route is fictitious.
Suggests the fix for part 1 is a baseline change — measure against what the rewritten-away command would have emitted — rather than only special-casing passthrough/failed-parse paths. Same shape as #2468 and #1561.
Found while reviewing #3941; not filing separately since it's the same metric.
Second mechanism for part 1, found reviewing #3941's latest push, and this one is specific to non-UTF-8 input.
TimedExecution::track takes &str and immediately reduces both sides through estimate_tokens, which is just text.len() / 4. So the strings are materialised only to have their byte length taken. The new byte fast path in read::run therefore does:
timer.track(
&format!("cat {}", file.display()),
"rtk read",
&String::from_utf8_lossy(&bytes), // whole input
&String::from_utf8_lossy(window),
);
For valid UTF-8 from_utf8_lossy borrows and this is free. For invalid input every bad byte becomes a 3-byte U+FFFD, so the input side inflates ~3x while the window usually doesn't — a one-sided distortion that overstates savings on exactly the binary files this path was added to support.
Measured on two 406-byte files, both --tail-lines 1, window 5 bytes:
| input | recorded in/out | recorded savings | true |
|---|---|---|---|
400 × \xff + \ntail\n |
302 / 2 | 99.34% | 102 / 2 → 98.04% |
400 × a + \ntail\n |
102 / 2 | 98.04% | correct |
Same root cause shows up as memory: a 144 MB binary peaks at 411 MB RSS, ~260 MB of which is the lossy copy that exists only to be measured. (The valid-UTF-8 path actually got lighter in that push, 293 MB → 151 MB, because the borrow replaced a String round-trip.)
Fix is local and does not need track's signature changed for every caller — a length-taking sibling next to the existing track_passthrough would do, e.g. track_sizes(orig, rtk, input_len, output_len), with the byte path passing bytes.len() and window.len().
Not filed separately and not blocking #3941 — the numbers it distorts are the ones this issue is already about.
#3943 (head eed26a42e) changes the shape of the from_utf8_lossy mechanism above without removing it. Its windowed fast paths book from_utf8_lossy(window) on both sides, so the ratio comes out right but both counts are the lossy size. Measured on develop 5ab629136 and on eed26a42e, with a separate history DB for each run:
| input | develop | #3943 |
|---|---|---|
3,000-byte file with 400 invalid bytes (ok\n\xff\xfe bad\nmore\n × 200), rtk read --tail-lines 3 --level none |
950 → 5, 99.5% (the whole input, lossy: 3,800 bytes) | 5 → 5, 0% |
same file, --head-lines 3 |
750 → 5, 99.3% (file size) | 5 → 5, 0% |
/dev/urandom --head-lines 2 |
159 → 286, −79.9% | 198 → 198, 0% (434 bytes printed, about 109 by bytes / 4) |
Stdout is byte-identical between the two builds for the file; /dev/urandom differs per run. On develop the distortion is one-sided in both directions: the byte-window path counts the whole input after lossy expansion, and the head path on a device counts the raw window against the lossy output, which books a negative row. With #3943 both sides are the lossy window, so savings read 0% and the absolute totals are inflated by up to 3× per invalid byte. The raw-byte accounting offered on #3943 for after it lands would close this on these paths.
All three parts are fixed on develop by #3344 (e87da19b): a run no parser tier understood is shown from both streams and booked as a parse failure instead of savings, and the tee hint's ~/ now resolves against the invoking shell's HOME with forward slashes. Labelled resolved-pending-close until it ships in a stable release.