LOW: Add eviction policy for conversation history to prevent memory leak #39
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
bot/utils/conversation_history.py stores per-channel conversation history in a Python dict in globals (globals.conversation_histories). Each channel the bot interacts with gets an entry that grows over time.
While individual channel histories may be bounded (the ConversationHistory class likely has a max length), the number of CHANNELS tracked grows without bound. Over weeks/months of operation:
This is a slow memory leak that compounds over long uptimes.
Current Behavior
Proposed Solution
Add an LRU or time-based eviction policy:
Option A: LRU with max size
Option B: Time-based TTL
Add a last_accessed timestamp to each ConversationHistory. Run a periodic cleanup (e.g., every hour via APScheduler) that evicts entries older than N hours.
Option C: Both (LRU + TTL)
Combine max size and time-based eviction for the most robust solution.
Impact
Files Affected