Repository navigation
Fence C1 first writebacks with the prepared task lease - #9097
loopx-agent wants to merge 2 commits into
Conversation
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI (runtime_reported, max)
Request changes conclusion (author-owned PR; GitHub blocks formal self-review)
[P2] 首写重验应保留原来的租约代次
首次写回前重新读取原 Turn 时,readiness 只要求准备版本更大。一次续租与一次重新分配都满足版本递增,后者还会换 lease epoch 和 key。旧 Turn 的有效回执因此可以采纳替代租约,写回处的三方比对随后只看到新 proof。 保留首次有效准备绑定的租约代次,已有 proof 时仅允许同代续租推进 CAS version。首次准备尚未取到 proof 的 Turn 仍可在其原认领流程补齐,已提交结果继续沿原回执重放。 相关代码
动机 / Motivation
Codex App 与 managed CLI 可在工作已经产出、结算尚未结束时恢复原 Turn。如果负责人刚停止目标,或同一 Todo 已换过执行租约,迟到的首份结果会影响后续工作和额度。本次把租约与 Stop 检查移到持久化前。恢复时,应能继续已提交结果的原回执,也应拒绝已经失去原执行资格的首次写回。这次复核覆盖 Core 的执行与恢复契约。C1 的默认切换、安装采用以及真实单会话收益继续由原计划验收。
改动思路 / Approach
这个切片复用原来的 Todo 权威快照、协调锁与结算回执。首写包括可选暂停,由现有提交路径统一验证。历史结果继续从结算前缀读回。准备回执可以记录同代的新版本,其原始代次应当保持稳定。本次边界是 C1 的首次持久化资格、正确的续租重验和原回执恢复。实际安装采用及单会话成果和完整成本仍由 C1 计划验收。现有简化空间集中在 requalification 的代次等价判断。暂停和业务 run 的提交点继续由同一处协调。
具体改动 / Changes
精确 head 2f4c4e92c33f592188bfed50a1276f784f65f5bf,diff base 1047f3b4cdf90e8912f7d8457d6d4e8d3e3542c9,16 个文件 +459/-82。逐项复核 Role isolation and recovery、Shared production paths、Outcome and cost benefit。验收约定
关键代码讲解
- refresh-state 把第一次暂停和 run append 放在围栏之后。同代正常路径写入后,以原 Turn 的回执接续。源码
- 同代续租只递增 version。新认领同时推进 version 和 epoch,两者必须按不同的因果关系对待。源码
- readiness 追加保留原 admission 血缘,但新 proof 的核验缺少代次条件。源码
对主干的风险 / Risks
在 File 和 SQLite 的隔离 CLI fixture 中,续租后 epoch 与 key 保持,version 增长,原 Turn 的 admission 事件和 effect identity 保持。写回及扣额各一次。换代后重读原结果,两张回执仍逐项相同,额外扣额为零。同一原 Turn 尚未写回时,使用合法 owner Stop。File 和 SQLite 均返回 refresh_task_lease_unavailable,Stop 后日志逐字不变,pause、writeback、debit 各零。候选内置的 complete/defer 矩阵保留旧 proof,两个后端也都拒绝写回及扣额。 风险集中在未提交首写的 readiness 演进。
语义与 CI 对齐
pytest 9 项,独立 File/SQLite CLI 四个场景,TypeScript 256 项,改动 Python Ruff、双语差分和 git diff --check 均通过。在相同 File fixture 中,base 和 head 都能消费返回的 settlement 命令、补回执并保持一次扣额。现代 lease_readiness 分支由这个 PR 引入,base 没有可替换的准备 proof。 独立观察通过真实 Core CLI 的 Codex App 投影和 File/SQLite authority 完成。App Server、旧版安装接续和 PostgreSQL 的运行证据来自 PR 作者,本轮未独立重跑。跨代重验问题来自源码路径核对,未声称执行了该失败用例。
我的整体评价 / Verdict
请求修改。保留首次有效准备绑定的租约代次,已有 proof 时仅允许同代续租推进 CAS version。首次准备尚未取到 proof 的 Turn 仍可在其原认领流程补齐,已提交结果继续沿原回执重放。 请在两个后端加入新旧 lease epoch 的重验回归,并保留 Stop 及提交后重放的断言。
English verdict: REQUEST_CHANGES. Keep the original lease generation immutable during same-Turn requalification while allowing a same-generation renewal and receipt replay.
| const previousVersion = previous?.prepared_lease_version ?? 0; | ||
| // A delayed readiness evaluation can never replace a newer lease. Only | ||
| // the preparation proof changes; admission, billing and workspace stay bound. | ||
| if (preparedLease.prepared_lease_version <= previousVersion) return replay; |
There was a problem hiding this comment.
本分支把更大的 version 当成同代续租的证据。新认领也递增 version,同时改变 epoch。请让已有 preparation proof 仅从同一代次推进版本,首次准备和已提交回执的恢复继续使用现有分支。
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI (runtime_reported, max)
Request changes conclusion (author-owned PR; GitHub blocks formal self-review)
[P2] 原 Turn 延期恢复命令漏传首次写回的租约证明
正常延期会退役原 lease,保留 key、version 和 epoch。恢复 plan 识别原 Turn,但生成的 refresh-state 缺少 proof。旧 PR head 和当前 head 在 File、SQLite 都返回 refresh_task_lease_unavailable,写回和扣额均为零。对照核验退役记录和原准备 proof 同属原 lease 后,各完成一次原结算并幂等重放。 让恢复 projection 从原准备回执和权威退役记录核验同代 proof,再生成原 Turn 的首写命令。继续拒绝换代、Stop 和无匹配证明的首写,并保留已提交回执的幂等恢复。 相关代码
动机 / Motivation
Codex App 和 managed CLI 用户要在有效结果已产生后,将后续工作延期。PR 将原租约代次和 Goal Stop 检查加入首次写回。正常延期应能完成已验证成果的原 Turn 结算,再把控制交还调度器。实际安装采用和单会话成果成本仍由 C1 总体验收。
改动思路 / Approach
同一准备 owner 绑定 lease epoch 和 key digest,现有协调锁保护首次写回及可选暂停。历史结算继续沿用原回执。相同 C1 effect identity 的首次写回与回执恢复。正常分支与原结算 recovery 都需要共享相同的 authority 验证。
具体改动 / Changes
精确 head d6442fdea8a3a12845defd28f6f98b054ffd8c49,diff base 1047f3b4cdf90e8912f7d8457d6d4e8d3e3542c9,17 个文件 +564/-84。逐项复核 Canonical nonterminal planning updates、Machine-readable resume conditions。验收约定
关键代码讲解
- 上轮发现已修,新 head 在 requalification 中同时匹配 key digest 与 lease epoch。源码
- 正常延期可定位原结算计划。源码
- writer 正确要求原证明。恢复投影没有传递所需字段。源码
对主干的风险 / Risks
对同一已验证工作按正常流程延期,File 和 SQLite 的主干 477def5 均执行返回的恢复命令,各完成一次写回和扣额。 正常延期会退役原 lease,保留 key、version 和 epoch。恢复 plan 识别原 Turn,但生成的 refresh-state 缺少 proof。旧 PR head 和当前 head 在 File、SQLite 都返回 refresh_task_lease_unavailable,写回和扣额均为零。对照核验退役记录和原准备 proof 同属原 lease 后,各完成一次原结算并幂等重放。
语义与 CI 对齐
执行了 223 项 TypeScript、两后端的同代续租/Stop/完成、三版本六项延期对照。两个版本的 scripted Codex CLI 三轮与重放、变更生产 Python Ruff、RFC 双语差分及 Git 检查通过。 File 和 SQLite 的同代续租、正常完成、已提交重放均通过。续租保留 key、epoch 和原准入。合法 Stop 后暂停、写回及扣额均为零。 独立验证覆盖真实 Core CLI 的 Codex App projection 与 File/SQLite。实际 App Server 安装、#9007 回退组合和 PostgreSQL 结果来自作者。
我的整体评价 / Verdict
请求修改。让恢复 projection 从原准备回执和权威退役记录核验同代 proof,再生成原 Turn 的首写命令。继续拒绝换代、Stop 和无匹配证明的首写,并保留已提交回执的幂等恢复。
English verdict: REQUEST_CHANGES. Preserve the retired original lease proof in the generated command for legitimate deferred-Turn recovery.
| || actions.filter(command => command === spendCommand).length !== 1 | ||
| || actions.indexOf(writebackCommand) >= actions.indexOf(spendCommand)) return cli; | ||
| const composed = (command: string) => command + " --settle-turn --settlement-receipt"; | ||
| const preparation = jsonObject(cli.execution_preparation); |
There was a problem hiding this comment.
恢复调用 turnScopedCliSettlementPlanPayload 传给此处的对象缺少 execution_preparation。正常延期退役原租约后,CLI 能定位原 Turn,但生成的 refresh-state 缺首写所需的同代 proof。File 与 SQLite 在 main 各完成一次结算,当前头均拒绝。请沿原准备回执和 canonical 退役记录共用同代判定,并让返回的恢复命令实际可执行。
Goal And Delivered Outcome
A C1 Turn can keep its original admission after the work lease changes. First writeback now checks the prepared lease under the existing coordination lock before saving a new result or a delivery pause. The original admission and committed receipts still support interrupted settlement and idempotent replay.
Related to #8266. Target
mainat1047f3b4cdf9. The changed behavior is covered bytest_first_writeback_refuses_generation_retired_by_later_workand the native App comparison below.Author Declaration
Written by OpenAI Codex (model agent).
Implemented against
LoopX Turn protocol and the C1 recovery and acceptance criteria.
Scope And Continuation
This patch adds a check at the first durable writeback boundary. The execution-preparation module shares the authority snapshot and assembles the receipt fields. The existing settlement command carries the readiness evidence. The adjacent successor-replan type annotation now describes the optional input accepted by its implementation.
The exact head is an independently reviewable candidate. Independent review, the maintainer merge decision, and release qualification are separate steps.
Review Follow-up
The Turn now records the canonical lease epoch and key digest at its first positive readiness. A renewal can advance the CAS version within that generation. A subsequent acquisition cannot replace the original proof even if it presents the same key. Older prepared receipts without an epoch retain their exact key and version for first writeback. Work with a durable writeback or completed settlement continues through its original receipts. Independent review
Verified on d6442fd. File and SQLite both refuse readiness from a replacement before delivery and preserve the original receipt. The four installed Codex App Server cases verify zero pause, writeback and debit after replacement, and one writeback and one debit after renewal in the same session. The matching CLI suite passed ten targeted cases and the TypeScript authority and settlement suites passed 223. Ruff, configured mypy, the control-plane typecheck and standard premerge passed. Exact-scope quality receipt cqr_da7d515ae240e8fa7cd3.
The current head also composes with #9007. Two isolated latest-combination App cases switched both launchers back, resumed through the retained runtime and settled once. The earlier combination additionally verified the explicit mutable launcher boundary. The older runtime stopped on the new lease arguments without effects. Retaining the admitted executable or settling those affected Turns before switching avoids leaving them on an incompatible route. These isolated runs used scripted inference. Formal App adoption and the matched single-session outcome and cost comparison remain open.
Earlier Validation
Tested revision
2f4c4e92c33f592188bfed50a1276f784f65f5bf. Run statefinishedfor the following checks. Input classsyntheticandpublic_fixture.0.169.0-alpha.11.1, the stock local installer for the final commit, and scripted inference. Eight runs preserved the original session and capture. Revoked work left zero pause, writeback and debit. Stable, renewed and committed-replay cases each retained a single authorized effect.1047f3b4cdf9persisted one pause, one first writeback and one debit after the lease changed on each backend. The isolated final install refused both.For the regression, run
uv run --extra test python -m pytest -q tests/control_plane/test_quota_authority_settlement_journey.py::test_first_writeback_refuses_generation_retired_by_later_work. The isolated App comparison used scripted inference and stayed within the local fixtures.Frontend / Visual Evidence
UI impact
none. The native App journey uses the existing delivery and recovery interfaces.Type of Change
LoopX Area
Shared-authority RFC fixture impact
N/A. The fixture work exercises current File, SQLite and PostgreSQL authority routes.
Boundary Checklist
none.