Skip to content

Conversation

@shtse8
Copy link
Contributor

@shtse8 shtse8 commented Dec 18, 2025

Summary

  • Fix critical memory leak: pendingFileChanges array was never cleared in lowMemoryMode
  • Each file change accumulated indefinitely, causing 100+GB memory usage over time
  • Add proper resource cleanup with CodebaseIndexer.close() method
  • Fix VectorStorage.close() to actually release LanceDB connection
  • Add graceful shutdown handler to MCP server

Root Cause

In rebuildSearchIndex(), when incrementalEngine is null (lowMemoryMode default), the function returned early without clearing pendingFileChanges. This caused the array to grow unbounded with each file change event.

Test plan

  • All existing tests pass
  • Manual testing with file watching confirms memory stays stable
  • Graceful shutdown (SIGINT/SIGTERM) properly releases resources

Root cause: In lowMemoryMode (default for PersistentStorage),
`pendingFileChanges` array was never cleared because
`incrementalEngine` is null, causing the early return in
`rebuildSearchIndex()` to skip cleanup.

Each file change pushed {newContent: full file content} to
the array, accumulating 100+GB over time in long-running
processes.

Fixes:
- Clear pendingFileChanges in rebuildSearchIndex early return
- Wrap rebuild logic in try/finally for exception safety
- Clear pendingFileChanges in stopWatch()
- Add CodebaseIndexer.close() for proper resource cleanup
- Fix VectorStorage.close() to actually close LanceDB connection
- Add graceful shutdown to MCP server calling indexer.close()
@vercel
Copy link

vercel bot commented Dec 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
coderag Ready Ready Preview, Comment Dec 18, 2025 2:12pm

@shtse8 shtse8 merged commit 3c83d15 into main Dec 18, 2025
5 checks passed
@shtse8 shtse8 deleted the fix/memory-leak-clean branch December 18, 2025 14:12
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.

2 participants