Skip to content

test(tmux): 确保私有 server 在清理目录前退出 - #3687

Merged
deepcoldy merged 4 commits into
masterfrom
fix-3683-tmux-teardown
Nov 21, 2026
Merged

deepcoldy merged 4 commits into
masterfrom
fix-3683-tmux-teardown

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

问题

Closes #3683。

测试的私有 tmux server 在 kill-server 失败、或子测试被直接 SIGKILL 后,可能仍存活;紧接着删除 socket/scratch 目录会让它失联并长期占用进程与内存。sandbox lab 的 fake CLI 也有同类残留路径。

修改

  • 新增共享 test-process-reaper:
    • 同步记录 socket intent 和可用的 PID + 启动标识,回收前核验身份,避免 PID 复用误杀;
    • Linux 通过 /proc/net/unix inode 与 /proc/<pid>/fd 对应关系定位 server,socket 已 unlink 也能找到;
    • 非 Linux 使用 lsof -U 做同路径解析;
    • pending intent 在有界窗口内等待启动证据,检查失败时保留注册表/scratch 并置失败退出码,不再把“无法检查”当成“已经死亡”;
    • sandbox 按本次随机生成的完整 fake-CLI 路径匹配 /proc/<pid>/cmdline,不做宿主进程名或 fleet socket 扫描。
  • tmux fence 在 exec real client 前同步写 intent,保持 real client 的 timeout/signal/PID 语义;kill-server 前同步捕获 PID。
  • Bun runner 把注册表放进子进程 scratch,在 process-group sweep 前后各做一次回收,覆盖 server 已脱离进程组但尚未 bind 的启动窗口。
  • issue 点名的 Claude startup/restart、Codex launcher、共享 Claude harness 和 sandbox lab 改用统一的“先杀后删”清理;sandbox 同时注册 fake-CLI 路径。

影响面

仅修改测试 runner、测试 fence 和测试 harness,不改产品代码。共享 tmux shim 覆盖所有经 PATH 调用 tmux 的测试;真实 worker / sandbox 的 PTY 路径不变。非 Linux 的 lsof 解析有行为回归,但本环境不能进行 macOS live 验证。

验证

  • bun run build:通过(含 typecheck)。
  • 最终 head 的 test/tmux-*.test.ts:40 文件通过,973 passed / 1 skipped。
  • issue 相关 6 个 worker/harness 文件:17/17 通过。
  • 进程回收聚焦回归(Vitest):20/20 通过;Bun 同组:8 + 2 条全部通过。
  • worker-codex-actor-launcher Bun:6/6 通过。
  • sandbox tmux restore 场景:Vitest 与 Bun 均通过。
  • test/test-hygiene.test.ts:28/28 通过。
  • 变异复验均咬红、恢复后转绿:
    • 摘掉直接 PID 回退;
    • 摘掉 fence 全局回收;
    • 摘掉 runner scratch 回收;
    • 禁用 procfs 解析;
    • 将启动等待窗口置零(真实 detached client 在 runner 返回后启动)。

🤖 Generated with Claude Code

CI 首跑暴露两个 test-process-reaper 接线缺陷:

1. bun-runner-shards 集成测试的 scripts 复制清单漏了新文件
   test-process-reaper.mjs,shard fixture 里的 run-bun-tests 因此
   `Cannot find module './test-process-reaper.mjs'`(bun-test 1/4、4/4)。
   把该文件加入复制清单。

2. reaper registryFiles 的 readdirSync 在 fence root 被并发删除时
   (Bun teardown 竞态)可能返回 undefined 而非抛错,`for...of entries`
   抛 TypeError(bun-test 2/4 herdr-discovery)。对非数组结果提前返回
   空注册表——已消失的 root 不再持有任何 server。

均为测试基础设施、无产品代码改动。变异验证:移除复制清单项 shards
集成测试复现模块缺失;移除数组守卫 herdr 复现 TypeError,还原全绿。

Co-Authored-By: Claude Fable 5 <[email protected]>

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增量复审 head 9ff9b86f10bd8a49ffa3a6a5bdc51bf48639ae2e:两处修复都与首跑 CI 的失败路径精确对应,代码侧认可,待新 head 首跑 CI 结论。

  • test/bun-runner-shards.integration.test.ts 补上 test-process-reaper.mjs:这是临时 shard fixture 运行真实 runner 所需的运行时模块,声明文件不需要复制。
  • scripts/test-process-reaper.mjs 对 fence root 的 readdirSync 增加非数组返回守卫:root 在并发 teardown 中消失时按空注册表处理,不再进入 for...of。/proc 的其它目录读取没有这条 root 删除生命周期,无需扩大改动。

独立验证(未沿用提交中的数字):

  • bun run typecheck:通过。
  • Vitest:shard fixture + 两个 reaper 文件,16/16 通过。
  • Bun 分文件执行:
    • bun-runner-shards.integration.test.ts:6/6;
    • herdr-discovery.test.ts:16/16;
    • tmux-process-reaper.test.ts:8/8;
    • bun-runner-process-reaper.integration.test.ts:2/2。

