Skip to content

fix(dispatch): 群成员实时查询超时时提示可调大 BOTMUX_LARK_LIST_BOTS_API_TIMEOUT_MS - #3012

Merged
deepcoldy merged 2 commits into
masterfrom
fix/dispatch-member-timeout-hint-2008
Nov 7, 2026
Merged

deepcoldy merged 2 commits into
masterfrom
fix/dispatch-member-timeout-hint-2008

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

现象

botmux dispatch --bot-app 在建立协作身份前会实时查询群内 Bot 成员(/members/bots 与 is_in_chat)。到飞书往返较慢时,查询超过 listBotsApiTimeoutMs(默认 3000ms)即失败退出,报错只有一句原始文本:

dispatch 协作身份解析失败: live_membership_unavailable: live_chat_bot_members_unavailable: list chat bot members timed out after 3000ms

看不出这是可调的本地超时,也不知道该调哪个变量。

根因

promiseWithTimeout 超时时抛的是普通 Error,listChatBotsViaMembersBots 与 resolveCurrentChatBotOpenIdsByLarkAppIds 只把它的文本拼进 reason / message。超时与飞书业务错误码、网络错误在结构上无法区分,dispatch 也就给不出针对性的提示。

修法

  • src/im/lark/client.ts:promiseWithTimeout 改为抛带 timeoutMs 字段的 LarkCallTimeoutError(不导出,错误文本与原来逐字一致)。成员查询的失败结果在且仅在该错误类型时带上当时生效的 timeoutMs,/members/bots 与 is_in_chat 两处都透传到 resolveCurrentChatBotOpenIdsByLarkAppIds 的失败结果(新增可选字段)。
  • src/cli.ts:dispatch 只在该字段存在时,在原报错后追加一行:
    群成员实时查询在 3000ms 内未返回;网络较慢时可调大环境变量 BOTMUX_LARK_LIST_BOTS_API_TIMEOUT_MS(毫秒)后重试。
    判定看错误类型,不匹配文本。
  • 仍然 fail-closed:不重试、不降级到历史成员、不新增参数。

影响面

  • promiseWithTimeout 只有成员查询里的两处调用。listChatBotsViaMembersBots 的其它调用方(bots list、建群、项目群、exact chat grant、sibling 解析)读到的 reason / cacheable / 错误文本都没变,只是多一个可选字段,bots list 的失败缓存与兜底行为不变。
  • daemon 侧调用严格解析器的地方(workflow 发送者证明、resolveBotInChat 等)只读 ok / error / message / mappings,行为不变。
  • 不涉及 CLI 适配器、后端、会话类型;不加配置、不改持久化格式。老用户除了超时时多一行提示外没有变化。
  • 未覆盖:dispatch 后续经 daemon IPC 建立协作授权时,如果 daemon 侧的成员查询超时,报错仍是「dispatch 协作授权未就绪…」,不带这句提示;那需要跨 HTTP 传递失败结构,不在本次范围。

验证

  • bunx vitest run --project unit test/dispatch-thread-id.test.ts test/list-chat-bot-members.test.ts test/exact-chat-grant.test.ts test/test-hygiene.test.ts test/bots-list-cred-registration.test.ts --maxWorkers=2:5 个文件 133 个用例通过。
    • 新增用例跑真实的 cmdDispatch 和真实的严格解析器,只替换 larkGet 与本机 Bot 配置。
    • 修复前两个超时用例失败,输出只有 ... timed out after 20ms,不含变量名。
  • 变异(逐一还原):
    • 提示改成无条件输出 → 两个业务错误码用例变红;
    • 判定改成对文本匹配 timed out → 232011 用例变红(其 msg 故意带 "timed out");
    • 去掉 /members/bots 或 is_in_chat 路径的 timeoutMs 透传 → 对应超时用例变红。
  • bunx tsc --noEmit、bun run build 通过。

Fixes #2008

现象:dispatch --bot-app 建立协作身份前实时查询群内 Bot 成员(/members/bots 与 is_in_chat),在到飞书往返较慢的网络下超过 listBotsApiTimeoutMs(默认 3000ms)即失败退出,报错只有原始文本「list chat bot members timed out after 3000ms」,看不出这是可调的本地超时,也不知道该调哪个变量。

根因:promiseWithTimeout 超时时抛出的是普通 Error,listChatBotsViaMembersBots 与 resolveCurrentChatBotOpenIdsByLarkAppIds 只把它的文本拼进 reason/message,超时与飞书业务错误码、网络错误在结构上无法区分,dispatch 侧也就无从给出针对性提示。

修法:promiseWithTimeout 改为抛出带 timeoutMs 字段的 LarkCallTimeoutError(文本不变);成员查询失败结果在且仅在该错误类型时带上当时生效的 timeoutMs,resolveCurrentChatBotOpenIdsByLarkAppIds 的失败结果透传该字段;dispatch 仅在该字段存在时于原报错后追加一句:群成员实时查询超时、可调大环境变量 BOTMUX_LARK_LIST_BOTS_API_TIMEOUT_MS。仍然 fail-closed,不重试、不降级、不新增参数;业务错误码与其它异常的输出不变,bots list、send、授权与工作流等其它调用方只读原有字段,行为不变。

验证:
- bunx vitest run --project unit test/dispatch-thread-id.test.ts test/list-chat-bot-members.test.ts test/exact-chat-grant.test.ts test/test-hygiene.test.ts test/bots-list-cred-registration.test.ts --maxWorkers=2:5 个文件 133 个用例全部通过;新增用例在修复前的代码上 2 个超时用例失败(输出只有 timed out after 20ms,不含变量名)
- bunx tsc --noEmit -p tsconfig.json:通过
- bun run build:通过
@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(dispatch): 查群 bot 成员超时即整个 dispatch 失败,与 bots list 的兜底行为不一致

1 participant