Repository navigation
fix(lark): 本机起不动 CLI 时不注册飞书长连接 - #3018
Merged
Merged
Conversation
现象:同一飞书应用在多台机器上各起一个 daemon 时,本机起不动 CLI 的节点照样注册长连接。飞书把该应用的事件分给所有连接,这个节点分到的消息全部报「会话启动失败」,而其它节点的日志里看不到这些消息。 根因:daemon 注册飞书长连接前只判断 apiOnly,没有判断本机能否启动该 bot 的 CLI(src/daemon.ts 调 startLarkEventDispatcher 处)。 修法:新增 missingCliExecutableAfterRetry(src/setup/cli-availability.ts)。它先做不起进程的 PATH 查找;找不到时用 checkCliAvailabilityAsync 走登录 / 交互 shell 兜底;确定缺失后像启动检查一样等 3 秒再查一次。只有启动要用的可执行文件确实不存在才返回原因;shell 探测超时或出错、forge doctor 失败、启动配置非法都不算缺失,仍照常订阅。daemon 在非 durable primary 模式下据此跳过该 bot 的 startLarkEventDispatcher,并用 logger.error 说明原因和恢复方法。checkCliAvailabilityAsync 的确定缺失结果补上 missingExecutable 标记,与同步版一致。 验证: - bunx vitest run --project unit test/cli-availability.test.ts test/dashboard-cli-availability-request.test.ts test/dashboard-agent-save-probe.test.ts test/codem-adapter.test.ts:53 passed - bunx vitest run --project unit test/dashboard-cli-availability.test.ts:9 passed,1 skipped(浏览器用例) - bunx vitest run --project unit test/test-hygiene.test.ts:28 passed - bunx tsc --noEmit -p tsconfig.json:通过 - bun run build:通过
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 7, 2026 10:54
|
🚀 Released in v3.59.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
现象
同一飞书应用在多台机器上各起一个 daemon 时,本机起不动 CLI 的节点(CLI 没装、
cliPathOverride/wrapperCli指向不存在的路径)照样注册飞书长连接。飞书把该应用的事件分给所有连接,这个节点分到的消息全部报「会话启动失败」,其它能正常启动的节点日志里看不到这些消息。根因
daemon 在非 durable primary 模式下注册长连接前只判断
apiOnly,不判断本机能否启动这个 bot 的 CLI(src/daemon.ts中startLarkEventDispatcher的注册处)。修法
missingCliExecutableAfterRetry(src/setup/cli-availability.ts):先做不起进程的 PATH 查找;找不到时走checkCliAvailabilityAsync的登录 / 交互 shell 兜底;确定缺失后像启动检查一样等 3 秒再查一次。只有「启动要用的可执行文件确实不存在」才返回原因;shell 探测超时或出错、forge doctor 失败、启动配置非法都不算缺失,照常订阅。判定跟随实际启动的命令(配了wrapperCli就看 wrapper)。startDaemon据此跳过该 bot 的startLarkEventDispatcher,用logger.error写明原因和恢复方式;同 daemon 的其它 bot 照常订阅。checkCliAvailabilityAsync的确定缺失结果补上missingExecutable标记,与同步版一致。影响面
/cli切换等;出站发送不受影响。.cmd/.ps1shim 被误判为可执行的问题(Node 在 Windows 上把X_OK当F_OK),这类节点仍会被判为可启动并照常订阅;按 issue 里维护者的意见拆开另做。验证
test/cli-availability.test.ts用例(临时目录 + 假登录 shell):配置路径不存在且等待后仍不存在时返回原因;在配置路径 / PATH / 仅登录 shell 中找到时不返回;shell 探测出错按未知处理;等待期间 CLI 重新出现时不返回;配置了 wrapper 时按 wrapper 判定;无本地可执行文件的 agent、非法启动配置、forge doctor 失败都不返回,且启动时不运行 doctor。startDaemon内的接线是一处if,没有现成的启动级用例驱动它,本 PR 未新增。bunx vitest run --project unit test/cli-availability.test.ts:28 passedbunx tsc --noEmit -p tsconfig.json:通过bun run build:通过Fixes #745