perf(discord): eager multibot detection from msg.author#465
Merged
thepagent merged 1 commit intoopenabdev:mainfrom Apr 19, 2026
Merged
Conversation
Instead of fetching thread history to detect other bots on every unmentioned message, detect multi-bot threads eagerly from msg.author: when a bot message arrives in a thread, cache multibot_threads immediately — zero API calls needed. This eliminates per-message fetches in MultibotMentions mode for single-bot threads (which would never find other bots but fetched every time to check). - Add early detection before gating: msg.author.bot → cache multibot - Simplify bot_participated_in_thread: cached_involved → return immediately with cached_multibot, no MultibotMentions special-casing Builds on openabdev#464
|
All PRs must reference a prior Discord discussion to ensure community alignment before implementation. Please edit the PR description to include a link like: This PR will be automatically closed in 3 days if the link is not added. |
thepagent
approved these changes
Apr 19, 2026
This was referenced Apr 19, 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
Builds on #464. Eliminates unnecessary API fetches in
multibot-mentionsmode.Problem
In #464,
bot_participated_in_thread()fetches up to 200 messages on every unmentioned message inMultibotMentionsmode — even in single-bot threads where no other bot will ever be found. This is becausecached_involved = truecould not short-circuit without knowingother_bot_present.Solution
Detect multi-bot threads eagerly from
msg.authorinstead of fetching history:When a bot message arrives in a thread, we already know it is multi-bot. No fetch needed.
This allows
bot_participated_in_thread()to short-circuit oncached_involvedalone:Impact
Cold-start note
After bot restart, both caches are empty. If a thread is already multi-bot but the next message is from a user (not a bot), early detection won't trigger and
cached_multibot = false. However,cached_involvedis also false (cleared on restart), sobot_participated_in_threadwill fetch — and the fetch includesother_bot_presentdetection, which repopulates the cache. This is safe and consistent with #464 behavior — just one fallback fetch on the first message after restart.Changes (
src/discord.rs, +12/-6)msg.authorbefore gating logicbot_participated_in_thread:cached_involved→ return(true, cached_multibot)immediately, no mode-specific branching