rtk-ai/rtk

rtk git diff/show --max-lines may inflate savings same way as #1045

Open

#1561 opened on Apr 27, 2026

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Rust (48,085 stars) (2,914 forks)batch import
bugeffort-smallfilter-qualitygood first issue

Description

Context

Follow-up flagged by @pszymkowiak in PR #1076 review.

#1045 was about rtk read counting user-requested line truncation as RTK token savings. The same pattern likely exists in:

  • src/cmds/git/git.rs:200git diff tracking
  • src/cmds/git/git.rs:314git show tracking

Both currently track against the compacted output. compact_diff itself is real RTK compression so that part is legitimate — but when a user passes --max-lines N to rtk git diff / rtk git show, the truncated portion gets counted as savings same as the original bug.

Reproduce (likely)

rtk git diff --max-lines 5  # large diff
rtk gain --history          # check if the saved-tokens row for this command is suspiciously high

Suggested fix

Apply the same pattern as #1076:

  1. Extract a pick_tracking_output(pre_truncation: Option<&str>, rtk_output: &str) -> &str helper (already lives in src/cmds/system/read.rs after #1076 merges — could be promoted to src/core/utils.rs).
  2. Capture the post-compact / pre-truncation content via std::mem::take when --max-lines is active.
  3. Pass the pre-truncation slice to timer.track() instead of the windowed output.

Out of scope here

  • Polluted historical data (separate concern — needs server-side cap or one-off migration, also flagged in #1076 review).

cc @pszymkowiak — opening as you suggested.

Contributor guide