#19112: fix(memory): prevent OOM on memory_get with large files
size: S
trusted-contributor
Cluster:
QMD Memory Management Fixes
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
#11364: fix(memory/qmd): prevent cascading failure when query fails or retu...
by blazerui · 2026-02-07
75.0%
#21217: fix: memory prune command to prevent unbounded MEMORY.md growth
by theognis1002 · 2026-02-19
72.7%
#9624: fix(memory): resolve QMD search returning empty results [AI-assisted]
by kowshik24 · 2026-02-05
72.7%
#15307: fix(memory): handle mixed/no-results QMD query output
by MohammadErfan-Jabbari · 2026-02-13
72.5%
#9438: fix: auto-detect low-memory environments and prevent test OOM
by CompassHXM · 2026-02-05
72.3%
#15945: fix(memory-flush): only write memoryFlushCompactionCount when compa...
by aldoeliacim · 2026-02-14
72.1%
#21471: fix: check QMD backend before memory search config
by lbo728 · 2026-02-20
71.6%
#9149: Fix: Allow QMD backend to work without OpenAI auth
by vishaltandale00 · 2026-02-04
70.3%
#19115: fix(logging): improved redaction for config objects and unquoted keys
by Clawborn · 2026-02-17
70.3%
#21242: fix(memory): add token budget limits for memory tools (#21187)
by Asm3r96 · 2026-02-19
70.0%