Repository navigation
Conversation
The path-based search buffered the engine's entire stdout via `.output()`, then copied it again with `from_utf8_lossy`. `rtk rg <pattern> logs/` over a 30 GB tree emitted 4.6 GB of matches, so rtk peaked at ~9 GB and the calling agent was OOM-killed. `| head -220` did not help: nothing is written until the child exits, so the consumer never gets to close the pipe. Route the capture through `run_streaming`'s `CaptureOnly`, which already caps retention at `RAW_CAP` (10 MiB) and warns when it truncates. The grouped form only ever renders `grep_max_results` matches, so output is unchanged for any search under the cap (the byte-identity contract in `grep_faithful_format_test` still holds); above it, the "N matches in M files" header becomes a floor. Measured on a 64 MiB file of matches: peak allocation dropped from >90 MiB to the cap, and the search went from 2m25s to 25s (the parse pass now runs over 10 MiB, not everything). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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
rtk grep/rtk rgover a path buffers the engine's entire stdout via.output(), then copies it again withfrom_utf8_lossy. On a 30 GB log tree the search emitted 4.6 GB of matches, rtk peaked at ~9 GB, and the calling agent was OOM-killed (Out of memory: Killed process (.rtk-wrapped) total-vm:8987044kB).| head -220is no escape hatch on this path: nothing is written until the child exits, so the consumer never gets to close the pipe.run_streaming'sCaptureOnly, which already caps retention atRAW_CAP(10 MiB) and warns when it truncates. One-line change plus a regression test — the streaming machinery was already there, the path-based branch just wasn't using it.Output is unchanged for any search under the cap, so the byte-identity contract in
grep_faithful_format_teststill holds. Above the cap the grouped form only ever rendersgrep_max_resultsmatches anyway; theN matches in M filesheader becomes a floor, and stderr says so.Measured on a 64 MiB file of matches: peak allocation dropped from >90 MiB to the cap, and the search went from 2m25s to 25s (debug) / 10s (release), because the parse pass now runs over 10 MiB instead of everything.
Test plan
cargo fmt --all && cargo clippy --all-targets && cargo testcore::tracking::tests::*flake on this machine (a different one each run, ondevelopunmodified too) — they share the real tracking DB.tests/search_memory_test.rs: 64 MiB of matches searched underulimit -v 400000. Fails ondevelopwithmemory allocation of 92274688 bytes failed, passes here.rtk grep <pat> <64MiB file>output byte-identical to the released binary on normal searches; the capped case prints the grouped form plus the truncation warning.🤖 Generated with Claude Code