Skip to content

fix(git): filter git show <rev>:<path> blob reads past a size threshold - #3154

Closed
albatrossflyon-coder wants to merge 1 commit into
rtk-ai:developfrom
albatrossflyon-coder:fix/git-show-blob-token-waste
Closed

albatrossflyon-coder wants to merge 1 commit into
rtk-ai:developfrom
albatrossflyon-coder:fix/git-show-blob-token-waste

Conversation

@albatrossflyon-coder

Copy link
Copy Markdown
Contributor

Fixes #3116

Root cause

git show <rev>:<path> (blob read form) was routed to raw passthrough unconditionally in run_show, same as --stat/--pretty output. Unlike the diff form of git show, which auto-compacts below in the same function, the blob form never went through any filtering — confirmed against a real 5-week command-history DB: 436 calls, 3.82M input tokens, 0.6% aggregate savings vs. 50%+ for the <rev> -- <path> diff form.

Fix

  • Blobs at or under 200 lines (BLOB_FILTER_LINE_THRESHOLD) stay byte-identical passthrough — not worth a filter pass, per the issue's own suggested conservative threshold.
  • Past that, the blob is run through the existing MinimalFilter (the same comment/blank-line-stripping filter rtk read -l minimal uses), with the language detected from the path segment of the rev:path arg.
  • never_worse (already used everywhere else in this file) guards the result — if filtering doesn't actually shrink the output, raw is shown instead.
  • Tracking label switches to (blob-filtered) vs (passthrough) depending on whether filtering actually reduced size, so telemetry can distinguish the two going forward.

Verification

  • cargo test — 2474 passed, 0 failed (3 new tests added: under-threshold passthrough stays byte-identical, over-threshold strips comments while preserving code, unknown-extension blobs are still bounded by never_worse).
  • cargo fmt --check / cargo clippy -- -D warnings — clean.
  • Live repro against this repo's own git.rs (3367 lines): raw git show HEAD:src/cmds/git/git.rs is 113,289 bytes; rtk git show of the same blob is 105,016 bytes (comments/blank-lines stripped, code untouched — diffed to confirm no code lines were removed, only // comment lines).
  • Small file (Cargo.toml, well under the threshold) is confirmed byte-identical between git show and rtk git show.

The 200-line threshold is a first cut per the issue's own suggestion ("so tiny files stay passthrough") — happy to tune it if you'd rather key off byte size or make it configurable.

`git show <rev>:<path>` prints a file's content at a revision (not a
diff), but the handler routed it to raw passthrough unconditionally —
telemetry from a 5-week history DB showed 436 calls, 3.82M input
tokens, 0.6% savings, vs. 50%+ for the diff form of the same command.

Blobs at or under 200 lines still pass through untouched. Past that,
run the same comment-stripping filter `rtk read -l minimal` uses,
keyed off the path's extension, guarded by the existing never_worse
check so filtering can never cost more than raw output.

Fixes rtk-ai#3116
@KuSh

KuSh commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks for working on this. Blob reads with rtk git show <rev>:<path> are now filtered on develop by #3265 (merged 2026-09-11, shipped in v0.50.0): large blobs get an 8 KiB preview with a hint pointing at the rest, and #3116 was closed on that basis. Small blobs already pass through unchanged there, as this PR proposed. If a case is still missed, please comment here or reopen.

@KuSh KuSh closed this Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk git show <rev>:<path> is a file read but routes to passthrough (0% savings) instead of the read filter

2 participants