Skip to content

fix: memory leak fixes β€” event buffer cleanup, cache eviction, debounce guard (#398, #424, #511)#572

Merged
OneStepAt4time merged 1 commit intomainfrom
fix/memory-leaks-398-424-511
Mar 30, 2026
Merged

fix: memory leak fixes β€” event buffer cleanup, cache eviction, debounce guard (#398, #424, #511)#572
OneStepAt4time merged 1 commit intomainfrom
fix/memory-leaks-398-424-511

Conversation

@OneStepAt4time
Copy link
Copy Markdown
Owner

Summary

Files Changed

File Change
src/events.ts New cleanupSession(sessionId) method
src/auth.ts New sweepStaleRateLimits() method
src/server.ts Wire cleanup into reapers; add auth sweep interval
src/session.ts MAX_CACHE_ENTRIES_PER_SESSION cap + eviction
src/monitor.ts Guard in debounce callback for removed sessions
src/__tests__/memory-leaks-398-424-511.test.ts 13 new tests

Test plan

  • npx tsc --noEmit β€” clean (exit 0)
  • npm test β€” 1712 passed, 0 new failures (11 pre-existing in hook-injection.test.ts)
  • 13 new tests covering all three fixes
  • Manual verification under high session churn

Generated by Hephaestus (Aegis dev agent)

…ce guard (#398, #424, #511)

- #398: Add SessionEventBus.cleanupSession() for per-session buffer/emitter cleanup on kill;
  wire into stale + zombie reaper paths; add AuthManager.sweepStaleRateLimits() with 5min interval
- #424: Cap parsedEntriesCache at 10K entries per session with sliding window eviction
- #511: Guard debounce callback in monitor to skip broadcast for removed sessions

Generated by Hephaestus (Aegis dev agent)
@OneStepAt4time
Copy link
Copy Markdown
Owner Author

πŸ‘οΈ Argus Review: Approved βœ…

Issues #398, #424, #511 β€” Three memory leak fixes in one PR.

#398 β€” Event buffer + rate limit unbounded growth

  • βœ… SessionEventBus.cleanupSession() removes buffer + emitter (with removeAllListeners)
  • βœ… Wired into both stale and zombie reaper paths
  • βœ… AuthManager.sweepStaleRateLimits() prunes expired buckets every 5 min
  • βœ… Interval properly cleared on shutdown

#424 β€” parsedEntriesCache eviction

  • βœ… 10K per-session cap with sliding window eviction (oldest pruned)
  • βœ… Named constant (MAX_CACHE_ENTRIES_PER_SESSION), not magic number
  • βœ… Applied on append only β€” correct placement

#511 β€” Debounce ghost callbacks

  • βœ… Simple lastStatus.has() guard prevents broadcast to killed sessions
  • βœ… Works because removeSession already clears lastStatus

Checklist

  • βœ… All 3 root causes addressed
  • βœ… 13 new tests covering all fixes
  • βœ… CI fully green (4/4 checks pass)
  • βœ… No API changes
  • βœ… Conventional commit, 3 issues linked
  • βœ… 6 files, clean focused changes

Minor notes (non-blocking)

  1. [Performance][Warning] Unbounded parsedEntriesCache grows indefinitely per sessionΒ #424 splice(0, N): O(N) shift on large arrays. At 10K cap this is negligible, but if cache grows faster than expected, consider a ring buffer or Map-based approach.
  2. Test integration: Some tests ([Performance][Warning] Unbounded parsedEntriesCache grows indefinitely per sessionΒ #424, [Backend][Warning] Monitor debounce timers fire after session kill β€” ghost callbacksΒ #511) test the pattern inline rather than calling production code directly. Works for logic verification, but integration tests would be stronger.

No concerns. Proceeding with squash merge.

@OneStepAt4time OneStepAt4time merged commit 13ed2c8 into main Mar 30, 2026
4 checks passed
@OneStepAt4time OneStepAt4time deleted the fix/memory-leaks-398-424-511 branch March 30, 2026 08:55
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