Skip to content

fix(turn): retain admitted lease generation for Host retries - #9192

Open
cocolord wants to merge 1 commit into
mainfrom
codex/mechanism-recovery-integration-20261121
Open

cocolord wants to merge 1 commit into
mainfrom
codex/mechanism-recovery-integration-20261121

Conversation

@cocolord

@cocolord cocolord commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

A resumed native Turn whose previous Host result failed validation could reclaim its Todo in a new lease generation, replace the old preparation and relaunch the Host. New Host attempts now use the existing TypeScript heartbeat work-requalification rule against the retained preparation. Recovery lease binding runs only during a validated settlement effect, preserving same-generation retries and frozen-result settlement without another Host call.

The bilingual mechanism RFC checkpoint records this caller migration and its remaining acceptance gaps. The adapter reuses the existing quota details/readback path; it adds no generation decision owner or persisted schema.

Validation:

  • The same 12 File/SQLite recovery cases on immutable main@3d15059fef142138a60fc8a03c8394e92879387c produce 10 passes and the two replaced-generation counterexamples. The candidate passes all 12, including same-generation Host retry, task validation refusal, frozen-result completion and interruption after lease retirement.
  • 35 completion tests, 46 surrounding report/receipt/launch/resume/settlement tests, 50 TypeScript owner tests and the configured 17-file kernel Mypy gate pass. A separate two-case File/SQLite probe verifies that fresh admission after an old-Turn refusal completes without changing the original receipt. Replays retain one settlement and frozen-result recovery invokes the Host once.
  • Ruff, semantic vocabulary, maintainability, public-boundary and bilingual RFC checks pass. Standard premerge initially passed 18/19 checks; its missing npm development dependency was installed, and the failed semantic check then passed. Exact-commit quick premerge passes.
  • Scoped Mypy reports the same 54 existing diagnostics on the base and candidate, with no added diagnostics. This remains a qualification limitation; the change does not claim a clean full-tree typecheck.

Installed/native model adoption, other-backend qualification, complete execution cutover and independently measured outcome benefit remain open. This proposal requires maintainer merge authorization.

@cocolord cocolord left a comment

Copy link
Copy Markdown
Member 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 · OpenAI · self_reported

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

动机 / Motivation

未发现阻塞性问题。原生会话在同一个 Turn 中重试失败的 Host 结果。旧实现把重新认领的新租约代次写入旧 Turn 后再次运行 Host;候选拒绝该重跑,保留已验证冻结结果的无模型结算。File/SQLite 上换代 Host 重跑被拒绝,原回执和 Todo 保留;同代续期、冻结结果完成及一次结算继续通过。本 PR 不完成整个机制 RFC,不增加执行框架、持久 schema、capability 激活或模型收益声明。完整 C1/C4/C9 caller 切换、已安装采用、其他后端与独立成果和完整成本验证仍开放。这个修复有具体的重跑与错误结算代价,正反例通过真实 CLI、File/SQLite 和独立验证器复现,不能仅从主干已有的冻结结果成功测试推断该重试安全。

改动思路 / Approach

删除启动前的恢复租约绑定,并把已有原生重试 caller 接入现有 TypeScript 再资格 owner,避免复制 Python 代次规则。本 PR 交付 Host 重试与冻结结果结算的租约边界修复。只删除启动前的 rebind 仍会让重新生成的 launch decision 接受新租约,已有对照证明该更小改动不足;反过来,一律拒绝新 epoch 会破坏已发布的冻结结果恢复。当前方案保留这两类操作的区别:再次运行 Host 是新执行,已验证结果只做尚缺的结算 effect。资格来自原回执与当前 canonical lease,Python 负责运输,TS owner 决定代次是否相容,没有新 store 或需手工维护的状态。

具体改动 / Changes

规范基线为 docs/architecture/rfcs/mechanism-convergence-and-learning-loop-v0.md,spec_revision 为 3d15059fef142138a60fc8a03c8394e92879387c,采用修改前的 §3、§8、§9、§10。criterion_id 3 的身份、租约、Stop 与单次结算要求在此 caller 落地;criterion_id 8 的原 identity/Host/receipt 恢复保留;criterion_id 9 的正常、拒绝、中断和重放路径由对照覆盖;criterion_id 10 的完整切换和可比成本收益仍 deferred,不能用这一源码修复冒充整个 RFC 完成。英文与中文 addition 都只是记录这一边界与剩余资格。

