Skip to content

Bug: Gateway sends Discord session messages to Feishu channel (critical message routing bug) #68378

Description

@Suidge

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

  1. Have both Discord and Feishu channels enabled
  2. Configure bindings for both channels (Discord DM → agent-codex, Feishu DM → agent-qwen)
  3. Start a conversation in Discord DM with the bot
  4. Agent generates a response in the Discord session
  5. 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:

  1. Session context correctly identifies the channel as discord (sessionKey: agent:agent-qwen:discord:direct:...)
  2. However, when delivering the response, the Gateway incorrectly invokes feishu/outbound instead of discord/outbound
  3. 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:

  1. Disable one of the channels (Discord or Feishu) to avoid cross-channel routing
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions