mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix: add size cap to assistant thread metadata cache
Prevents unbounded memory growth in _assistant_threads dict. Evicts oldest entries when exceeding _ASSISTANT_THREADS_MAX (5000), matching the pattern used by _mentioned_threads and _seen_messages.
This commit is contained in:
parent
30a0fcaec8
commit
241bd4fc7e
2 changed files with 29 additions and 0 deletions
|
|
@ -100,6 +100,7 @@ class SlackAdapter(BasePlatformAdapter):
|
|||
# events, and they carry the user/thread identity needed for stable
|
||||
# session + memory scoping.
|
||||
self._assistant_threads: Dict[Tuple[str, str], Dict[str, str]] = {}
|
||||
self._ASSISTANT_THREADS_MAX = 5000
|
||||
|
||||
async def connect(self) -> bool:
|
||||
"""Connect to Slack via Socket Mode."""
|
||||
|
|
@ -826,6 +827,12 @@ class SlackAdapter(BasePlatformAdapter):
|
|||
merged.update({k: v for k, v in metadata.items() if v})
|
||||
self._assistant_threads[key] = merged
|
||||
|
||||
# Evict oldest entries when the cache exceeds the limit
|
||||
if len(self._assistant_threads) > self._ASSISTANT_THREADS_MAX:
|
||||
excess = len(self._assistant_threads) - self._ASSISTANT_THREADS_MAX // 2
|
||||
for old_key in list(self._assistant_threads)[:excess]:
|
||||
del self._assistant_threads[old_key]
|
||||
|
||||
team_id = merged.get("team_id", "")
|
||||
if team_id and channel_id:
|
||||
self._channel_team[channel_id] = team_id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue