[AI-assisted] fix(history): add LRU eviction for groupHistories to prevent memory leak#2389
Merged
thewilloftheshadow merged 2 commits intoopenclaw:mainfrom Jan 26, 2026
Conversation
Add evictOldHistoryKeys() function that removes oldest keys when the history map exceeds MAX_HISTORY_KEYS (1000). Called automatically in appendHistoryEntry() to bound memory growth. The map previously grew unbounded as users interacted with more groups over time. Growth is O(unique groups) not O(messages), but still causes slow memory accumulation on long-running instances. Fixes #2384
ba92349 to
8e495db
Compare
thewilloftheshadow
added a commit
that referenced
this pull request
Jan 26, 2026
thewilloftheshadow
added a commit
that referenced
this pull request
Jan 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds automatic LRU-style eviction to history maps to prevent unbounded memory growth in long-running instances.
Problem
The
groupHistoriesMap (and similar maps in Signal, WhatsApp, iMessage monitors) grows unbounded as users interact with more groups over time:While
clearHistoryEntries()empties values, keys are never deleted. Growth is O(unique groups), causing slow but steady memory accumulation.Solution
Added to
src/auto-reply/reply/history.ts:Called automatically in
appendHistoryEntry()to bound map size. Uses Map's insertion order for LRU-like behavior.Benefits
Testing
pnpm build)pnpm lint)AI Disclosure
This PR was AI-assisted (Claude/Codex). The issue was discovered through automated code analysis comparing memory patterns across long-running instances.
Fixes #2384