Repository navigation
test(agent-core-v2): take wall-clock races out of the SSH probe, MCP crash and compaction failure cases - #5486
Conversation
…cases Both cases make every compaction attempt fail with a retryable error and assert what happens once the retries are exhausted. Unlike the other retry cases in the file they ran on real timers, so each sat through four rounds of real backoff, about 8.5 s per case. Use fake timers and advance past the backoff the way the neighbouring retry cases do. The assertions, including retry_count: 4, are unchanged; the two cases now take about 0.3 s each.
…ssh startup The case gives the platform probe a real 300 ms budget against a fake ssh that stalls, then read the fake's call log. Under load the fake can be killed by the timeout before it is scheduled far enough to write that log, and the case failed reading a missing file (2 of 18 runs with six copies and six CPU burners). A /bin/sh fake does not help: its median start is far lower, but the long tail that loses the race is scheduling, not interpreter start-up. Assert what the case is about instead of the fake's progress: the connect fails because the probe timed out, which the error message now pins (the executor's initialize timeout has the same kind), and the log holds at most the one uname probe and never an executor launch. A mutation that falls back to POSIX and launches the executor after a probe timeout still fails the case. 36 of 36 runs pass under the same load.
…exits The crash-after-connect fixture exited a fixed delay after its transport started, which is before the client finishes the initialize handshake and the tool listing. When the handshake took longer than the delay (500 ms in the connection manager case, 50 ms in the stdio client case), connect returned with the server already failed. The fixture now exits once the test creates a signal file, and both cases create it only after they have observed the connected state. The assertions are unchanged; the client case also checks that no close evidence arrived before the signal.
|
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: |
#5474 landed on main as one squashed commit, so the prompt cache files this branch carried from it now come from main as merged, including the review fixes made after this branch forked. Two main changes met the MCP migration: - #5486 made the crash-after-connect fixture exit when the test creates a signal file instead of after a fixed delay. The fixture is gone, so the testkit's exitAfterConnect now takes whenFile in place of afterMs, crashAfterConnectServer passes it on, and both crash cases keep the signal they create once they have seen the connected state. - #5488 added hostPathClass to the MCP stubs for Windows path classes. The stubs keep it beside the testkit-based servers.
Requirement or Bug
接着 #5458、#5476 和 #5479,继续清理 agent-core-v2 全量测试里的偶发失败。这个 PR 修三处:两处是用例拿真实的短时限和子进程的启动速度赛跑,一处是两条用例真等了重试退避。三处都只改测试,产品代码不动。
Bug Reproduction Steps
同时运行 6 份下面的命令,另开 6 个吃满 CPU 的进程:
pnpm exec vitest run packages/agent-core-v2/test/remote/session.test.ts -t "SSH platform detection before executor launch":bounds a stalled probe and never starts the executor18 次失败 2 次,报ENOENT ... /calls。pnpm exec vitest run packages/agent-core-v2/test/mcpCore/connection-manager.test.ts -t "flips connected stdio servers to failed":这次压测没有复现。之前一次全量里失败过,报expected 'failed' to be 'connected'。pnpm exec vitest run packages/agent-core-v2/test/agent/fullCompaction/fullCompaction.test.ts:不会失败,但有两条用例每次各跑约 8.5 秒。Root Cause
SSH 探测用例。 用例给平台探测一个真实的 300ms 时限,让假的
ssh一直卡住,最后读假ssh写下的调用记录。假ssh是一个 Node 脚本,启动后才写记录。机器一忙,它还没被调度到写记录那一步,就被时限杀掉了,用例读记录文件时报 ENOENT。换成/bin/sh写的假ssh也没用:在同样的负载下量了 240 次,从启动到写记录,Node 脚本的中位数是 56ms,sh 是 7ms,但两者都有 6 次超过 300ms。长尾来自进程排不上调度,不是解释器启动慢。MCP 崩溃用例。 夹具在传输层启动后过一段固定时间退出:连接管理器那条是 500ms,stdio 客户端那条是 50ms。传输层启动早于客户端完成握手和工具列表,所以握手慢于这个时间时,
connect返回之前子进程就已经退出了。两条压缩失败用例。 同一个文件里的其他重试用例都用了假计时器,这两条没有。所以每次都真等 4 轮重试退避。
Code Changes
['uname -s'],这依赖假进程来得及写记录。现在断言两件事:一是connect失败的原因是探测超时(kind: 'timeout',报错含SSH platform probe timed out);二是记录要么为空、要么只有一次uname -s,绝不出现执行器命令。只有记录文件不存在时才视为空,其他读取错误照常抛出KIMI_TEST_MCP_EXIT_WHEN_FILE指定的文件出现再退出。两条用例都先确认已经连上,再创建这个文件。stdio 客户端那条还新增断言:触发之前没有收到关闭证据retry_count: 4为什么 SSH 探测用例改断言不算削弱
这条用例要证明两件事:卡住的探测会被时限截断;截断后不会去启动执行器。
kind: 'timeout'。可是执行器初始化超时的kind也是timeout,光靠 kind 分不清是哪一步超时,只能再靠记录文件。现在加上报错文本,能直接确认是探测超时。阅读指南
三个提交各改一处,彼此独立。MCP 那个提交同时改了夹具
test/mcpCore/fixtures/crash-after-connect-stdio-server.mjs和使用它的两个测试文件。原来的KIMI_TEST_MCP_EXIT_AFTER_MS只有这两条用例在用,已经删除。Behavior Changes and Affected Users
None。产品代码、配置和契约文件都没有改动,只影响 agent-core-v2 的测试。
没有 changeset:只改了测试。
验证
只在 macOS 上验证过,Linux 和 Windows 交给 CI。SSH 探测那组用例在 Windows 上本来就跳过。MCP 夹具改用文件信号,而不用
SIGUSR2这类信号,就是为了在 Windows 上也能用。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.