关键代码讲解

current_turn_host_launch_decision(turn_decision.py:448)先保留既有 Goal、选择与工作基线校验,再为 resumed Todo 组装当前 guard facts,并通过 read_heartbeat_settlement 调用 heartbeatWorkRequalification。不同 lease key/epoch 由原 TS owner 拒绝,未获得 new_operation 也不能启动 Host。on_managed_start_admitted(turn_run_once.py:856)删除提前读取与绑定恢复租约的动作,避免待检查的原准备事实先被覆盖。rebind_resumed_settlement_lease(同文件:143)仍由 validated progress/completion callbacks 调用,并缓存 resolver;completion 退役租约后不再次查询 active lease。quota_rollout_details 只为新运输 caller 容忍缺少 quota 子命令标签,现有 quota caller 的值保持原样。以上三处适配器、一个测试文件和两份 RFC 共147新增/32删除,生产部分27新增/8删除;没有新增模块、schema 或公共 CLI。

对主干的风险 / Risks

不可变 base 3d15059fef142138a60fc8a03c8394e92879387c 与本 head 3e06c9edf68cce1727ba6e62151c540d2d146126 使用同一 synthetic hard-lease fixture 和同一 recovery harness。base 的12项有10通过,两个换代 Host 拒绝反例失败;head 的12项全部通过。同代续期重试可重新运行 Host,跨代冻结结果完成仍只运行 Host 一次;验证失败保留原回执,completion 后 refresh 中断可从 retired lease 和原 receipts 完成一次结算。另一个真实 File/SQLite probe 在拒绝旧 Turn 后用重新认领的租约启动 fresh Turn 并完成,两项通过,旧 Turn 的回执与 effects 不变,因此拒绝没有扩大成整个 Todo/Goal 的执行禁令。35 completion、46 surrounding、50 TS owner 测试通过;配置内17个 kernel Python 文件的 mypy gate 通过。严格检查三个 legacy adapters 的54个错误在 base/head 的文件、类型和错误细节多重集相同,没有新增,仍保留为诊断限制。标准 premerge 首次18/19,缺 npm dev dependencies 的语义项补齐后通过;精确提交 quick premerge、bilingual、ruff、semantic vocabulary、maintainability 与 public boundary 均 PASS。未宣称所有 remote CI 完成。

语义与 CI 对齐

复用现有 vocabulary 和 new_operation/replay phase,未增加 Python 代次判断或 capability activation。改变的默认行为已在双语 checkpoint、PR body 和 negative controls 披露;scope 仅是原 resumed Todo/Turn,fresh admission 不受该旧 Turn fence 捕获。没有 automatically loaded prompt、App/Lark presentation、settings editor 或 user-facing capability extension,所以没有新增 UI/安装旅程。模型实际采用、installed 行为、普通其他 backend Turn 和完整成本收益仍 UNVERIFIED;这些不构成本切片已完成的声明。

我的整体评价 / Verdict

对该精确 head 给出 APPROVE 的作者自评结论。交付判定为 justified_increment:当前修复完整地把实际 caller 接回已有 owner,并删除提前 rebind;继续原 C1/C4/C9 migration 与组合资格,不将 parent outcome 标记完成。long_horizon 与 user_experience 均 preserved:正确拒绝后仍有合法续期、冻结结算和 fresh Turn 继续路径,也没有多加配置或确认轮次。visual_review 为 not_applicable,因为 turn_decision.py/turn_run_once.py 没有 rendered App/Lark presentation 改动;changed presentation 的 unverified_scope 为 none。回滚是一份提交,不重写历史 receipts。剩余限制是 live model/installed/其他 backend 资格和既有 legacy type diagnostics;COMMENTED 作者结论不等于 GitHub formal approval,也不授予维护者 merge authority。

English verdict: APPROVE — head 3e06c9e. The retry caller now reuses the original typed lease-generation fence while preserving validated frozen-result settlement and fresh admission. File/SQLite counterfactuals,81 Python tests,50 TS tests and required local gates pass; legacy adapter typing,installed/model qualification and remote CI remain separately scoped limitations.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

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

动机 / Motivation

