Repository navigation
test(worker): 功能计时从 worker 加载完成后开始,修复两个 bun 腿冷加载偶发 - #3562
Merged
Merged
Conversation
Bun 腿每个测试文件使用全新 TMPDIR,tsx 的编译缓存为空,文件里第一个 源码 worker 要冷编译整个模块图;CI 高负载下这一步用了 7–12 秒,吃掉了 从 spawn 起算的 20 秒 / 10 秒功能预算。 新增 spawnLoadedSourceWorker:引导脚本装上生产 IPC 预加载、导入完整 worker 后才回 worker_ipc_ready,测试等到它(独立 30 秒上限)再发 init, 功能计时只覆盖 worker 行为。与 #3544 的源码启动夹具是同一边界。 Closes #3550 Closes #3551 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 18, 2026 09:49
This was referenced Nov 18, 2026
deepcoldy
commented
Nov 18, 2026
deepcoldy
left a comment
Owner
Author
There was a problem hiding this comment.
复审结论:0 P1/P2,代码层面可合
复审对象为远端 head c542f698fcf89b6363c15c5bd38e885da4103701;本地 rebase 版与远端补丁的 patch-id 均为 7ff6cff7dfbcba4fba121eec27299cebeefe7187,两个新 helper 的 blob 也逐字一致。复审期间 master 新增的 004891ebf 仅修改 Doubao 适配器及其测试,与本 PR 零文件交集。
代码核查
test/helpers/source-worker-bootstrap.ts:5-7先安装生产 IPC preload,再导入完整 worker,最后发送加载回执;worker 在src/worker.ts:39242-39275注册正式 message handler 并发出WORKER_IPC_HANDLER_READY_EVENT后,导入才完成。因此父进程收到回执再发init时,preload 已移除缓冲监听器,投递路径与原先直接启动源码 worker 一致。test/helpers/source-worker-boot.ts:41-63的加载回执、提前退出和 30 秒超时三条结束路径都会清理 timer 与 listener;调用方在test/worker-busy-marker-bounded-fallback.integration.test.ts:100-110和test/worker-traex-program-status.integration.test.ts:152-167均有失败后的子进程清理。worker_ipc_ready只被新 helper 用作加载同步;两个测试的功能断言均按具体消息类型过滤,不会把该回执误计为prompt_ready或业务通知。编译版 worker 分支保持原启动方式。- 改动仅限测试 helper、两个集成测试及 typecheck 列表,
src/零改动,不改变生产 session、其他 CLI 或后端行为。
实际验证
bun run build:通过(含 typecheck)。bun run test test/worker-busy-marker-bounded-fallback.integration.test.ts test/worker-traex-program-status.integration.test.ts:2 文件、11/11 通过。- 为两个 Bun 定向运行分别设置全新空
TMPDIR,确保 tsx 冷缓存:busy-marker 3/3、TraeX 8/8 通过。 bun run test test/test-hygiene.test.ts test/bun-runner-selectors.test.ts:68/68 通过。- 非阻断观察:高负载(load 约 20–25)下,TraeX 完整文件的一次普通 Bun 运行中,PTY session-lock 用例曾在
test/worker-traex-program-status.integration.test.ts:237-240的 15 秒功能等待超时;该用例单独复跑通过,完整文件随后普通复跑及冷缓存复跑均 8/8 通过。失败发生在加载回执和init之后,本 PR 未改变该功能预算或对应 worker 逻辑,记录为既有功能阶段竞争 flake,不作为本 PR 阻断项。
截至本结论发布,远端 CI 的 build、bun-test 1/4、test 4/4 及三个 binary 检查已通过,其余分片仍在排队或运行;实际合并仍须以全部必需检查全绿为准。
This was referenced Nov 18, 2026
|
@deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。 这次运行覆盖 7a7307e…697de2f8e(10 个提交),同批合入的还有 #3540 #3552 #3556 #3530 #3558 #3563 #3561 #3560 #3564,失败不一定由本 PR 引起。
|
This was referenced Nov 18, 2026
|
🚀 Released in v3.59.20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改了什么
两个在 bun 腿偶发红的集成用例,失败原因相同:用例的功能计时从 spawn worker 那一刻开始,把源码 worker 的冷加载时间也算了进去。本 PR 只改测试:
test/helpers/source-worker-boot.ts的spawnLoadedSourceWorker()和引导入口test/helpers/source-worker-bootstrap.ts。引导脚本先装上生产用的 IPC 预加载,再导入完整的src/worker.ts,导入完成后才回worker_ipc_ready。调用方等到这个回执再发init。等回执的上限单独算(30 秒),不占用例的功能预算。test/worker-busy-marker-bounded-fallback.integration.test.ts:3 个用例都改为等 worker 加载完成后再发init,原有的 20 秒、12 秒和 30 秒等待都从init起算。test/worker-traex-program-status.integration.test.ts:源码 worker 也改成同样的方式,10 秒首条输入预算从init起算。编译版 worker(BOTMUX_TEST_WORKER_BINARY)没有冷编译这一步,保持原路径。SOURCE_WORKER_LOAD_TIMEOUT_MS)。tsconfig.typecheck.json,由bun run build的类型检查覆盖。worker-codex-startup-readiness和worker-traex-startup-readiness的源码夹具在 #3544 里用的就是这个计时边界。本 PR 把它抽成共享 helper,用在这两个文件上。与 #3556 的关系:#3556 给 TraeX Auto、启动就绪等几个起很多 worker 的文件加了预编译快照,目的是缩短加载时间。本 PR 解决的是计时边界:不管加载要多久,都不计入功能预算。两者互补。这两个文件每个只起 3~8 个 worker,没有为它们额外引入快照编译。
Closes #3550
Closes #3551
两个 issue 的根因相同,修法是同一处,所以合在一个 PR 里。
根因
node --import tsx src/worker.ts启动,启动时间主要花在 tsx 编译 worker 的整个模块图上。tsx 把编译缓存放在os.tmpdir()下,而 bun 腿给每个测试文件分配一个全新的 TMPDIR(scripts/run-bun-tests.mjs的mintFencedEnv)。所以每个文件里的第一个 worker 都要冷编译。这两个失败用例都是各自文件的第一个用例。vitest 腿的各文件共用同一个 TMPDIR,缓存是热的,所以这两条从没在 vitest 腿上红过。Worker started的时间比较):busy-marker 用例要等两次 3.5 秒的忙碌探测,有界兜底才放行(worker 进入延后后约 7 秒)。加载用掉 12 秒后,20 秒预算剩下的不够。issue 里说的「延后之后日志一直没有新行」不是 worker 卡住:worker 活着时启动后 15 秒必然会打一行
First prompt timeout,而这几次在 worker 启动后约 8 秒用例就超时结束了。TraeX 用例同理,加载后只剩 2–3 秒,来不及完成粘贴和回车。验证
pty 0.214.1 reports=true在 8 秒加载延迟下通过(13.6 秒)。expected bounded prompt_ready(日志停在deferring prompt ready (reason=deferred-busy-marker));first input written on the startup idle report。bun test --timeout=180000逐文件运行:busy-marker 3/3 通过,traex-program-status 8/8 通过。bunx vitest run --project unit(这两个文件):11/11 通过。3c18c1578(含 perf(test): 缓存 worker 编译并稳定 MCP 启动验证 #3556)后的树上重跑。bun run build通过(含新 helper 的类型检查);两个测试文件另用临时 tsconfig 跑tsc --noEmit也通过;test-hygiene、bun-runner-selectors68/68 通过。影响范围
只改测试和测试 helper,不改生产代码。新 helper 只在这两个文件里使用;其它测试和编译版 worker 的路径不变。
🤖 Generated with Claude Code