Skip to content

fix(codex): 为App容量失败接入有限续跑和持久结算 - #2473

Merged
deepcoldy merged 13 commits into
deepcoldy:masterfrom
uestcwangci:fix/codex-app-capacity-recovery-20261028
Oct 30, 2026
Merged

deepcoldy merged 13 commits into
deepcoldy:masterfrom
uestcwangci:fix/codex-app-capacity-recovery-20261028

Conversation

@uestcwangci

@uestcwangci uestcwangci commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex App 原生容量失败原先以普通 final 文本结算为成功,导致任务结束后必须手动发送「继续」。现在将结构化失败通过签名 final、IPC、持久 terminal 与结束事件贯通,并接入已有 codexCapacityRecovery 开关。默认关闭;开启后等待15秒、45秒,最多续跑两次,沿用原线程/checkpoint,不重放原任务。普通503、限流、鉴权、答复里的错误文字及未知传输结果不触发;adopt、HTTP、会议接收会话排除。

恢复从原逻辑轮冻结的应用/真人证明准备身份,缺证明即停止;新消息、停止或配置关闭在backoff和异步准备期间均取消。standalone异步答复后续轮尚未纳入普通IM容量恢复,不声称所有异步容量失败都会重试。

一致性与异常修复:

  • ledger、ACK高水位与pending terminal收据同次sessions文件替换保存;首步写失败回滚,投影失败保留收据,启动核对并恢复,避免签名final已提交但worker在额外IPC前退出造成失败静默。
  • HTTP steer组真实final失败会传给全部成员:async成员记失败、wait成员拒绝,不写成功记录。canonical与bounded-history steered completion均保留失败分类。
  • 原生 failed terminal缺error对象时归为通用失败,避免JSON.stringify(undefined)后toLowerCase抛错导致runner退出;覆盖单轮和steer组。prepare/enqueue身份负例保留。
  • 普通merge同步master 651a7d3,唯一冲突是runner import,保留容量分类与主干进程证明两者,没有rebase/force-push。
  • 修复CI既有Pi启动用例的夹具时序:从固定6秒输出改为观测阶段驱动startup/running两次paint;worker sampler启动后才画首屏,验证启动假idle被拒后才推进真实turn。没有改Pi生产逻辑、跳过用例或放宽断言。

验证:

  • 当前合并树完整 bun run build通过;相关5文件118项通过,原生runner完整113/113通过,覆盖容量单轮/steer两路径、无error单轮/steer、原生引擎空闲恢复及签名协议。
  • Pi完整Bun1.4.3文件16/16通过(223秒);Node完整文件16/16通过(220秒),目标用例限制2核同样通过。隔离副本移除启动证据守卫后新分阶段测试失败,仍能捕获真实提前ready回归。
  • 之前容量实现的9文件638项、真实时序19探针与15守卫突变、持久重放和身份负例证据保留于提交历史。覆盖人工取消、半写恢复、周期与等待交叠。
  • 新head 36930a482已普通push;本地验证已完成,远端CI首跑尚未完成(build已绿,其余运行中)。未自动合并、打tag或发布。

共享普通轮协调器仅新增可选App收据,无收据CLI保持原行为。runner各自解释codex-app/minimax协议,其他CLI不变;进程/PTY控制与卡片布局不变,无环境专用放行。Linux本地验证不等同macOS/Windows实机验收,未主动制造真实模型容量故障。之前本机版本只代表当时交付,不能据此认为最新head已部署。

DeepCold review and others added 2 commits October 29, 2026 05:30
…ity-recovery-20261028

冲突解决(仅并集,无静默取舍):
- src/core/worker-pool.ts:保留本 PR 的三条恢复 import 与 master deepcoldy#2442 的 deployment-continuation import
- test/codex-app-runner.integration.test.ts:保留本 PR capacity-error 用例,并纳入 master 新增的 live-steer 变体
- test/helpers/codex-app-capacity-harness.ts:补 deepcoldy#2442 后 sendWorkerSessionInput 闭包引用的 deploymentContinuationAuthority/cancelDeploymentContinuation/updateDeploymentContinuation 空桩

