fix(grep): tee log for +N more overflow now holds full untruncated lines#3001
Open
albatrossflyon-coder wants to merge 1 commit into
Open
Conversation
rtk grep -r's per-file cap and clean_line's max-length truncation both draw from the same by_file entries, and only the truncated (cleaned) copy was ever kept. The "+N more ... [see remaining: tail -n +N ...]" hint points at a tee log that's supposed to restore full fidelity for the lines that didn't fit in the display, but since only the truncated copy existed by that point, the tee log was just as lossy — there was no way to recover a matched line's full text at all once it exceeded the length threshold. Carry the original (pre-clean_line) content alongside the cleaned copy in by_file's entries, and use the raw copy when building match_block for the tee log, while the interactive display keeps using the cleaned copy as before. Same token-budget-friendly display, but the recovery path this now actually recovers. Fixes rtk-ai#2988
tapheret2
reviewed
Jul 15, 2026
tapheret2
left a comment
There was a problem hiding this comment.
Review: fix(grep): tee log for +N more overflow now holds full untruncated lines
Files: src/cmds/system/search.rs
Size: +31 / -7
Notes
- Static pass on the patch: no obvious blockers from the diff alone.
Thanks @albatrossflyon-coder — independent review on the patch.
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
Fixes #2988 (the tee-log-fidelity half of it — see scope note below).
rtk grep -rcaps per-file results and truncates long lines viaclean_line, then points overflow at a tee log via a+N more ... [see remaining: tail -n +N ...]hint. The bug:clean_line's truncated outputis the only copy of each line kept in
by_file's entries — theoriginal, untruncated text is discarded right after truncation. Both the
interactive display and the tee log build from that same already-lossy
copy, so the tee log — whose entire purpose is full-fidelity recovery —
was just as truncated as the display it's supposed to recover from. There
was no way to get a matched line's full text back once it crossed the
length threshold, even by following the tool's own pointed-to recovery
path.
Fix
by_file's entries now carry both the cleaned (display) text and theoriginal raw text:
(line_num, is_match, cleaned, raw). The interactivebodyoutput keeps usingcleaned, unchanged.match_block— whichbuilds both the tee log content and the
skipped_filesoverflow block —now uses
rawinstead. Same compact display, but the recovery pathactually recovers.
Scope note
The issue also raised two related but distinct observations I left out of
this PR, since they're either a separate bug or a design call for a
maintainer:
rtk read's behavior) is a design decision, not a pure bug — didn't wantto bundle a behavior change into a fidelity fix.
--max-len" observation looked like apossibly-separate bug in a different code path; didn't want to guess at
a fix for something I hadn't isolated.
Happy to open a follow-up for either if a maintainer wants them tackled
separately.
Testing
lines, alternating short/padded-past-80-chars) against the local build:
before the fix, the tee log's recovered lines were still
...-truncatedexactly as reported; after the fix,
tail -n +26 <tee log>shows thecomplete untruncated line text.
cargo test: 2449 passed, 8 ignored, 0 failed (1 more pass than before —the new regression test)
test_match_block_uses_raw_not_cleaned_contentonmatch_blockdirectlycargo clippy --all-targets -- -D warnings: cleancargo fmt --check: clean