Skip to content

test(worker): remote-runner 接管用例等 turn_input_committed 到达再断言,修 bun-test 高负载竞态 - #2611

Merged
deepcoldy merged 1 commit into
masterfrom
fix/remote-runner-committed-race
Oct 30, 2026
Merged

deepcoldy merged 1 commit into
masterfrom
fix/remote-runner-committed-race

Conversation

@deepcoldy

@deepcoldy deepcoldy commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

背景

bun-test 在一次 PR 首跑中红了 test/worker-remote-runner.integration.test.ts 的「reattaches an active provider turn and emits its original terminal without replaying input」:expect(messages).toEqual(arrayContaining(...turn_input_committed for om_turn_followup...)) 失败,而同一轮里该 turn 的 turn_execution_started / final_output / turn_terminal 全部到达。该测试文件在多个相邻 commit 上 blob 逐字相同、邻近 CI run 通过,属时序竞态而非逻辑回归。

根因(真实 spawn worker + provider 探针实证,非读代码推断)

follow-up 在 recovered turn 终态后被 flush 提交时:

  • turn_input_committed 由 runner status: busy 请求 resolve 之后的微任务发出(src/worker.ts 提交成功后的 deferred-commit 分支);
  • 该 turn 的 turn_terminal 在 provider final 行落地时由 backend 同步回调发出。

当 provider 零延迟把 status: busy 与 final 合并进同一次 stdout 写入(同一 chunk)时,backend 在一次同步处理中先跑 final 回调(发 terminal),busy 的 resolve 微任务后跑(发 committed),于是 committed 经 worker IPC 到达父进程晚于 terminal。探针实测稳定晚 6–393μs。原用例在「轮询等到 terminal」后立刻断言 committed 已在数组里,等于假设两条通道(provider stdout 回调链 vs worker→父进程 IPC)有先后保证——它们没有。这与 #2597 修的引擎 attestation 用例是同一类「socket ack 与 worker IPC 不保证顺序」竞态。

生产侧提交确认确实有发(committed 总是在数百微秒到毫秒内到达,从未丢失),真实 provider 的 busy ACK 与 final 之间隔着整轮执行时间,不会同 chunk,因此生产无此顺序,本 PR 只修测试。

改动

test/worker-remote-runner.integration.test.ts:在等到 follow-up turn_terminal 之后、对消息数组做快照断言之前,加一个 waitFor 等该 turn(attempt 9、durablePrimaryInbox)的 turn_input_committed IPC 到达。waitFor 带 10s deadline,receipt 真缺失时仍会失败,不掩盖真实回归。与 #2597 的处理方式一致,纯测试改动,不碰 src。

验证(Linux,bun 1.4.x)

  • bun test --timeout=180000 test/worker-remote-runner.integration.test.ts:6/6 通过(CI 的 bun-test 用 180s per-test 超时)。
  • bun run test -- test/worker-remote-runner.integration.test.ts(vitest/node):6/6 通过。
  • 变异复验(bun,与 CI bun-test 同引擎):在 src/worker.ts 提交确认前临时注入 120ms 延迟(模拟高负载下 receipt 晚到超过测试 50ms 轮询窗口)——
    • 旧断言(无 waitFor):精确复现 CI 的 ExpectArrayContaining {} 失败;
    • 新断言(加 waitFor):通过;
    • 撤除延迟:双引擎 6/6 通过。注入代码仅为本地探针,已还原,不在本 PR。

影响面:单个集成测试文件;不改生产代码、CLI、PTY/Tmux、持久化或通知。

本地复现注意

  • 该用例内含约 16s 的等待,bun test 默认 per-test 超时只有 5s,裸跑 bun test <file> 必然超时失败,与 CI 无关;CI 的 bun-test 由 scripts/run-bun-tests.mjs 以 TEST_TIMEOUT_MS = 180_000 运行。本地复现请用 bun test --timeout=180000 test/worker-remote-runner.integration.test.ts。
  • CI 钉 Bun 1.4.3(setup-bun@v2);本地用 1.4.4 验证结论同构(该竞态只涉及 worker IPC 与 microtask 排序,这两个版本无相关变更)。

…st 高负载竞态

follow-up 在 recovered turn 终态后被 flush 提交时,turn_input_committed
由 runner status:busy 请求 resolve 后的微任务发出,而该 turn 的
turn_terminal 在 final 行落地时同步发出;provider 零延迟把 busy ACK 与
final 合并进同一 stdout chunk、且 runner 高负载(bun-test 串行 1824 文件)
时,receipt 经 worker IPC 到达父进程会晚于 terminal。原用例在「等到
terminal」后立即断言 committed,跨通道无顺序保证(与 #2597
引擎 attestation 用例同类),高负载下偶发 ExpectArrayContaining 失败。

生产侧提交确认确实有发(探针实证:同 chunk 下 committed 仅晚 terminal
6–393μs,5s 内必达),非生产缺陷。改为 waitFor 等 committed IPC 到达
再做快照断言;receipt 真缺失时 waitFor 10s 超时仍 fail,不掩盖回归。

变异复验(bun,CI 同引擎):在提交确认前注入 120ms 延迟,旧断言精确
复现 CI 的 ExpectArrayContaining 失败,新断言通过;无延迟双引擎 6/6 绿。

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy
deepcoldy merged commit 369617d into master Oct 30, 2026
15 checks passed
@github-actions

Copy link
Copy Markdown

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

这次运行覆盖 3400614…0946357b3(9 个提交),同批合入的还有 #2542 #2600 #2578 #2590 #2612 #2594 #2548 #2615,失败不一定由本 PR 引起。

用例 跑道 状态 失败信息
Gemini basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, the main content area displays a topic conversation. I am looking for a specific text bubble from "Gemini" containing the string "ACK-e2e-gemini-179337940473…

@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