Repository navigation
Conversation
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.
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. |
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--max-lines/--tail-lineswindow to the raw tracking baseline that is applied to filtered output.Test plan
cargo fmt --all --checkcargo test prepare_outputs -- --nocapturecargo test apply_line_window -- --nocapturegit diff --checkcargo fmt --all && cargo clippy --all-targets && cargo testrtk read --max-lines 2 <file>output inspected