SIGN IN SIGN UP

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

0 0 73 Python

fix(backend/copilot-bot): only answer other bots when @mentioned (#13174)

### Why / What / How

**Why:** Two AutoPilot deployments (prod + AutoPilot-Dev) sharing a
Discord server fell into an infinite feedback loop. Both were subscribed
to the same thread, so each one kept answering the other's replies —
forever.

PR #13039 ("allow bot-to-bot") swapped the original `if
message.author.bot: return` skip for a self-ID-only check, on the
assumption that the @mention requirement (channels) and
thread-subscription requirement (threads) would bound bot-to-bot
traffic. They don't: a sibling deployment is a *different user ID*, so
the self-ID check never catches it, and once both bots subscribe to a
thread the subscription gate is satisfied for **each** of them.

**What:** `_should_ignore_message` (Discord adapter) now ignores another
bot's message **unless that bot explicitly @mentions us**. Our own
messages are still always skipped; human messages are unaffected.

**How:** Three guard branches:
1. Author is us → ignore (Discord echoes our own sends back over the
gateway).
2. Author is another bot → ignore *unless* `_is_mentioned()` (the bot
@mentioned us).
3. Otherwise (human) → don't ignore.

This kills the silent thread loop — a plain bot reply with no @mention
is dropped — while keeping the intentional bot-to-bot path open: a bot
that explicitly addresses AutoPilot still gets a response.

> Residual note: two bots that @mention *each other* every turn can
still loop. That is a much narrower failure mode and is the deliberate
"bots can talk" path, so it is intentionally left open. A turn-count
circuit breaker can be added later if needed.

### Changes 🏗️

- `_should_ignore_message` (Discord adapter): skip another bot's message
unless it @mentions us; the existing self-skip is preserved.
- Tests: replaced `test_allows_other_bot_message` with
`test_ignores_unmentioned_bot_message` (regression test for the loop)
and `test_allows_mentioned_bot_message`.

### Checklist 📋

#### For code changes:
- [x] I have clearly listed my changes in the PR description
- [x] I have made a test plan
- [x] I have tested my changes according to the test plan:
- [x] `test_ignores_unmentioned_bot_message` fails against the pre-fix
code (reproduces the loop) and passes after the fix
- [x] `test_allows_mentioned_bot_message` confirms an explicit @mention
from another bot still gets through
- [x] Full Discord adapter suite green (`poetry run pytest
backend/copilot/bot/adapters/discord/adapter_test.py` — 42 passed),
`black` + `ruff` clean
B
Bently committed
8cc307208d1ca90b0e05184e1651706b218ad9f2
Parent: 7d8eee1
Committed by GitHub <noreply@github.com> on 5/27/2026, 1:02:35 PM