Repository navigation
test(agent-core-v2): fix macOS-only subagent timeouts and a racy notification test - #5458
Conversation
…OS automounter The engine harness, the bootstrap stub and the loopback remote used /home/test as the user's home. On macOS /home is served by autofs, so every lookup under it takes about 40ms. A watcher on the missing ~/.agents/skills retries every 250ms, so the subagent deadline tests in tool.test.ts, which advance fake time by two hours, spent 30s in lookups and timed out on macOS only. /nonexistent is the conventional home that does not exist, cannot be created by a normal user, and fails a lookup at once on every platform.
The group notification case finished three subagent runs at once, but each completion reads its output from disk before it is queued. When the first completion settled before the others had completed, the loop started a turn with one notification and the next notifications launched a second, unscripted request. The case now holds each completion message until all three tasks have completed, which is the simultaneous completion the loop folds into one turn.
|
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
全量测试里一直有一些用例在 main 上也会失败,或者单独跑能过、全量跑会失败。每次全量对比都要人工甄别这些噪声,真正的回归容易混在里面。这个 PR 修其中根因已经查清的两处。
Bug Reproduction Steps
pnpm exec vitest run packages/agent-core-v2/test/tool/tool.test.ts:三条「子 agent 没有截止时间」的用例每次都在 30 秒超时,Linux CI 上通过。pnpm exec vitest run packages/agent-core-v2/test/agent/task/idle-notification-repro.test.ts:IDLE × N: a GROUP of bg agents completes偶发报告「request fix: escape all control characters in TOML basic strings #7 had no scripted step」,全量负载下更容易出现。Root Cause
tool.test.ts在 macOS 上超时。 引擎 harness、bootstrap 桩和 loopback 远端都用/home/test当用户主目录。macOS 的/home由 autofs(auto_home)提供,在它下面每查找一次路径约需 40ms;Linux 上没有这层,查找立即返回。用例里有一个监听器在等不存在的~/.agents/skills,每 250ms 重试一次。这三条用例要把假时间推进两小时来证明没有截止时间,相当于触发近 3 万次查找,在 macOS 上要十几分钟。通知用例偶发失败。 三个后台 agent 同时结束,但每个完成都要先从磁盘读出输出,才把通知放进队列。loop 本身会等所有「已完成、通知还没组装好」的任务就绪后再开回合(
hasPendingCompletions),所以只要三个任务都已完成,三条通知就会并进同一个回合。用例的问题在于:如果第一个任务的通知在另外两个任务完成之前就组装好了,loop 会先用这一条开回合,后两条再开第二个回合,发出一次没写剧本的请求。Code Changes
/nonexistenttest/harness/agent.ts、test/app/bootstrap/stubs.ts、test/remote/helpers/loopback.ts三处。这三处会真的被拿去访问文件系统,其余写成/home/test的地方只是字符串断言,没有改。/nonexistent是 Debian 给没有主目录的系统用户约定的路径:在各平台上都不存在,普通用户也建不出来,查找立即失败。保留了原来「主目录不存在、测试也写不进去」的语义IAgentTaskOutputService.createCompletion,等三个任务都走到完成后,再一起放行通知的组装。用例本来要测的就是「同时完成」,现在把这个前提写成确定的条件阅读指南
两处改动彼此独立,一个提交一处。第一处只有三行,重点看提交说明里的根因;第二处看
completeTogether和它在用例里的调用位置。Behavior Changes and Affected Users
产品代码没有改动,只影响 agent-core-v2 的测试。
/home/test/nonexistent没有 changeset:只改了测试。
验证
只在 macOS 上验证过,Linux 和 Windows 交给 CI。改动只涉及一个不存在的路径,在 Windows 上和原来的
/home/test一样解析成当前盘符下一个不存在的目录。/home/test/.agents/skills每次查找加建监听约 40ms,/nonexistent/.agents/skills约 0.1ms。tool.test.ts:150 条全部通过(之前 3 条超时)。单文件耗时:wire/resume.test.ts的用例执行时间从 22.3 秒降到 2.0 秒,agent/loop/loop.test.ts从 30.7 秒降到 10.7 秒。idle-notification-repro.test.ts:修改前在 macOS 上三次里会失败一次,修改后连续 8 次通过。packages/agent-core-v2全量:8,349 条,失败 5 条,都是本 PR 之外、正在逐条处理的已知问题:remote/process.test.ts2 条(大量进程组在假计时器下超时,后一条被前一条连累)、features/tower/store.test.ts1 条(等文件锁超时)、agent/media/tools/read-media.test.ts的 HEIC 2 条(真实解码耗时 40–58 秒)。和 main 上同样单独跑的全量相比,墙钟时间从 353 秒降到 323 秒,各文件耗时合计从 2,100 秒降到 1,864 秒。pnpm lint:通过。agent-core-v2 类型检查通过。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.