openclaw - 💡(How to fix) Fix [Bug] 多渠道会话隔离问题:消息路由到错误的渠道 (session isolation & channel routing bug) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#52204Fetched 2026-04-08 01:14:19
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
0
Timeline (top)
commented ×1

Root Cause

Root Cause Analysis

Code Example

{
  "deliveryContext": {
    "channel": "feishu"
  },
  "origin": {
    "provider": "feishu"
  }
}

---

# ✅ 正确:使用 message 工具,系统自动路由
message(action="send", media="/path/to/image.png")

# ❌ 错误:手动调用飞书 API
requests.post('https://open.feishu.cn/open-apis/im/v1/messages')
RAW_BUFFERClick to expand / collapse

Bug Description

当同时启用飞书和微信两个渠道时,OpenClaw 会绕过系统自动路由机制,导致消息发送到错误的渠道。

Environment

  • OpenClaw version: 2026.3.13
  • Channels enabled: feishu, openclaw-weixin
  • Primary agent: main

Reproduction Steps

  1. 配置飞书渠道(channels.feishu.enabled = true)
  2. 配置微信渠道(channels.wechat.enabled = true,通过 openclaw-weixin 插件)
  3. 在微信渠道发送消息
  4. Agent 回复时,有时消息会被发送到飞书渠道而不是微信渠道

Expected Behavior

  • 微信渠道收到的消息,回复应该自动路由回微信渠道
  • 飞书渠道收到的消息,回复应该自动路由回飞书渠道
  • 每个渠道的 session 应该完全隔离

Actual Behavior

  • 系统有时会混淆渠道路由
  • 微信消息的回复被发送到飞书
  • 飞书消息的回复被发送到微信

Root Cause Analysis

1. Session 状态混淆

  • 当前 session 的 deliveryContext 可能未正确更新
  • 示例:微信消息激活了微信 session,但 deliveryContext 仍指向飞书

2. 手动调用 API 绕过路由

  • 当使用飞书 API 直接发送消息时(如 requests.post 到 open.feishu.cn)
  • 绕过了系统的自动路由机制
  • 导致消息发送到错误的渠道

3. Session Key 管理

  • 多渠道场景下,session key 应该包含渠道信息
  • 当前实现可能存在渠道信息丢失的问题

Technical Details

当前 Session 状态示例

{
  "deliveryContext": {
    "channel": "feishu"
  },
  "origin": {
    "provider": "feishu"
  }
}

正确的路由机制

# ✅ 正确:使用 message 工具,系统自动路由
message(action="send", media="/path/to/image.png")

# ❌ 错误:手动调用飞书 API
requests.post('https://open.feishu.cn/open-apis/im/v1/messages')

Impact and Severity

  • Severity: High
  • Impact:
    • 用户体验混乱(消息发送到错误的渠道)
    • 会话隔离失效
    • 可能导致敏感信息泄漏到错误的渠道

Suggested Fix

  1. 强化 Session 隔离 - 确保每个渠道有独立的 session key
  2. 自动路由机制 - 所有消息发送必须经过系统路由
  3. Context Token 管理 - 微信渠道需要 contextToken 来关联对话
  4. 文档更新 - 添加多渠道配置的最佳实践和测试用例

Additional Context

  • 微信插件版本:@tencent-weixin/openclaw-weixin v1.0.2
  • 测试环境:macOS, OpenClaw 2026.3.13

extent analysis

Fix Plan

To resolve the issue of messages being sent to the wrong channel when both Feishu and WeChat channels are enabled, follow these steps:

  1. Enhance Session Isolation:

    • Ensure each channel has an independent session key.
    • Modify the session management code to include channel information in the session key.
  2. Implement Automatic Routing Mechanism:

    • Enforce all message sending to go through the system's routing mechanism.
    • Update the code to use the message utility for sending messages, as shown in the example:
      # Correct: Using message utility for automatic routing
      message(action="send", media="/path/to/image.png")
  3. Manage Context Token for WeChat Channel:

    • Ensure the WeChat channel uses a context token to associate conversations.
    • Update the WeChat plugin configuration to include context token management.
  4. Update Documentation:

    • Add best practices for multi-channel configuration.
    • Include test cases for multi-channel scenarios.

Example Code Changes

For the session management, you might need to update the session creation logic to include the channel information:

def create_session(channel, user_id):
    session_key = f"{channel}_{user_id}"  # Include channel in session key
    # ... rest of the session creation logic ...
    return session_key

For automatic routing, ensure all message sending functions use the message utility:

def send_message(media):
    # Using message utility for automatic routing
    message(action="send", media=media)

Verification

To verify the fix, follow these steps:

  • Enable both Feishu and WeChat channels.
  • Send messages from each channel and verify they are routed correctly.
  • Test session isolation by ensuring messages from one channel do not appear in the other channel.

Extra Tips

  • Regularly review and update the session management and routing logic to prevent similar issues.
  • Consider implementing additional logging to monitor channel routing and session management for easier debugging.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING