Repository navigation
test(codex): 修复 codex-app-threads 读到半写文件与冷启动截止时间导致的偶发失败 - #2124
Merged
Merged
Conversation
测试轮询假 app-server 正在写的文件,CI 高负载时会读到写了一半的内容:
- pid 文件由 writeFileSync 先建空文件再写入,测试在这个窗口读到 '',
Number('') 为 0;process.kill(0, 0) 探测的是测试自己的进程组,永远成功,
于是必然报「fake Codex app-server 0 was not reaped」(abort / force-close 两例)。
- 请求日志在追加中被读取,空文件或半行交给 JSON.parse,报
「Unexpected end of JSON input」(timeout 一例,即 #2118 上红的那条)。
改为:fixture 在 PID 末尾写换行,测试复用 helpers/pid-file 的 waitForPidFile
只认完整 PID;轮询日志时只解析以换行结尾的整行。生产代码不在这条链上,未改。
Refs #2079
Co-Authored-By: Claude Opus 5.5 <[email protected]>
成功路径与路径校验用例测的是 RPC 做了什么,不是多快;500ms/1000ms 的截止 时间同时覆盖了 fixture 冷启动,2 核压测下会报 initialize timed out。只有 hang-archive 需要截止时间触发,保留短值。 Refs #2079 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 21, 2026 20:58
Owner
Author
|
已合并 PR #2124 → f3ae866(squash) 门禁:首审与 Pure(pi) 复审都在 head b82b44b 上给出可合(0 P1 / 0 P2)/ 必需 CI(build、test)与 bun-test、bun-binary* 共 14 项首跑全绿 / 老用户无 breakchange:只改测试与测试 fixture,生产代码零改动 / 落地树与审过的树 patch-id 一致 follow-up:
未做:发版、部署(需另行指令) |
This was referenced Oct 21, 2026
|
🚀 Released in v3.49.0 |
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.
改了什么
只改测试与测试 fixture,生产代码未动。
test/fixtures/fake-codex-app-server.mjs写 PID 时末尾加换行;test/codex-app-threads.test.ts的三个回收用例改用现成的test/helpers/pid-file.ts的waitForPidFile(要求^[1-9][0-9]*\n$才返回)。split('\n').slice(0, -1)),不再把空文件或写了一半的行交给JSON.parse。Codex archive lifecycle RPC里成功路径和路径校验用例的截止时间从 500ms/1000ms 改为 10s;只有hang-archive需要截止时间触发,保留 500ms。为什么(根因)
CI 上这个文件近两周红了 10 次(扫了约 1000 次 CI 运行的失败 job),共三种形态,都是测试读取方式的问题,与生产代码无关:
fake Codex app-server 0 was not reaped(abort / force-close 两例)writeFileSync先建空文件再写入,测试在existsSync为真后立刻读,读到'',Number('')为 0。process.kill(0, 0)探测的是测试自己所在的进程组,永远成功,所以 2 秒后必然报「没回收」Unexpected end of JSON input/JSON Parse error: Unexpected EOF(timeout 一例,#2118 上红的就是这条)''.trim().split('\n')得到[''],JSON.parse('')抛错initialize timed out after 200mssetCodexAppThreadName不读initializeTimeoutMs,master 已修,本 PR 不涉及第 3 项是本地对照压测时发现的:未改动的 master 在 2 核压 16 路下出现
Codex app-server initialize timed out after 500ms。截止时间同时覆盖了 fixture 的 node 冷启动。这些用例断言的是 RPC 做了什么,不是快慢,所以不应被它卡住。生产代码排查:
CodexAppServerProbe的超时、回收、force-close 路径在这几种失败里都按预期工作,失败全部发生在测试读文件这一步。另外查到CodexAppServerProbe往子进程stdin写入时没挂error监听,与本偶发无关,归入 #2079 的 EPIPE 一类另行处理。影响面
test/codex-app-threads.test.ts与test/fixtures/fake-codex-app-server.mjs。codex-app-runner.integration、worker-codex-app-turn-routing.integration)读 pid 用的是Number(readFileSync(...)),末尾换行对它们没有影响(Number('123\n') === 123)。split('\n').filter(Boolean)读,空文件的情况已经挡住;剩下「一行跨页写入时读到半行」的微秒级窗口,扫描到的 CI 记录里零次出现,本 PR 不动。验证
Refs #2079
🤖 Generated with Claude Code