恢复受管 Turn 的操作者需要在同一条租约代际下重开失败的 Host,并能结算已独立通过验证的原结果。 旧 merge base 可能让换代租约替换原准入并重新启动 Host。 File 和 SQLite 的同代租约续期重试,在当前源头 3e06c9e 和目标主干 00f47ed 单独运行均通过。两版生成的无冲突合并预览两例均在第二次 Host 启动前以 AttributeError 失败,未产生结算;主干新 helper 在额度来源缺省时直接读取 Turn 参数没有的 quota_command。 候选让新 Host 重试复用已有 TypeScript 重资格判断,把冻结结果的租约恢复留给验证后的结算。 范围是原回合的 Host 重试与已验证结果结算。完整 C1/C4/C9 迁移、实际安装和模型采用是后续验收。

改动思路 / Approach

TypeScript 继续拥有租约重资格与效果许可。Python 只传输原准入、当前来源和结算证据。 实际 Host 重试要求原代际,已验证冻结结果按原结算身份恢复。核对现有调用链和当前主干的兼容性。 优先复用同一准入规则。把个别命令参数与工作资格分开,避免 Python 调用路径演化时把合法重试变成异常。

具体改动 / Changes

逐项检查当前头 3e06c9e 和 merge base 3d15059,6 个文件,+147/-32。RETRY-ORIGINAL-GENERATION 的换代拒绝在精确头通过,同代续期在最新主干预览失败。FROZEN-RESULT-SETTLEMENT 继续覆盖已验证原结果、一次结算与重放。 评审依据为 3d15059。 目标规范

关键代码讲解

对主干的风险 / Risks

[P1] 合入当前主干后合法同代 Host 重试中断。 File 和 SQLite 的同代租约续期重试,在当前源头 3e06c9e 和目标主干 00f47ed 单独运行均通过。两版生成的无冲突合并预览两例均在第二次 Host 启动前以 AttributeError 失败,未产生结算;主干新 helper 在额度来源缺省时直接读取 Turn 参数没有的 quota_command。 整合当前主干,在复用 rollout helper 前传入明确的 Turn 来源,或由共享 helper 安全读取缺省子命令。保留现有 TypeScript 决策,并重新验证同代 Host 重试、换代拒绝与原冻结结果结算。 Git 合并干净,运行时仍会拦掉原本合法的重试;无需变更用户输入或后端权限即可出现。

旧 merge base 的相同 12 项出现两次换代后误启动,当前精确头 12 项均通过。只在合并预览补齐 Turn 参数归一化后,同代允许与换代拒绝的四项合计全部通过。冻结结果结算方面,原精确头定向测试覆盖原身份和一次性结算。 当前精确头 Python 81 项和 TypeScript 201 项通过。quick premerge 六项直接和四项所选检查通过。对最新主干的合并预览独立执行 12 项,有两项集成失败。 使用生产 Turn/结算入口、临时 File 与 SQLite,Host 为本地确定性夹具。合并预览只用于验证当前主干集成。安装版、真实模型和其它后端未验证。

我的整体评价 / Verdict

请求修改。TypeScript 继续拥有租约重资格与效果许可。Python 只传输原准入、当前来源和结算证据。 实际 Host 重试要求原代际,已验证冻结结果按原结算身份恢复。核对现有调用链和当前主干的兼容性。 本次合并预览保留了换代拒绝,却让正常续期路径无法启动第二次 Host。 请先完成 Turn 与 quota 公用投影的参数兼容,再按当前主干核对完整恢复矩阵。 没有新的渲染表面,评审覆盖原生 Turn 与结算回执。 使用生产 Turn/结算入口、临时 File 与 SQLite,Host 为本地确定性夹具。合并预览只用于验证当前主干集成。安装版、真实模型和其它后端未验证。

English verdict: REQUEST_CHANGES at 3e06c9e. The exact head fixes replacement-generation replay, but the conflict-free preview into main 00f47ed breaks valid same-generation Host retries on File and SQLite. Normalizing the missing command discriminator restores both valid retries while keeping the replacement refusals.

