Skip to content

fix(codex): 线程改名的等待预算与单次请求超时拆成两个参数 - #2593

Merged
deepcoldy merged 2 commits into
masterfrom
fix/codex-thread-name-rpc-timeout
Oct 30, 2026
Merged

deepcoldy merged 2 commits into
masterfrom
fix/codex-thread-name-rpc-timeout

Conversation

@deepcoldy

@deepcoldy deepcoldy commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Closes #2454。

问题

setCodexAppThreadName 的 timeoutMs 一个值管两件事:

  • 等待首条预览(waitForExistingPreview)/ 等 updatedAt 越过基线(waitForUpdatedAfter)的总预算,用完就降级、照样写标题,这是预期结果;
  • 之后 thread/name/set 和校验用 thread/read 的单次请求超时,超了就是失败。

测试为了让等待阶段耗尽,传 40–200ms 的 timeoutMs,name/set 也就只有这么点时间,繁忙的 CI runner 上本机往返一超就红(#2454:run 40554189061、run 40891465999)。#2525 已经在测试侧把出事的两条用例放大到秒级,但「预算低于 50ms 轮询下限」那条必须传 40ms,只改测试修不掉。

改动

新增选项 waitBudgetMs,与 timeoutMs 分工:

参数 管什么 默认值
timeoutMs 单次请求超时:thread/name/set、校验 thread/read(以及 initializeTimeoutMs 的默认值,同原来) 7000ms(不变)
waitBudgetMs(新) 等预览 / 等 updatedAt 的总预算,耗尽即降级写标题 等于 timeoutMs

waitForThreadPreview / waitForThreadUpdatedAfter 内部逻辑不变(每次 read 取 min(剩余预算, 2000ms),低于 50ms 下限就停)。

对老用户无影响的依据

  • 默认值保持原语义:不传 waitBudgetMs 时它等于 timeoutMs,两段用的值和改前完全相同;timeoutMs 的默认 7000ms 也没变。
  • 生产唯一调用方没改:src/worker.ts 只传 timeoutMs: 10_000,所以等待预算和请求超时仍都是 10 秒,与改前逐值相同。worker 内部还有一条不经过这个函数的路径(engine.waitForThreadPreview(10_000) 等),本 PR 不涉及。
  • 这是内部服务函数,不是配置项或命令,没有用户可见的入口。
  • 有一条用例专门守这个默认值:只传 timeoutMs: 1_000 时,等待阶段最多发几次 read(默认值若不跟随 timeoutMs,次数会多得多)。

测试改动

  • 原来靠很小的 timeoutMs 压等待预算的 6 条用例(预览始终不可用、慢读耗尽预览预算、低于轮询下限、慢读耗尽 updatedAt 预算、两条钉住墙钟的尾窗用例),以及「尾窗里的非超时错误要穿透」那条,都改为 waitBudgetMs 压预算、timeoutMs: 20_000。被测关系都不变;test(codex): 慢 thread/read 兜底标题用例放大预算,name/set 不再被 200ms RPC 超时掐断 #2525 为绕开这个问题放大到秒级的两条,改回 200ms 预算 / 300ms 慢读,跑得更快。
  • 新增 2 条:
    • 等待预算 200ms 用完后,name/set 和写后的校验 read 仍有完整的请求超时:假 app-server 把这两次回复都拖慢 300ms,比等待预算还长,标题照样写入;
    • 不传 waitBudgetMs 时等待预算等于 timeoutMs(见上)。
  • 假 app-server 新增 FAKE_CODEX_NAME_SET_DELAY_MS 和 FAKE_CODEX_VERIFY_READ_DELAY_MS,分别拖慢 name/set 和写后的校验 read,默认都是 0,不影响其他用例。

验证

  • 整文件确定性对照:用 FAKE_CODEX_NAME_SET_DELAY_MS=250 把每次 name/set 拖慢 250ms,模拟繁忙 runner:
    • master 的实现和用例:4 条失败(预览始终不可用、低于轮询下限、两条钉住墙钟的尾窗用例),全是 name/set 被小预算掐断;
    • 本 PR:34 条全过。
  • 变异(isolate-run,逐个改、跑、还原)4/4 被捕获:
    • 忽略 waitBudgetMs;
    • name/set 改用等待预算作为超时;
    • 写后的校验 read 改用等待预算作为超时(交叉复审补的 P3);
    • 默认值改成 7000 而不是跟随 timeoutMs。
  • bun run build 通过;相关 10 个文件 705 例 vitest 全绿;本文件 bun test --timeout=180000(全新 HOME/TMPDIR)34 例全绿。

🤖 Generated with Claude Code

setCodexAppThreadName 的 timeoutMs 同时是等待首条预览 / updatedAt 的总预算和之后
thread/name/set、校验 read 的单次请求超时;测试为压短等待传 40–200ms,name/set 也
只剩这么点时间,繁忙 runner 上偶发超时(#2454)。新增 waitBudgetMs 只管等待,默认
等于 timeoutMs;timeoutMs 只管单次请求(默认仍 7000)。生产调用方只传 timeoutMs:
10_000,两项都仍是 10 秒,行为不变。用例改用 waitBudgetMs 压等待,请求超时给足。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@deepcoldy
deepcoldy merged commit 0488dcb into master Oct 30, 2026
15 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner Author

合后核验:落地提交 0488dcb(标题带 #2593、正文为空),落地树与「master 172976d + 审过的 head 6811cb1」逐一相同;#2454 已随合入关闭。

@deepcoldy
deepcoldy deleted the fix/codex-thread-name-rpc-timeout branch October 30, 2026 13:10
This was referenced Oct 30, 2026
@github-actions

Copy link
Copy Markdown

@deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。

这次运行覆盖 89a9cea…22d1c8d0b(20 个提交),同批合入的还有 #2546 #2556 #2589 #2591 #2545 #2538 #2595 #2596 #2597 #2581 #2539 #2598 #2515 #2536 #2575 #2366 #2606 #2544 #2603,失败不一定由本 PR 引起。

用例 跑道 状态 失败信息
Kimi basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, the middle column displays a welcome message "欢迎加入群组" (Welcome to the group) and system notifications about group creation and settings, rather than a list o…
Gemini basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, the main content area displays a topic conversation. I can see messages from "Gemini".
Codex DM chat mode replies inline and keeps one session feishu-core-dm-modes-codex failed Feishu Messenger chat list did not load after 4 attempts (URL: https://acn2e4mfbjx2.feishu.cn/next/messenger/, title: 消息 - 飞书). A login redirect means the saved storage state expired; a skeleton list…

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

🚀 Released in v3.56.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.

test(codex): setCodexAppThreadName 的 timeoutMs 同时约束 preview 等待与 name-set RPC,高负载下假红

1 participant