Co-Authored-By: Claude Code <[email protected]>
settleSteeredCompletion(canonical)与 reconcileSteeredGroupFromHistory
(非 canonical 历史对账)两条组 settle 路径此前不设置 turn.failureCode,
finalizeAcceptedGroup 的真实 final 因而不带 errorCode:worker 不发
turnFailed,合并组被当成功结算,parked 的 http_async/http_wait 早期
成员也随真实 final 被记为 completed。两处与单轮路径一样调用
codexAppTurnFailureCode 分类;新增 fixture 行为 steer-capacity /
steer-capacity-history 的真 runner 集成用例覆盖两条路径,摘掉任一行
修复只咬对应那条用例(vitest 与 bun 双引擎均验证)。

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner

复审(pi)发现 1 个 P2,已在本分支追加提交修复,同步说明如下。

P2:steer 合并组里的原生容量失败丢失结构化失败码,会被当成功结算

  • 单轮路径 completeActiveTurnFromNative 已设置 turn.failureCode,但组模式的两条 settle 路径都漏了:
    • settleSteeredCompletion(canonical 完成)
    • reconcileSteeredGroupFromHistory(非 canonical,走 bounded-history 对账)
  • 后果:合并组真实 final 不带 errorCode → worker 不发 turnFailed → 真实 final 失败时,fanOutSteerGroupFinal 走成功分支,parked 的 http_async 成员被 recordCompleted 记为完成、http_wait 成员 resolve 成错误文本,Lark 侧终态为 completed。这与文档中「合并执行的早期 HTTP 成员随真实 final 一起失败」不一致。

修复(commit 6941317):两条 settle 路径各补一行 turn.failureCode = codexAppTurnFailureCode(nativeTurn / matched),与单轮路径同一分类(仅原生 status:failed + ServerOverloaded 识别为容量码,其它为 codex_app_turn_failed,答复中的错误文字不分类)。

测试:新增 fixture 行为 steer-capacity(canonical)与 steer-capacity-history(非 canonical + history 匹配),新增的真 runner 集成用例断言真实 final 精确带 errorCode: codex_capacity_exceeded、superseded 成员不带码。摘掉任一行修复只有对应的那一条用例变红(vitest 与 bun 双引擎均验证);codex-app-runner.integration.test.ts 110/110 全绿,容量恢复 27/27 双引擎全绿,bun run build 通过。

另外按维护流程用 merge 同步了最新 master(commit 5fa2e4c,共 12 个提交;两处冲突仅 import 与一处测试枚举的并集,无静默取舍)。

这是自动双审流程的增量修改,最终结论以维护者复审为准。

…veryCli 桩

deepcoldy#2473 把 Ctrl+C/ESC 取消恢复的 CLI 判定改为 codexCapacityRecoveryCli(...),
deepcoldy#2442 的 daemon-deployment-continuation.test 用 new Function(with(scope))
抽取 sendWorkerSessionInput 裸闭包执行,合并后该自由变量在其自建作用域
缺失(ReferenceError),3 个 term_action 用例在 vitest 与 bun 双引擎红。
从 codex-app-failure 源模块导入真实函数补桩,不手抄判定;生产代码无改动
(合并树其余 523 分片用例与 1/3/4 分片全绿,本文件 30/30 双引擎)。

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner

增量同步(CI 已绿):

  • 6941317 的首跑 CI 有 3 项红,根因不是生产代码:test/daemon-deployment-continuation.test.ts(fix(recovery): 发布中断后按原身份续跑普通 Codex 任务 #2442)用 new Function('with(scope)') 抽取 sendWorkerSessionInput 裸闭包执行,本 PR 把其中 Ctrl+C/ESC 的 CLI 判定改为 codexCapacityRecoveryCli(...) 后,该测试自建作用域缺少这个自由变量(ReferenceError),3 个 term_action 用例在 vitest 与 bun 双引擎红。
  • 修复提交 b49296c:该测试从 codex-app-failure 源模块导入真实 codexCapacityRecoveryCli 补桩,生产代码零改动;全仓 grep 确认只有这一个文件以抽裸闭包方式加载该函数,其余均为 mock 或真实 import。
  • 当前 head b49296c 的 CI 首跑 run 40778722148 全绿(build / bun-binary 三平台 / network-boundary / bun-test 34m31s / test 4 分片,pull_request 事件,11 项 success)。本地 daemon-deployment-continuation 30/30、codex-app-runner.integration 110/110、容量恢复 27/27 在 vitest 与 bun 双引擎均通过。

仍以维护者在当前 head 的复审为准。

DeepCold review and others added 3 commits October 29, 2026 13:11
codexAppTurnFailureCode 在已判 status==='failed' 后无条件下调
isCodexCapacityError(turn.error);turn/completed 为 failed 但不带
error 字段(协议变体)时 error 为 undefined,而 JSON.stringify(undefined)
返回 undefined(非字符串),codexTaskFailureCode 的 serialized.toLowerCase()
抛 TypeError。该异常在 AppServerClient 的同步通知分发上无人接,整个
runner 进程 exit 1,单轮(completeActiveTurnFromNative)与组
(settleSteeredCompletion)路径都崩,本轮会话退成 ambiguous 恢复。

入口先判 !turn.error 直接返回 codex_app_turn_failed(与
codex-rpc-engine.ts:909 的 turn.error ? ... : '' 同一写法);error:null
本就不崩、行为不变,容量错误在 error 存在时仍照常识别。

回归(真 runner + 签名控制通道):fixture 增 failed-no-error(单轮)与
steer-failed-no-error(组)行为,断言产出 final、errorCode 为通用码、
进程存活;分类器补 missing/null/undefined 直接单测。修复前两集成用例均
exit 1 + TypeError(红),修复后 vitest 与 bun 双引擎绿;摘守卫三档
(集成两例+单测)都咬红。

Co-Authored-By: Claude Code <[email protected]>
prepare(await 身份发布前 caller 缺失即抛)与 enqueue(异步 prepare
窗口内证明被移除的纵深闸门)此前各摘掉后测试仍绿。新增两条经真实 attach
的假时钟用例:缺冻结证明时 prepare 在身份发布前拒绝、不派发;证明在
异步 prepare 期间消失时 enqueue 返回 false 落 attention_required。
摘掉任一接线只咬对应用例(变异双引擎验证)。

Co-Authored-By: Claude Code <[email protected]>
…ity-recovery-20261028

二次同步 master(875bb2dfc..d6e6cb8,含 deepcoldy#2468/deepcoldy#2474/deepcoldy#2481/deepcoldy#2491/deepcoldy#2493/deepcoldy#2499 等)。
仅 src/core/worker-pool.ts 与本分支有交集,git 自动合并干净、无冲突标记;
已重新 build 并跑 codex-app-runner.integration / 容量恢复两文件 /
codex-app-engine-identity / worker-codex-app-engine-root /
daemon-deployment-continuation / ordinary-turn-recovery 共 261 项全绿。

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy

Copy link
Copy Markdown
Owner

增量(pi 第二轮 P2,crash 级):

问题:原生 turn/completed 为 status:'failed' 但不带 error 字段时,codexAppTurnFailureCode 无条件调用 isCodexCapacityError(undefined);JSON.stringify(undefined) 返回 undefined(不是字符串),codexTaskFailureCode 的 serialized.toLowerCase() 抛 TypeError。该异常在 AppServerClient 同步通知分发上无人接,整个 runner exit 1,单轮与 steer 组路径都崩,会话退成 ambiguous 恢复。error: null 本就不崩(stringify(null)==='null')。

修复 edf6a4a:分类器入口先判 if (!turn.error) return 'codex_app_turn_failed',与 codex-rpc-engine.ts:909 的 turn.error ? ... : '' 同写法;容量错误在 error 存在时仍正常识别,生产零其他改动。

回归与变异:fixture 新增 failed-no-error(单轮)与 steer-failed-no-error(组),真 runner + 签名通道断言 final 产出、errorCode 为通用码、进程存活——修前两例均 exit 1 + TypeError,修后绿;分类器补 missing/null/undefined 单测。摘掉守卫后集成两例 + 单测三档都咬红(vitest 与 bun 双引擎)。

P3:另提交 b708fdf 补上 prepare/enqueue 两处身份接线的负向探针(此前摘掉仍绿,现各只咬对应用例)。pi 提的另一处 committed-seq 短路 reconcile 探针位于不可低成本抽取的大 IPC 闭包内,留 follow-up;reportIdentityConflict 经 pi 确认与本次无关,亦留 follow-up。

另 merge 同步了最新 master(3ad0ef807,875bb2dfc..d6e6cb8,含 #2468/#2474/#2481/#2491/#2493/#2499;仅 worker-pool 交集,git 自动合并干净),合并树 261 项相关测试全绿。仍以维护者在当前 head 的复审为准。

monkey.wc and others added 6 commits October 29, 2026 19:47
…ity-recovery-2473-final

在作者最新 head 36930a4 上同步 master 至 0345cc5(其 merge base
651a7d3 之后的 4 个提交:deepcoldy#2526/deepcoldy#2513/deepcoldy#2523/deepcoldy#2525)。唯一冲突在
worker-argv-reaction-status 首轮 re-arm 用例的启动等待段:作者已在
deepcoldy#2513 合入前用信号驱动 fixture(paint-phase 文件按观测阶段推进,消除
固定 6s 墙钟,即复审建议的根治方向)重写了该用例,merge 已把 fake
定义取为信号驱动版,故等待段配套取作者版(等 projected-working 采样器
再写 startup 信号);deepcoldy#2513 配 setTimeout fake 的 fresh-empty 等待与
信号 fake 不兼容、不采用,其启动保证被作者版更强的等待覆盖。
codex-app-runner.integration 自动合并,PR 容量用例与 deepcoldy#2523/deepcoldy#2526
改动并存。Pi 用例双引擎 + 2 核 isolate 重载 3 次绿、全文件 16/16;
codex 集成/容量/engine/deployment 共 210 项 vitest 绿。

Co-Authored-By: Claude Code <[email protected]>
merge 作者信号驱动版 Pi 夹具时,把该用例(re-arms a startup-window
false idle)原本由 deepcoldy#2513 单独给的 boot 等待预算丢成了 waitForLog 默认
10s。信号 fake 的锚点(projected working,约 3.0–3.7s)比 deepcoldy#2513 的
fresh-empty 锚点(约 1.1s)晚约 2s,净余量反而更薄;2 核重载实测 boot
涨到 4.9–5.1s、800ms 预算探针即超时,是无保护余量的等待。仅这一处
(deepcoldy#2513 当时也只给这一个用例传参)补 WORKER_BOOT_TIMEOUT_MS,另外两处
projected-working 等待在 master 本就走默认预算,不改动。零生产影响。

Co-Authored-By: Claude Code <[email protected]>
…ity-recovery-2473-final

四次同步 master(0345cc5f1..eb43116,14 提交,含 deepcoldy#2514/deepcoldy#2534/deepcoldy#2535/deepcoldy#2541/
deepcoldy#2467/deepcoldy#2550/deepcoldy#2553/deepcoldy#2554/deepcoldy#2557/deepcoldy#2561/deepcoldy#2562 等)。与本 PR 仅 worker-pool.ts /
worker.ts 文件交集,git 自动合并干净、无冲突标记;PR 关键接线(codexApp
TurnFailureCode 四处、!turn.error 守卫、pool 恢复落账、worker 签名 final
失败字段、Pi boot 20s 预算)逐处 grep 仍在原位。合并树 build 过、
codex 集成/容量/engine/deployment/schedule 共 276 项 vitest 绿、
容量+Pi argv 46 项 bun 绿。

Co-Authored-By: Claude Code <[email protected]>
…ity-recovery-2473-final

五次同步 master(eb4311607..4896715,9 提交,含 deepcoldy#2563 真机沙盒跑道/deepcoldy#2547 沙盒
四修/deepcoldy#2577 herdr 认窗格/deepcoldy#2522 失效终端入口/deepcoldy#2558 白名单沙盒/deepcoldy#2552 会话控制
页精简/deepcoldy#2570 自动更新跳过/deepcoldy#2537 沙盒文档/deepcoldy#2580 Pi 恢复复制)。与本 PR 仅
worker-pool.ts / worker.ts 文件交集(deepcoldy#2547/deepcoldy#2522/deepcoldy#2558),git 自动合并干净、
无冲突标记;PR 关键接线(codexAppTurnFailureCode 四处、!turn.error 守卫、
pool 恢复落账、worker 签名 final 失败字段、Pi boot 20s 预算)逐处 grep 仍在
原位。合并树 build 过、codex 集成/容量/engine/deployment 243 项 vitest 绿、
容量 30 + Pi argv 1 项 bun 绿。

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy
deepcoldy merged commit 23f2c22 into deepcoldy:master Oct 30, 2026
11 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner

已合并 ✅ 感谢 @uestcwangci(Wang Chad / monkey.wc)的实现与多轮配合,包括在评审过程中独立修复 Pi 启动夹具竞态(信号驱动版比临时调超时更彻底)和同步主干。

最终落地:squash 为 23f2c22 fix(codex): 为App容量失败接入有限续跑和持久结算 (#2473),保留作者署名。合入时 master 实际基点比评审预验树新了一个并行合入的 #2568(antigravity),已核验落地树 == merge-tree(实际基点, PR head) 逐字节同一、两侧改动正交共存、build/tsc 与相关测试全绿。

评审中共同补上的内容(均经真 runner + 签名控制通道与双引擎变异验证):

  • steer 合并组(canonical / bounded-history)两条 settle 路径补 turn.failureCode;
  • 原生 status:'failed' 缺 error 对象时按通用失败码结算,不再让未捕获 TypeError 杀死 runner;
  • HTTP steer 真实失败(含 parked 成员)按失败结算而非成功;
  • 原子化「签名 final ledger + ACK 高水位 + 待恢复 terminal 收据」,替换 worker 崩溃后的人工继续;
  • 续跑身份只信任验收时冻结的真人证明;
  • Pi 首轮 boot 等待恢复 20s 预算。

遗留 follow-up(非阻断,不影响本次):

  1. reportIdentityConflict 走自造错误文案、不经 turn.failureCode,其失败终态的结构化码可另行评估。
  2. worker-pool 已提交 seq 短路分支的 reconcileOrdinaryTurnRecoveryTerminalReceipt 缺直接负向探针(位于不便抽取 seam 的大型 IPC 闭包内)。

再次感谢,欢迎继续贡献。

@github-actions

Copy link
Copy Markdown

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

这次运行覆盖 1f1ddf8…313e01661(4 个提交),同批合入的还有 #2568 #2619 #2585,失败不一定由本 PR 引起。

用例 跑道 状态 失败信息
Gemini basic bot flow feishu-core-clis failed waitFor timeout: Based on the screenshot, the main content area displays a conversation titled "话题" (Topic) from "申晗和Gemini的会话".
Codex DM chat mode replies inline and keeps one session feishu-core-dm-modes-codex failed No reply matching /已切换私聊会话模式为:new-topic/ after "/reply-mode new-topic" within 60000ms

deepcoldy pushed a commit that referenced this pull request Oct 31, 2026
同步最新 master(#2585 回复页脚控制台入口、#2605 TraeX 额度池顺序续跑、
#2630、#2619、#2473、#2568 共 6 提交)。与本 PR 仅在四个 i18n/页面文件
交集(bot-defaults-page.tsx、dashboard/web/i18n.ts、i18n zh/en),均为
各自新增不同键的同段并存,git 自动合并无冲突:本 PR 的 sharedSandbox* /
sandbox_advice.* 全套与 master 的 replyFooter / autoModelQuota* 键共存。

Co-Authored-By: Claude Code <[email protected]>
@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.

2 participants