Repository navigation
test(agent-core-v2): keep the process-group and HEIC cases inside the timeout under load - #5476
Conversation
…s-group reap timers The cache-limit case schedules one 5 s reap timer per exited group and advanced fake time with advanceTimersByTimeAsync, which yields to the real event loop after every one of the 4097 timers. Idle that took about 7 s; with six copies and six CPU burners it reached 24 s, and the full suite pushed it past the 30 s test timeout. When it timed out, the async advance kept firing the old timers in the background, so the next case's process.kill spy saw thousands of calls and failed too. The reap callback is synchronous, so advanceTimersByTime fires the same timers in the same order with the same assertions. Under the same load the slowest run drops to 9 s, and a sync advance cannot outlive its test.
…e deep equality Two read-media cases check that a 4 MB and a 5 MB HEIC are stored untouched, and did it with toEqual on the Buffers. Vitest's deep equality walks typed arrays element by element: on 5 MB that alone takes about 4 s idle, 15 s with six copies and six CPU burners, and 40-58 s in the full suite, past the 30 s test timeout. The tool itself finishes in a few milliseconds. Assert the byte length, then Buffer.compare, as the other media tests already do. A truncated store now reports both sizes, and a changed byte still fails. Under the same load the slowest run drops to 18 ms.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
Requirement or Bug
接着 #5458,继续清理 agent-core-v2 全量测试里在 main 上也会失败的用例。这个 PR 修两处:
remote/process.test.ts的进程组缓存上限用例,以及read-media.test.ts的两条 HEIC 用例。它们单独跑能过,全量负载下会超过 30 秒的用例时限。Bug Reproduction Steps
pnpm exec vitest run packages/agent-core-v2/test/remote/process.test.ts -t "finished process-group ownership",另开 6 个吃满 CPU 的进程。缓存上限用例最慢一次 23.8 秒,离时限只剩不到 30%。在 agent-core-v2 全量里它会超时,紧接着的does not retain POSIX process groups for a Windows executor跟着失败,报process.kill被调用了上千次。read-media.test.ts -t "preserves a HEIC above":两条用例最慢一次 15.5 秒,全量里 40–58 秒。Root Cause
进程组用例。 用例为 4097 个已退出的进程组各排一个 5 秒的回收计时器,然后用
vi.advanceTimersByTimeAsync推进假时间。异步推进每触发一个计时器都要让出一次真实的事件循环,4097 个计时器就是 4097 次让出,机器一忙耗时就会成倍增长。超时后,这次异步推进还在后台继续触发旧计时器,下一条用例刚装上的process.kill监视就收到了这些调用,所以下一条是被连累的。HEIC 用例。 工具执行只要几毫秒,时间都花在最后的
expect(Buffer.from(stored!.bytes)).toEqual(heic)上。Vitest 的深度比较会逐个元素地遍历 typed array,单独测一个 5 MB 的 Buffer:toEqual要 4.1 秒,Buffer.compare和equals各约 1 毫秒。两处都是测试侧的根本修复:去掉了与被测契约无关的开销,产品代码没有改动。
Code Changes
await vi.advanceTimersByTimeAsync(5_000)改成vi.advanceTimersByTime(5_000)。ProcessManager.scheduleGroupReap的回调是同步的:查一次进程组,进程组不存在就删除,否则重排计时器。同步推进触发的计时器和顺序都不变,断言也不变。同步推进在返回前跑完,不会在用例结束后还留在后台运行Buffer.compareBuffer.compare(...) === 0,和image-originals.test.ts、sessionMediaStore.test.ts的写法一致。被测的是「超出预算的 HEIC 原样保存」,最可能的回归是截断或压缩,长度不一致时报错会直接给出两个长度阅读指南
两处改动彼此独立,各一个提交,每个提交只改一个测试文件的两到四行。进程组用例的回调见
src/remote/server/processManager.ts的scheduleGroupReap。Behavior Changes and Affected Users
None。产品代码、配置和契约文件都没有改动;两个测试文件的用例数和要证明的契约也没变。
没有 changeset:只改了测试。
验证
只在 macOS 上验证过,Linux 和 Windows 交给 CI。两处改动不涉及路径、子进程或平台分支。
负载对比用的是同一个脚本:6 份副本同时跑,另有 6 个吃满 CPU 的进程,每组各 12 次。
does not evict live groups at the former cache limit and reaps missing groupspreserves a HEIC above the former provider inline budgetpreserves a HEIC above the read budget for deferred inline resolution进程组用例剩下的 9 秒,来自假计时器库每触发一个计时器都要扫描全部计时器的开销。这条用例要证明的正是「超过原来的缓存上限 4096 也不会淘汰」,所以没有减少计时器数量。
HEIC 的新断言仍然能抓到回归。临时改坏
readMediaFileTool.ts里存入的字节后,两条用例都失败了,产品代码已还原:expected 4194327 to be 4194328。Buffer.compare的断言失败。扫过
test/agent/media下全部 345 条用例,其他对 Buffer 用toEqual的地方数据都很小,或者已经在用.equals。修改后这个目录里最慢的用例是 1.8 秒。remote/process.test.ts23 条通过;read-media.test.ts60 条通过,用例执行时间从约 10 秒降到 1.7 秒。pnpm lint通过,agent-core-v2 类型检查通过,pnpm run check:duplication没有新增重复。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.