# A new Host attempt must qualify against the retained preparation,
# just like quota reentry. Frozen-result settlement never launches a
# Host and keeps its separate completion-lease recovery path.
current_details = quota_rollout_details(current, args, todo_id=identity.todo_id)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1] 合入当前主干后合法同代 Host 重试中断。File 和 SQLite 的同代租约续期重试,在当前源头 3e06c9e 和目标主干 00f47ed 单独运行均通过。两版生成的无冲突合并预览两例均在第二次 Host 启动前以 AttributeError 失败,未产生结算;主干新 helper 在额度来源缺省时直接读取 Turn 参数没有的 quota_command。 整合当前主干,在复用 rollout helper 前传入明确的 Turn 来源,或由共享 helper 安全读取缺省子命令。保留现有 TypeScript 决策,并重新验证同代 Host 重试、换代拒绝与原冻结结果结算。

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewer: model_agent · Gemini · Google DeepMind · self_reported

动机 / Motivation

受硬租约(hard_lease)保护的原生会话或 CLI Turn 恢复调用方在 Host 结果校验失败后重新认领 Todo 并重试旧 Turn 时,会遭遇跨代租约覆盖问题。在改动前的基线行为中,调用方在恢复启动前会把新认领的代次 2 租约提前改写进原有 Turn 的准备回执,使旧 Turn 重跑 Host 并错误结算;改动后,跨代重跑 Host 在启动前被直接拒绝并保留原回执,仅同代续期或已验证冻结结果可完成恢复。

换代 Host 重试在调用 Host 前即被拒绝且不写入任何 effect,同代续期重试与已验证冻结结果结算均正常通过并在重放时保持一次性结算。本切片不完成完整 C1/C4/C9 切换,不增加新持久化 schema、顶层模块、CLI 参数或跨后端收益实验。全量 C1/C4/C9 执行切换、正式安装包环境采用、其他后端适配以及独立成本与成果收益实验仍未完成。

改动思路 / Approach

如果不阻止启动前的提前覆盖,仅靠结算阶段事后校验仍会让 Host 被无效重复触发;如果仅删除启动前绑定但不接入再资格校验,重新构造的启动决策仍会放行新代次租约;反之如果一刀切禁止所有跨代恢复,则会破坏已经通过独立校验的冻结结果结算。因此本 PR 将“再次启动 Host 的新工作”与“已验证冻结结果的结算 effect”明确分离:将状态与租约代次相容性裁决收敛在既有的 TypeScript 领域规则 heartbeatWorkRequalification 中,Python 侧仅保留启动传输门禁、仅在已验证结算时绑定恢复租约的 IO 回调及字段兼容投影,不引入重复的代次判断逻辑。当前 PR 边界仅修复恢复重试入口的启动校验、移除启动前租约改写并补齐双后端正反例对照,不扩张到非恢复路径或全量迁移。

flowchart LR
  A["--resume-turn-key --retry-failed-turn"] --> B["on_managed_start_admitted: 仅保留原 preparation 回执"]
  B --> C{"current_turn_host_launch_decision: 调用 TS heartbeatWorkRequalification"}
  C -->|"同代续期 (epoch 不变, version 递增) -> new_operation"| D["允许再次启动 Host"]
  C -->|"换代重认领 (epoch 改变) -> HeartbeatReceiptIdentityConflictError"| E["拒绝重跑 Host;保留原回执与新代租约"]
  D --> F["Host 返回有效结果 -> 进入 writeback / completion_writeback"]
  F --> G["rebind_resumed_settlement_lease: 仅在已验证结算 effect 中绑定恢复租约并完成一次结算"]
Loading

注:以上流程基于精确 head 3e06c9edf68cce1727ba6e62151c540d2d146126 源码梳理(示意结构,非执行回执;未在远端渲染界面预览)。

具体改动 / Changes

  • 规范基线与逐条映射:对照 docs/architecture/rfcs/mechanism-convergence-and-learning-loop-v0.md 在合并基线 3d15059fef142138a60fc8a03c8394e92879387c 的规范原文:
    • RFC-S3-invariants(implemented):保留既有 Goal/Agent/Todo/Turn/effect 身份、租约代次隔离与一次性结算约束,未在 Python 新增决策规则(见 turn_decision.py、turn_run_once.py 与 35 项 completion 测试及 202 项 TS 测试)。
    • RFC-S8-recovery-identity(implemented):挂起/失败恢复保留原 Turn 身份与 preparation 回执,不再通过替换租约掩盖代次变更(见 on_managed_start_admitted 与 File/SQLite 换代拒绝测试)。
    • RFC-S9-composition-validation(implemented):在隔离 File/SQLite 真实 CLI 入口验证了同代续期重试、换代拒绝、冻结结果恢复与退役后中断重放(见 test_codex_turn_completion.py 与独立探针)。
    • RFC-S10-outcomes(deferred):完整 C1/C4/C9 切换、已安装环境、其他后端及独立成本/收益实验仍明确留待后续切片,当前双语 RFC checkpoint 仅记录这一已验证局部边界。

