Skip to content

test(ci): 根治 schedule-repair 锁竞态与 v3 临时目录 teardown 两个高负载 flake - #3238

Merged
deepcoldy merged 1 commit into
masterfrom
test/fix-ci-flakes-3232-3235
Nov 9, 2026
Merged

deepcoldy merged 1 commit into
masterfrom
test/fix-ci-flakes-3232-3235

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

背景

两个只在高负载 CI runner 上复现的测试 flake,已经在多个 PR 和 master push 上红过,按 G4 不能靠同 SHA 重跑放行。本 PR 只改测试,src 零改动。

#3232:根因是锁竞态,不是 pumpUntil 步进太多

CI 日志显示两条用例失败方式不同:一条 150ms 即逻辑断言失败,另一条被它连累挂满 120s;相邻用例只要 20–40ms,所以「假时钟步进轮次占满墙钟」不成立,调大步进反而失败更快。

真正根因:TurnSendLedger.execute 包在 withFileLock 里,dispatch 要等拿到文件锁之后才执行。高负载下拿锁要花真实时间,测试却已经 settleLater 并开始推假时钟,于是结算跑在这次 send 登记为 in-flight 之前,之后永远走不到 unknown。

修法(slowFinal 测试夹具):

  1. 新增 entered promise,在 dispatch 真正被调用(已拿锁、已登记 in-flight)时 resolve;两个调用点先 await send.entered 再推假时钟、再结算,保证登记先于结算。
  2. 把 finish 登记进 pending:某条用例中途失败、没走到自己的 finish 时,afterEach 也能释放这次悬着的 fenced send,不会把后续用例拖到 120s 超时。
  3. pumpUntil 的步进保持 1s / 500ms 不变。

#3235:Node 22 的 rmSync 重试救不了迟到文件

Node 22 的 rmSync 只在第一轮删子项,之后的重试只重试 rmdir,且第 i 次重试前同步 sleep i × retryDelay——旧配置 maxRetries: 60, retryDelay: 100 实际阻塞约 Σ i×100ms = 183s,与 CI 失败用例耗时 183043ms 吻合。第一轮之后才落地的文件后续重试永远不会补删,同步 sleep 还卡住同进程的 fire-and-forget 写,所以单纯加大 rmSync 预算既赢不了、又会把 shard 卡死约 30 分钟。

修法(test/helpers/v3-external-harness.ts 的 cleanupBotRuns):

  • 改成异步重删循环,每轮用 rmSync(..., { maxRetries: 0 }) 整体删一次(重新覆盖迟到文件),轮间 await setTimeout 让出主线程,让后台写有机会收尾。
  • 只在 ENOTEMPTY / EBUSY / EPERM 时等待,30s 墙钟上限;正常无竞争路径第一轮就返回,零额外延迟。
  • 函数由同步改为 async,四个不返回 promise 的裸调用点补上 await;其余 afterEach(() => cleanupBotRuns()) 箭头本身返回 promise,vitest 会 await,无需改。

验证

CI 用 Node 22,本地默认 Node 24,两者的 rmSync 失败行为不同,因此在 Node v22.21.1(匹配 CI)和 Bun 1.4.4 下分别验证:

影响面

只动测试与测试 helper,不改任何生产代码、配置或持久化格式。

🤖 Generated with Claude Code

Fixes #3232
Fixes #3235

两个只在高负载 CI runner 上复现的测试 flake,均为测试侧问题、src 零改动。

#3232 schedule-repair-adversarial-review(test(4/4)):
根因不是 pumpUntil 步进太多,而是锁竞态——TurnSendLedger.execute 包在
withFileLock 里,dispatch 在拿到文件锁之后才执行;高负载下拿锁要花真实
时间,测试却已经 settleLater 并推假时钟,结算跑在 send 登记 in-flight
之前,之后永远走不到 unknown(CI 里 line536 用例 150ms 即逻辑失败,
line636 被它连累挂满 120s)。修法:
- slowFinal 暴露 entered(dispatch 真正进入时 resolve),两个调用点先
  await send.entered 再推时钟、再结算,保证 in-flight 先登记。
- 把 finish 登记进 pending,用例中途失败没走到 finish 时 afterEach 也能
  释放悬着的 fenced send,不再连累后续用例超时。
- pumpUntil 步进保持 1s/500ms 不变。

#3235 workflow-node-daemon cleanupBotRuns(test(2/4) ENOTEMPTY):
Node22 的 rmSync 只在第一轮删子项,后续重试只重试 rmdir 且第 i 轮前
同步 sleep i*retryDelay(旧 60×100ms 实际阻塞约 183s,CI 失败耗时
183043ms 与之吻合);第一轮之后才落地的文件永远不会被补删,同步 sleep
还卡住同进程的 fire-and-forget 写。加大 rmSync 预算既赢不了又会把 shard
卡死。修法:cleanupBotRuns 改为异步重删循环,每轮整体 rm(maxRetries:0)
重新删掉迟到文件,轮间 await 让出主线程让后台写收尾,30s 墙钟上限,只在
撞 ENOTEMPTY/EBUSY/EPERM 时等待,正常路径零延迟;四个裸调用点补 await。

验证(Node v22.21.1 匹配 CI,另跑 Bun 1.4.4):
- typecheck、build 通过;17 个相关测试文件 365 用例双运行时全绿。
- #3232 探针:pbkdf2 占满线程池复现锁延迟,去 entered 门控时目标用例
  133ms 复现 CI 同签名失败、恢复后通过;去 pending 登记时释放探针挂满
  10s 超时,恢复后通过。
- #3235 探针:独立子进程在首轮 rm 期间持续落盘,新异步循环 978ms 清理
  成功;去掉重试循环即抛与 CI 逐字相同的 ENOTEMPTY。探针为临时验证、未提交。

Co-Authored-By: Claude Fable 5 <[email protected]>
@deepcoldy
deepcoldy merged commit 91743e6 into master Nov 9, 2026
15 checks passed
deepcoldy pushed a commit to Phoobobo/botmux that referenced this pull request Nov 9, 2026
master 新进的 deepcoldy#2865、决策看板文字换行修复、deepcoldy#3238 都不碰本 PR 的 5 个文件。

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

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

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

这次运行覆盖 91743e6。

用例 跑道 状态 失败信息
Claude basic bot flow feishu-core-claude failed waitFor timeout: Based on the screenshot, I am examining the main content area (right panel) which displays a conversation thread. There is a specific card component located above the text bubble con…
OpenCode basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, I am examining the main content area (right panel) which displays a conversation topic. There is a prominent card from "OpenCode" located above the text bubb…
Pi basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, I am examining the main content area (right panel) which displays a conversation thread. There is a prominent card component located above the text bubble co…
OhMyPi basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, I am examining the main content area which displays a conversation thread. There is a specific card from "OhMyPi" located above the text bubble containing "A…
Kimi basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, I am examining the main content area (right panel) which displays a conversation with "Kimi". There is a prominent card titled "🖥 Kimi • e2e-kimi-1794211409…
Antigravity basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, I am examining the main content area (right panel) which displays a conversation topic. There is a prominent card from "Antigravity" located above the text b…
Grok basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, I am examining the main content area which displays a conversation thread. There is a specific card titled "Grok Build • e2e-grok-1794213089742..." located a…
Consecutive message queue feishu-core-queue failed openThreadForMessage: couldn't find topic entry containing "e2e-consec-1-1794212425521" within 30000ms

@github-actions

Copy link
Copy Markdown

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

1 participant