Skip to content

test(traex): 修复 auto-model 容量切换通知计数的跨通道时序 flake(#2260) - #2267

Merged
deepcoldy merged 3 commits into
masterfrom
fix/traex-auto-model-notify-wait
Oct 24, 2026
Merged

deepcoldy merged 3 commits into
masterfrom
fix/traex-auto-model-notify-wait

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

背景

test/traex-auto-model.integration.test.ts >「prefers the earlier available model, proceeds if it queues, then retains it for the next turn」在 CI 上间歇失败(真实 worker + PTY):

expect(received).toHaveLength(expected)
Expected length: 2
Received length: 1
  at test/traex-auto-model.integration.test.ts:453

跨通道时序竞态:用例 f.wait(() => rows(f.submissions).length === 3) 等的是 PTY 写入通道(fake CLI 的 submissions 文件),紧接着却在另一条异步 worker IPC 通道(f.messages)上断言容量切换通知有 2 条,没有等待该通道。生产代码里 worker 是先发 user_notify 再 restartCliProcess(通知严格早于重启),但 worker→测试的 IPC 投递在 runner 高负载下会晚于重启后第 3 条 submission 落盘,于是断言时刻只看到 1 条。

跨树复现记录见 #2260:不含本 PR 相关改动的 master run(d58850919)在同一用例同一行以相同的 2→1 失败;更早三个 master run 通过;本地低负载整文件 10/10 通过——负载敏感。

改动(仅测试,不动 src)

  1. 断言前先 f.wait 到 f.messages 通道确实出现第 2 条通知(在同一通道上等待再断言)。
  2. fixture 新增测试钩子 delaySecondModelOrderNoticeMs:生成一个 worker bootstrap,把第 2 条容量切换通知的 process.send 延迟指定毫秒,确定性复现「通知晚于第 3 条 submission 到达」。该用例启用 4000ms(本地实测通知领先第 3 条 submission 仅 2–3 秒,4s 稳定反转到达顺序;对 100s 用例超时余量充足)。钩子默认 0、完全不影响其他用例;同时把原有 activityMode 的 heartbeat bootstrap 与新钩子合并为同一段生成逻辑。

变异证据(bun 1.4.4,本文件单跑)

形状 结果
延迟 4s + 新写法(先 wait 再断言) pass(整文件 11/11)
延迟 4s + 旧写法(去掉 wait 立即断言) fail:Expected 2 / Received 1,与 CI 失败同形
无延迟(默认参数,等价原行为) pass

即:守卫在真实延迟下旧写法稳定变红、新写法稳定通过,不依赖 CI 负载。

验证

  • bun test test/traex-auto-model.integration.test.ts:11 pass / 0 fail(本地两次全文件跑)
  • 未动 src,无需其他回归。

合入后 #2230 rebase/merge 本提交即可解除其 bun-test 门禁(#2260)。

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

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