Skip to content

test(traex): 分离 replacement 冷启动与功能就绪等待 - #3761

Merged
deepcoldy merged 4 commits into
masterfrom
wt/botmux-3745-test-traex-terminal-pty-desyn
Nov 24, 2026
Merged

deepcoldy merged 4 commits into
masterfrom
wt/botmux-3745-test-traex-terminal-pty-desyn

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

根因

Fixes #3745。

失败并不是 replacement generation 已运行 35s 仍未就绪,而是测试从发送 restart 起只用默认 12s 等待 prompt_ready,这段窗口同时承担了 Auto 的冷启动前置工作:

  1. 不支持 app-server 的 fake TraeX 让 model/list helper 按既有生产策略等待 8s 后 fail-open;
  2. 随后的 runtime admission / spawn 继续耗时;
  3. 失败日志中 replacement 在等待到期前约 0.45s 才 spawn,尚未获得首次重绘与空闲检测机会。

同一文件 auto=undefined 不经过这次目录预检,所以同轮通过。绿色基线的 Auto 用例已需约 31s,新增启动链路使重启后的 12s 窗口处于边界。证据指向测试的冷启动墙钟预算,而非输入隔离或 replacement 状态竞态。

修改

  • 初次与 replacement 就绪改为直接等待 worker 的 prompt_ready IPC 事件,不再以 25ms 轮询竞争事件处理。
  • waitForWorkerMessage 增加可选事件谓词;replacement 只接受重启前未收集到的新消息对象,重启前已有的 prompt_ready 不会重复满足这次等待。
  • 冷启动单独使用 60s 上限,整例上限调整为 90s;功能观测仍保留原来的 12s/6s 窗口。
  • 所有 quarantine、输入次数、PID 更换、fresh input 和禁止重放断言均保持不变。

回归证据

在与 #3745 现场完全相同的事故 SHA 8f1641a0fc6686ea65290726afc9004670b4a520 上,用独立临时 worktree 做 A/B;仅替换本 PR 的测试文件,生产代码不变。加压方式为目标文件与相关 runtime-gate 文件并发、共同限制在 2 个 CPU,避免整机压满:

taskset -c 0,1 bun run test -- \
  test/traex-terminal-pty-desync.repro.integration.test.ts \
  test/traex-runtime-gate.test.ts --maxWorkers=2 --reporter=verbose
  • 旧测试逻辑:连续 2/2 轮复现;每轮均为 auto=false 与 auto=true 报 timed out waiting for replacement generation readiness,另外两个用例通过。
  • 修复后:同一事故 SHA、同一命令连续 3/3 轮全绿;每轮目标 4/4,加上 gate 文件为 34 passed | 3 skipped。
  • 当前基线 Vitest 未加压:目标 4/4 通过。
  • 当前基线 Bun、双 CPU:bun test test/worker-ipc-waiter.test.ts test/traex-terminal-pty-desync.repro.integration.test.ts,9/9 通过。
  • bun run test -- test/worker-ipc-waiter.test.ts:5/5 通过。
  • bun run typecheck:通过。
  • bun run build:通过。

为什么不会掩盖真问题

本次没有放宽任何输入投递、quarantine 释放、终态归因或重启后防重放的功能窗口,也没有添加 retry。只有冷启动等待使用更长上限;真正的新 generation 不发送 prompt_ready 仍会失败,重启前已收集的就绪事件不会重复满足等待。后续 fresh input 必须写入新 PID 且提交次数精确相等,因此 replacement 卡死、错误复用旧进程或重放隔离输入仍会咬红。

影响范围

仅修改测试与测试 helper,不改生产代码、持久状态、配置或发布内容。worker-ipc-waiter 新参数可选,既有调用行为不变;目标集成测试覆盖 TraeX PTY 的普通/Auto、主动重启/崩溃恢复组合。其他 CLI、IM 平台和会话类型不受影响。全量 Vitest/Bun 由 CI 验证。

🤖 Generated with Claude Code

- 通过 IPC 等待新 generation 的 prompt_ready,并排除旧事件\n- 为冷启动保留独立预算,功能观测与防重放断言窗口不变\n- 补充 IPC waiter 事件过滤的行为回归

