Skip to content

feat: add memory monitoring and proactive compaction#167

Merged
laynepenney merged 2 commits intomainfrom
feat/memory-monitor
Jan 26, 2026
Merged

feat: add memory monitoring and proactive compaction#167
laynepenney merged 2 commits intomainfrom
feat/memory-monitor

Conversation

@laynepenney
Copy link
Copy Markdown
Collaborator

Summary

Add memory monitoring system to prevent heap out of memory errors during long-running Codi sessions.

Problem

V8 heap OOM crashes occur when long-running sessions accumulate large conversation histories (~4GB heap limit).

Solution

Added memory monitoring with:

  • Real-time heap tracking using v8.getHeapStatistics()
  • Three alert levels: warning (60%), compact (70%), critical (85%)
  • Proactive compaction at 70% usage
  • 30-second throttle to prevent thrashing
  • New /compact memory command

Files

  • src/memory-monitor.ts: New memory monitor
  • src/agent.ts: Integrate monitor + proactiveCompact()
  • src/commands/compact-commands.ts: Add memory subcommand
  • src/index.ts: Add MEMORY_STATUS handler

Testing

  • Build passes
  • All 324 tests pass

Usage

/compact memory shows heap usage and stats

Add memory monitoring system to prevent heap out of memory errors:
- Real-time heap usage tracking with configurable thresholds
- Three alert levels: warning (60%), compact (70%), critical (85%)
- 30-second minimum interval between automatic compactions
- Proactive compaction triggered when memory usage exceeds 70%
- New '/compact memory' command to check heap usage

This addresses the V8 heap out of memory crash that occurs during
long-running sessions with large conversation histories.

Files:
- src/memory-monitor.ts: New memory monitoring system
- src/agent.ts: Integrate memory monitor and add proactive compaction
- src/commands/compact-commands.ts: Add memory subcommand
- src/index.ts: Add memory status display handler

Wingman: Codi <codi@layne.pro>
Fix E16 error by using correct snake_case property names from Node.js v8 API:
- Fix property names: used_heap_size, heap_size_limit, etc.
- Use proper ES module import for v8
- Add additional utility methods: isCritical(), getDetailedSnapshot()
- Test confirms memory monitor works correctly

Build and all 324 tests pass successfully.

Wingman: Codi <codi@layne.pro>
@laynepenney
Copy link
Copy Markdown
Collaborator Author

Final Self-Review: All tests pass, build successful, memory monitor functional. 15/15 edge cases tested. Ready to merge.

@laynepenney laynepenney merged commit 3b4af10 into main Jan 26, 2026
3 checks passed
@laynepenney laynepenney deleted the feat/memory-monitor branch January 26, 2026 03:43
laynepenney added a commit that referenced this pull request Jan 26, 2026
* feat: add memory monitoring and proactive compaction

Add memory monitoring system to prevent heap out of memory errors:
- Real-time heap usage tracking with configurable thresholds
- Three alert levels: warning (60%), compact (70%), critical (85%)
- 30-second minimum interval between automatic compactions
- Proactive compaction triggered when memory usage exceeds 70%
- New '/compact memory' command to check heap usage

This addresses the V8 heap out of memory crash that occurs during
long-running sessions with large conversation histories.

Files:
- src/memory-monitor.ts: New memory monitoring system
- src/agent.ts: Integrate memory monitor and add proactive compaction
- src/commands/compact-commands.ts: Add memory subcommand
- src/index.ts: Add memory status display handler

Wingman: Codi <codi@layne.pro>

* fix: ensure proper v8.getHeapStatistics() integration

Fix E16 error by using correct snake_case property names from Node.js v8 API:
- Fix property names: used_heap_size, heap_size_limit, etc.
- Use proper ES module import for v8
- Add additional utility methods: isCritical(), getDetailedSnapshot()
- Test confirms memory monitor works correctly

Build and all 324 tests pass successfully.

Wingman: Codi <codi@layne.pro>
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.

1 participant