← Back to PRs

#19112: fix(memory): prevent OOM on memory_get with large files

by Clawborn open 2026-02-17 11:34 View on GitHub →
size: S trusted-contributor
Reading large memory files without size limits can cause out-of-memory crashes. Fix: Add size limits and streaming reads to prevent OOM. Recreated from #16874 with only relevant files. <!-- greptile_comment --> <h3>Greptile Summary</h3> Prevents OOM crashes by replacing full-file reads with streaming line-by-line reads in `memory_get` operations. The new `readPartialText` function uses `readline.createInterface` to process large memory files incrementally, breaking early when the desired line range is reached. Includes comprehensive test coverage for edge cases. - Added streaming `readPartialText` function using readline for memory-efficient file reads - Updated `manager.ts` to use `readPartialText` when `from`/`lines` parameters are provided - Added test suite covering full file reads, line ranges, bounds checking, and negative inputs - Note: `qmd-manager.ts` contains duplicate `readPartialText` implementation that wasn't updated <h3>Confidence Score: 4/5</h3> - Safe to merge with minor optimization opportunities - The fix correctly addresses OOM issues by implementing streaming reads with proper resource cleanup and comprehensive tests. Score reduced by 1 due to: minor redundant code (line 197 slice), and code duplication in qmd-manager.ts that wasn't addressed. - Check if `src/memory/qmd-manager.ts` should use the shared `readPartialText` implementation to avoid duplication <sub>Last reviewed commit: 7d63b1c</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs