openclaw - 💡(How to fix) Fix feat: bot-to-bot loop detection when allowBots=true [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#58789Fetched 2026-04-08 02:32:35
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
mentioned ×1subscribed ×1

Code Example

{
  channels: {
    discord: {
      allowBots: true,
      botLoopProtection: {
        enabled: true,           // default: true when allowBots=true
        maxBotToBotPerMinute: 3, // max bot→bot messages per minute per pair
        cooldownSeconds: 60,     // pause bot→bot after hitting limit
      }
    }
  }
}
RAW_BUFFERClick to expand / collapse

Problem

When allowBots: true is enabled to allow multi-agent collaboration in a Discord channel, two bots can enter an infinite loop:

  1. Bot A posts a message that @Bot B
  2. Bot B receives it, processes it, responds with @Bot A
  3. Bot A receives that, processes it, responds with @Bot B
  4. Repeat until rate-limited

In our case, this ran for 42+ iterations before Anthropic rate limits stopped it, causing:

  • ~80 duplicate messages in session history
  • All other agents on the same API key became rate-limited
  • Wasted tokens/credits

Current behavior

allowBots: true + requireMention: true allows bot-to-bot @ mentions with no frequency limiting. The gateway has no awareness that a bot-to-bot conversation is looping.

Proposed solution

Add bot-to-bot loop detection at the gateway level:

{
  channels: {
    discord: {
      allowBots: true,
      botLoopProtection: {
        enabled: true,           // default: true when allowBots=true
        maxBotToBotPerMinute: 3, // max bot→bot messages per minute per pair
        cooldownSeconds: 60,     // pause bot→bot after hitting limit
      }
    }
  }
}

Detection logic

Track (senderBotId, receiverBotId, channelId) tuples with timestamps:

  • If the same bot pair exchanges > N messages in M seconds → suppress
  • Log a warning: [discord] bot-to-bot loop detected (botA↔botB), suppressing for 60s
  • After cooldown, allow again (the conversation may have moved on)

Why not just disable allowBots?

Multi-agent collaboration is a core use case. Agents need to @ each other for task delegation, code review, etc. The fix should be rate limiting, not disabling.

Environment

  • OpenClaw 2026.3.28
  • Two gateways (production + Docker staging) with different bot tokens in the same Discord server
  • Channel has requireMention: false for one bot and requireMention: true for the other

extent analysis

TL;DR

Implement bot-to-bot loop detection at the gateway level to prevent infinite loops when allowBots: true is enabled.

Guidance

  • Add a botLoopProtection configuration to the Discord channel settings with enabled: true to detect and prevent bot-to-bot loops.
  • Set maxBotToBotPerMinute to a suitable value (e.g., 3) to limit the number of bot-to-bot messages per minute per pair.
  • Configure cooldownSeconds to pause bot-to-bot conversations after hitting the limit (e.g., 60 seconds).
  • Verify the fix by testing the bot-to-bot conversation scenario and checking for the suppression of excessive messages.

Example

{
  channels: {
    discord: {
      allowBots: true,
      botLoopProtection: {
        enabled: true,
        maxBotToBotPerMinute: 3,
        cooldownSeconds: 60
      }
    }
  }
}

Notes

This solution assumes that the botLoopProtection configuration is properly implemented and functional. The values for maxBotToBotPerMinute and cooldownSeconds may need to be adjusted based on the specific use case and requirements.

Recommendation

Apply the proposed botLoopProtection workaround to prevent bot-to-bot loops and rate limiting issues, as it allows for multi-agent collaboration while preventing excessive message exchanges.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING