Skip to content

test(codex): attestation 文件改为写临时文件再改名,避免假 Codex 读到空文件 - #3155

Merged
deepcoldy merged 1 commit into
masterfrom
fix/codex-lazy-attestation-torn-read
Nov 8, 2026
Merged

deepcoldy merged 1 commit into
masterfrom
fix/codex-lazy-attestation-torn-read

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

Fixes #3154

改了什么

test/worker-codex-lazy-rollout-ownership.integration.test.ts 的夹具收到 managed_turn_origin 时,原来用 writeFileSync 原地重写 attestation 文件,现在改为先写临时文件再 renameSync。只改测试,不碰产品代码。

为什么

启动探测用例里 worker 会为同一轮反复重发 managed_turn_origin(进程号从探测进程换到真实 CLI 时都会重发),夹具每次都原地重写这个文件;假 Codex 在首次提交时读它。本地打点 3 次,每次这一轮都重写 6 次,最后一次重写离假 Codex 读取只有 2–14ms。writeFileSync 先截断再写,读恰好落在两步之间就读到空串,夹具最后 JSON.parse('') 报 Unexpected end of JSON input,CI 上偶发红(run 42436901239 / job 128597566113,同 run 其余 622 个文件全绿)。

改名写入后,读到的只会是旧内容或新内容。

验证

  • 并发读写对照(一个进程持续重写、另一个进程持续读,各 3 秒):原地重写 754137 次读里 705903 次读到空;写临时文件再 rename,524833 次读 0 次读到空。
  • npx vitest run --project unit test/worker-codex-lazy-rollout-ownership.integration.test.ts:两次各 8/8 通过。
  • bun test ./test/worker-codex-lazy-rollout-ownership.integration.test.ts:8 pass / 0 fail。
  • npx tsc --noEmit:通过。

影响面

只改这一个测试文件的夹具;和 #2892 修的 slow-launcher 超时不是同一个问题。

🤖 Generated with Claude Code

启动探测用例里,worker 会为同一轮多次重发 managed_turn_origin(进程号从探测进程
换到真实 CLI 时都会重发),测试每收到一次就原地重写 attestation 文件。本地打点:
最后一次重写离假 Codex 首次提交时读这个文件只有 2–14ms。writeFileSync 先截断再写,
读恰好落在两步之间就读到空串,夹具里 JSON.parse('') 报
"Unexpected end of JSON input",用例在 CI 上偶发红。

改为写临时文件再 rename,读到的只会是旧内容或新内容。同样的并发读写对照:
原地重写 75 万次读里 70 万次读到空,改名写入 52 万次读 0 次读到空。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@deepcoldy
deepcoldy merged commit 4c1cfc4 into master Nov 8, 2026
15 checks passed
deepcoldy pushed a commit that referenced this pull request Nov 8, 2026
@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flake: codex lazy-rollout 启动探测用例偶发读到空的 attestation 文件(Unexpected end of JSON input)

1 participant