Bug type
Regression (worked before, now fails)
Summary
Summary
I found a Discord preflight / mention-gating bug where message handling is too
permissive in some agent-routing cases.
The issue is not just “mention required vs not required”. The preflight logic
can still treat the wrong content as attention for the current agent, especially
when:
- another configured agent is being addressed
- a role mention is present
- an agent/role mention appears later in quoted text
- a configured agent bot is the sender in a mention-only channel
- a home-channel message names a different configured agent
This leads to incorrect routing / reply decisions in Discord.
Observed Problem
Discord message preflight should be strict about who is being addressed right
now.
Instead, the current behavior can allow messages through when they should be
dropped because:
- the message is really targeting another configured agent
- the message contains another role mention, not the current agent
- the apparent “mention” is only present later in quoted/copied text
- the sender is another configured agent bot in a mention-gated channel
- a plain-text delegation like “get Codey to help” is allowed in the current
agent’s home channel instead of being ignored/rerouted
Expected Behavior
Discord preflight should:
- only treat the current agent as mentioned when the attention signal is clearly
for that agent
- ignore later quoted mentions / pasted examples
- drop messages that explicitly target another configured agent
- drop unrelated role mentions
- avoid cross-agent bot-trigger loops in mention-only channels
- avoid broad “search the whole message” behavior for mention detection
Root Cause
The preflight mention logic needs tighter attention scoping and stricter
handling of other-agent / role mentions.
The local fix did three main things:
1. Limit mention detection to the attention window
Instead of treating the whole message body as equally relevant, the fix derives
a short attention window:
- normalize newlines
- take the first paragraph
- collapse whitespace
- truncate to 240 chars
This prevents a quoted command/example later in the message from being treated
as an active mention.
Local constant added:
DISCORD_MENTION_ATTENTION_WINDOW_CHARS = 240
Helper added:
extractDiscordMentionAttentionText(text)
2. Detect when another configured Discord agent is being addressed
The fix enumerates configured Discord-bound agents from bindings and checks
whether the message is actually naming / mentioning another configured agent.
Helpers added:
hasAgentSpecificMentionConfig(...)
isConfiguredDiscordAgentSender(...)
resolveOtherMentionedDiscordAgents(...)
This allows preflight to drop messages when:
- another configured agent is explicitly mentioned
- another configured agent is delegated to by name in plain text
- another configured agent bot is the sender in a mention-only channel
3. Treat role mentions more carefully
Role mentions were tightened so that:
- a role mention only counts if it appears in the attention window
- role labels can match agent names where appropriate
- unrelated role mentions cause the message to be dropped
- quoted role mentions later in the message do not count as a current mention
Helpers added:
matchesRoleLabelInText(...)
resolveMentionedRoleAttention(...)
Local Implementation Details
File changed
src/discord/monitor/message-handler.preflight.ts
Main behavior changes
- added a 240-char attention window for mention detection
- built “current-agent mention text” from:
- short attention text
- role labels found in the attention window
- resolved “other mentioned agents” from configured Discord bindings
- dropped guild messages when:
- another configured agent is mentioned
- another role is mentioned and it is not the current agent
- the sender is another configured agent bot in a mention-only channel
- ensured quoted/later examples do not satisfy mention gating
File changed
src/discord/monitor/message-handler.preflight.test.ts
Test coverage added locally
The local patch adds regression tests for cases including:
- home-channel messages that explicitly mention another configured agent
- home-channel plain-text delegation to another configured agent
- plain agent names not counting as valid mentions in mention-gated channels
- mention-gated home channels dropping messages that target another agent by
plain name
- non-agent human mentions still being allowed
- unrelated role mentions being dropped
- role mentions with role names matching an agent being treated as valid agent
mentions
- quoted role mentions later in the message being ignored
- cross-channel mentions sent by another configured agent bot being dropped
Scale of Local Patch
Local patch stats:
src/discord/monitor/message-handler.preflight.ts
src/discord/monitor/message-handler.preflight.test.ts
- 954 insertions, 5 deletions
Local commit message:
fix: tighten discord mention gating
Suggested Repro Cases
These are the cases I would use to reproduce:
-
In a home channel for agent A, send a message explicitly mentioning agent B
Expected: drop for A
-
In a home channel for agent A, send plain-text delegation like:
- “get Codey to help”
Expected: drop for A
-
In a mention-required channel, include the target agent/role mention only in
a later quoted/example paragraph
Expected: drop
-
Mention an unrelated role in a guild channel
Expected: drop unless that role clearly maps to the current agent
-
Send a message from another configured agent bot in a mention-only channel
Expected: drop to prevent cross-agent loops
Impact
This affects Discord routing correctness and can produce:
- incorrect replies in the wrong channels
- noisy cross-agent behavior
- false-positive mention detection
- possible bot-to-bot triggering in mention-only paths
Notes
I do not have push access to the repo, so I am reporting the fix details here in
enough detail for maintainers to reproduce or reimplement it directly.
Steps to reproduce
Steps to Reproduce
- Configure two Discord-bound agents, for example agent A and agent B, each
with normal routing/bindings.
- Send a message in agent A’s home channel that explicitly targets agent B, for
example:
@agent-b can you handle this?
- Observe that agent A can still pass preflight / treat the message as eligible
instead of dropping it.
Additional cases that reproduce the same class of bug:
-
In agent A’s home channel, send plain-text delegation to another configured
agent, for example:
get Codey to help with this
-
Observe that agent A may still treat this as valid input instead of
recognizing it targets another agent.
-
In a mention-gated channel, send a message where the only apparent agent/role
mention appears later in quoted text, for example:
Here is the example someone told me to send: @agent-a please help
-
Observe that the later quoted mention can satisfy mention gating even though
it is not the active attention target.
-
In a guild channel, mention an unrelated role that does not correspond to the
current agent.
-
Observe that preflight can be too permissive instead of dropping the message.
-
In a mention-only channel, send a message from another configured agent bot.
-
Observe risk of cross-agent triggering instead of the message being dropped.
Then add this right after it:
Expected behavior
Expected Result
Preflight should only allow the message through when the current agent is
clearly the active target in the opening attention text. Messages targeting
another configured agent, unrelated roles, quoted later mentions, or other agent
bots in mention-only paths should be dropped.
Actual behavior
Actual Result
Preflight can be too permissive and allow messages through based on broader
message scanning, later quoted mentions, or other-agent/role signals that should
not count as active attention for the current agent.
OpenClaw version
2026.3.9 (19b9637)
Operating system
macOS 26.3.1 (build 25D2128)
Install method
ppm
Model
moonshot/kimi-k2.5
Provider / routing chain
Discord -> accountId "default" -> token provider "discord_tokens" -> route binding to agentId "nudge" -> model moonshot/kimi-k2.5 Config file location: /Users/nudge/.openclaw/openclaw.json
Config file / key location
No response
Additional provider/model setup details
No response
Logs, screenshots, and evidence
Logs / evidence:
- Private/local install, so I cannot attach externally accessible logs or file
paths.
- The issue was reproduced in live Discord routing with a Nudge-bound Discord
account using the default Discord account route.
- Local investigation isolated the problem to Discord preflight mention gating,
where attention detection was too broad and could count later quoted mentions,
unrelated role mentions, or other-agent targets as valid attention for the
current agent.
- A local fix resolved this by restricting mention detection to a short opening
attention window, detecting other configured Discord agents as competing
targets, and tightening role-mention handling.
- Local regression coverage for the fix included:
- another configured agent explicitly mentioned in the current agent’s home
channel
- plain-text delegation to another configured agent
- unrelated role mentions
- quoted later mentions
- role labels that map to the current agent
- another configured agent bot speaking in a mention-gated path
- Local patch size:
- 2 files changed
- 954 insertions
- 5 deletions
- commit message: fix: tighten discord mention gating
Impact and severity
No response
Additional information
Suggested Fix Direction
Tighten Discord preflight mention detection so attention is determined from a
short opening window rather than the full message body.
Implementation approach:
- normalize newlines
- inspect only the first paragraph / opening attention text
- collapse whitespace
- truncate mention detection to a short window (for example 240 chars)
- ignore agent/role mentions that appear later in quoted or pasted text
- detect when another configured Discord agent is the actual target and drop for
the current agent
- treat unrelated role mentions as non-matching
- drop messages from other configured agent bots in mention-only channels
Regression coverage should include:
- another configured agent explicitly mentioned in the current agent’s home
channel
- plain-text delegation to another configured agent
- unrelated role mentions
- quoted later mentions
- role labels that map to the current agent
- another configured agent bot speaking in a mention-gated path
Bug type
Regression (worked before, now fails)
Summary
Summary
I found a Discord preflight / mention-gating bug where message handling is too
permissive in some agent-routing cases.
The issue is not just “mention required vs not required”. The preflight logic
can still treat the wrong content as attention for the current agent, especially
when:
This leads to incorrect routing / reply decisions in Discord.
Observed Problem
Discord message preflight should be strict about who is being addressed right
now.
Instead, the current behavior can allow messages through when they should be
dropped because:
agent’s home channel instead of being ignored/rerouted
Expected Behavior
Discord preflight should:
for that agent
Root Cause
The preflight mention logic needs tighter attention scoping and stricter
handling of other-agent / role mentions.
The local fix did three main things:
1. Limit mention detection to the attention window
Instead of treating the whole message body as equally relevant, the fix derives
a short attention window:
This prevents a quoted command/example later in the message from being treated
as an active mention.
Local constant added:
DISCORD_MENTION_ATTENTION_WINDOW_CHARS = 240Helper added:
extractDiscordMentionAttentionText(text)2. Detect when another configured Discord agent is being addressed
The fix enumerates configured Discord-bound agents from bindings and checks
whether the message is actually naming / mentioning another configured agent.
Helpers added:
hasAgentSpecificMentionConfig(...)isConfiguredDiscordAgentSender(...)resolveOtherMentionedDiscordAgents(...)This allows preflight to drop messages when:
3. Treat role mentions more carefully
Role mentions were tightened so that:
Helpers added:
matchesRoleLabelInText(...)resolveMentionedRoleAttention(...)Local Implementation Details
File changed
src/discord/monitor/message-handler.preflight.tsMain behavior changes
File changed
src/discord/monitor/message-handler.preflight.test.tsTest coverage added locally
The local patch adds regression tests for cases including:
plain name
mentions
Scale of Local Patch
Local patch stats:
src/discord/monitor/message-handler.preflight.tssrc/discord/monitor/message-handler.preflight.test.tsLocal commit message:
fix: tighten discord mention gatingSuggested Repro Cases
These are the cases I would use to reproduce:
In a home channel for agent A, send a message explicitly mentioning agent B
Expected: drop for A
In a home channel for agent A, send plain-text delegation like:
Expected: drop for A
In a mention-required channel, include the target agent/role mention only in
a later quoted/example paragraph
Expected: drop
Mention an unrelated role in a guild channel
Expected: drop unless that role clearly maps to the current agent
Send a message from another configured agent bot in a mention-only channel
Expected: drop to prevent cross-agent loops
Impact
This affects Discord routing correctness and can produce:
Notes
I do not have push access to the repo, so I am reporting the fix details here in
enough detail for maintainers to reproduce or reimplement it directly.
Steps to reproduce
Steps to Reproduce
with normal routing/bindings.
example:
@agent-b can you handle this?instead of dropping it.
Additional cases that reproduce the same class of bug:
In agent A’s home channel, send plain-text delegation to another configured
agent, for example:
get Codey to help with thisObserve that agent A may still treat this as valid input instead of
recognizing it targets another agent.
In a mention-gated channel, send a message where the only apparent agent/role
mention appears later in quoted text, for example:
Here is the example someone told me to send: @agent-a please helpObserve that the later quoted mention can satisfy mention gating even though
it is not the active attention target.
In a guild channel, mention an unrelated role that does not correspond to the
current agent.
Observe that preflight can be too permissive instead of dropping the message.
In a mention-only channel, send a message from another configured agent bot.
Observe risk of cross-agent triggering instead of the message being dropped.
Then add this right after it:
Expected behavior
Expected Result
Preflight should only allow the message through when the current agent is
clearly the active target in the opening attention text. Messages targeting
another configured agent, unrelated roles, quoted later mentions, or other agent
bots in mention-only paths should be dropped.
Actual behavior
Actual Result
Preflight can be too permissive and allow messages through based on broader
message scanning, later quoted mentions, or other-agent/role signals that should
not count as active attention for the current agent.
OpenClaw version
2026.3.9 (19b9637)
Operating system
macOS 26.3.1 (build 25D2128)
Install method
ppm
Model
moonshot/kimi-k2.5
Provider / routing chain
Discord -> accountId "default" -> token provider "discord_tokens" -> route binding to agentId "nudge" -> model moonshot/kimi-k2.5 Config file location: /Users/nudge/.openclaw/openclaw.json
Config file / key location
No response
Additional provider/model setup details
No response
Logs, screenshots, and evidence
Impact and severity
No response
Additional information
Suggested Fix Direction
Tighten Discord preflight mention detection so attention is determined from a
short opening window rather than the full message body.
Implementation approach:
the current agent
Regression coverage should include:
channel