Skip to content

Recover an interrupted Turn when the original worker lease has been replaced - #9304

Merged
loopx-agent merged 2 commits into
mainfrom
codex/turn-recovery-readback-20261123
Nov 23, 2026
Merged

loopx-agent merged 2 commits into
mainfrom
codex/turn-recovery-readback-20261123

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Recovery behavior

Retrying a failed writeback with the original Turn ID could return the same receipt identity conflict on every attempt, even though the registered worker could already preview an administrative closeout. The prior-Turn recovery scan excluded the Turn being retried.

The guard now asks the existing settlement owner to inspect the original Turn when its prepared lease may have changed. Earlier debts keep their ordering. The owner checks the original receipt, current canonical lease and absence of settlement effects before offering the existing no-debit preview. The preview and commit retain their existing ownership checks.

Verification

  • The regression failed on both File and SQLite on the base revision. Both providers returned the original lease generation conflict.
  • The new CLI regression covers explicit and inferred Todo binding, previews the closeout, commits it and replays it. It checks the original receipt bytes and verifies that the Todo stays open without a quota debit.
  • At f15d38f8896c, 63 focused tests and all 17 standard premerge checks passed. The first patch exceeded the decision-function complexity limit. This revision isolates the receipt comparison and passes the original limit.
  • Built and installed the Core wheel into an isolated environment. The public console and packaged dispatcher passed on both File and SQLite (four cases), including preview, commit, replay and byte-for-byte admission readback.
  • The existing clock fence also rejected an ambiguous SQLite replacement acquired in the same recorded second as the admission. The lease timestamp had whole-second precision and the receipt had fractional precision. Using a later verifiable lease in the isolated fixture closed the original Turn with no debit; replay preserved the original receipt. Automatic handling of that clock ambiguity remains open.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

正在恢复一次已准入工作、后来由系统换发执行租约的 CLI 或 Codex App 操作者。 基线的 prior-Turn 检查跳过正在重试的回合。操作者沿原回合重试时仍遇到原 lease identity conflict,无法通过该重试发现可执行的收尾路径。 在原回合重试中发现已存在的无扣额收尾,保留原回执、Todo 状态和 lease 权限。

File 和 SQLite 上同一原回合丢失 prepared lease generation,由同一 Agent 获得新租约。使用原 Turn ID 重试,Todo ID 分别显式给出和从回执推断。 基线返回 heartbeat_receipt_identity_conflict。候选在通用 CLI 与 Codex App 两个 guard 入口均返回原 Turn 的 execution_loss_closeout 预览。已验证提交一次、再次执行给出幂等回执、Todo 保持开放且无扣额。

原 generation 保持,或原回合早已 settled,或替换 lease 属于同 Goal 的另一 Agent。 必须区分普通继续、原回合已结束和需要当前 control writer 的无扣额收尾。 同 generation 两边保留普通继续,已结算回合两边继续 skip。另一 Agent 获得 lease 时,候选进入 control writer 等待,实际 closeout 的外部适用性仍由旧 owner 拒绝。 实际验证的是 File/SQLite 的两种 quota guard 配置和收尾回读。SourceSession 精确根的直接 generic guard 在两边均遇到原有 collection error。已有精确根收尾本身受回归套件覆盖。

改动思路 / Approach

Python 从已绑定的原回执和当前准备信息决定是否附加查询。TypeScript settlement owner 用原事实和 canonical lease 核实,仅在旧路径应收尾时重用 recovery plan。 保留已有 prior debt 扫描与收尾 owner,仅在发现原准备代次可能丢失时把同一回合加入查询。校验和提交继续走已有操作。

具体改动 / Changes

关键代码讲解

评审头 f15d38f,合并基线 3070de3。5 个文件,+83/−3。 依据 Original prepared generation replaced 和 No-debit recovery and current writer proof 核对现有入口。 仓库规范 原有收尾 owner

  • _prepared_execution_needs_readback。按原 OPEN 阶段、绑定 Todo 与 lease epoch 判定是否要查询。 代码
  • _prior_closeout_preflight。在现有 source admission 内向 typed owner 发只读查询。 代码
  • preflightPriorHostTurnCloseoutForOwner。先查旧债,然后只在当前候选通过 lost-generation 证明时提供原回合的恢复计划。 代码
  • observeFencedExecution。从 canonical lease 验证原代次已被替换,再判断当前控制写入者。 代码

对主干的风险 / Risks

语义与 CI 对齐

定向 205 个 TS 测试通过。两组真实 provider 各复跑 5 种状态、4 种 guard 参数组合。 另有候选 47 项和基线 45 项 Python 收尾、恢复准入回归通过。Quick premerge 的 6 项直接和 4 项选中检查通过。 这里验证到 CLI 的 Codex App guard 路由。正式安装的桌面执行体验和独立的 SourceSession guard 待另外资格确认。

我的整体评价 / Verdict

同意此提交的代码改动。租约不同代时仍先预览,再由已验证的当前控制写入者收尾。普通工作与消费 continue 仍走自己的前置条件。 依同一原回执重试可读到唯一收尾,新回合仍使用普通工作入口。

English verdict: APPROVE — the original Turn can discover the existing no-debit closeout after lease replacement without widening delivery or writer authority. Exact head f15d38f.

@BigDataDZ BigDataDZ left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

独立评审(native Windows 环境)——APPROVE

独立核对 head:f15d38f88(refactor(quota): isolate the prepared lease readback decision)。未沿用既有评审结论;本地真实 Windows 全量执行本 PR 的测试文件:

  • tests/control_plane/test_execution_loss_closeout_cli.py → 15 passed, 4 skipped。4 个 skip 均为 requires directory symlink privileges 的既有环境条件,不涉及本 PR 行为面;新增的 test_original_turn_reentry_projects_execution_loss_without_repeating_work 在 file/sqlite 双 provider 下均通过。

代码审查结论:

  1. 自阻塞守卫正确:currentTurn 候选仅在 executionLoss 成立时进入 closeout 指令(if (currentTurn && !executionLoss) continue),且 missingReceipts === null 时 currentTurn 直接跳过——重试者不会因扫描到自己而再次阻塞,也不会为未经证明的丢失发出无谓指令。
  2. 既有债务优先序保持:bound.candidates 追加在 prior 扫描结果之后,persisted newest-first 顺序未被扰动;turnsValidated 合并计数保留了预算语义。
  3. 触发条件收敛:_prepared_execution_needs_readback 仅在 OPEN 回放阶段 + prepared lease 存在 + 当前投影与回执 epoch 不一致时才请求 readback,普通重试路径不增加额外 IO。

一个非阻塞观察(性能层面,不要求本 PR 处理):prepared_lease_epoch 与 execution_preparation.lease_epoch 的相等比较依赖两侧字段类型一致;若历史投影一侧为字符串一侧为数值,将恒不相等并使每次 OPEN 阶段重试都请求一次 readback。当前两侧同源产出类型一致,故仅作记录。

文档双语更新与行为一致。

@loopx-agent
loopx-agent merged commit 92e23df into main Nov 23, 2026
44 of 52 checks passed
@loopx-agent
loopx-agent deleted the codex/turn-recovery-readback-20261123 branch November 23, 2026 14:23
@BigDataDZ

Copy link
Copy Markdown
Contributor

补充说明:我那票批准的范围

我的 APPROVED(2026-11-23 13:23 UTC)依据两件事:通读了全量 diff;在 native Windows 上运行了本 PR 的测试文件 tests/control_plane/test_execution_loss_closeout_cli.py(15 passed / 4 skipped)。评审里写的就是这些。

但有一点我批准前没有检查,也没有写明:该 head(f15d38f88)上的 Python 测试套件当时尚未跑完。 Python Tests run 45126581391 的 6 个 test-shard 从 08:35 UTC 起一直没有完成,在本 PR 合并(14:23:09 UTC)6 秒后被取消。随后的 pytest 与 merge-gate failure 出现在取消之后,此前没有任何分片跑完,所以它们反映的是运行未完成,而不是测试断言失败。

合并后我试着确认包含本次改动的完整套件是否在别处跑完:合并提交 92e23df56 的 CI 被后续提交取代,main 上最近的 Python Tests 运行也几乎全部是 cancelled,我没有找到已完成的运行。

就我验证过的范围,行为与 PR 描述一致,我没有发现改动本身有问题。这条说明只是把批准的依据和缺口讲清楚。如果流程上需要,建议在包含 92e23df56 的 main 上补跑一次完整套件。

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