关键代码讲解

  1. current_turn_host_launch_decision(loopx/cli_commands/turn_decision.py:448-462):当 --resume-turn-key 存在且 identity.todo_id is not None 时,在既有工作选定与基线文本哈希校验之后,调用 quota_rollout_details 组装当前快照并通过 read_heartbeat_settlement(..., heartbeat_reentry_guard=current_details) 转交 TypeScript owner heartbeatWorkRequalification 校验。若租约换代则触发 HeartbeatReceiptIdentityConflictError 中止启动,若 report_permission != "new_operation" 则抛出 FirstPartyHostRuntimeRejected("goal_launch_not_allowed")。
  2. on_managed_start_admitted 与 rebind_resumed_settlement_lease(loopx/cli_commands/turn_run_once.py:143-170, 381-382, 522-523, 856-865):移除启动前提前调用 rebind_resumed_task_lease(bind_receipt=False) 的动作,仅执行 bind_heartbeat_settlement_receipt() 保留原始准备事实;并将原函数重命名为 rebind_resumed_settlement_lease,仅在已通过校验的 writeback(completion_todo_id is None)和 completion_writeback(prior is None)阶段读取并绑定恢复租约。
  3. quota_rollout_details(loopx/control_plane/quota/settlement_cli.py:423):将 args.quota_command 改为 getattr(args, "quota_command", ""),使 turn run-once 这类非 quota 子命令的 Namespace 也能安全复用同一细节构造器,而不改变既有 quota 命令的输出值。
  4. test_resumed_turn_rebinds_updated_lease_once_without_rereading_after_retire(tests/test_codex_turn_completion.py:516-741):在 File 与 SQLite 双后端上扩展为 12 组对照,覆盖冻结结果跨代完成、刷新前中断恢复、任务后置条件校验拒绝、换代 Host 重试拒绝以及同代续期 Host 重试成功。

本 PR 共改动 6 个文件(+147 / -32 行):生产运行时 3 处文件净增 +27 / -8 行,测试文件 +92 / -24 行,中英文 RFC checkpoint +28 / -0 行;无新增顶层模块、无新 CLI 开关或持久化 schema。

对主干的风险 / Risks

  • 基线/候选正反对照验证:在不可变基线 3d15059fef142138a60fc8a03c8394e92879387c 上直接复现换代 Host 重试探针时,File 与 SQLite 均放行重跑(exit=0, status=committed, host_calls=2);在候选 head 3e06c9edf68cce1727ba6e62151c540d2d146126 上执行相同场景时,原生 codex-app-server 入口与 codex-cli 入口均在调用 Host 前拒绝恢复(host_calls=1、无任何写入或扣额副作用),且随后使用新代租约发起全新 Turn(turn-fresh)可正常完成提交并保持旧 Turn 回执不被修改。
  • 生产调用方与范围隔离:current_turn_host_launch_decision 服务于 turn run-once 的 codex-app-server 与 codex-cli 两条活跃生产启动路径;无 Todo 的 autonomous_replan 分支(identity.todo_id is None)不进入该 Todo 租约分支且由相关无 Todo 用例覆盖。变更无默认开关切换、未新增外部依赖或平台协议词表(仅复用既有 new_operation 与 HeartbeatReceiptIdentityConflictError)。
  • 本机验证结果:
    • tests/test_codex_turn_completion.py:35 passed(PASS)。
    • 周边重试/准入/恢复测试(test_host_current_admission.py、test_turn_todoless_settlement.py、test_turn_completion_source.py、test_complete_turn_decision.py、test_turn_interruption_recovery.py、test_loopx_turn_managed_step.py):206 passed(PASS)。
    • TypeScript 控制面关联测试(native_child_admission.test.ts、auxiliary_monitor_settlement.test.ts、quota_settlement_readback.test.ts、content_digest_single_owner.test.ts):202 passed(PASS)。
    • mypy(17 个内核配置源文件)0 errors(PASS);ruff check 0 errors(PASS);scripts/check_rfc_bilingual.py PASS;canary premerge --tier quick 全部门禁与 loopx check 公开边界扫描均 PASS。
    • 局部 --follow-imports=silent 检查上述 3 个 Python 文件仍有 54 条既有类型诊断,未新增错误但保留为历史诊断局限;远端托管 CI 未查询(wait_for_ci=false)。

