Bug Summary
Gateway sends Discord session messages to Feishu channel instead of Discord
When an agent responds in a Discord direct message session, the message is incorrectly delivered to Feishu private chat instead of Discord. This is a critical message routing bug in the Gateway delivery subsystem.
Environment
- OpenClaw Version: v2026.4.x (latest as of 2026-04-18)
- OS: macOS Darwin 25.4.0 (arm64)
- Node: v25.9.0
- Channels: Discord (enabled), Feishu (enabled)
- Model: bailian/qwen3.5-plus / openai-codex/gpt-5.4
Configuration
Both channels are enabled with correct bindings:
{
"channels": {
"discord": { "enabled": true, ... },
"feishu": { "enabled": true, ... }
},
"bindings": [
{
"type": "route",
"agentId": "agent-qwen",
"match": { "channel": "feishu", "peer": { "kind": "direct", "id": "<FEISHU_USER_ID_REDACTED>" } }
},
{
"type": "route",
"agentId": "agent-codex",
"match": { "channel": "discord", "peer": { "kind": "direct", "id": "<DISCORD_USER_ID_REDACTED>" } }
}
],
"delivery": {}
}
Expected: Discord DM → Discord channel, Feishu DM → Feishu channel
Actual: Discord session messages are being sent to Feishu
Reproduction Steps
- Have both Discord and Feishu channels enabled
- Configure bindings for both channels (Discord DM → agent-codex, Feishu DM → agent-qwen)
- Start a conversation in Discord DM with the bot
- Agent generates a response in the Discord session
- Observe that the message is delivered to Feishu private chat instead of Discord
Evidence from Logs
Timeline (Asia/Shanghai timezone):
10:47:10.478 - Session processing: agent:agent-qwen:discord:direct:<DISCORD_USER_ID_REDACTED>
10:47:10.484 - Turn completed for Discord session
10:47:10.797 - ❌ BUG: feishu: sendText: target=user:<FEISHU_USER_ID_REDACTED>
10:47:10.798 - ❌ BUG: feishu: sendTextLark: target=user:<FEISHU_USER_ID_REDACTED>
10:47:10.800 - ❌ BUG: feishu: creating message to <FEISHU_USER_ID_REDACTED> (msg_type=post)
Key observation: The session key is agent:agent-qwen:discord:direct:<DISCORD_USER_ID_REDACTED> (Discord channel), but the delivery subsystem calls feishu/outbound to send the message.
Log Snippets
{"subsystem":"agent/embedded","message":"[context-engine] deferred turn maintenance queued taskId=ee99536e-a5fe-4c36-a80e-53347ea38af7 sessionKey=agent:agent-qwen:discord:direct:<DISCORD_USER_ID_REDACTED>","time":"2026-04-18T10:47:10.486+08:00"}
{"subsystem":"feishu/outbound/outbound","message":"feishu: sendText: target=user:<FEISHU_USER_ID_REDACTED>, textLength=322","time":"2026-04-18T10:47:10.798+08:00"}
{"subsystem":"feishu/outbound/deliver","message":"feishu: sendTextLark: target=user:<FEISHU_USER_ID_REDACTED>, textLength=322","time":"2026-04-18T10:47:10.798+08:00"}
User Impact
- Severity: Critical (P0)
- Impact: Messages are delivered to wrong channels, causing:
- User confusion (receiving messages on unexpected platforms)
- Privacy concerns (messages may be visible to wrong audiences)
- Broken multi-channel deployments (cannot reliably use multiple channels simultaneously)
Root Cause Analysis (Preliminary)
The bug appears to be in the Gateway message delivery subsystem:
- Session context correctly identifies the channel as
discord (sessionKey: agent:agent-qwen:discord:direct:...)
- However, when delivering the response, the Gateway incorrectly invokes
feishu/outbound instead of discord/outbound
- This suggests either:
- Session state pollution: Feishu and Discord sessions are sharing/corrupting delivery context
- DeliveryContext override: The deliveryContext is being dynamically modified at runtime
- Routing logic bug: The channel selection logic in the delivery subsystem is using incorrect criteria
Expected Behavior
- Messages from Discord sessions should be sent via
discord/outbound subsystem
- Messages from Feishu sessions should be sent via
feishu/outbound subsystem
- Each session's
deliveryContext.channel should determine the outbound channel
Actual Behavior
- Discord session (
agent:agent-qwen:discord:direct:<DISCORD_USER_ID_REDACTED>) messages are sent via feishu/outbound to Feishu user <FEISHU_USER_ID_REDACTED>
Workaround
Currently no reliable workaround. Users experiencing this issue may need to:
- Disable one of the channels (Discord or Feishu) to avoid cross-channel routing
- Clear session state files and restart Gateway (may temporarily resolve, but bug can recur)
Additional Context
- This bug was discovered during a routine configuration change (adding Discord DM routing for agent-codex)
- The user had both channels active simultaneously
- Session files show correct
deliveryContext configuration, but runtime behavior diverges
Files Available for Debugging
- Gateway logs:
/tmp/openclaw/openclaw-2026-04-18.log (contains full message routing trace)
- Session files:
~/.openclaw/agents/agent-qwen/sessions/*.jsonl
- Configuration:
~/.openclaw/openclaw.json
Labels Suggested
bug
gateway
critical
message-routing
feishu
discord
Note: User IDs have been redacted for privacy protection. Full logs available upon request for debugging.
Bug Summary
Gateway sends Discord session messages to Feishu channel instead of Discord
When an agent responds in a Discord direct message session, the message is incorrectly delivered to Feishu private chat instead of Discord. This is a critical message routing bug in the Gateway delivery subsystem.
Environment
Configuration
Both channels are enabled with correct bindings:
{ "channels": { "discord": { "enabled": true, ... }, "feishu": { "enabled": true, ... } }, "bindings": [ { "type": "route", "agentId": "agent-qwen", "match": { "channel": "feishu", "peer": { "kind": "direct", "id": "<FEISHU_USER_ID_REDACTED>" } } }, { "type": "route", "agentId": "agent-codex", "match": { "channel": "discord", "peer": { "kind": "direct", "id": "<DISCORD_USER_ID_REDACTED>" } } } ], "delivery": {} }Expected: Discord DM → Discord channel, Feishu DM → Feishu channel
Actual: Discord session messages are being sent to Feishu
Reproduction Steps
Evidence from Logs
Timeline (Asia/Shanghai timezone):
Key observation: The session key is
agent:agent-qwen:discord:direct:<DISCORD_USER_ID_REDACTED>(Discord channel), but the delivery subsystem callsfeishu/outboundto send the message.Log Snippets
{"subsystem":"agent/embedded","message":"[context-engine] deferred turn maintenance queued taskId=ee99536e-a5fe-4c36-a80e-53347ea38af7 sessionKey=agent:agent-qwen:discord:direct:<DISCORD_USER_ID_REDACTED>","time":"2026-04-18T10:47:10.486+08:00"} {"subsystem":"feishu/outbound/outbound","message":"feishu: sendText: target=user:<FEISHU_USER_ID_REDACTED>, textLength=322","time":"2026-04-18T10:47:10.798+08:00"} {"subsystem":"feishu/outbound/deliver","message":"feishu: sendTextLark: target=user:<FEISHU_USER_ID_REDACTED>, textLength=322","time":"2026-04-18T10:47:10.798+08:00"}User Impact
Root Cause Analysis (Preliminary)
The bug appears to be in the Gateway message delivery subsystem:
discord(sessionKey:agent:agent-qwen:discord:direct:...)feishu/outboundinstead ofdiscord/outboundExpected Behavior
discord/outboundsubsystemfeishu/outboundsubsystemdeliveryContext.channelshould determine the outbound channelActual Behavior
agent:agent-qwen:discord:direct:<DISCORD_USER_ID_REDACTED>) messages are sent viafeishu/outboundto Feishu user<FEISHU_USER_ID_REDACTED>Workaround
Currently no reliable workaround. Users experiencing this issue may need to:
Additional Context
deliveryContextconfiguration, but runtime behavior divergesFiles Available for Debugging
/tmp/openclaw/openclaw-2026-04-18.log(contains full message routing trace)~/.openclaw/agents/agent-qwen/sessions/*.jsonl~/.openclaw/openclaw.jsonLabels Suggested
buggatewaycriticalmessage-routingfeishudiscordNote: User IDs have been redacted for privacy protection. Full logs available upon request for debugging.