Repository navigation
test(tmux): 根治共享会话死窗格用例的偶发红(tmux 丢 SIGCHLD 不回填退出码) - #3225
Merged
deepcoldy merged 1 commit intoNov 8, 2026
Merged
Conversation
tmux < 3.6 带 libutempter 时(CI 的 Ubuntu tmux 3.4 即是)销毁窗格会丢掉窗格进程的 SIGCHLD(tmux#4559),窗格一直读成 1:,直到 server 再有别的子进程退出才回填。 「共享会话」用例自己写的 240 次轮询只看 tmux 回填,等的事件不会自己发生,于是偶发红。 - waitForDeadPane 读到 1: 时先发一次同步 run-shell true:tmux 回收它的任务时会一并 回收丢了的僵尸,run-shell 返回时状态已回填;server 屏蔽 SIGCHLD(#2453 实验室)时 跳过,改用内核记录兜底。去掉读数预算,只保留总时长上界,且只在到点后发起的读仍无 结论时才放弃。 - 共享会话场景抽成 expectLiveSessionWithDeadPaneKept,改用该等待器、按 pane id 断言; 在永不回收的实验室 server 上再跑一遍作为确定性回归。 - 假 tmux 用例补上回收触发、无进展读取不耗尽等待、被调度走之前的旧答案不作数三条。 - 等待器的断言把 seen 作为失败消息:toMatchObject 不打印预期之外的字段,原注释说的 「失败 diff 里能看到 seen」其实看不到,再红时 CI 日志直接给出读到的状态序列。 只改测试;产品的回收判定只看 pane_dead,状态读取早有内核兜底,不受影响。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 8, 2026 18:53
deepcoldy
pushed a commit
to fangyeqing/botmux
that referenced
this pull request
Nov 8, 2026
合入 deepcoldy#3181(ask --mention)、deepcoldy#2864(替身仅凭 App ID 配置)、deepcoldy#3225(tmux 死窗格用例去偶发)。 无文本冲突。两侧都改过的 src/cli.ts、src/core/dashboard-ipc-server.ts、src/daemon.ts、 src/types.ts、test/dashboard-ipc.test.ts 改动落在不同代码块:master 侧是 ask 点名与替身 App ID,本分支侧是会话合约,彼此不读写对方的字段。 Co-Authored-By: Claude Fable 5 <[email protected]>
This was referenced Nov 8, 2026
|
🚀 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.
Fixes #3216
问题
test/tmux-pipe-exit-code.test.ts的「never reaps a session whose dead pane shares it with a live pane」在 CI 上偶发红(期望['0:','1:8'],实得['0:','1:']),挡住了 #2662 的首跑(job 128760845720)。根因:不是饿死,是 tmux 丢了窗格进程的 SIGCHLD
utempter_remove_record会把 SIGCHLD 设成SIG_DFL并解除屏蔽,去 fork 并等待 helper。窗格进程如果恰好在这个窗口里走完退出,它的 SIGCHLD 被内核丢弃;tmux 不再 waitpid,窗格一直读成1:(已死、无退出码),pane-diedhook 也不触发,直到 server 再有别的子进程退出。上游 tmux#4559:3.6a 在server-fn.c的utempter_remove_record后补了kill(getpid(), SIGCHLD),3.4 只在创建路径(spawn.c)有这一行。1:时问内核,测试夹具由 test(tmux): 尸体夹具改等确定信号,tmux 不回收 pane 进程时从内核取退出码 #2476 让waitForDeadPane用同样的内核兜底。这条用例是之后 fix(worker): 启动命令遇到 Claude 切换确认框时按配置确认;新建 tmux 会话前清掉同名死会话 #2981 加的,没用waitForDeadPane,自己写了一段只看 tmux 回填的 240 次轮询;它等的事件不会自己发生,等多久都没用。test(tmux): 死 pane 退出状态等待按读计数给预算,消除饥饿下墙钟耗尽 flake #3083 把墙钟预算改成读数预算,前提是「只是慢」,而这里是「不会来」。确定性复现
在
isolate-run里的私有挂载命名空间(unshare --mount)中把那个窗口撑开,不碰宿主:libutempter 的 helper 被 bind-mount 成「参数是del时sleep 0.5」的脚本;窗格的 shell 包一层,命令以exit N结尾时先放开 pty(tmux 读到 EOF),150 ms 后再以同一退出码退出。另外编了两个带 libutempter 的 tmux:3.4(与 CI 同版本同配置)和 3.6a(上游修复版)。每组 20 次,split 一个sh -c "exit 8",pane_dead=1后等 1 s 看状态:run-shell true丢失只来自 helper 窗口:3.6a 和不带 libutempter 的 3.4 在同一环境里都不丢;丢了之后一次同步
run-shell true就回填。不加实验环境时,这个竞态取决于宿主当时的调度:只把 tmux server 钉在一个 CPU 上,00:44–01:02 间多数探针是大部分甚至全部丢失(26/30、15/15、40/40),同样的参数在 01:01 和 01:47 又是 0/30。这解释了 CI 上「偶发」而不是「一加负载就红」。
改动(只改这一个测试文件)
waitForDeadPane:1:时先发一次同步run-shell true。tmux 的回收循环一次收完所有僵尸,run-shell只在自己的任务被回收后才返回,所以它返回时 tmux 已经自己回填了状态,接着立刻重读。这是 tmux 自己的确定信号,不靠猜。run-shell(只会等满客户端超时),用内核记录兜底(原有逻辑)。seen带上状态轨迹(相同读数折叠成x次数),并作为断言的失败消息:原来的toMatchObject不打印预期之外的字段,注释说的「失败 diff 里能看到 seen」其实看不到。现在再红会直接给出如1::33602:33596 x472的轨迹。expectLiveSessionWithDeadPaneKept,改用上面的等待器,按 pane id 断言「一活一死」、同名新建报 duplicate session、活窗格 pid 不变、死窗格仍是 exit 8。普通 server 上的原用例(标题不变)调用它;另在 test(tmux): #2446 之后 tmux-pipe-exit-code 仍把真实退出码报成 1(3/127 → 1) #2453 实验室 server 上加一条,那里状态永远不回填,在任何机器上都是 CI 的形状。为什么产品路径不受影响(老用户零 breaking change)
没有改
src/下任何文件。产品里同类的等待都已经不依赖 tmux 回填:reapDeadSessionHoldingName(新建会话撞名时是否回收旧会话)只看每个窗格的#{pane_dead},状态只进日志;1:已经是「已死」,判定不变。本 PR 实验室版的共享会话用例正好证明:状态永远不回填时,混合会话也不会被回收。resolvePaneDeath/capturePaneDeath/readPaneDeath/collectPipePaneDeathEvidence读到1:时用readUnreapedPaneExit问内核(fix(tmux): tmux 未回收 pane 进程时从内核取真实退出码,不再把 3/127 报成 1 #2457);readPaneDeath对老版本还会发run-shell -b true触发回收(fix(tmux): 兼容旧版本退出保留和输出订阅 #2419,注释里已引 tmux#4559)。验证
确定性实验环境里连跑(
isolate-run --cpus 4+ 慢 helper)「定向」= 每轮一个新 vitest 进程跑
-t 'never reaps a session whose dead pane'(修复前 1 条,修复后 2 条:普通 + 实验室);「整个文件」= 每轮跑完整个文件。修复前用的是 master 上的原文件副本。修复前的红与 CI 同一签名:expected [ '0:', '1:' ] to deeply equal [ '0:', '1:8' ]。L1-before-lab-3.3aL2-after-lab-3.3aL3-before-lab-3.4utL4-after-lab-3.4utL6-before-lab-3.3a-fileL5-after-lab-3.3a-fileL7-after-lab-3.4ut-file同一环境里对修复后的文件做变异(只跑普通 server 上的共享会话用例,tmux 3.3a),两条出路各自都够,都去掉才红:
自然条件下加压连跑(无实验环境)
全部
isolate-run --cpus 4。空转进程是yes >/dev/null,和 tmux server 在同一个 4 核配额的 cgroup 里,会一起被限流;「tmux 钉 CPU2」是 PATH 里的taskset包装,只钉 tmux。Q1-before-pinned-quietQ2-after-pinned-quietW4-before-pinned-quiet-fileW5-after-pinned-quiet-fileR1-before-pinned-lightR2-after-pinned-lightT1-before-pinnedT2-after-pinnedT3-before-loadT4-after-loadP1-before-pinned-floatP2-after-pinned-floatW1-before-pinned-float-fileW2-after-pinned-float-fileW3-after-load-file这些轮次里修复前的文件也全绿,自然竞态在这段时间没有出现。修复前唯一一次自然复现是 00:45 的 3 轮(tmux 钉 CPU2、不加空转进程,3/3 红,与 CI 同签名);之后同样参数的 Q1 跑了 30 轮全绿。所以回归结论以上面的确定性环境为准,这张表只说明修复后在各种压力下没有新问题。
变异(宿主,每条定向跑相关用例)
run-shell回收触发'',期望'8')seen: '1:',7992 ms)单次定向运行(rebase 到 master 后)
npx vitest run --project unit --maxWorkers=2 test/tmux-pipe-exit-code.test.ts:60 passed(114.9 s)bun test --timeout=180000 test/tmux-pipe-exit-code.test.ts:60 pass / 0 fail(114.1 s)tsc(tsconfig.typecheck.json的编译选项 +src/**/*.d.ts,只含本文件;该文件不在tsconfig.typecheck.json的 include 里):本文件 0 错(改前同为 0)后续(本 PR 不动)
test/tmux-legacy-pipe-guard.test.ts里有同样的等法(5 s 墙钟等1:77),但只在真 tmux 2.8 上跑、CI 跳过,不会挡 PR;以后要在 2.8 上跑稳可以改用同一个等待器。🤖 Generated with Claude Code