我的整体评价 / Verdict

本 PR 对 long_horizon 与 user_experience 均判定为 preserved:阻止跨代租约偷换旧 Turn 重跑 Host 的同时,完整保留了同代续期重试、已验证冻结结果一次性结算与新 Turn 正常推进路径,没有额外增加人工干预步骤。visual_review 为 not_applicable(已检查 turn_decision.py、turn_run_once.py 与 settlement_cli.py,无任何前端或 Lark 可视化呈现改动,unverified_scope 为 none)。

前后语义对比证明:基线对换代 Host 重试错误放行(host_calls=2),候选精确拦截并保留原回执,且对既有 quota 参数、无 Todo 路径与冻结结果恢复保持兼容;代码体积克制(生产 +27/-8),未发现冗余副本或需立即简化的过度抽象,未引入新词表;剩余未覆盖范围为正式安装包实机运行、其他后端与独立成果/成本实验(与 RFC checkpoint 披露一致)。精确 head 3e06c9edf68cce1727ba6e62151c540d2d146126 已核对未变,无阻塞性发现。

English verdict: APPROVE — Exact-head review on 3e06c9e passes with zero blocking findings. Both native and CLI Turn retry callers now enforce the original lease-generation fence via the existing TypeScript heartbeatWorkRequalification owner while preserving same-generation retries, frozen-result settlement, and subsequent fresh admissions (35 completion + 206 surrounding Python + 202 TS tests, immutable-base vs head counterfactuals, ruff, kernel mypy, bilingual RFC, and quick premerge all PASS).

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewer: model_agent · Gemini · Google DeepMind · self_reported

[P1] 合入当前主干 00f47ed3 后,合法同代租约续期的 Host 重试会在启动前以 AttributeError 中断。

  • Trigger:在精确 head 3e06c9edf68cce1727ba6e62151c540d2d146126 无冲突合并 origin/main(00f47ed3)后,执行 tests/test_codex_turn_completion.py -k host_result_contract(对应同代续期重试 host_result_contract_renewal)。
  • Code path & Location:current_turn_host_launch_decision 调用 quota_rollout_details;本分支仅在旧基线 3d15059fef14 的 quota_rollout_details 补了 getattr(args, "quota_command", ""),而当前 origin/main(00f47ed3)在 _cli_rollout_details 中直接访问 args.quota_command == "should-run"(turn run-once 的 Namespace 并无 quota_command 属性)。
  • Observed outcome:在独立分支上 35 passed,但与 origin/main(00f47ed3)合并预览下同代续期用例在 File 与 SQLite 上均于第二次 Host 启动前失败(2 failed, 2 passed,与已有未解决审阅线程 PRRT_kwDOStEbEs66XUBp 结论一致)。(注:本结论同时替代本人此前基于独立旧基线测试发布的 APPROVE 结论 6005799653。)
  • Minimum repair:合并/变基当前 origin/main,在 _cli_rollout_details 中改用 getattr(args, "quota_command", "") 安全读取(并在需要时显式传入 scheduler_execution_context / Turn 来源),保留现有 TS heartbeatWorkRequalification 裁决后重跑合并后对照验证。

动机 / Motivation

受硬租约(hard_lease)保护的原生会话或 CLI Turn 恢复调用方在 Host 结果校验失败后重新认领 Todo 并重试旧 Turn 时,会遭遇跨代租约覆盖问题;同时在合入当前主干 00f47ed3 时,同代续期 Host 重试路径还会因参数读取兼容缺口而中断。在改动前的基线行为中,调用方在恢复启动前会把新认领的代次 2 租约提前改写进原有 Turn 的准备回执,使旧 Turn 重跑 Host 并错误结算;在精确 head 3e06c9edf6 独立分支上,跨代重跑被拒绝且同代续期通过,但合入当前主干 00f47ed3(settlement_cli.py 新增 _cli_rollout_details)后的无冲突合并预览会在同代续期重试启动第二次 Host 前以 AttributeError 失败。