Co-Authored-By: Kimi <[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 02fe603b5c40733fb14c45f06517e021dc120fe6。本地 rebase 到最新 master 4c32e2be57 后的 95ca659697 与远端提交 patch-id 一致;差异仍只有 3 个测试文件,master 新增的 #3750 与这些文件无交集。

非阻断项

  1. P3|删除死变量:test/traex-terminal-pty-desync.repro.integration.test.ts:419 的 readyBeforeRestart 在改成 Set 谓词后没有任何读取,建议合前顺手删除。
  2. P3|记录覆盖边界:将 :446 的 replacement accept 谓词改成恒真后,该集成测试仍 4/4 通过,所以它并不直接钉住“拒绝历史 ready”的语义。该语义由 test/worker-ipc-waiter.test.ts:36 的 helper 单测直接守护;后续 fresh-input、精确提交次数及 PID 更换断言仍守住端到端功能结果,因此不阻断本 PR。

既有边界(不要求本 PR 扩大范围)

test/traex-terminal-pty-desync.repro.integration.test.ts:416-446 的 CLI-crash 分支在 kill 和等待 claude_exit 之前建立 Set;若旧 generation 的 delayed prompt_ready 在这个窗口首次到达,它会被视为新对象。旧实现的数值基线也建立在同一位置,因此这不是本 PR 引入的回归。本项仅为代码路径语义说明,未构造 delayed-ready 复现,也不要求本次 flake 修复处理。

实际验证

  • bun run typecheck:通过。
  • bun run build:通过。
  • bun run test -- test/worker-ipc-waiter.test.ts test/traex-terminal-pty-desync.repro.integration.test.ts:2 文件、9/9 通过。
  • bun test test/worker-ipc-waiter.test.ts test/traex-terminal-pty-desync.repro.integration.test.ts:9/9 通过。
  • 变异 A:helper 忽略 accept 后,新增单测按预期咬红(误返回旧 ready);恢复后 5/5 通过。
  • 变异 B:集成测试 replacement accept 恒真,4/4 通过,确认上述覆盖边界。两次变异后均已恢复,git diff 与 cached diff 均为空。
  • CI test (2/4) 中目标集成测试 4/4 通过。当前 test (1/4) 唯一失败为 test/bun-runner-process-reaper.integration.test.ts 的 client delayed 1s 用例,属于 #3759 跟踪、#3760 处理中的既有竞态;本 PR 未触碰该文件或生产代码。其余当前 checks 为绿,但 aggregate test 仍红,合并仍应以 required checks 全绿为前提。

DeepCold review and others added 2 commits November 24, 2026 15:07
readyBeforeRestart 在改用 Set 快照谓词后已无读取方,删除。

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 增量复审:代码零阻断,CI 首跑待完成

复审对象为 fb337ac4a908c1b6cad156bb8e8378c263ec1a10。

  • 02fe603b 仍是新历史的直接祖先,原作者提交哈希未变,符合 fast-forward 增量。
  • merge commit c5e1b2e 的两个父提交精确为旧 PR head 02fe603b 与 master fbc448d964。从旧 head 带入的是 master 的 #3750、#3770 两段历史;对 fbc448d964 反向比较 merge 树,仍只有本 PR 原来的 3 个测试文件,没有额外手工改动。
  • fb337ac4 精确为 test/traex-terminal-pty-desync.repro.integration.test.ts 的 1 行删除,仅移除已确认无读取方的 readyBeforeRestart;Set 快照、accept 谓词、超时及功能断言均未变化。
  • 最终相对 fbc448d964 的 PR diff 仍只有 3 个测试文件,git diff --check 通过。
  • 复审期间 master 前进到 0d3e6e5d(#3764),其文件清单与本 PR 3 文件零交集,PR 仍为 MERGEABLE,不需要仅为这次 master 前进再造 head。

本地增量复验:

  • bun run typecheck:通过。
  • bun run test -- test/worker-ipc-waiter.test.ts test/traex-terminal-pty-desync.repro.integration.test.ts:2 文件、9/9 通过。
  • 工作区无残留修改。

当前 CI run 45347142483 与 CodeQL run 45347137394 尚在进行;代码增量可合,但 squash 仍以新 head 首跑 required checks 全绿为条件。

@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.

7a3dc6301c merge 增量复审:代码零阻断,等待新首跑

  • 新 merge commit 的父提交精确为上一 PR head fb337ac4a9 与 master 67ca6e9316;旧 head 仍是直接祖先,没有改写已审提交。
  • 从 fb337ac4a9 看,本次只带入 master 的 #3764、#3762、#3758、#3778 等增量;这些差异与本 PR 的 3 个测试文件零交集。
  • 反向比较 67ca6e9316..7a3dc6301c,仍只有 worker-ipc-waiter helper、其单测和 TraeX desync 集成测试,净 diff 为 36 insertions / 12 deletions;没有额外手工修改,git diff --check 通过。
  • 上一 head 的死变量清理保持不变,本次没有改动 readiness 谓词、超时或功能断言。

本地复验:

  • bun run typecheck:通过。
  • bun run test -- test/worker-ipc-waiter.test.ts test/traex-terminal-pty-desync.repro.integration.test.ts:2 文件、9/9 通过。
  • 工作区无残留修改。

新 CI run 45362498211 与 CodeQL run 45362489726 尚待完成。本增量代码可合;squash 仍以 7a3dc6301c 的 required checks 首跑全绿为前提。

@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.

最终门禁确认:7a3dc6301c 复审通过且首跑全绿

  • CI run 45362498211:head_sha=7a3dc6301cc989930b8575378fc423875db31725、run_attempt=1、status=completed、conclusion=success。
  • CI 的 14 个 job 全部为 completed/success:build、4 个 Vitest shard、4 个 Bun shard、3 个 binary job,以及 test / bun-test 两个聚合检查均绿。
  • CodeQL run 45362489726 同为 attempt 1、completed/success,3 个 Analyze job 均绿。
  • 发布时 PR head 仍为 7a3dc6301c,与本轮 merge 增量复审及本地 9/9 目标测试的对象一致;工作区无残留修改。

因此本 head 同时满足代码增量复审零阻断与新 head 首跑 required checks 全绿,可以按既定流程 squash。

@deepcoldy
deepcoldy merged commit 86f44b8 into master Nov 24, 2026
18 checks passed
@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(traex): traex-terminal-pty-desync 集成测试偶发 readiness 超时 flake

1 participant