未发现新的代码阻塞。合并仍以 run 44874815178 首跑全绿为准。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已按方案 B 追加修复并 ff 推送:df4a5f7657b668c43dde077fa8e2e637c9ad4dbd。

  • fence root 恢复为 /tmp/bmxt-*,不再嵌套到 botmux-bun-child-*;
  • scratch 仅保存 tmux-root 映射,pre-sweep 与 removeScratch 都通过映射回收并清理 root;无映射时保留原 nested 兜底;
  • createTmuxFence 对显式 root 仅接受 /tmp/bmxt-* 的空目录,避免复用或删除非测试目录;
  • 原 reaper nested 扫描和启动等待逻辑不变。

针对 CI 的 -L 长 UUID socket 形状补了真实 runner 回归:长 root 时子测试 new-session 稳定失败,短 root 映射后通过;将 runner 变异回 BOTMUX_TMUX_FENCE_PARENT=scratch 后再次确定性失败,恢复后转绿。

验证:

  • bun run build / typecheck:通过;
  • Vitest 聚焦回归:26/26;
  • Bun:runner reaper 2/2、shard fixture 6/6、herdr-discovery 16/16;
  • Bun runner self-check:通过。

新 head 的首跑 CI 已触发,继续以全绿为合码门禁。

POSIX child 的 fence root 保持 /tmp/bmxt-* 短拓扑,root 路径追加到
scratch manifest;runner 在正常关闭、信号取消和启动竞态中同时回收
scratch 与清单内的所有 root,并保留原有 nested registry/sandbox reaper。
Windows 不使用 /tmp,继续走 scratch/PARENT。损坏或截断的 manifest
仍回收可确认的进程,但保留现场并让运行失败,避免静默漏清理。

回归覆盖真实 runner 的 OSC7501 长 label socket 预算、多 fence、无
child teardown、延迟 server 启动及截断 manifest + detached fake CLI。
旧长路径变异收到 153 字节并咬红;跳过损坏清单 reaper 的变异留下
同一进程 identity 并咬红,恢复后均通过。

验证:bun run build;bun run test -- 相关 3 文件(17/17);
Bun 原生 runner 集成测试(3/3);node scripts/run-bun-tests.mjs
--self-check;真实 program-status-relay(23 pass、3 skip、0 fail)。
Windows 路径已静态复核,未做 Windows 实机验证。

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

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审当前远端 head 6eb1f50643029837435dc98487abf7ce5ca1c0d5:没有推送或覆盖我本地曾尝试的另一条路线,以下结论只针对这份 manifest 实现。

这版采用 BOTMUX_TMUX_FENCE_ROOTS 多短 root 清单,而不是单 root 复用:每次嵌套 createTmuxFence 都生成独立 /tmp/bmxt-* root,因此 deny log、socket 和 teardown 不互相污染;runner 按 manifest 统一回收。manifest 只接受 /tmp/bmxt-* 直接子目录,截断或非法记录会失败并保留清理证据,没有形成任意目录删除入口。

独立验证:

  • 带真实 bunfig/preload 的 runner 嵌套场景(fenced-run、systemd-fence、minimax-long-entry、tmux-process-reaper):4/4 文件通过。
  • bun run build / typecheck:通过。
  • Vitest 聚焦回归:27/27。
  • Bun:tmux-process-reaper 8/8、bun-runner-process-reaper 3/3、herdr-discovery 16/16。

当前实现覆盖了二次创建、长 socket、损坏 manifest、延迟启动和回收生命周期,未发现新的代码阻塞。合入仍以 run 44881028082 首跑全绿为准。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

首跑门禁已满足:run 44881028082(attempt=1,head 6eb1f50643029837435dc98487abf7ce5ca1c0d5)全部 job 成功。

  • 四个 bun-test shard 与四个 test shard 全部通过;
  • build、三个 binary job、聚合 test/bun-test 均通过;
  • PR 当前其它 checks(含 CodeQL)也全部为 SUCCESS。

结合此前的实现复核、真实 runner 嵌套场景和变异验证,#3687 已具备按既定流程合入 master 的条件。后续 #3684 同步到该 master 后,应以新 head 自己的首跑结果继续判断,不沿用本次绿灯替代。

@deepcoldy
deepcoldy merged commit b58b18a into master Nov 21, 2026
18 checks passed
@github-actions

Copy link
Copy Markdown

@deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。

这次运行覆盖 b58b18a…200cdf615(2 个提交),同批合入的还有 #3416,失败不一定由本 PR 引起。

用例 跑道 状态 失败信息
Codex basic bot flow feishu-core-codex failed Replanned 20 times, exceeding the limit. Please configure a larger value for replanningCycleLimit (or use MIDSCENE_REPLANNING_CYCLE_LIMIT) to handle more complex tasks.

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.27

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.

test: 集成测试的私有 tmux server 在 teardown 失败后泄漏(本机累计 246 个,最老 13 天)

1 participant