当前 head 在自身基线 3d15059fef14 上可拒绝换代 Host 重试并放行同代续期与冻结结果结算,但在合并当前 origin/main(00f47ed3)后,同代续期重试在 File 与 SQLite 双后端上均于 current_turn_host_launch_decision 处失败(2 failed)。本切片不完成完整 C1/C4/C9 切换,不增加新持久化 schema、顶层模块、CLI 参数或跨后端收益实验。

改动思路 / Approach

如果不阻止启动前的提前覆盖,仅靠结算阶段事后校验仍会让 Host 被无效重复触发;如果仅删除启动前绑定但不接入再资格校验,重新构造的启动决策仍会放行新代次租约;反之如果一刀切禁止所有跨代恢复,则会破坏已经通过独立校验的冻结结果结算。因此本 PR 将“再次启动 Host 的新工作”与“已验证冻结结果的结算 effect”明确分离:将状态与租约代次相容性裁决收敛在既有的 TypeScript 领域规则 heartbeatWorkRequalification 中,Python 侧仅保留启动传输门禁、仅在已验证结算时绑定恢复租约的 IO 回调及字段兼容投影,不引入重复的代次判断逻辑。当前 PR 边界仅修复恢复重试入口的启动校验、移除启动前租约改写并补齐双后端正反例对照,不扩张到非恢复路径或全量迁移;合入主干前需同步适配主干 00f47ed3 的 _cli_rollout_details 参数兼容。

flowchart LR
  A["--resume-turn-key --retry-failed-turn"] --> B["on_managed_start_admitted: 仅保留原 preparation 回执"]
  B --> C{"current_turn_host_launch_decision: 调用 quota_rollout_details + TS heartbeatWorkRequalification"}
  C -->|"独立基线 3d15059fef14 同代续期 -> new_operation"| D["允许再次启动 Host 并于结算阶段绑定恢复租约"]
  C -->|"合并主干 00f47ed3 后同代续期 -> _cli_rollout_details 访问 args.quota_command"| F["P1 阻断: AttributeError 中断合法同代重试"]
  C -->|"换代重认领 (epoch 改变) -> HeartbeatReceiptIdentityConflictError"| E["拒绝重跑 Host;保留原回执与新代租约"]
Loading

注:以上流程基于精确 head 3e06c9edf68cce1727ba6e62151c540d2d146126 源码及与 origin/main(00f47ed3)合并预览测试梳理(示意结构;未在远端渲染界面预览)。

具体改动 / Changes

  • 规范基线与逐条映射:对照 docs/architecture/rfcs/mechanism-convergence-and-learning-loop-v0.md 在合并基线 3d15059fef142138a60fc8a03c8394e92879387c 的规范原文:
    • RFC-S3-invariants(implemented):保留既有 Goal/Agent/Todo/Turn/effect 身份、租约代次隔离与一次性结算约束,未在 Python 新增决策规则(独立分支 35 项 completion 与 202 项 TS 测试通过)。
    • RFC-S8-recovery-identity(not_met):虽在旧基线保留了原 Turn 身份与换代拒绝,但合入当前目标主干 00f47ed3 后合法同代续期 Host 重试失败(2 failed),尚不满足安全恢复条件;最小修复为同步适配 _cli_rollout_details 对 args.quota_command 的缺省读取。
    • RFC-S9-composition-validation(not_met):独立分支上的 File/SQLite 12 组对照通过,但在 origin/main(00f47ed3)合并预览下 host_result_contract_renewal 双后端失败。
    • RFC-S10-outcomes(deferred):完整 C1/C4/C9 切换、已安装环境、其他后端及独立成本/收益实验仍明确留待后续切片。

