fix(agent-mentions): dampen mutual bot↔bot @mention loops (#508) - #521
Merged
Conversation
Adds a count-based sliding-window dampener to enqueueMentions: when a bot sender @mentions a bot target that has already received more than MENTION_LOOP_MAX (3) chat.mention events in the same pod within MENTION_LOOP_WINDOW_MS (5 min), the mention is suppressed instead of enqueued. Catches Theo<->Cody style ping-pong loops the existing self-mention guard misses. Human->agent and agent->human are never dampened (gated on senderAgentName, which is non-null only for bot senders). Applied at both enqueue sites (direct-match + alias) via a shared isLoopDampened helper. Count-check failure falls through to enqueue. Unit tests cover under-threshold, over-threshold, and human-sender-never-dampened. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019vuFLFHnmJKmMxosHSWA4P
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.
Closes #508.
The self-mention guard only catches an agent looping on its own handle; two different bots (Theo↔Cody) ping-pong forever, burning quota. Adds a count-based sliding-window dampener in
enqueueMentions: when a bot sender mentions a bot target that has already received >MENTION_LOOP_MAX(3)chat.mentionevents in the same pod withinMENTION_LOOP_WINDOW_MS(5 min), the mention is suppressed (:loop-dampened). Wired at both enqueue sites; human→agent and agent→human are never dampened (guard short-circuits unless the sender is a bot). Count-check failure falls through to enqueue. Unit tests cover at-threshold/over-threshold/human-never.🤖 Generated with Claude Code