Skip to content

fix(read): window tracking baseline - #2699

Closed
wyf027 wants to merge 1 commit into
rtk-ai:developfrom
wyf027:fix/read-window-tracking-1045
Closed

wyf027 wants to merge 1 commit into
rtk-ai:developfrom
wyf027:fix/read-window-tracking-1045

Conversation

@wyf027

@wyf027 wyf027 commented Jun 28, 2026

Copy link
Copy Markdown

Summary

Test plan

  • cargo fmt --all --check
  • cargo test prepare_outputs -- --nocapture
  • cargo test apply_line_window -- --nocapture
  • git diff --check
  • cargo fmt --all && cargo clippy --all-targets && cargo test
  • Manual testing: rtk read --max-lines 2 <file> output inspected

@CLAassistant

CLAassistant commented Jun 28, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

pszymkowiak added a commit that referenced this pull request Sep 8, 2026
Adapted from stale community PR #2699 (fixes the same defect as the
closed-as-duplicate #1045: "truncation via --max-lines incorrectly
counted as token savings, producing 250M+ saved tokens in one
command" -- a real bioinformatics-file repro).

rtk read's --max-lines/--tail-lines window was applied only to the
filtered output before comparing it against the raw content for
tracking. The raw baseline stayed the FULL file. Content the user
explicitly asked NOT to see (outside the window) was then counted as
"token savings" -- but that's the user choosing to see less, not RTK
compressing anything.

Extracted prepare_outputs() to window both raw and filtered content
identically before the timer.track() comparison. 3 new tests,
including one proving real filter savings INSIDE the window (e.g. a
stripped comment) still get counted correctly -- only content outside
the window stops counting.

Verified live: `rtk read --max-lines 5` on a 50,000-line file with no
real filtering (level=none) now correctly records 0 saved tokens
(previously, even after this branch's earlier cap fix alone, it
recorded ~7,458 saved tokens / 99% -- a bounded but still fake
"compression" that was actually just the window).
pszymkowiak added a commit that referenced this pull request Sep 8, 2026
Independent codex review of this branch caught a real regression in
the previous commit: prepare_outputs() computed a single windowed
"raw" value and returned it as both the tracking baseline AND the
value fed into never_worse()/print!() -- so windowing the raw side for
tracking purposes could also change what actually gets PRINTED to the
user. Concrete failure: comparing two already-windowed strings can
flip never_worse's fallback, printing an unfiltered raw excerpt
instead of the real filtered content.

This bug was already present in the stale community PR (#2699) this
commit's parent was adapted from -- caught by independent review, not
by that PR's own tests, which never exercised the display path.

Fix: split the concern. run()/run_stdin() go back to computing
raw/shown exactly as before this branch touched them (full,
unwindowed content feeds the display safety net, unchanged). A new
tracking_baseline() helper -- returning a single String, not a pair,
so this bug class can't be silently reintroduced -- computes ONLY the
windowed value passed to timer.track().

Replaced the 3 prepare_outputs tests with tracking_baseline
equivalents, and added a new #[ignore]-gated integration test running
the real binary end-to-end (rtk read --level minimal --max-lines 2 on
a file with a comment RTK should strip) asserting the printed output
never contains the raw comment -- directly reproducing and guarding
against the exact scenario the review caught.
@rtk-release-bot

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale due to 90 days of inactivity. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. Your contribution is very much appreciated — we're sorry we haven't been able to review it yet.

@rtk-release-bot

Copy link
Copy Markdown
Contributor

Closing this pull request after a prolonged period of inactivity. If this is still relevant, please ask for it to be reopened. Thank you!

@rtk-release-bot rtk-release-bot Bot closed this Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk read: truncation via --max-lines incorrectly counted as token savings, producing 250M+ saved tokens in one command

2 participants