Repository navigation
Fence C1 first writebacks with the prepared task lease - #9097
loopx-agent wants to merge 6 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.
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
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 结果来自作者。
补充同条件验证。候选广域 CLI 套件 291 项通过、16 项失败。原主干重跑全部失败项时,正常延期 2 项与自动归档后首写 4 项通过。其余 10 项历史 ACK 用例在本地对照中也失败。自动归档后,旧首写调用返回 refresh_task_lease_unavailable。File、SQLite 使用同一原准备 proof 的对照各成功结算一次。将自动归档也纳入本次首写兼容回归。
我的整体评价 / Verdict
请求修改。让恢复 projection 从原准备回执和权威退役记录核验同代 proof,再生成原 Turn 的首写命令。继续拒绝换代、Stop 和无匹配证明的首写,并保留已提交回执的幂等恢复。
English verdict: REQUEST_CHANGES. Preserve the retired original lease proof in the generated command for legitimate deferred-Turn recovery.
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 · Gemini · Google DeepMind · self_reported
Request changes conclusion (author-owned PR; GitHub blocks formal self-review)
动机 / Motivation
受影响角色与触发任务:使用 hard_lease Handoff Mode 执行 quota should-run -> refresh-state 首次写回的控制器、Host Runner 与周期结算链路。
前后对比场景(Before / After):在基线提交上,即使 Turn 1 在首次写回前失去了任务租约 L1(被释放并由 L2 接管),Turn 1 仍能通过 refresh-state 提交 in_flight_continuation 写回;并且同 Turn 在租约替换后重入 quota should-run 在前序 head 上还能用替换租约晋升。在本 PR 的当前 head 上,非阻塞首次写回与跨代租约重入已被正确拦截,但走 blocked_retry 路径(如开放 Todo 的 outcome_gap + blocked)的首次写回仍被 state_refresh.py 的 blocked_retry is None 条件跳过租约校验,使已失活的 Turn 1 仍能提交写回、结算为 typed_blocked_writeback_no_spend 并写入 5 分钟冷却等待,导致当前合法租约持有者 L2 立即被拒绝执行。
可观测结果与边界:非阻塞 hard_lease 首次写回在租约被释放/替换或 Goal 停止时已稳定拒绝并返回 refresh_task_lease_unavailable,heartbeatWorkRequalification 也已按 prepared_lease_epoch 拒绝跨代替换租约并允许同代续期;但实测仍有两处阻塞缺陷:一是 state_refresh.py 在 blocked_retry is not None 时跳过 guard_first_writeback_execution,使已失活 Turn 仍可向开放 Todo 写坏后续调度;二是合法延期后的 unsettled_host_turn_recovery(unsettled_host_turn.py:504 / settlement_plan.ts:101)生成写回恢复命令时遗漏已退役租约 proof,导致合法恢复反而被拒绝为 refresh_task_lease_unavailable。
非目标(Non-goals):本 PR 不改动 soft_claim 语义、不放开 legacy 模式下的新执行、也不涉及 blocked_wait.ts 的 5 分钟重试时钟策略或前端/Lark 展示层。
从 C1 架构基线来看,不修该问题会让失活 Turn 竞态写回(甚至在被新版控制器/租约取代后继续修改推进记录与投递暂停),因此补齐“先校验当前准备租约代际再落首次写回”具有明确工程价值。同时作者在最新 head d6442fdea8a3a12845defd28f6f98b054ffd8c49 通过引入 prepared_lease_epoch 已经修复了前一轮审查指出的跨代 lease_readiness 晋升漏洞;但 state_refresh.py 第 1602 行无条件放行 blocked_retry is not None 的缺口仍未闭合。
改动思路 / Approach
本次改动围绕“准备阶段记录代际 → 首次写回统一加锁验代际”两条主线展开:
- 工作项与准入侧:
loopx/control_plane/work_items/execution_preparation.ts(projectExecutionPreparation)与loopx/control_plane/quota/execution_preparation.py(prepared_lease_receipt_fields、quota_prepared_lease_receipt_fields)在hard_lease下把lease_proof连同lease_epoch一并编码进quota_should_run回执(prepared_lease_key_sha256、prepared_lease_version、prepared_lease_epoch);同时在heartbeatWorkRequalification(heartbeat_receipt_identity.ts)中允许同代续期(同key且同epoch且version递增)追加settlement_receipt_revision="lease_readiness",而拒绝跨代或更换 key 的替换租约,并抛出heartbeat_receipt_identity_conflict(由settlement.py转为HeartbeatReceiptIdentityConflictError)。 - 计划与首次写回围栏侧:
composedCliSettlementChannel(settlement_plan.ts)把--task-lease-idempotency-key与--task-lease-expected-version注入command_template与semantic_closeout_command_template;refresh_state_run(state_refresh.py)在落盘之前先调用guard_first_writeback_execution,通过shadow_maintenance_lock_target与跨运行时注册表锁复核最新租约及 Goal 未停止状态,并将persist_external_delivery_pause延迟到该围栏之后执行。 - 架构所有权评估:把首次写回租约校验(
guard_first_writeback_execution)放在execution_preparation.py、同 Turn 代际校验(heartbeatWorkRequalification)放在 TSheartbeat_receipt_identity.ts、CLI fence 参数注入放在settlement_plan.ts,所有权划分合理且可复用;当前唯独state_refresh.py:1600-1610对blocked_retry做了全量豁免,破坏了核心不变量。当前 PR 边界已覆盖quota should-run、首次正常/完成/延期写回与外部投递暂停持久化,但尚未把blocked_retry(尤其是开放 Todo 的quota_blocked_retry_v0与跨代阻塞)纳入同一写回围栏。
需要注意:对历史不含 prepared_lease_epoch 的回执,TS heartbeatWorkRequalification(第 284–286 行)与 Python guard_first_writeback_execution(第 215–221 行)均拒绝再沿用升级版本,保守保留历史精确版本匹配;但在 heartbeat_receipt.py:323-326 的 ensure_turn_heartbeat_settlement_receipt 直接路径中,调用 prepared_lease_receipt_fields(task_lease_proof) 时未传递 lease_epoch,值得顺带确认是否需要同步补全。
具体改动 / Changes
- 精确评审基线与规范对照:
spec_ref:docs/architecture/rfcs/controller-executor-unified-contract-v0.mdspec_revision:1047f3b4cdf90e8912f7d8457d6d4e8d3e3542c9- 验收条款映射:
C1-LEASE-FENCE(not_met):RFC §227–244、§654–658 要求 Core 在首次写回提交前由当前单写者claim/lease与代际围栏拦截旧控制器世代。当前loopx/state_refresh.py:1600-1610因blocked_retry is None条件对阻塞类首次写回完全跳过guard_first_writeback_execution,导致开放 Todo 的quota_blocked_retry_v0在租约被释放并由 L2 接管后仍能由 Turn 1 提交写回、结算并阻塞 L2(需在state_refresh.py去掉该全量豁免并按租约代际校验)。C1-LEASE-GEN-REENTRY(implemented):同 Turn 重入准入可沿用原绑定更新同代租约就绪度而不接纳跨代替换租约(loopx/control_plane/quota/heartbeat_receipt_identity.ts:heartbeatWorkRequalification,由native_child_admission.test.ts与test_original_turn_refuses_readiness_from_a_replacement_lease验证)。C1-STOP-PAUSE(implemented):外部投递暂停持久化位于首次写回围栏与 Goal 停止校验之后(loopx/state_refresh.py:1600-1614与loopx/control_plane/quota/refresh_external_delivery.py:persist_external_delivery_pause,由test_first_writeback_refuses_generation_retired_by_later_work验证)。
- 改动规模分类(17 个文件,+564 / -84):生产运行时 14 个文件(+380 / -83),测试 3 个文件(+184 / -1)。
关键代码讲解
loopx/state_refresh.py:1599-1614—refresh_state_run
首次写回前构造guard_first_writeback_execution上下文并在其内部落盘日志和persist_external_delivery_pause;但第 1602 行加入了and blocked_retry is None,使所有blocked_retry非空的首次写回(包括todo.status == "open"产生的quota_blocked_retry_v0)在进入日志写入前根本不经过租约代际与锁校验。loopx/control_plane/quota/execution_preparation.py:179-249—guard_first_writeback_execution
先获取shadow_maintenance_lock_target排他锁,再读取最新权威快照与projectExecutionPreparation投影。当 Todo 已非open时通过include_retired_lease_for_writeback=True读取原退役租约证明,核对requested_proof == current_proof及prepared_lease的key_sha256、version、epoch三元组,并在跨运行时锁内检查goal_is_stopped(goal)。loopx/control_plane/quota/heartbeat_receipt_identity.ts:253-299—heartbeatWorkRequalification
在 Turn 仍处于open且未进入 closeout 时,检查已有previous准备租约与当前preparedLease:若prepared_lease_key_sha256改变,或有prepared_lease_epoch时发生跨代切换(!== previous.prepared_lease_epoch),直接抛出heartbeat_receipt_identity_conflict;同代续期版本号严格递增时追加lease_readiness投影。loopx/control_plane/quota/settlement_plan.ts:23-63—composedCliSettlementChannel
针对hard_lease已就绪计划,自动把--task-lease-idempotency-key与--task-lease-expected-version拼入command_template与semantic_closeout_command_template,确保连同outcome_gap/blocked语义收口命令模板在内本身都已携带租约围栏参数,证明state_refresh.py第 1602 行无需为命令行收口跳过围栏。
对主干的风险 / Risks
[P1 · Blocking] blocked_retry is not None 跳过 guard_first_writeback_execution,导致已失活 Turn 仍可提交阻塞写回并饿死新租约持有者
- 触发条件与代码路径:在
handoff_mode="hard_lease"且status="open"的 Todo 上,Turn 1 持有租约 L1(epoch 1)并通过quota should-run准入后,在未写回前 L1 被task-lease release释放,并由 L2(run-9097-new-p3k-2)重新取得活动租约(should_run=True, status="connected_without_run")。随后已被 fence 的 Turn 1 调用refresh-state --todo-id ... --turn-instance-id <T1> --progress-result-class blocked --delivery-outcome outcome_gap --next-action "..." --settle-turn。state_refresh.py:1229-1236调用require_blocked_retry_wait生成quota_blocked_retry_v0(source="turn_settlement",附带 5 分钟resume_at),随后state_refresh.py:1600-1604因blocked_retry is not None完全跳过guard_first_writeback_execution。 - 实测结果(
file与sqlite均在当前 headd6442fdea8a3a12845defd28f6f98b054ffd8c49复现):- 同一场景下
delivery_outcome="outcome_progress"(in_flight_continuation)在基线1047f3b4cdf90e8912f7d8457d6d4e8d3e3542c9会放行(rc=0, appended=True),在当前 headd6442fdea8a3a12845defd28f6f98b054ffd8c49已被正确拦截(rc=1, error_code="refresh_task_lease_unavailable")。 - 但改为
--progress-result-class blocked --delivery-outcome outcome_gap后,在file和sqlite上均返回rc=0, ok=True, appended=True、settlement_progress.state="settled"、closeout_kind="typed_blocked_writeback_no_spend",同时写入refresh_recommendation_v0并落盘 5 分钟quota_blocked_retry_v0冷却;紧接着即便重新执行quota should-run,新租约持有者/后续 Turn 在带--todo-id时被拒绝(should_run=False, error_code="quota_action_selection_rejected"),不带--todo-id时被迫进入decision="agent_scope_wait"(等待旧 Turn 伪造的 5 分钟resume_at)。 - 对照 Goal 停止路径(
goal.status="stopped"):实测blocked_retry写回在file/sqlite上返回rc=1(已有前置检查拦截),不会绕过 Goal 停止。
- 同一场景下
- 最小修复方案:移除
loopx/state_refresh.py:1602的and blocked_retry is None豁免,让所有 Todo 绑定首次写回统一进入guard_first_writeback_execution;对todo.status == "open"/"deferred"的quota_blocked_retry_v0与quota_blocked_causal_wait_v0,要求仍匹配当前活动准备租约与代际;对todo.status == "blocked"的quota_blocked_lifecycle_v0(由todo update --status blocked原子退役租约),复用execution_preparation.py:209-221的include_retired_lease_for_writeback=True并校验prepared_lease匹配该退役租约代际(同时确认测试覆盖blocked状态且 L2 接管后再阻塞的反例)。
[P1 · Blocking] 合法延期后的 unsettled_host_turn_recovery 写回命令遗漏已退役租约 proof(独立复现验证)
-
触发条件与代码路径:在
hard_lease模式下,Turn 1 经todo claim与quota should-run --codex-app获得准入(normal_delivery_allowed=True),随后在首次写回前通过合法todo update --status deferred --claim-operation-id ...延期 Todo(原子退役 L1)。同一 Turn 再次进入quota should-run --codex-app --todo-id ... --turn-instance-id <T1>触发apply_receipt_bound_wait_recovery(loopx/control_plane/quota/unsettled_host_turn.py:504-517)调用build_turn_scoped_cli_settlement_plan(..., composed_settlement=True)。然而loopx/control_plane/quota/settlement_plan.ts:101-103在composed_settlement=True时调用composedCliSettlementChannel并未传入execution_preparation,导致生成的quota_settlement_plan_v2command_template完全缺失--task-lease-idempotency-key与--task-lease-expected-version参数。 -
实测结果(
file与sqlite均在当前 headd6442fdea8a3a12845defd28f6f98b054ffd8c49复现):执行恢复返回的durable_writeback.command_template(已按规范填充占位符),file与sqlite均失败退出:rc=1, ok=False, error_code="refresh_task_lease_unavailable"(has_lease_flag=False),无法完成合法恢复。 -
最小修复方案:当
unsettled_host_turn.py生成恢复durable_writeback命令时,从权威快照中经include_retired_lease_for_writeback=True核验与原prepared_lease同代(key_sha256、version、epoch一致)的退役租约 proof,并将其传入turnScopedCliSettlementPlanPayload/composedCliSettlementChannel以携带--task-lease-*参数;继续拒绝跨代换租或 Goal Stop。 -
非阻塞补充提示(P3):
loopx/control_plane/quota/heartbeat_receipt.py:323-326在ensure_turn_heartbeat_settlement_receipt中调用prepared_lease_receipt_fields(task_lease_proof)未传入lease_epoch。常规quota should-run -> codex_execution_preparation路径由quota_prepared_lease_receipt_fields/lease_readiness补全prepared_lease_epoch,但若未来有调用方在无前置quota_should_run时直接带task_lease_proof创建回执,将因缺少prepared_lease_epoch而在同代续期重入时被拒绝。
语义与 CI 对齐
- 受影响契约:
docs/architecture/rfcs/controller-executor-unified-contract-v0.md(C1 首次写回单写者租约围栏)与loopx/control_plane/quota/settlement_plan.ts(semantic_closeout_command_template已包含--task-lease-*)。 - 对齐结论:
violated(reuse_existing— 无需新增词汇,复用现有guard_first_writeback_execution对blocked_retry落闸即可;check_rfc_bilingual.py、ruff、13 套 TS 控制面单测 537/537 及本地 pytest 核心回归均已在本地实跑,未轮询远程 CI)。
我的整体评价 / Verdict
- 长程(
long_horizon)与用户体验(user_experience):long_horizon判定为regression(blocked_retry未受 C1 围栏保护会导致失活 Turn 在租约交接后仍提交并饿死合法持有者 L2 至少 5 分钟);user_experience判定为preserved,且visual_review为not_applicable(本 PR 仅涉及控制面租约准备、配额准入与 CLIrefresh-state写回,未修改前端/渲染展示路径,无待视觉核验范围none)。 - 可观测语义、代码规模与范围适配:基线
1047f3b4cdf90e8912f7d8457d6d4e8d3e3542c9vs 当前 headd6442fdea8a3a12845defd28f6f98b054ffd8c49在file与sqlite实测证明in_flight_continuation已收紧为refresh_task_lease_unavailable,跨代重入已被heartbeatWorkRequalification阻断;scope_coverage因blocked_retry同容器旁路判定为overbroad;所有新增逻辑均落在现有控制面与适配层所有权内,无重复状态或无主模块,代码体积合理(待移除blocked_retry is None旁路并补全负例回归后即可)。 - 词汇与验证结论(复核于
d6442fdea8a3a12845defd28f6f98b054ffd8c49):沿用并扩展既有收据字段词汇(prepared_lease_required、prepared_lease_epoch、lease_readiness);本地验证结果:scripts/check_rfc_bilingual.py --base origin/main --head HEAD:PASSruff check(全部 11 个改动.py文件):PASSnode --no-warnings --experimental-sqlite --experimental-strip-types --test(13 个相关控制面 TS 测试文件):PASS(537 passed, 0 failed)tsc -p tsconfig.control-plane.json --noEmit(借主仓@types):所有生产 TS 文件及测试均 0 error,仅tests/control_plane_ts/content_digest_single_owner.test.ts因只读独立 worktree 无node_modules报缺少'typescript'包声明- Pytest(
test_quota_authority_settlement_journey.py+test_turn_run_once_claim_preparation.py):85 passed in 179.89s (test_quota_authority_settlement_journey.py + test_turn_run_once_claim_preparation.py) - 实机 CLI 对比探针(
file&sqlite):跨代拦截与同代续期 PASS;blocked_retry失活 Turn 写回绕过并阻塞 L2 FAIL(复现 P1)。
请保留本 PR 为打开状态,修复 loopx/state_refresh.py:1600-1610 的 blocked_retry is None 旁路并补充开放/阻塞态被 L2 接管后的 refresh-state --progress-result-class blocked 负例测试后可重新复核。
English verdict: REQUEST_CHANGES
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
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)
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
Codex App 和 managed CLI 的长任务要在运行结束时保存成果。领取任务时分配的租约代次决定哪次运行有权首次写回。 上一提交中,任务正常延期后,返回的命令无法结算已验证的结果。旧运行在租约换代后也可能写入阻塞等待,推迟现持有人的工作。 本次复验确认,同代任务延期或归档后能结算原运行。代次被替换时,旧运行的首次写回被拒绝。 本次复验覆盖任务准备、结果写入和原回执恢复。 实际安装采用与 C1 成果成本仍待既有验收。
改动思路 / Approach
既有 canonical Todo 与 lease snapshot 提供 key、version、epoch。首次写回在同一协调锁内校验原准备回执与当前事实,终态还检查本次完成回执。已提交的重放走原结算账本。本次交付覆盖 C1 首次写回、同代退役后的恢复和 managed CLI 的准备回执。活动 Todo 必须提供与当前同代准备一致的 proof。退役恢复从锁内 snapshot 读取同代 proof,保持原生成命令和回执兼容。
具体改动 / Changes
精确 head 5744a1893783b608601c9edc45923e1415b50b72,diff base 1047f3b4cdf90e8912f7d8457d6d4e8d3e3542c9,25 个文件 +818/-183。逐项复核 Role isolation and recovery、Shared production paths、Outcome and cost benefit。验收约定
关键代码讲解
- 更新后的首次写回检查同时覆盖已准备的 blocker。换代拒绝发生在投递暂停、run 文件和账本写入之前。源码
- 同代退役允许沿原回执恢复,同代续租只更新版本;完成状态还需原 Turn 的完成证明。源码
- canonical transaction 保留真实 epoch,managed run-once 将其传入准备回执;旧头 File 的配对探测只读到 key digest 和 version。源码
对主干的风险 / Risks
上一头在 File、SQLite 的原生延期恢复均返回 refresh_task_lease_unavailable,只有补入原证明的对照才能结算。独立 managed CLI 对照也观察到旧回执有 key digest 和 version,缺 epoch。 File 和 SQLite 直接执行原 Turn 返回的延期恢复命令,各读回一次写回及扣额。合法归档通过原验证和结算,重放零新增。两种存储经实际 run-once 把第二代租约的 key digest、version、epoch 写入同一准备回执。 File 和 SQLite 均拒绝同 Todo 换代后的首次 blocked 写回和换代后再延期、完成的写回。有无显式旧 proof 均拒绝,未追加写回日志或扣额。正常已准备 blocker 与准入前行政 blocker 继续按原语义无扣额收口。相同 blocker 测试重跑上一头时,四个换代分支仍追加写回。 当前主干 8e9a28a866 与候选的组合在测试副本上复验了 blocker、延期与 managed receipt。 先前延期评审 · 先前 blocker 评审
语义与 CI 对齐
32 项当前义务 Python 回归及 132 项 TypeScript 测试通过。当前主干 overlay 上复验 12 项锁与恢复用例,另跑两后端 managed CLI 原始准备回执及重放。标准预合并 6 项直接检查及 18 项选中检查和变更 Python Ruff 均通过。 扩展兼容套件另有 30 项通过,含正常自动归档及普通宿主重放。两项 captured no-Todo 签名反例在候选、上一头和主干 477def5 上同样得到 complete Turn decision content integrity mismatch。 管理偏好设置为本地验证,托管 CI 状态保留未知。
我的整体评价 / Verdict
同意此 head 的代码评审。可先交付首次写回与原回执恢复,managed CLI 通过真实本地存储验证。宿主子进程使用确定性 fixture,实际 App Server 安装及回退组合沿作者验证。
English verdict: APPROVE. The exact head restores legitimate retired-lease closeout, fences stale prepared blockers, and records the real managed lease epoch on File and SQLite.
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)
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
Codex App 和 managed CLI 的长任务结束时要保存结果。 换租曾留下旧运行还能写回的问题,正常延期也曾挡住合法结果。此提交整理了验证这两条边界的用例。 本次复验确认,原租约同代的延期仍能结算,换代的旧运行在新增效果前被拒绝。 本次代码结论覆盖第一次写回、原回执恢复和共享测试设置。 真实 App 的正式采用和 C1 成果成本仍沿原 RFC 验收。
改动思路 / Approach
首次写回在原协调锁内比较 canonical lease、原准备回执和当前生命周期。已提交效果由原账本重放。当前提交把三份相同的合成 hard_lease 设置抽进同一 function-scoped fixture。保留原执行和断言覆盖,验证有价值的同代恢复和旧代次拒绝。活动 Todo 必须提供与当前同代准备一致的 proof。退役恢复从锁内 snapshot 读取同代 proof,保持原生成命令和回执兼容。
具体改动 / Changes
精确 head 55c5d256f9741a403f0c6f17976cc05cd4f2fbd2,diff base 1047f3b4cdf90e8912f7d8457d6d4e8d3e3542c9,25 个文件 +813/-183。逐项复核 Role isolation and recovery、Shared production paths、Outcome and cost benefit。验收约定
关键代码讲解
- 三组测试共用准备方法,每个用例仍建立独立 tmp_path,File、SQLite 和原参数表达式逐项一致。源码
- 同代续租前进 version,改变 key 或代次的旧准备重入被拒绝。源码
- 在锁内核对退役事实与原准备,合法结果可以按原 Turn 结算。源码
对主干的风险 / Risks
上一版 5744a18937 到当前只有 tests/control_plane/test_quota_authority_settlement_journey.py 变化。比较抽象语法树确认三份准备语句、参数生成和断言逐项一致。共享 fixture 每次建立独立 canonical 存储。 单提交差异
续租讨论的修复继续生效,同代 version 可前进,新代次无法替换原准备。延期讨论按返回命令做了两后端复验,验证各写回和扣额一次。准备过的 typed blocker 同样经过首写授权校验。 续租讨论 · 延期讨论
File 和 SQLite 均能直接执行原 Turn 返回的延期命令,各写回和扣额一次,重放不追加。managed CLI 从同两种 provider 记录第二代租约,宿主只启动一次。 上一版运行时结论
语义与 CI 对齐
精确头通过 71 项 authority journey、14 项聚焦兼容、132 项 TypeScript。主干 8e9a28a866 与此 head 的组合通过 18 项共享 fixture 用例。标准预合并 6 项直接检查和 18 项选中检查、变更 Ruff 均通过。 托管 CI 状态保留未知。作者的组合安装恢复了两个 launcher 和原会话,用例含合法延期、合法阻塞与换代拒绝。容量演练仍有磁盘限制。实际安装来自作者。
我的整体评价 / Verdict
同意此精确提交。共享测试设置保留了同代恢复、换代首写拒绝和原回执的重复执行边界。用例仍独立建库,后续失败可定位到具体存储和租约条件,发布验收沿原 C1 计划。
English verdict: APPROVE. The exact head preserves all File and SQLite counterfactuals after fixture consolidation. The production blobs match the previously reviewed runtime.
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. The initial implementation targeted
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
d6442fdea8a3candidate also composed 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.Deferred, blocked and managed closeout
Tested head
5744a1893783b608601c9edc45923e1415b50b72. Targetmainat8e9a28a866da06cc6fd63e78709910fe35dad564.A legitimate Todo lifecycle transition retires the current lease. The first writeback checks the original prepared lease against the locked canonical snapshot. A retained lease with the original key digest and epoch qualifies a deferred or blocked closeout. Renewal may advance its version within that same epoch. Legacy preparation records without an epoch keep their exact-version check.
The canonical Todo read now preserves the real epoch. The managed Turn carries that epoch from its checked execution context into its original receipt. The lease-record decoder loads independently of acquisition and the receipt uses the common SHA-256 matcher.
A prepared Turn's typed blocked writeback passes through the first-writeback fence before recording a retry or pause. Pre-admission administrative closeout remains available through the existing typed route. Work on the replacement generation cannot qualify the prior Turn's writeback.
The prior candidate refused valid deferred recovery. The intermediate candidate also projected a real epoch of 2 as 1 on both File and SQLite. The current install exercises ordinary deferral, higher-epoch same-generation renewal followed by deferral, and canonical blocked recovery. Each valid deferred run writes and debits once. Each valid blocked run writes once with zero debit. Both forms reject a replacement generation with zero writes and debits. Replays preserve the original receipts.
The blocked App path uses the recovery command actually advertised for its original Turn. The tests use the installed local release and Codex App Server 0.169.0-alpha.11.1 with scripted inference. Review-A approved this runtime revision. Formal adoption remains open. Deferred recovery review, Blocked writeback review
cqr_b5630c3a49145b11ee8dverified.Formal App adoption, additional supported host coverage, active legacy-path retirement, and the matched single-session outcome and full-cost comparison remain open.
Paired rollback of an admitted Turn
The native run combined #9097 at
5744a1893783b608601c9edc45923e1415b50b72and #9007 at52efe8d251249df82c54434d3ff32ab95492fe03withmainat8e9a28a866da06cc6fd63e78709910fe35dad564. The current head55c5d256f9741a403f0c6f17976cc05cd4f2fbd2shares one hard-lease fixture across three existing tests. The only changed file since the reviewed runtime is the authority journey test module. All production blobs are byte-identical. The module passed 71 tests after the change, and the full PR diff now totals 996 lines. Standard premerge passed the six direct and 18 selected checks on the final head. Exact change-quality receiptcqr_2abbe06afb286e062293verified.The isolated archive installation used macOS Codex App Server
0.169.0-alpha.11.1with scripted local inference. The real update command switched bothloopxandloopx-apply-rruleto archivef8ef1a63f12f. The original prepared session resumed using its retained admitted executable and the original capture and receipt.The switch preserved the authoritative Todo revision and canonical record digest, and added no settlement effects. The combined checkout passed 83 rollback-owner tests with three Windows-only cases skipped. Formal installed-profile adoption and matched single-session outcome and full-cost qualification remain open. Prior exact-runtime approval, Paired launcher rollback PR
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.