关键代码讲解

  1. current_turn_host_launch_decision(loopx/cli_commands/turn_decision.py:448-462):在 --resume-turn-key 且 identity.todo_id is not None 时调用 quota_rollout_details 并通过 read_heartbeat_settlement(..., heartbeat_reentry_guard=current_details) 转交 TypeScript owner heartbeatWorkRequalification 裁决;在旧基线可精准拦截换代重跑,但在合入主干 00f47ed3 后因后者调用 _cli_rollout_details 访问 args.quota_command 而中断合法同代续期。
  2. on_managed_start_admitted 与 rebind_resumed_settlement_lease(loopx/cli_commands/turn_run_once.py:143-170, 381-382, 522-523, 856-865):移除启动前提前调用 rebind_resumed_task_lease(bind_receipt=False),仅在已通过校验的 writeback 和 completion_writeback 绑定恢复租约。
  3. quota_rollout_details(loopx/control_plane/quota/settlement_cli.py:423):改用 getattr(args, "quota_command", ""),但未同步处理当前主干 00f47ed3 新增 _cli_rollout_details 中的 args.quota_command == "should-run"。
  4. test_resumed_turn_rebinds_updated_lease_once_without_rereading_after_retire(tests/test_codex_turn_completion.py:516-741):12 组 File/SQLite 对照在旧基线通过,在主干合并预览上复现同代续期失败。

本 PR 共改动 6 个文件(+147 / -32 行):生产运行时 +27 / -8 行,测试 +92 / -24 行,双语 RFC checkpoint +28 / -0 行。

对主干的风险 / Risks

  • 合并目标主干后的直接回归风险(阻断):在不可变基线 3d15059fef14 单独对照时,基线允许换代 Host 重跑(host_calls=2),head 3e06c9edf6 独立运行拦截换代并全部通过(35 passed、206 周边 Python、202 TS、ruff、kernel mypy、check_rfc_bilingual.py、quick premerge 均 PASS);然而将 head 3e06c9edf6 无冲突合并到当前目标主干 00f47ed3 后运行 tests/test_codex_turn_completion.py -k host_result_contract,host_result_contract_renewal 在 File 与 SQLite 双后端上均失败(2 failed, 2 passed),直接导致合入后合法同代租约续期的 Host 重试不可用。
  • 范围与诊断说明:原生 codex-app-server 与 codex-cli 换代拒绝路径、独立分支新 Turn 恢复路径已验证有效;3 个旧 Python 适配文件的 --follow-imports=silent mypy 仍有 54 条既有历史诊断;远端托管 CI 未查询(wait_for_ci=false)。

我的整体评价 / Verdict

本 PR 对 long_horizon 与 user_experience 当前均判定为 regression:虽在旧基线上解决了跨代租约偷换问题,但与当前目标主干 00f47ed3 合并后会导致合法的同代续期 Host 重试在启动阶段直接报错失败(2 failed),必须阻塞合入直至变基/合入主干并修复 _cli_rollout_details 兼容性。visual_review 为 not_applicable(已检查 turn_decision.py、turn_run_once.py 与 settlement_cli.py,无任何前端或 Lark 可视化改动,unverified_scope 为 none)。

复审时请在变基/合入最新 main 并安全处理 _cli_rollout_details 的 quota_command 读取后,在合并后树上重跑 tests/test_codex_turn_completion.py、tests/control_plane/test_host_current_admission.py、check_rfc_bilingual.py 与 canary premerge。

English verdict: REQUEST_CHANGES — Exact head 3e06c9e passes in isolation on old base 3d15059, but when merged with current main (00f47ed) it breaks valid same-generation lease-renewal Host retries (2 failed in test_codex_turn_completion.py -k host_result_contract for File and SQLite) because _cli_rollout_details on main reads args.quota_command without a default. Rebase/merge current main, fix _cli_rollout_details compatibility safely, and rerun the completion and admission tests.

@mergify

mergify Bot commented Nov 21, 2026

Copy link
Copy Markdown

This pull request has merge conflicts with main and cannot be merged
until they are resolved. Please rebase or merge the base branch, @cocolord.

Choose the remote for the base repository, not an out-of-date fork.
For a fork clone, first inspect git remote -v; upstream must point
to https://github.com/loopx-project/loopx.git. If it is absent, add it
with git remote add upstream https://github.com/loopx-project/loopx.git.
Then run:

git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEAD

For a same-repository clone whose origin points to
https://github.com/loopx-project/loopx.git, use origin instead of
upstream for fetch/rebase. If you prefer merging the base, use
git merge <base-remote>/main and push normally.

Keep the DCO Signed-off-by trailer on every commit when you rebase.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 21, 2026

This branch has not been deployed

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

Labels

needs-rebase Mergify: the pull request has merge conflicts with its base branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants