fix(yuanbao): evict stale entries from _member_cache on TTL expiry - #23384
Closed
AhmetArif0 wants to merge 1 commit into
Closed
fix(yuanbao): evict stale entries from _member_cache on TTL expiry#23384AhmetArif0 wants to merge 1 commit into
AhmetArif0 wants to merge 1 commit into
Conversation
_build_msg_body_with_mentions() checks the TTL of each _member_cache entry and returns an empty member list when the entry is stale, but never removes the entry from the dict. Over time every group_code the bot has ever queried accumulates a permanent entry, retaining the full member list (potentially thousands of records per group) until disconnect(). Fix: delete the stale entry at the point it is detected as expired. The next call to get_group_member_list_raw() for the same group will repopulate the cache with fresh data as before. Symmetric with the existing TTL pattern in MessageDeduplicator, which evicts on access.
Contributor
|
Thanks for the focused cache-lifetime fix. The premise remains valid on current main: Problems
Suggested changes
This is an automated hermes-sweeper review. |
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.
Problem
_build_msg_body_with_mentions()inMessageSenderchecks whether a cached member list has expired, but never removes the stale entry:When the TTL has elapsed,
membersis set to[]and the stale entry is silently kept in the dict. Everygroup_codethe bot has ever queried retains a permanent entry in_member_cache— holding the full member list (potentially thousands of records per group) untildisconnect(). In a long-running bot serving many groups, this becomes an unbounded memory leak.get_group_member_list_raw()overwrites the entry on a fresh fetch for the same group, so active groups don't accumulate duplicates. But inactive or departed groups never get a fresh fetch, so their entry is never overwritten or removed.Fix
Delete the stale entry at the point it is detected as expired:
The next call to
get_group_member_list_raw()for the same group will repopulate the cache with fresh data, as it did before.Notes
_build_msg_body_with_mentionsis the only read path for_member_cache(one call site at L4104). The only write path isget_group_member_list_raw()at L3615. No concurrency concern — asyncio is single-threaded.MessageDeduplicator(used for inbound dedup on the same adapter), which also evicts on access when TTL expires.MEMBER_CACHE_TTL_S = 300.0(5 minutes), same value asMessageDeduplicator(ttl_seconds=300).Testing
Tested on: macOS