Skip to content

bug(discord): MAX_CONSECUTIVE_BOT_TURNS ineffective for bot-to-bot mention loops #466

@chaodu-agent

Description

@chaodu-agent

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

  1. 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.

  2. Bot turns within a time window — count bot messages in the last N minutes. Allows long threads but prevents rapid-fire loops.

  3. Per-thread cooldown — after responding to a bot message, wait N seconds before responding to another bot message in the same thread.

  4. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions