Skip to content

feat(discord): trusted bot @mention bypasses involvement gate#967

Merged
thepagent merged 3 commits into
mainfrom
feat/trusted-bot-involvement-bypass
Jun 1, 2026
Merged

feat(discord): trusted bot @mention bypasses involvement gate#967
thepagent merged 3 commits into
mainfrom
feat/trusted-bot-involvement-bypass

Conversation

@chaodu-agent
Copy link
Copy Markdown
Collaborator

@chaodu-agent chaodu-agent commented Jun 1, 2026

What

Allow trusted bots to @mention other bots into threads — treating the mention identically to a human @mention. The target bot becomes involved in the thread and will process the message.

Why

The current involvement gate (documented in #950) enforces "humans are gatekeepers" — only humans can pull a bot into a thread via @mention. Bot-to-bot @mention of a non-involved bot is silently dropped because allow_bot_messages defaults to Off, which rejects all bot messages before any other check runs.

This creates friction for legitimate bot-to-bot coordination:

  • A coordinator bot (e.g. 超渡) cannot pull reviewer bots into a thread
  • Multi-agent workflows require a human to manually @mention every bot
  • The trusted_bot_ids config already expresses trust, but that trust is gated behind the mode check

How

In the bot message gating block (src/discord.rs), added a trusted_mention check before the allow_bot_messages mode switch:

let trusted_mention = is_mentioned
    && !self.trusted_bot_ids.is_empty()
    && self.trusted_bot_ids.contains(&msg.author.id.get());

if !trusted_mention {
    match self.allow_bot_messages { ... }
    // trusted_bot_ids filter also here
}

If a trusted bot explicitly @mentions this bot, the entire mode check and trusted filter are skipped — the message proceeds as if it came from a human.

Behavior change

Scenario Before After
Trusted bot @mentions this bot (mode=Off) ❌ Dropped ✅ Processed (same as human)
Trusted bot @mentions this bot (mode=Mentions) ✅ Already worked ✅ Still works
Untrusted bot @mentions this bot ❌ Dropped ❌ Still dropped
Trusted bot message without @mention ❌ Dropped (mode=Off) ❌ Still dropped

Opt-in only — no surprise for existing users

This feature is strictly opt-in:

  • trusted_bot_ids defaults to empty → behavior is identical to before
  • Only admins who explicitly configure trusted_bot_ids get the new capability
  • No new config flag needed — trusted_bot_ids = [] (default) is the opt-out
  • Enterprise users who have not configured trusted_bot_ids are completely unaffected

If a future need arises to allow trusted_bot_ids for other purposes without granting involvement bypass, we can add a dedicated flag at that point. For now, configuring trusted_bot_ids implies trust for thread involvement.

Safety

  • No new config — uses existing trusted_bot_ids field
  • Explicit trust only — admin must configure which bots are trusted
  • Requires @mention — trusted bots without explicit @mention still follow normal gating
  • Loop preventionmax_bot_turns and bot_turns tracker still apply after involvement
  • Backward compatible — empty trusted_bot_ids (default) preserves current behavior exactly

Testing

Added 4 unit tests for the pure is_trusted_bot_mention decision function:

  • Trusted bot with @mention → bypass ✅
  • Untrusted bot with @mention → no bypass
  • Trusted bot without @mention → no bypass
  • Empty trusted_bot_ids → no bypass

Refs #949, #950

Allow trusted bots to @mention other bots into threads, treating the
mention the same as a human @mention. Previously, all bot messages were
blocked by the allow_bot_messages mode check (defaults to Off), even
from trusted bots. Now, if a bot is in trusted_bot_ids AND explicitly
@mentions this bot, the mode check is skipped entirely.

This enables bot-to-bot coordination (e.g. a coordinator bot pulling
reviewer bots into threads) without requiring human intervention for
every thread.
@chaodu-agent chaodu-agent requested a review from thepagent as a code owner June 1, 2026 14:31
@github-actions github-actions Bot added the closing-soon PR missing Discord Discussion URL — will auto-close in 3 days label Jun 1, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

⚠️ This PR is missing a Discord Discussion URL in the body.

All PRs must reference a prior Discord discussion to ensure community alignment before implementation.

Please edit the PR description to include a link like:

Discord Discussion URL: https://discord.com/channels/...

This PR will be automatically closed in 3 days if the link is not added.

- Expanded code comment to explain this is a 'bot admission override'
  not just an involvement gate bypass
- Updated config doc for trusted_bot_ids to document the @mention
  override behavior
- Added should_admit_bot_message() integration test helper that mirrors
  the actual gating logic in EventHandler::message
- Added 6 integration tests covering: Off+trusted mention (pass),
  Off+untrusted (block), Off+trusted no mention (block),
  Off+empty trusted_ids (block), Mentions+trusted (pass),
  All+untrusted (block)
@thepagent thepagent removed the closing-soon PR missing Discord Discussion URL — will auto-close in 3 days label Jun 1, 2026
- messaging.md: update design principle, gate flow diagram, practical
  impact table, config table, and add dedicated 'Trusted bot admission
  override' section
- discord.md: update trusted_bot_ids section and involvement gate
  examples to show trusted bot path
- config-reference.md: update trusted_bot_ids description
@github-actions github-actions Bot added the closing-soon PR missing Discord Discussion URL — will auto-close in 3 days label Jun 1, 2026
@chaodu-agent
Copy link
Copy Markdown
Collaborator Author

LGTM ✅ — Trusted bot admission override

What This PR Does

Allows trusted bots to @mention other bots into threads, treating the mention identically to a human @mention. The target bot becomes involved and processes the message regardless of allow_bot_messages mode.

How It Works

Adds a trusted_mention check before the allow_bot_messages mode switch. If the sender is in trusted_bot_ids AND explicitly @mentions this bot, the entire mode check is bypassed.

Findings

# Severity Finding Location
1 🟢 Code comment clearly documents this as "admission override" not just involvement bypass src/discord.rs:457
2 🟢 Integration tests (should_admit_bot_message) cover the full gating path with 6 scenarios src/discord.rs:2958
3 🟢 Docs updated across messaging.md, discord.md, config-reference.md docs/*
4 🟢 Default empty trusted_bot_ids = zero behavioral change for existing users src/config.rs
Review Team
  • 覺渡法師: LGTM ✅
  • 普渡法師: Initial findings addressed (semantic clarity + tests)
  • 口渡法師: Initial findings addressed (docs + regression tests)
  • 擺渡法師: Initial findings addressed (overloaded semantics documented)
What's Good (🟢)
  • trusted_bot_ids semantic expansion is now fully documented in code, config, and user-facing docs
  • should_admit_bot_message() pins the full gate behavior for regression safety
  • Strictly opt-in — no surprise for existing deployments
  • Clean separation: trusted mention bypass is a single let + if wrapper around existing logic

@github-actions github-actions Bot added pending-maintainer and removed closing-soon PR missing Discord Discussion URL — will auto-close in 3 days labels Jun 1, 2026
@thepagent thepagent merged commit 67aab8c into main Jun 1, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants