openclaw - ✅(Solved) Fix [Feature]: 飞书多账号场景下的工具账号优先级问题 [1 pull requests, 1 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#59399Fetched 2026-04-08 02:24:17
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
referenced ×2cross-referenced ×1labeled ×1

Fix Action

Fixed

PR fix notes

PR #59420: fix(feishu): prioritize message source account over defaultAccount

Description (problem / solution / changelog)

Fixes #59399

Summary

When multiple Feishu accounts are configured, the account that received the message should take priority over the configured defaultAccount.

Before

  1. Explicit accountId parameter
  2. Configured defaultAccount ❌
  3. Message source account

After

  1. Explicit accountId parameter
  2. Message source account ✅
  3. Configured defaultAccount (fallback)

Impact

This ensures that when a user interacts with bot A, the tools operate on tenant A's resources, not tenant B's (which was configured as default).

Test Plan

  • Configure multiple Feishu accounts
  • Set a defaultAccount
  • Send message to non-default bot
  • Verify tools use the correct account

🤖 Generated with ClawHub

Changed files

  • extensions/feishu/src/tool-account.ts (modified, +17/-14)

Code Example

{
  "channels": {
    "feishu": {
      "enabled": true,
      "connectionMode": "websocket",
      "defaultAccount": "xingzhe",
      "accounts": {
        "wukong": {
          "appId": "cli_a9203598d57adbc0",
          "appSecret": "xxx",
          "botName": "悟空"
        },
        "xingzhe": {
          "appId": "cli_a9463dbe26b8dbca",
          "appSecret": "xxx",
          "botName": "行者"
        }
      }
    }
  }
}

---

// 当前实现
accountId:
  params.executeParams?.accountId ??      // 1. 工具调用显式指定
  readConfiguredDefaultAccountId(cfg) ??   // 2. 配置的 defaultAccount ⚠️
  params.defaultAccountId                  // 3. ctx.agentAccountId(消息来源)

---

用户在悟空机器人发送消息 → 工具使用 wukong 账号 → 操作悟空租户的文档
用户在行者机器人发送消息 → 工具使用 xingzhe 账号 → 操作行者租户的文档

---

"在行者那边创建文档" → accountId="xingzhe" → 使用行者账号

---

// 建议的实现
accountId:
  params.executeParams?.accountId ??      // 1. 工具调用显式指定(最高优先级)
  params.defaultAccountId ??               // 2. ctx.agentAccountId(消息来源)← 提升优先级
  readConfiguredDefaultAccountId(cfg)      // 3. 配置的 defaultAccount(兜底)

---

{
  "channels": {
    "feishu": {
      "accountPriority": "source-first",  // 或 "default-first"
      ...
    }
  }
}

---

{
  "channels": {
    "feishu": {
      // 不要设置 defaultAccount
      "accounts": { ... }
    }
  }
}
RAW_BUFFERClick to expand / collapse

Summary

问题摘要

当 OpenClaw 配置了多个不同飞书组织下的机器人时,飞书工具(如 feishu_doc)无法正确识别消息来源的机器人账号,导致操作飞书文档时出现权限错误。


环境信息

  • OpenClaw 版本:2026.3.13
  • 飞书插件版本:2026.3.13
  • 配置账号数:3个(来自不同飞书组织)

场景描述

配置示例

{
  "channels": {
    "feishu": {
      "enabled": true,
      "connectionMode": "websocket",
      "defaultAccount": "xingzhe",
      "accounts": {
        "wukong": {
          "appId": "cli_a9203598d57adbc0",
          "appSecret": "xxx",
          "botName": "悟空"
        },
        "xingzhe": {
          "appId": "cli_a9463dbe26b8dbca",
          "appSecret": "xxx",
          "botName": "行者"
        }
      }
    }
  }
}

场景一:消息来源账号被忽略

  1. 用户在 悟空机器人(属于租户 A)的私聊中发送消息
  2. 消息进站时,accountId 正确识别为 wukong
  3. 用户请求操作飞书文档(如创建文档)
  4. 工具调用时,实际使用的是 defaultAccount: "xingzhe"
  5. 结果:权限错误(因为行者机器人没有悟空租户的文档权限)

场景二:动态指定账号也存在优先级问题

  1. 用户尝试通过关键词(如"在悟空那边创建文档")指定账号
  2. Agent 识别到关键词,调用工具时传入 accountId: "wukong"
  3. 但由于 defaultAccount 优先级更高,仍然使用了错误的账号
  4. 结果:操作失败或权限错误

根本原因

tool-account.ts 中,账号解析的优先级设计不合理:

// 当前实现
accountId:
  params.executeParams?.accountId ??      // 1. 工具调用显式指定
  readConfiguredDefaultAccountId(cfg) ??   // 2. 配置的 defaultAccount ⚠️
  params.defaultAccountId                  // 3. ctx.agentAccountId(消息来源)

问题

  • defaultAccount 的优先级高于 ctx.agentAccountId(消息来源账号)
  • 当配置了 defaultAccount 时,消息来源账号会被忽略
  • 即使显式指定 accountId,如果优先级逻辑有其他问题,仍可能失败

Problem to solve

期望行为

行为一:自动识别消息来源

当用户通过飞书机器人私聊或群聊发送消息时,飞书工具应自动使用消息来源对应的机器人账号操作文档。

用户在悟空机器人发送消息 → 工具使用 wukong 账号 → 操作悟空租户的文档
用户在行者机器人发送消息 → 工具使用 xingzhe 账号 → 操作行者租户的文档

行为二:显式指定优先

当用户或 Agent 显式指定 accountId 时,应优先使用指定的账号。

"在行者那边创建文档" → accountId="xingzhe" → 使用行者账号

行为三:默认账号作为兜底

只有在没有消息来源账号且没有显式指定时,才使用 defaultAccount

Proposed solution

建议解决方案

方案一:调整优先级(推荐)

修改 tool-account.ts 的账号解析优先级:

// 建议的实现
accountId:
  params.executeParams?.accountId ??      // 1. 工具调用显式指定(最高优先级)
  params.defaultAccountId ??               // 2. ctx.agentAccountId(消息来源)← 提升优先级
  readConfiguredDefaultAccountId(cfg)      // 3. 配置的 defaultAccount(兜底)

方案二:提供配置选项

新增配置项,让用户选择账号优先级策略:

{
  "channels": {
    "feishu": {
      "accountPriority": "source-first",  // 或 "default-first"
      ...
    }
  }
}

方案三:工具上下文传递优化

确保 ctx.agentAccountId 在所有工具调用场景中都正确传递,包括:

  • 直接工具调用
  • 子代理调用
  • 多轮对话场景

临时解决方案

删除 defaultAccount 配置项:

{
  "channels": {
    "feishu": {
      // 不要设置 defaultAccount
      "accounts": { ... }
    }
  }
}

但这不是理想的解决方案,因为:

  1. 用户可能需要配置默认账号用于非飞书进站的场景
  2. 优先级问题仍然存在,只是绕过了

Alternatives considered

No response

Impact

<html> <body> <!--StartFragment--><h3 style="box-sizing: border-box; color: rgb(60, 60, 67); font-family: Inter, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: -0.135px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(248, 249, 250); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">受影响的用户/系统/渠道</h3><ul style="box-sizing: border-box; margin: 0px; padding-left: 1.2em; color: rgb(60, 60, 67); font-family: Inter, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: -0.135px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(248, 249, 250); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><li style="box-sizing: border-box;">所有配置多飞书租户账号的用户</li><li style="box-sizing: border-box; margin-top: 0.25em;">飞书插件全部工具</li><li style="box-sizing: border-box; margin-top: 0.25em;">飞书私聊、群聊渠道</li><li style="box-sizing: border-box; margin-top: 0.25em;">多组织企业客户场景</li></ul><h3 style="box-sizing: border-box; color: rgb(60, 60, 67); font-family: Inter, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: -0.135px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(248, 249, 250); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">严重程度</h3><p style="box-sizing: border-box; margin: 0px; color: rgb(60, 60, 67); font-family: Inter, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: -0.135px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(248, 249, 250); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><strong style="box-sizing: border-box;">严重(妨碍工作流程)</strong><span> </span>- 核心功能完全不可用</p><h3 style="box-sizing: border-box; color: rgb(60, 60, 67); font-family: Inter, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: -0.135px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(248, 249, 250); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">频率</h3><p style="box-sizing: border-box; margin: 0px; color: rgb(60, 60, 67); font-family: Inter, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: -0.135px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(248, 249, 250); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><strong style="box-sizing: border-box;">始终发生</strong><span> </span>- 100% 复现</p><h3 style="box-sizing: border-box; color: rgb(60, 60, 67); font-family: Inter, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: -0.135px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(248, 249, 250); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">后果</h3> 后果 | 影响 -- | -- 功能完全失效 | 文档操作权限错误 用户体验极差 | 困惑为何配置正确却无法操作 额外手工操作 | 需要删除配置或手动指定账号 信任度下降 | 功能"看起来支持"但实际不可用 企业部署受阻 | 跨组织场景无法使用 调试成本高 | 普通用户难以定位根因 <h3 style="box-sizing: border-box; color: rgb(60, 60, 67); font-family: Inter, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: -0.135px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(248, 249, 250); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">紧迫性</h3><p style="box-sizing: border-box; margin: 0px; color: rgb(60, 60, 67); font-family: Inter, -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: -0.135px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(248, 249, 250); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><strong style="box-sizing: border-box;">高紧迫性</strong><span> </span>- 建议下个版本尽快修复</p><!--EndFragment--> </body> </html>

Evidence/examples

No response

Additional information

No response

extent analysis

TL;DR

修改 tool-account.ts 中的账号解析优先级,确保消息来源账号优先于默认账号。

Guidance

  1. 检查当前实现: 查看 tool-account.ts 中的账号解析逻辑,确认当前的优先级顺序。
  2. 调整优先级: 修改账号解析优先级,确保 params.defaultAccountId (消息来源账号) 优先于 readConfiguredDefaultAccountId(cfg) (默认账号)。
  3. 验证行为: 测试修改后的实现,确保工具正确使用消息来源账号操作文档。

Example

// 建议的实现
accountId:
  params.executeParams?.accountId ??      // 1. 工具调用显式指定(最高优先级)
  params.defaultAccountId ??               // 2. ctx.agentAccountId(消息来源)← 提升优先级
  readConfiguredDefaultAccountId(cfg)      // 3. 配置的 defaultAccount(兜底)

Notes

  • 修改优先级后,需要重新测试所有相关场景,包括显式指定账号、消息来源账号和默认账号。
  • 如果存在其他优先级相关的逻辑,需要同时检查和调整,以避免意外行为。

Recommendation

Apply workaround: 修改 tool-account.ts 中的账号解析优先级,确保消息来源账号优先于默认账号。这样可以立即解决当前的问题,避免因默认账号优先级导致的权限错误。

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

openclaw - ✅(Solved) Fix [Feature]: 飞书多账号场景下的工具账号优先级问题 [1 pull requests, 1 participants]