Repository navigation
test(tmux): 集成测试收尾先停住并杀掉 worker 整棵进程树,再删私有 TMUX_TMPDIR - #2231
Merged
Merged
Conversation
SIGKILL 只杀 worker 本身,它被杀前刚发出的同步 tmux 调用(sh、tmux 客户端) 还活着;测试随即删掉私有 TMUX_TMPDIR,还没解析 socket 的客户端会回落到 /tmp 指向宿主 tmux server,被 tmux 围栏拒绝,整个文件在收尾时判红(#2214)。 新增 test/helpers/process-tree.ts 的 killProcessTree:先 SIGSTOP worker 让它 不能再 fork,再反复读进程表、把新出现的后代逐个 SIGSTOP 直到没有新的,然后 整树 SIGKILL 并等 worker 退出。已经脱离进程树的守护进程(tmux server)不受 影响,harness 模拟 daemon 重启的 restart() 语义不变。claude harness 的清理改为 可等待、先杀 worker 树再删目录;另外五个自带收尾的私有 tmux 集成测试同样改用它。 Fixes #2214 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 23, 2026 14:39
|
|
||
| /** A process that writes `marker` after `delayMs` unless it is killed first. */ | ||
| const lateWriter = (marker: string, delayMs: number) => | ||
| `setTimeout(() => require('node:fs').writeFileSync(${JSON.stringify(marker)}, 'still running'), ${delayMs});`; |
复审 P3:ps 没设 maxBuffer、也不查错误,输出被截断或 ps 失败时会静默少掉后代, 退化成只杀根进程(正是 #2214)。改为带 PROCESS_TABLE_MAX_BUFFER,失败即报错; 进程树遍历放进 try/finally,无论如何已收集到的进程(至少根进程)都会被 SIGKILL, 不会停在 SIGSTOP。新增用例:PATH 里放一个必然失败的假 ps。 另把 worker-kimi-effort(TMUX_TMPDIR 即随后删除的 root)与 session-env-worker 两处「正常 close 超时后 SIGKILL worker」的兜底改用 killProcessTree。 Refs #2214 Co-Authored-By: Claude Opus 5.5 <[email protected]>
复审 P3-5:上一提交让 helper 在 ps 失败时抛错,但它跑在 finally / cleanup 里—— 五处 `await` 会用 "ps failed" 顶替测试的真实失败并跳过后面的 kill-server、rmSync, 两处 `void` 会变成未处理的 rejection 把整个文件判红(容器里没有 procps 时全部命中)。 改为永不 reject:读不到进程表时 process.emitWarning 说明只杀到了哪些 pid,已找到的 进程(至少根进程)照样 SIGKILL,不会停在 SIGSTOP。调用方无需改动。 Refs #2214 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
Author
|
已合并 PR #2231 → 5c72a74(squash,作者 deepcoldy),关闭 #2214。
|
|
🚀 Released in v3.51.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 #2214
改了什么(纯测试改动)
新增
test/helpers/process-tree.ts的killProcessTree(child):SIGSTOP这个子进程,让它不能再 fork;ps -A -o pid=,ppid=反复读进程表,把新出现的后代逐个SIGSTOP,直到读不到新的为止;SIGKILL,并等子进程退出(有上限)。已经脱离进程树的守护进程(tmux server 是 double-fork 出来的)不受影响。
test/helpers/claude-worker-harness.ts:cleanUpClaudeHarnesses返回 Promise,三个使用方原本就是afterEach(cleanUpClaudeHarnesses),无需改动);restart()也改用它。pane 和 CLI 挂在 tmux server 下面,不在 worker 的进程树里,所以 restart 的语义不变。另外五个自己写收尾的私有 tmux 集成测试,把「SIGKILL worker + 等 2s」换成
killProcessTree(还有两处「先正常 close、超时后 SIGKILL」的兜底也一并换了,见第 4 条):worker-claude-startup-command-first-promptworker-codex-model-migration-pickerworker-codex-startup-readinessworker-collaborative-oncallworker-codex-actor-launcher复审后追加(提交
992dd3545,复审 P3):killProcessTree调ps时带上PROCESS_TABLE_MAX_BUFFER,ps失败或输出被截断时会明确发现,不再静默少掉后代;8f504f88d,复审 P3-5):helper 不抛错,只发一条process.emitWarning,说明只杀到了哪些 pid,已经找到的进程(至少根进程)照样 SIGKILL,不会停在 SIGSTOP 状态。之所以不抛,是因为它跑在finally和 cleanup 里,自己抛错会顶替测试的真实失败,还会跳过后面的kill-server和rmSync;worker-kimi-effort(它的 TMUX_TMPDIR 就是随后删除的 root)和session-env-worker:「正常 close,5 秒超时后 SIGKILL」的兜底也改用killProcessTree。为什么
SIGKILL 只杀它发给的那个进程。worker 被杀的那一刻如果正在同步执行
tmux …(execFileSync/execSync起的 sh 和 tmux 客户端),这些子进程会活下来。随后测试删掉私有的 TMUX_TMPDIR,还没来得及解析 socket 的客户端按 tmux 的规则回落到/tmp,也就是宿主机的 tmux server。tmux 围栏挡住了这次调用,但会把整个文件判红。三次观测的被拒调用都是 worker 自己的探测(display-message … #{pane_id}/#{alternate_on}),master 上也出现过。影响面
只改测试和测试 helper,生产代码零改动。
验证
bun run build✅;tsc --noEmit✅;test-hygiene+tmux-test-isolation-guard28/28 ✅test/process-tree.test.ts(vitest / bun 都通过),2 个用例:「已脱离进程树的守护进程不受影响」这条用例是契约用例,用来防止有人把清理改成更宽的杀法,没有做对应的变异。
process-tree.test.ts新增用例「进程表读不到时只告警、不抛错,而且子进程照样被杀」(PATH 里放一个必然失败的假ps);worker-kimi-effort和session-env-worker在 vitest、bun 下各跑一次,全部通过。display-message延迟 1.5s;用例等到出现一个新的在途调用时才结束;文件里再放一个后续用例,让文件保持打开。/tmp/tmux-0/botmux … -L botmux display-message -p -t bmx-…,与 test(tmux): 集成测试收尾 SIGKILL worker 后立即删除 TMUX_TMPDIR,worker 在途的 tmux 调用回落到 /tmp 被围栏拒绝 #2214 一致)worker-claude-clear-restore、worker-claude-cold-resume、session-env-stamp-reattach、worker-claude-startup-command-first-prompt、worker-codex-model-migration-picker、worker-codex-startup-readiness、worker-collaborative-oncall、worker-codex-actor-launcher。(第一批里有 13 次失败,原因是压测脚本给的 TMPDIR 太长,tmux socket 路径超过上限,报
File name too long,与改动无关。脚本改成短目录名后补跑,13/13 通过。)codex-app-runner.integration的一条偶发上(与本 PR 无关),已记 test(codex-app-runner): native user input 的 refused/timedOut 用例在看到 turn/interrupt 后立即断言 stdout,跨通道无先后保证,bun-test 间歇失败 #2232,并另开 test(codex-app-runner): native user input 失败分支等 stdout 送达再断言,不再跨通道抢先读 #2233 根治。test(codex-app-runner): native user input 失败分支等 stdout 送达再断言,不再跨通道抢先读 #2233 合入后,本分支会合入 master,再在新 head 上重跑 CI。🤖 Generated with Claude Code