Skip to content

test(cli): 放大 shell 回收用例启动预算,修 bun-test 正对照竞态 - #2596

Merged
deepcoldy merged 2 commits into
masterfrom
fix/resolve-shell-retirement-timeout-budget
Oct 30, 2026
Merged

deepcoldy merged 2 commits into
masterfrom
fix/resolve-shell-retirement-timeout-budget

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

背景

test/resolve-command-shell-parse.test.ts 的「async shell process-group retirement > retires rc background children after complete/timeout with a positive control」在 #2543 的 bun-test 首跑(run 41023870882 / job 123957266873)红在 timeout 变体 229 行:expect(pids().length).toBeGreaterThan(0) 拿到 0。

根因

用例给 resolveCommandAsync 的 timeoutMs 只有 100ms。fixture 的 rc 启动后第一件事是后台拉起 sleep 45 并 echo $! 到 pidfile;但在 bun-test 全量并发(1823 个文件、多进程同时 fork)的高负载 runner 上,新 fork 出的 /bin/sh 可能超过 100ms 才被调度。resolver 的定时器先触发,对整个探测进程组发 SIGKILL(registry.ts 的 finish()),rc 从未执行到 echo $!,pidfile 保持为空,正对照于是读到 0。

complete 与 timeout 两个变体共用这同一条启动窗口,这次只是 timeout 变体被撞上。与 #2272 同族但不同断言窗口(#2272 是回收完成后的残留读取,232 行;本次是 229 行正对照)。

改了什么(仅测试,src 零改动)

  • 两个变体的 resolver 预算统一从 100ms 放大到 2s:
    • complete 变体的 rc 自身远在预算内退出,用例不因此变慢;
    • timeout 变体前景 sleep 5 仍确定性走超时路径(inconclusive: true 不变);
    • 生产调用默认预算本就是 5s,100ms 只是测试人为压紧,2s 仍只覆盖「进程能被调度起来」这一最小前提。
  • 229 行从「await 后立即读」改成 2s 有界等待新 pid 出现(吸收观测时序;真正关闭启动竞态的是放大后的预算)。

验证

  • 机制复现:给 fixture 注入 250ms 的启动前停顿(模拟调度延迟 >100ms),旧代码两种变体各复现一次与 CI 逐字相同的 Expected: > 0 / Received: 0;同一停顿下修复后两变体全过。
  • 负载实测:isolate-run --cpus 1(8 个满载空转 + 8 路并发 bun 测试进程)下修复版 24/24 全绿;完整文件 vitest 18/18、bun:test 18/18。
  • 变异复验:删掉 src/adapters/cli/registry.ts 里 finish() 的进程组 SIGKILL,257 行 expect(running).toEqual([]) 在两个变体各咬红一次,确认改完的用例仍真实守着产品侧回收行为,不是被放松。
  • 未做同 SHA rerun;本 PR 合入 master 后,被挡 PR 同步 master 取新 head 首跑结果。

🤖 Generated with Claude Code

「retires rc background children after complete/timeout with a positive
control」给 resolveCommandAsync 的 timeoutMs 只有 100ms。fixture 的 rc
一启动就后台拉起 sleep 并 echo $! 到 pidfile;在 bun-test 全量并发
(1823 个文件)的高负载 runner 上,新 fork 出的 /bin/sh 可能超过
100ms 才被调度,resolver 的定时器先到、SIGKILL 整个进程组,pidfile
里什么都没写——229 行正对照 pids().length > 0 拿到 0(run
41023870882 / job 123957266873,挡在 #2543 的 bun-test 首跑)。

两种模式(complete / timeout)共用同一条启动窗口,把两者的预算统一
放大到 2s:
- complete 模式 rc 自身远在预算内退出,用例不因此变慢;
- timeout 模式前景 sleep 5 仍确定性地走超时路径;
- 2s 覆盖繁忙 runner 的进程启动(生产默认预算本就是 5s,100ms 只是
  测试人为压紧)。
另把「立即读 pidfile」改成 2s 有界等待,吸收观测时序;真正关闭启动
竞态的是放大后的预算。

验证:
- 本地给 fixture 注入 250ms 启动停顿精确复现 CI 报错(Expected > 0 /
  Received 0,两种模式各 1 次);同一停顿下修复后两模式全过。
- isolate-run 限 1 核 + 8 个满载空转 + 8 路并发 bun:修复版 24/24
  全绿;完整文件 vitest 18/18、bun:test 18/18。
- 变异:删掉 registry.ts 里 finish() 的进程组 SIGKILL,257 行
  toEqual([]) 两种模式各咬红 1 次,确认用例仍守着产品侧回收行为。

与 #2272 同族但不同窗口:#2272 是 complete 模式回收完成后的残留
(232 行),本次是 229 行正对照在 rc 被调度前就读取。

Co-Authored-By: Claude Code <[email protected]>
复审指出上一提交只给 timeout 变体 2s 预算,complete 变体仍是 100ms,
同一启动竞态仍在。两变体共用同一套 rc(先后台拉 sleep 并 echo $!),
预算必须一致。

注入启动前延迟实测:150ms / 250ms 两档下,旧版 complete 变体各复现一次
Expected > 0 / Received 0(timeout 因已给 2s 通过);统一 2s 后两档
两个变体全部通过。无延迟时 vitest 18/18、bun:test 18/18。

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy
deepcoldy merged commit c7d1151 into master Oct 30, 2026
14 checks passed
deepcoldy pushed a commit that referenced this pull request Oct 30, 2026
…2543 合码

# Conflicts:
#	src/adapters/backend/scratch-sandbox.ts
#	src/worker.ts
@deepcoldy

Copy link
Copy Markdown
Owner Author

复审中的一个非阻塞 P3(裸 bun test <file> 走 Bun 默认 5000ms 单测超时,timeout 变体合法墙钟约 2×2s ≈ 4s,高负载下本地定向跑会误超时;CI 传了 180s 不受影响)已修在 follow-up #2615:给该 it.each 加 }, 30_000),断言不变,附负载复现(4/8 红 → 8/8 绿)与变异复验。

@github-actions

Copy link
Copy Markdown

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

这次运行覆盖 89a9cea…22d1c8d0b(20 个提交),同批合入的还有 #2546 #2556 #2589 #2591 #2545 #2538 #2595 #2597 #2581 #2539 #2598 #2515 #2536 #2575 #2366 #2606 #2544 #2593 #2603,失败不一定由本 PR 引起。

用例 跑道 状态 失败信息
Kimi basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, the middle column displays a welcome message "欢迎加入群组" (Welcome to the group) and system notifications about group creation and settings, rather than a list o…
Gemini basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, the main content area displays a topic conversation. I can see messages from "Gemini".
Codex DM chat mode replies inline and keeps one session feishu-core-dm-modes-codex failed Feishu Messenger chat list did not load after 4 attempts (URL: https://acn2e4mfbjx2.feishu.cn/next/messenger/, title: 消息 - 飞书). A login redirect means the saved storage state expired; a skeleton list…

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

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