Problem
MAX_CONSECUTIVE_BOT_TURNS (hardcoded at 10) is meant to prevent runaway bot loops in allow_bot_messages = "all" mode. However, it only counts consecutive messages from other bots using take_while:
let consecutive_bot = recent.iter()
.take_while(|m| m.author.bot && m.author.id != bot_id)
.count();
When two bots @mention each other, the count never reaches the cap because each bot's own reply breaks the take_while chain:
Bot A: @BotB do something ← Bot B sees: consecutive_bot = 1
Bot B: @BotA done ← Bot A sees: consecutive_bot = 1
Bot A: @BotB do more ← Bot B sees: consecutive_bot = 1
... infinite loop, counter never exceeds 1
This applies to any multi-bot setup where bots collaborate via @mentions (e.g. code review → deploy handoff).
Suggested approaches
-
Total bot turns per thread — count all bot messages (including own) in the thread, cap at N. Simple but may be too restrictive for long-running threads.
-
Bot turns within a time window — count bot messages in the last N minutes. Allows long threads but prevents rapid-fire loops.
-
Per-thread cooldown — after responding to a bot message, wait N seconds before responding to another bot message in the same thread.
-
Configurable max_bot_turns — make the cap configurable (currently hardcoded at 10) and change the counting logic to total bot turns rather than consecutive.
Related
Problem
MAX_CONSECUTIVE_BOT_TURNS(hardcoded at 10) is meant to prevent runaway bot loops inallow_bot_messages = "all"mode. However, it only counts consecutive messages from other bots usingtake_while:When two bots @mention each other, the count never reaches the cap because each bot's own reply breaks the
take_whilechain:This applies to any multi-bot setup where bots collaborate via @mentions (e.g. code review → deploy handoff).
Suggested approaches
Total bot turns per thread — count all bot messages (including own) in the thread, cap at N. Simple but may be too restrictive for long-running threads.
Bot turns within a time window — count bot messages in the last N minutes. Allows long threads but prevents rapid-fire loops.
Per-thread cooldown — after responding to a bot message, wait N seconds before responding to another bot message in the same thread.
Configurable
max_bot_turns— make the cap configurable (currently hardcoded at 10) and change the counting logic to total bot turns rather than consecutive.Related
multibot-mentionsmode for allow_user_messages #464 —multibot-mentionsmode (reduces accidental triggers but does not prevent intentional mention loops)MAX_CONSECUTIVE_BOT_TURNSconstant insrc/discord.rs:20