Skip to content

test(bun-runner): 等待 tmux shim 写入 pending intent 后再退出,消除延迟收割启动竞态 - #3760

Merged
deepcoldy merged 1 commit into
masterfrom
fix/bun-runner-reaper-intent-race
Nov 24, 2026
Merged

deepcoldy merged 1 commit into
masterfrom
fix/bun-runner-reaper-intent-race

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

改了什么 & 为什么

Fixes #3759

test/bun-runner-process-reaper.integration.test.ts 的两个延迟启动用例(startup.test.ts 与 restart.test.ts)在 spawn(tmux, ..., { detached: true }); client.unref(); 后立即返回退出,未等待 fence.binDir/tmux shim 执行 record_server_intent 把 pending\t<socket>\t<pid> 写入 BOTMUX_TMUX_SERVER_LOG。在 CI 高负载下,bun test 进程可能先于 detached shim 启动完成而退出,导致 scripts/run-bun-tests.mjs 读到空日志提前收尾,随后 shim 才写日志并执行 sleep 1 拉起真实 tmux server,使外层 query.status !== 0 断言偶发失败(PR #3750 job 138072441598,全用例仅耗时 2564ms,其中 1800ms 为后置等待)。

本 PR 在测试体返回前仅等待 BOTMUX_TMUX_SERVER_LOG 出现对应 pending\t<socket>\t<client.pid> 记录(shim 刚进入 exec "$REAL" 的 sleep 阶段,真实 tmux server 仍未启动),既完整保留外层 runner 收割晚到 server 的被测行为,又消除高负载下的启动竞态。

影响范围评估

  • 仅修改 test/bun-runner-process-reaper.integration.test.ts,不改动任何生产代码、runner 或围栏脚本。
  • 仍使用真实 run-bun-tests.mjs + 真实 tmux shim + 1s / 5s 延迟 wrapper 端到端验证。

实际测试验证

bun test test/bun-runner-process-reaper.integration.test.ts
npx vitest run test/bun-runner-process-reaper.integration.test.ts

@deepcoldy

Copy link
Copy Markdown
Owner Author

CI test (2/4) 失败核查(确认与本 PR 无关)

head 1e371f4d2a 的首跑检查中,其余 17 项(含 CI/build、三平台 bun-binary、CodeQL、全部 4 组 CI/bun-test 以及本 PR 修改的 test/bun-runner-process-reaper.integration.test.ts 本身)均已通过,仅 test (2/4)(job 138106231110)失败在单个用例:

  • 失败用例:test/backend-outage-worker-report.integration.test.ts:48 › worker: claude_exit names a lost tmux server > reports \gone` when the server process dies, and nothing for an ordinary exit`
  • 日志摘要:worker b 启动探测时出现 [read-isolation] inconclusive liveness probe (unknown) ... refusing to start rather than clear/cold-spawn around a possibly-live confined pane,导致 prompt_ready 等待 60s 超时。
  • 与本 PR 无关:本 PR 仅修改 test/bun-runner-process-reaper.integration.test.ts(+19 行,仅作用于该测试内部生成的临时 startup.test.ts / restart.test.ts 夹具),未触碰任何 src/ 源码、test/helpers/backend-outage-lab.ts 或 test/backend-outage-worker-report.integration.test.ts,两者无共享代码路径、无共享临时目录/tmux socket。

因此不在本 PR 内修改该无关用例,保持 diff 干净。

@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 1e371f4d2a 与本地 rebase 后 d9d21b852b 的目标文件 blob 均为 d26e8fa1d4,stable patch-id 均为 a79297db9cda…;基线 origin/master=045ca7551b。diff 仍只有 test/bun-runner-process-reaper.integration.test.ts +19 行,不触及生产代码、runner 或围栏实现。
  • test/bun-runner-process-reaper.integration.test.ts:261-270、:339-345 等待本次 client 的 pending intent 后再退出,与 test/helpers/tmux-fence.ts:201-226 的同步写入及随后 exec 顺序吻合;等待发生在延迟 wrapper 启动真实 tmux 之前,没有削弱外层 runner 收割晚到 server 的被测场景。scripts/test-process-reaper.mjs:332-374 确实以该 intent 驱动有界等待与收割,原竞态闭合。
  • 变异复验:将两处 marker 的 client.pid 改为 999999 后,startup 1s、startup 5s、restart 三个目标用例均在 deadline 后失败,其余 4 个用例通过;恢复后目标文件 hash 与 HEAD 逐字一致。
  • 实际验证:bun test test/bun-runner-process-reaper.integration.test.ts 7/7 通过(24.76s);bunx vitest run test/bun-runner-process-reaper.integration.test.ts 7/7 通过(25.91s);bun run build 通过。
  • P3 nit(不阻断)::265、:340 的 marker 未带行尾 \n,与同仓既有同构等待的防御性写法略有差异;本场景 socket 独立且目标 pid 精确匹配,不要求为此修改。

远端当前仍有已说明的 test (2/4) 无关失败及汇总 test 失败;以上结论针对本 PR diff,实际合并仍需满足仓库常规 CI 与审批条件。

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.32

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(bun-runner): startup reaper 1s 延迟用例未等 shim 写入 intent 就退出,CI 高负载下漏收晚到 tmux server

1 participant