Repository navigation
fix(card): 页脚扩展命令退出后先读完输出再结算,修复间歇拿到空结果 - #2119
Merged
Merged
Conversation
runCardFooterExtensionCommand 在子进程 exit 时当场结算并销毁管道读端,而 exit 可能先于管道里最后一段输出递到 'data'(Bun 与 Node 的 CI 都出现过拿到空串), 命令正常输出后退出,页脚扩展段也会间歇丢失。 现在退出码为 0 时等 stdout 读到 EOF 再结算;setsid 逃逸者持着写端、EOF 不来时 最多再等 EXIT_DRAIN_MS(100ms),到点后再让出一次 I/O 轮询,事件循环被卡住超过 上限时也先读完管道里已有的输出。非 0 退出、超时、超限的处理不变。 新增两条确定性用例(受控假子进程决定 exit 与输出的先后),把修复改回 exit 当场 结算、或去掉到点后的那次 I/O 轮询,都会在 Node 与 Bun 下稳定变红。 Closes #2096 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 21, 2026 17:53
- 正常退出后等 EOF 跨过超时点时不被判成超时:exit(0) 分支清掉命令超时定时器是 新加的防线,原有用例守不住;假时钟在超时前发 exit 再推过超时点,去掉 clearTimeout 后 Node 与 Bun 下都稳定变红。 - stdout 先 EOF、随后非 0 退出时仍要 reject:'end' 回调里的 if (exited) 守卫没人 守,去掉后会把失败吞成成功;新用例在两个运行时下同样稳定变红。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
Author
|
已合并 →
|
deepcoldy
added a commit
to zsnjuts/botmux
that referenced
this pull request
Oct 21, 2026
This was referenced Oct 21, 2026
|
🚀 Released in v3.49.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.
Closes #2096
改了什么
src/services/card-footer-extension.ts的runCardFooterExtensionCommand(bots.jsoncardFooterExtension的命令执行器,daemon 按 bot 定时跑):'end')再结算。原来是在子进程'exit'当场结算并 destroy 管道读端。EXIT_DRAIN_MS = 100ms,到点后再隔一个setTimeout(0)才结算,让事件循环先轮询一次 I/O。这样即使事件循环被同步任务卡住超过 100ms,管道里已有的输出也会先读完再结算。原有的「不被逃逸者拖住」保持不变。spawnImpl(默认spawn),只供测试注入受控的假子进程。生产调用方不变。为什么
'exit'可以先于管道里最后一段输出递到'data':Node 文档写明 exit 时 stdio 可能仍开着;Bun 的node:child_process在 pidfd 就绪后经process.nextTick发exit,而 stdout 走 pull 式 ReadableStream,数据要经 promise 才推到'data'。在 exit 当场 destroy 读端,就会丢掉命令的全部输出,导致:test/card-footer-extension.test.ts「resolves from exit without waiting for a setsid escapee holding the stdout pipe」在 bun-test 和 vitest 分片上间歇失败(期望"done\n",拿到"");test/worker-pool-statusline-quota.test.ts的 cardFooterExtension 用例(普通的printf,没有逃逸进程)也红过同样的问题;根因的实测证据(Bun 1.4.3,与 CI 钉的版本一致):
runCardFooterExtensionCommand整组用例重复跑 15 轮,复现 1 次同样的失败;setImmediate,Node 下排在已就绪 I/O 之后,Bun 下排在 I/O 之前(30/30);排setTimeout(0)则两边都在 I/O 之后(15/15)。所以 drain 到点后的那一跳用setTimeout(0),不用setImmediate。影响面
card-footer-extension.ts一个函数。它在 daemon 进程里跑、与 CLI 无关,所以对所有 CLI、所有会话类型一致;跟 PTY/tmux 后端、sandbox 都无关。EXIT_DRAIN_MS仅供测试表达「卡住时长 > 上限」这一关系。测试
新增两条确定性用例,用受控的假子进程决定 exit 和输出谁先到(真实进程给不出确定顺序):
keeps output that is delivered after the exit event:先发
exit(0),再写入输出并 EOF,结果必须拿到输出。reads output already in the pipe before settling, even when the event loop stalls past the drain cap:stdout 用 Unix socket(写入同步进入对端内核接收队列,和管道一样)。在一次 I/O 回调里写入输出、发
exit(0),然后同步卡住事件循环EXIT_DRAIN_MS * 3;没有 EOF,结果也必须拿到输出。exit 放在 I/O 回调里发,是因为真实的 exit 就是这样递到的(Bun 靠 pidfd,Node 靠 SIGCHLD 信号管道)。does not turn a successful exit into a timeout while waiting for EOF:假时钟推到超时前
EXIT_DRAIN_MS / 2时发exit(0),逃逸者不给 EOF,再推过超时点;结果必须是输出而不是「timed out」。守的是 exit(0) 分支里清掉命令超时定时器这一行。still rejects a non-zero exit when stdout reaches EOF first:stdout 先 EOF、随后
exit(3),必须 reject。守的是'end'回调里「等 exit 再结算」的判断,去掉它会把失败吞成成功。原有的真实进程用例一条没改。
验证
本地(Bun 1.4.3 = CI 钉的版本;Node v22.21.1):
bun run build通过;改动的测试文件单独 tsc 检查 0 错误。bunx vitest run --project unit test/card-footer-extension.test.ts test/worker-pool-statusline-quota.test.ts test/test-hygiene.test.ts test/bun-runner-selectors.test.ts:4 个文件 97/97 通过。bun test分别跑:card-footer-extension 25 / worker-pool-statusline-quota 6 / test-hygiene 26 / bun-runner-selectors 40,全部通过。-t "setsid escapee holding the stdout pipe" --rerun-each 50):50/50 通过。runCardFooterExtensionCommand整组重复 9 轮,共 54 轮、486 个用例,0 失败。printf '%s' codex),全部正确;逃逸场景单次最长 130ms(Node)/ 160ms(Bun)。变异验证(改动源码后跑新用例,结束后已还原):
setTimeout(0),到点直接结算'end'不等 exit 就结算用例 2 的 exit 一开始放在
setImmediate里发,结果 M2 只在 Node 下变红,Bun 下仍然是绿的(Bun 在 immediate 之后会先轮询 I/O),所以改成在 I/O 回调里发。已知 / follow-up(不在本 PR 范围)
src/dashboard/managed-spawn.ts(按 stdout 的 JSON 取提示信息,丢了会退回通用文案)和src/services/skill-registry-store.ts的 agentbuddy 调用(按输出拼错误信息)。后果都是降级,不是错误结果,之后另开 PR 处理。pkill -f清理残留。同一台机器上并发跑这个文件时,两边会互相杀掉对方的sleep(本地验证时遇到过一次,CI 上每个 job 独立,不受影响)。🤖 Generated with Claude Code