Repository navigation
fix(codex-app): 预览等待在尾窗 RPC 超时时按预算耗尽降级而非抛出 - #2257
Merged
Merged
Conversation
waitForThreadPreview 的轮询用「剩余预算」作为 thread/read 的客户端超时, 但 withTimeout 超时时 reject 的不是 thread-not-loaded 错误,旧 catch 直接 throw 穿透整个轮询——机器繁忙时某次迭代只剩 1ms 预算就会以 "timed out after 1ms" 形状炸掉调用方,使兜底标题不写入(CI shard 红)。 与孪生 waitForThreadUpdatedAfter 对齐:catch 里先判 deadline 到期则按 「预览不可用」返回;并移植 codex-rpc-engine 的 MIN_POLL_REQUEST_BUDGET_MS =50ms 下限,不再发出注定超时的尾窗请求。 Co-Authored-By: Claude Code <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 24, 2026 04:31
按 #2257 复审: - MIN_POLL_REQUEST_BUDGET_MS 提至 src/core/codex-poll-budget.ts, codex-rpc-engine 与 services/codex-app-threads 共用同一导出,消除 两份 50ms 常量静默分叉的可能。 - 新增 floor 守卫用例:总预算 40ms(低于 50 下限)时等待阶段零 thread/read;阈值退回 <=0 的变异下用例变红。 - 新增 waitForThreadUpdatedAfter deadline 容错用例:慢响应耗尽预算 不抛、标题照写;删除该 catch 分支的变异变红。 - 夹具慢响应语义收窄为「第一次 thread/name/set 之前」生效,避免短 预算用例卡在写入后的校验 read 上。 Co-Authored-By: Claude Code <[email protected]>
复审 P2:两个元数据轮询 catch 里用 Date.now() >= deadline 判尾窗降级, 但 thread/read 的超时定时器由单调时钟调度、Date.now 是量化墙钟,繁忙时 catch 可能在 deadline 前 1ms 读到墙钟,超时错误照样穿透——正是本 PR 要消掉的形状,新加慢响应用例在负载下也会红。 改为识别「这次是不是我自己这条 thread/read 的客户端预算超时」: - 新增 CodexAppRequestTimeoutError,withTimeout 支持 onTimeout 注入, readThreadMetadata 的 thread/read 超时改抛该类型; - 仅当该次请求拿走整段剩余预算(未被 2000ms cap 截断)且错误是自身 thread/read 预算超时才降级;中部窗口超时、not-loaded、尾窗非超时 错误行为不变; - 补三条用例:preview/updatedAfter 各一条把 Date.now 钉在 deadline-1 仍要降级(真实 setTimeout 触发,不依赖墙钟;判据改回墙钟必红), 一条尾窗非超时 -32600 错误仍穿透(守卫放宽成吞一切错误的变异)。 Co-Authored-By: Claude Code <[email protected]>
复审第四枪变异发现 exhaustsBudget 没有行为守卫:删掉该谓词后既有 用例全绿,但被 2000ms cap 截断的中窗客户端超时会被误当成预算耗尽 静默降级(真 wedged app-server 在等待窗口中部就提前写兜底标题)。 补 preview / updatedAfter 两条用例:慢响应 3000ms > 2000ms cap、 总预算 10s,断言抛 /timed out after 2000ms/ 且不发 thread/name/set; 去掉 exhaustsBudget 的变异下两条均红。 Co-Authored-By: Claude Code <[email protected]>
|
🚀 Released in v3.51.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.
问题
master CI 的
test (1/3)偶发红(run 40059429448 等):CodexAppServerProbe.waitForThreadPreview(src/services/codex-app-threads.ts)的轮询把「剩余预算」Math.min(remaining, 2000)当作thread/read的客户端超时;但withTimeout超时产生的是普通超时错误,不是isThreadNotLoadedError认识的 -32600「thread not loaded」,旧 catch 直接throw err穿透整个轮询。机器繁忙、某次迭代进入循环时剩余预算只剩约 1ms 时,该请求必然在 deadline 处超时并炸出调用方——setCodexAppThreadName的兜底标题因此根本不写入。修复(与两处孪生实现对齐)
waitForThreadPreview的 catch 改为先判Date.now() >= deadline:预算耗尽(含客户端超时)一律按「预览不可用」返回 undefined,让调用方继续写兜底标题;deadline 之前只有 not-loaded 容错保留,其余真实错误照常抛。这与同类方法waitForThreadUpdatedAfter的 catch 顺序逐字一致。codex-rpc-engine.ts里既有的MIN_POLL_REQUEST_BUDGET_MS = 50下限:剩余预算低于 50ms 时不再发出注定超时的尾窗请求,直接返回。waitForThreadUpdatedAfter的循环同步改为同一 floor 判定(旧写法在 remaining ≤ 0 时会发出 0/负超时请求)。影响面:只改 codex app-server 标题同步 probe 的两个轮询等待方法;不动 RPC 核心、worker、适配器。真正的传输错误(如 server 崩溃)在 deadline 之前仍抛出;恰在 deadline 处降级后,后续 thread/name/set 仍会暴露不可达,不会静默吞掉致命故障。
验证
FAKE_CODEX_THREAD_READ_DELAY_MS(假 app-server 前 N 次 thread/read 延迟响应,默认 0 不影响既有用例)。Codex app-server thread/read timed out after 200ms(本地复现的整段耗尽形;CI 的 1ms 是同一穿透路径的尾窗形)。bun test25 pass;原 flaky 用例连跑 5 次稳定;bun run build(tsc + Dashboard + 审计)通过。背景
本 PR 修复的是 master 既有缺陷(相关代码最后修改在 #2129/#2124),不是 #2248 链引入;该链纯文档落地 commit 的 master CI 撞上了这条偶发红。
复审追加(c20fed9af)
复审发现 catch 里
Date.now() >= deadline是 1ms 竞态判据:超时定时器由单调时钟调度、Date.now()是量化墙钟,机器繁忙时 catch 可能在 deadline 前 1ms 读到墙钟,超时错误仍会穿透(与既有慢响应用例在负载下变红同一形状)。已改为识别「这次是不是自己这条 thread/read 拿走整段剩余预算后的客户端超时」(新增CodexAppRequestTimeoutError+withTimeout的onTimeout注入;仅 exhaustsBudget 的自身 read 超时才降级,中部窗口超时/not-loaded/尾窗非超时错误行为不变),并补三条用例:preview、updatedAfter 各一条把Date.now钉在 deadline 前 1ms、由真实定时器触发超时仍须降级(判据改回墙钟时两条均红),一条尾窗非超时 -32600 错误仍穿透(放宽成吞一切错误的变异时红)。复审追加 2(c867237b2)
复审第四枪变异发现
exhaustsBudget谓词本身缺行为守卫:删掉它后既有用例全绿,但被 2000ms cap 截断的「中窗」客户端超时会被误判为预算耗尽而静默降级(真 wedged app-server 在等待窗口中部就提前写兜底标题)。补 preview / updatedAfter 两条用例(慢响应 3000ms > 2000ms cap、总预算 10s,断言抛timed out after 2000ms且不发thread/name/set);去掉exhaustsBudget的变异下两条均红,32 项全绿。🤖 Generated with Claude Code