Skip to content

test(tmux): 尸体夹具改等确定信号,tmux 不回收 pane 进程时从内核取退出码 - #2476

Merged
deepcoldy merged 1 commit into
masterfrom
test/tmux-corpse-fixture-kernel-status
Oct 28, 2026
Merged

deepcoldy merged 1 commit into
masterfrom
test/tmux-corpse-fixture-kernel-status

Conversation

@deepcoldy

@deepcoldy deepcoldy commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

修 #2459 的测试夹具残余(该 issue 已于 09:18 以 #2457 为由关闭,但第五个实例发生在 #2457 之后,见 评论)。

现象

#2457 合入后,#2439 同步到 a17dd9e 的 head e937b14ae 上,run 40635916436 / bun-test(attempt 1)红在 test/tmux-pipe-exit-code.test.ts:

expect(deadStatus.status).toBe('77');   // test/tmux-pipe-exit-code.test.ts:280
Expected: "77"
Received: ""
(fail) tmux liveness probes treat a kept corpse as missing > launch selection reports the corpse as missing, not as a reattachable session [7479.91ms]

失败点不在报红的那条用例里,而在第二个 describe(尸体组)公共 beforeEach 的夹具 waitForDeadPane。bun 会把 hook 的失败记在当时正要进入的用例名上。夹具读了 240 次(7.5s),pane 一直是「已死、状态为空」。

同一次 run 里,生产路径的三条真实退出码用例(77 / 127 / exit 3)、信号死亡两条,以及 #2457 的三条实验室用例全部通过。所以生产侧已经由 #2457 修好,这次红的是测试夹具。#2459 第四个实例里尸体组的另一条红(delivers the synchronous corpse exit … 7700ms)也是这个夹具。

根因

和 #2453 / #2457 是同一个机制:tmux 只有 waitpid() 回收了 pane 进程之后,才会发布 #{pane_dead_status}。在那之前 pane 读作 1:(已死、无码),而 CI 上 tmux 有时整段时间都不回收。夹具只认 tmux 发布的状态,按读取次数等它变成非空,等多久都等不到。

#2439 首审建议改成「等确定的信号(如 tmux 钩子),或者单独放宽这个夹具的预算」。我实测过钩子:在不回收子进程的服务端上(屏蔽 SIGCHLD 起服务端),exit 77 的尸体一直是 1:,pane-died 钩子不触发;正常服务端上是 1:77,钩子触发。也就是说钩子和状态一样要等 tmux 回收,帮不上;放宽预算则只是把等待拉长,tmux 不回收时照样等不到。

修法(纯测试改动)

把 waitForDeadPane 提到模块顶层,改等确定的信号,也就是后端(#2457)现在用的那一个:

  • 读取格式加上 #{pane_pid}:#{pid};
  • pane 已死时:
    • tmux 发布了状态,就用 tmux 的;
    • 没发布,但进程仍是这台服务端未回收的僵尸,就用内核记下的退出码(readUnreapedPaneExit,与生产代码同一个函数);
  • 读数上限 240 次保留,但它现在只覆盖「tmux 发现 pane 已死」这一步,不再和 tmux 何时回收挂钩;
  • 用尽时,把最后看到的原始状态(seen)带进失败 diff,能分清是哪种问题:
    • pane 一直没死(0:…),饥饿或者 CLI 没退出;
    • 会话不见了(空,说明 remain-on-exit 没生效);
    • 已死但进程既没被回收、也不是本服务端的僵尸。
  • 尸体组 beforeEach 的前提断言改成 toMatchObject({ dead: true, status: '77' }),失败时 diff 里会带上 seen。

回归测试与复现

  • fix(tmux): tmux 未回收 pane 进程时从内核取真实退出码,不再把 3/127 报成 1 #2457 的实验室组(用 python 屏蔽 SIGCHLD 后起 tmux 服务端,服务端永远不回收 pane 进程)新增一条:在这种服务端上建一个 exit 77 的尸体会话,夹具必须拿到 77。
  • 变异:去掉夹具里读内核那一步,新用例稳定变红,形状与 CI 完全一致:
    expected { dead: true, status: '', …(1) } to match object { dead: true, status: '77' }
    × lets the corpse fixture learn the exit code tmux never publishes 7014ms
    
  • 加压(isolate-run,4 核;另起 6 个空转进程压满 CPU,8 个 worker 并发、各循环 3 轮):bun test 跑整个 tmux-pipe-exit-code.test.ts,24 轮共 816 例全部通过,每轮 115–118s(空载约 40s)。本机 tmux 3.3a 加压造不出「不回收」状态,所以压测只证明没有引入回归;能确定复现的是上面那条实验室用例和它的变异。

验证

  • test/tmux-pipe-exit-code.test.ts + test-hygiene:vitest 60 例全绿;bun test --timeout=120000 跑本文件 34 例全绿。
  • 只改这一个测试文件,src/ 零改动。

🤖 Generated with Claude Code

尸体组 beforeEach 的 waitForDeadPane 只认 tmux 发布的 pane_dead_status,而
tmux 只有回收了 pane 进程才会发布;CI 上它在整个等待窗口(240 次读、7.5s)
都没回收,夹具读到「已死、无码」而红(#2459)。改成与后端(#2457)同一个
确定信号:pane 已死后,tmux 发布了状态就用它,没发布但进程仍是服务端未回收
的僵尸时读内核记下的退出码。读数上限保留,只覆盖 tmux 发现 pane 死亡这一步;
用尽时把最后看到的原始状态带进失败信息,区分饥饿与真失败。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@deepcoldy
deepcoldy merged commit 19096f2 into master Oct 28, 2026
15 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner Author

合后核验:落地提交 19096f2(标题带 #2476、正文为空),落地树与「master 8c4bdd8 + 审过的 head e7bc2e6」逐一相同;master 上 19096f2 的 CI 已开跑(run 40690311693)。

交叉复审提的两条可选 P3,留作记录(都不影响合入):

  • 夹具里 kernel.kind === 'signaled' 那个分支,以及「只有 tmux 说已死才问内核」那道门,现在都没有用例守着。要收口的话,可以在实验室 server 上补一条 kill -9 $$ 的用例:期望 status: '',seen 里带 kernel 读数;
  • waitForDeadPane 注释说「'' 只在一直没拿到时出现」,但信号死亡的未回收僵尸同样返回 '',两者要靠 seen 区分。

@deepcoldy
deepcoldy deleted the test/tmux-corpse-fixture-kernel-status branch October 28, 2026 12:46
deepcoldy pushed a commit to darylchen97/botmux that referenced this pull request Oct 28, 2026
deepcoldy pushed a commit to darylchen97/botmux that referenced this pull request Oct 28, 2026
deepcoldy#2476 的 waitForDeadPane 改由内核记录补 tmux 未回收 pane 的退出码,
替代本夹具原有的 run-shell 一次性唤醒;生产路径两者互补(nudge 先于
kernel fallback)。deepcoldy#2453 实验室链式 remain-on-exit failed,旧版拒绝
该值,describe 按真实 tmux 版本 >=3.2 skip。

Co-Authored-By: Claude Code <[email protected]>
@github-actions

Copy link
Copy Markdown

🚀 Released in v3.55.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.

1 participant