Repository navigation
fix(todo): switch settled execution on explicit claim - #8941
huangruiteng wants to merge 4 commits into
Conversation
|
This pull request has merge conflicts with Choose the remote for the base repository, not an out-of-date fork. 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 HEADFor a same-repository clone whose Keep the DCO |
f06a9b0 to
ab21631
Compare
Signed-off-by: huangruiteng <huangrt01@163.com>
ab21631 to
3673be9
Compare
Signed-off-by: huangruiteng <huangrt01@163.com>
Signed-off-by: huangruiteng <huangrt01@163.com>
3673be9 to
ba7bbf7
Compare
Signed-off-by: huangruiteng <huangrt01@163.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent; gpt-6.1-sol; OpenAI; runtime_reported; reasoning_effort=max
动机 / Motivation
Agent 完成一个 Todo 后,显式领取同仓库下一个写范围重叠的 Todo 时,仍可能被自己的旧租约阻塞。 原来需要等旧租约过期或另外清理;本 PR 试图在确认原 Turn 已完整结算后,一次领取同时退役旧租约并取得新执行。 串行场景已验证能继续新任务,但最新 source Turn 的结算资格没有与切换提交同步,并发新 Turn 仍会失去执行租约。 本次 review 不批准合并、安装或 provider 切换,也不把 CLI 的修复视为整个多 Agent 产品已经验收。
改动思路 / Approach
显式 CLI self claim 在没有附带 lease key/version 时开启 switch intent;generic native API、自动恢复与 Chat confirmed-task start 仍默认关闭。原有 acquire reducer 先判断冲突,只对一个有效、同 owner、同仓库的 source 调用 quota readback;资格成立后,把 source release、target acquire、Todo owner 和 operation receipt 放进同一个 provider CAS。串行领取和同 operation replay 已通过真实 File adapter 验证。
沿用现有领取事务、租约判定和 quota readback owner 是合适边界;需要补齐的是 source 证据到提交的并发栅栏,而不是增加一个手工维护的 ready 状态。 本 PR 的可交付边界应是同一显式领取中,基于仍然有效的 source Turn 证据原子退役旧执行并取得新执行,包含拒绝、重试和原回执读回。 手动先 release 再 claim 会增加一次干预并拆开原子性;这不比复用既有 owner 更合适。下表是 exact head 55d4649e7092dd25d289797806f77fd4fc30247b 的源码与执行对照,无 Mermaid 渲染结论。
| 状态 | base | head |
|---|---|---|
| 最新 source 已结算,显式领取重叠 target | 拒绝,source 保持 active | 原子切换,replay 无额外写入 |
| 新 source Turn 在验证前已存在 | 拒绝 | 正确拒绝,并指向实际待结算 Turn |
| 新 source Turn 在验证后、提交前绑定 | 不进入切换 | 仍切换,source 被提前释放 |
| 非重叠范围或不同仓库 | 两个独立执行 | 保持独立,不释放 source |
具体改动 / Changes
审查完整 base ef099ae3ac3c08054b9d928fff48aefe2615b950 到 head 55d4649e7092dd25d289797806f77fd4fc30247b 的 14 文件 diff(+873/-13),包括 stacked #8948 的 probe release-root 隔离和无用 import 清理。任务依据是 PR #8941 的维护者原始问题及承诺;spec_ref: https://github.com/loopx-project/loopx/pull/8941;spec_revision: body-sha256:7e58bdd333b531dedad889cc34af8b747fcda769b627d127437159ec733fe334。既有 owner/key/version、CAS 与回执边界对照 canonical-lease-renew.md 的 base 文本。SWITCH-LATEST 为 not_met(并发新 Turn 未被栅栏覆盖);SWITCH-ATOMIC 为 implemented(同一 provider transaction 退役 source 并取得 target);SWITCH-FAIL-CLOSED 为 not_met(已有新 Turn 会拒绝,介入的新 Turn 却可漏过)。这些是本次任务的条件,不用后续 roadmap 门槛替代它们。
关键代码讲解
handle_todo_command把 switch intent 限定在显式 self claim,沿现有 Python mutation/local-authority 适配层传入 v2;不会因 provider 可用或 source 已结算而自动启用通用 API。verifySettledExecutionSwitch选择 source Todo 最新绑定 Turn,复用既有 quota settlement owner 核对 identity、writeback、spend 与 checkpoint。输出 proof 的 lease key/version/epoch 来自当前请求,但这不等于把 journal 来源锁到稍后的提交。prepareClaimExecution限制一条有效、同 owner、同仓库冲突,验证 proof 后复用普通 acquire reducer,不建立第二套 provider 判定。缺 spend、已存在的 newer Turn、foreign owner 均在独立 native probe 中拒绝且保持 provider 不变。executeCoordinationTodoClaim将两条 lease mutation 和原始 claim receipt 一起提交,并保留 old/new optional-bit replay 的兼容处理;该 CAS 防止 provider 并发修改,却没有把独立 heartbeat journal 的新绑定包含进去。
对主干的风险 / Risks
[P1] 将最新 source Turn 的验证与租约切换同步
位置:settled_execution_switch.ts:61。让 source-settled 完整结算,开始领取 target;verifier 读完快照后、真正 File commit 前,通过生产 ensure_turn_heartbeat_settlement_receipt writer 绑定 source-concurrent。观察到 claim 仍为 applied,source=released、target=active,execution_switch.settlement_identity 仍是 source-settled,且 replay 保留该结果。相反,把同一新 Turn 提前放在快照里会正确拒绝,因此现有 newer-Turn 测试通过不能排除此 race condition。source 的新 Turn 尚未结算就失去执行证明,后续合法进度/收口可能被打断。
这不是只 mock 一个“结算成功”返回值:竞争侧调用生产 Python receipt writer,领取侧通过公开 native adapter 和真实 FileAuthorityStore 提交;确定性 seam 只控制两者的交错时机。原 source 的 retained settlement 是隔离夹具,未声称运行真实模型或完整 host session。writer 使用 rollout-log lock,claim 使用 maintenance/provider fence,当前二者没有覆盖这个来源变化的共同栅栏。请把 source 绑定及结算资格纳入提交期间的同一并发保护,来源变化时拒绝或重新资格核验;仅在 commit 前再无锁读取一次仍留有窗口。回归应覆盖这个交错、无 source 退役/target 领取、实际最新 Turn 结算后的合法切换与原 operation replay。
语义与 CI 对齐
复用了既有 claim/lease/settlement owner,新增的是可选 intent 和派生 proof,而非人工同步 ready 状态。原先所有冲突 self claim 都拒绝,现在显式 CLI claim 会请求退役 source,这是已披露的行为改变。隐式 API、独立仓库/范围的对照保留原行为;不能用 typed 字段齐全或单一 provider CAS 推断 source 时间线也已同步。新 proof schema/error vocabulary 的完整 owning gate 随 premerge 留待重跑,不把未读 CI 当作通过。
验证结果:native snapshot/local adapter PASS 5;实际注册入口的 File/SQLite managed conformance 33 PASS / 13 FAIL,其中两后端新增的前五组 switch 场景通过;更广的锁超时、ambiguous readback 与 setup 失败逐项原因未完成 base 归因,不能重标为通过。恢复后的 CLI diagnostics、contract health、probe isolation 聚焦验证 PASS 130;typecheck:control-plane PASS。完整 Python differential 与 quick premerge 因本地 ENOSPC 恢复而中断,均为 UNVERIFIED。独立 real PostgreSQL 全套为 92 PASS / 311 FAIL;临时服务在 Docker metadata I/O 错误后退出,后续 ECONNREFUSED,故 PostgreSQL 资格仍未完成。保留这些失败,修复并恢复环境后重跑;它们与已独立复现的 File race 分开判断。按当前策略未查询、轮询或等待 CI。
我的整体评价 / Verdict
REQUEST_CHANGES。串行继续工作的收益已证实,机制规模与复用边界基本合理;当前缺口是执行资格的并发正确性,而非 PR 大小。long_horizon=regression:较新的 source Turn 可能在未结算时失去租约;user_experience=not_yet_proven:串行 CLI 少一次清理,但并发路径和 packaged caller 旅程未闭合。未涉及渲染页面,视觉检查不适用;unverified_scope: packaged Chat/installed execution,未把无 UI diff 当作其交付证明。Chat confirmed-task adapter 仍以不启用 switch 的 managed claim 调用,也未在本轮做完整界面/host qualification。
同一 base/head 夹具比较覆盖显式/隐式、缺 spend、既有 newer Turn、foreign owner、不同仓库、非重叠、250 个无关 Todo 与并发绑定;完整 JSON/Markdown 字段等价性、未来新增 subject、所有历史 reference 变体与 mixed-version 消费仍未穷尽,不扩大为通过结论。保留 operation receipt 的兼容分支有依据,CLI 两处重复 predicate 可局部去重,但不是阻塞项。修复上述来源栅栏并补齐必要 backend/gate 验证后,应在新的 exact head 复审;此 review 不授权 merge、安装或服务切换。
English verdict: REQUEST_CHANGES at 55d4649. A production heartbeat receipt writer can bind a newer unsettled source Turn between verification and the real File commit, yet the old source is retired. Serial switch/replay works; required PostgreSQL and full premerge qualification remain incomplete.
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent (declared_model=Gemini, declared_provider=Google, declaration_source=self_reported) — exact-head review of PR #8941 (55d4649e7092dd25d289797806f77fd4fc30247b)
动机
受影响调用方与场景:同一个 Agent 在启用 hard_lease 的 managed_execution 模式下通过默认 loopx todo claim 切换重叠 write_scopes 的 Todo,以及通过相同命令重放升级前普通 claim_operation_id 的既有调用方。
修改前:当源 Todo 的当前 Turn 已完成 refresh-state 与 quota spend-slot 结算但源 Todo 仍保持 open 并持有重叠 write_scopes 时,直接执行不带显式租约证明参数的新 Todo claim 会因 write_scope_conflict 被拒绝;修改后:默认开启 allow_settled_execution_switch 时自动原子释放已结算源租约并获取目标租约,但当前实现遗漏了 vision_checkpoint 门禁校验且破坏了升级前普通 claim 的幂等重放。
可观测结果:合法且 vision_checkpoint 已满足的已结算 Turn 可通过单次 loopx todo claim 原子完成源租约释放与目标租约获取,并在未结算时返回结构化 recovery 诊断;但未满足 vision_checkpoint 的 semantic_closeout Turn 仍能违规切换,且升级前普通 claim 重放会误报 coordination_operation_identity_mismatch。
非目标与范围边界:本次改动不包含 source_session_v1 / goal_ref 的协调租约绑定扩展,也不改变传入显式 --task-lease-idempotency-key 或 --task-lease-expected-version 时的硬租约版本校验行为。
同时,该 PR 当前栈底仍携带来自 #8948 的两条提交(8c08d0f9c2 隔离 cli-output-base-head-differential-smoke.py 的 probe release identity、8b92715eda 移除 tests/control_plane/test_contract_health.py 失效 import),并在第 4 条提交 55d4649e70 中为未结算拒绝补充了结构化恢复字段。
改动思路
本 PR 新增纯 TypeScript 判定模块 loopx/control_plane/coordination/settled_execution_switch.ts,将“已结算源 Turn”的校验注入 claim_execution.ts 与 todo_claim.ts:
- 在
prepareClaimExecution检测到同一agent_id名下存在唯一冲突活跃租约且启用allow_settled_execution_switch(未传入显式租约版本号/幂等键)时,通过注入的ClaimExecutionSwitchVerifier验证source_todo_id的最新绑定 Turn 结算状态并生成todo_settled_execution_switch_proof_v0; - 在
todo_claim.ts中将execution_switch写入coordination_todo_claim身份与原子 CAS 事务,同步把源 lease 置为released并为目标 Todo 写入新的 active lease; - 在
local_authority_runtime.ts、local_authority.py、mutation_api.py与loopx/cli_commands/todo.py透传allow_settled_execution_switch及未结算结构化恢复诊断字段(source_todo_id、source_turn_instance_id、settlement_progress、recovery)。
架构边界判断:将已结算切换判定放在 claim_execution.ts 与纯 TS 判定模块 settled_execution_switch.ts、由 todo_claim.ts 在同一 CAS 事务内原子释放源租约并获取目标租约的架构边界是合理的,但必须修复两项正确性阻断缺陷:在 settled_execution_switch.ts 补齐与 quota should-run 一致的 replay_phase / vision_checkpoint 校验,以及在 todo_claim.ts 的老收据兼容分支同步剥离 allow_settled_execution_switch。
当前边界声明:当前 PR 范围聚焦于 hard_lease 同 Agent 单源切换及 #8948 栈底两项基线修复,不含 source_session_v1 goal_ref 对齐(保留为 follow-up)。
具体改动
依据目标仓库规范 docs/product/core-control-plane/state-machine.md(固定基线修订 0532563a8f8d182191b69d53dab3429c098cabda)进行逐条验收映射:
HARD-LEASE-ATOMIC-EXECUTION-SWITCH(已实现,受阻塞缺陷影响):loopx/control_plane/coordination/settled_execution_switch.ts、claim_execution.ts、todo_claim.ts与local_authority_runtime.ts实现单源冲突检测、多源拒绝(multiple conflicting sources reject without releasing either)、双边 CAS 释放+获取以及 lost-ack 收据重放;local_authority.py、mutation_api.py与loopx/cli_commands/todo.py透传allow_settled_execution_switch(显式--task-lease-idempotency-key/--task-lease-expected-version时保持关闭)。STATE-MACHINE-VISION-CHECKPOINT-GATE(未满足 / 阻塞):state-machine.md规定 materialrefresh-state会产出vision_checkpoint_v0且缺失时不得静默视作完成闭环(quota should-run在live_decision.py:1074要求readback.replay_phase == "settled")。当前settled_execution_switch.ts:100-107仅判断progress.state === "settled"而不检视readback.replay_phase === "settled"或vision_checkpoint.satisfied === true。STATE-MACHINE-PLAIN-CLAIM-REPLAY-COMPAT(未满足 / 阻塞):todo_claim.ts:522-535在manage_execution兼容重放路径漏删legacyIntent.allow_settled_execution_switch,破坏升级前普通claim收据从默认 CLI(todo.py:396-407同时传双标志)的重放兼容性。- 测试与基线改动:
tests/control_plane_ts/settled_execution_switch.test.ts、tests/control_plane_ts/local_settled_execution_switch.test.ts、tests/control_plane_ts/managed_claim_execution_conformance.ts、tests/test_cli_argument_diagnostics.py,以及来自 #8948 的examples/control_plane/cli-output-base-head-differential-smoke.py、tests/control_plane/test_cli_output_differential.py与tests/control_plane/test_contract_health.py。
对主干的风险
在 exact head 55d4649e7092dd25d289797806f77fd4fc30247b 上经代码审查与真实 CLI 对抗复现,确认以下 2 项阻塞性问题 与 1 项后续关注项:
-
【P1 / Blocking】
verifySettledExecutionSwitch遗漏vision_checkpoint/replay_phase门禁校验(settled_execution_switch.ts:100-107)- 触发条件与代码路径:当源 Todo 的最新 Turn 在
delivery_boundary=semantic_closeout下执行refresh-state --delivery-outcome outcome_progress而未提供--agent-vision-json或--vision-unchanged-reason时,runs/index.jsonl写入vision_checkpoint: {required: true, satisfied: false, decision: "missing_required"}。随后执行quota spend-slot --execute会记账配额事件,但settlement_readback.ts:1473-1475因isAcceptedProgressWriteback检查vision_checkpoint.satisfied === true未通过,仍将readback.replay_phase保持为"open"(非"settled"),live_decision.py:1074中quota should-run也仍返回decision: "run"。 - 违规结果:
settled_execution_switch.ts:100-107仅检查settlementOk && progress?.state === "settled"(settlementProgress依赖delivery_outcome.ts:75的isTurnScopedSettlementOutcome,不检视vision_checkpoint),从而向todo_claim.ts返回合法证明。真实 CLI 实测确认:loopx todo claim --todo-id todo_target返回exit 0 / status: "applied",错误地提前释放了未闭环源 Todo 的 hard lease,这直接违背了 PR 描述宣称的vision-checkpoint校验与quota should-run的 settled 定义。 - 最小修复与回归测试:在
settled_execution_switch.ts要求readback.replay_phase === "settled"(并同步在拒绝detail暴露未满足 checkpoint 的恢复动作),在settled_execution_switch.test.ts与 CLI 测试中新增vision_checkpoint.satisfied === false(及缺失vision_checkpoint)负例,验证其被拒绝且源 lease 不释放。
- 触发条件与代码路径:当源 Todo 的最新 Turn 在
-
【P1 / Blocking】升级前普通
claim收据在默认 CLI 重放时失败(todo_claim.ts:522-535)- 触发条件与代码路径:
loopx/cli_commands/todo.py:396-407在未传入--task-lease-idempotency-key与--task-lease-expected-version时同时设置manage_execution=True与allow_settled_execution_switch=True。但在todo_claim.ts:522-535的旧普通claim(manage_execution: false)兼容回退中,第 525 行仅执行delete legacyIntent.manage_execution;,漏掉了delete legacyIntent.allow_settled_execution_switch;(第 533 行重试却显式传入allow_settled_execution_switch: false)。 - 违规结果:在
file_v0中写入一笔升级前普通claim收据(manage_execution: false、operation_id: "legacy-plain-op")后,通过真实 CLI 重放loopx todo claim --claim-operation-id legacy-plain-op,由于legacyIntent仍携带allow_settled_execution_switch: true,哈希比对失败,CLI 以退出码 1 返回coordination_operation_identity_mismatch而非replayed(no_change)。managed_claim_execution_conformance.ts现有用例未同时传allow_settled_execution_switch: true,因此漏过了该回归。 - 最小修复与回归测试:在
todo_claim.ts:524-525同时delete legacyIntent.allow_settled_execution_switch;,并在managed_claim_execution_conformance.ts(覆盖 File 与 SQLite)及 CLI 测试中校验携带双标志重放 pre-upgrade plain claim 收据返回replayed。
- 触发条件与代码路径:
-
【P2 / Follow-up】
source_session_v1/goal_ref与 #8948 基线栈清理latestBoundSourceTurn未按goal_ref过滤 rollout 事件,而readQuotaSettlementFromSnapshot默认构造aliasowner(quotaOwnerOwnsProjection会丢弃带goal_ref的记录),导致显式goal_ref场景误报state: "identity_required";鉴于goal_instance_binding_inventory_v1.json当前将todo_coordination_lease保持为goal_alias_only,记为后续随source_session_v1一并收敛项。此外 PR 仍包含未合入的 #8948 提交且存在 Mergify 冲突提示,待重整基线。
我的整体评价
PR #8941 用双边原子 CAS 与既有收据重放机制实现跨 Todo 已结算租约切换,整体设计沿用了协调域与结算域既有 owner(在 settled_execution_switch.ts、File/SQLite 多源冲突拒止、lost-ack 重放及显式 lease proof 隔离上表现良好)。但在 exact head 55d4649e7092dd25d289797806f77fd4fc30247b 上经真实 CLI 对抗验证存在上述 2 项阻塞性缺陷:未完成 vision_checkpoint 闭环的 semantic_closeout Turn 仍可释放源租约并切换,且升级前普通 claim 收据从 CLI 幂等重放必定失败。需修复上述两处缺陷并补齐对抗回归测试后再提交复审。
English verdict: REQUEST_CHANGES
|
This pull request has merge conflicts with Choose the remote for the base repository, not an out-of-date fork. 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 HEADFor a same-repository clone whose Keep the DCO |
An agent that has fully settled one Todo can still hold its hard lease, so an explicit claim of the next overlapping Todo in the same repository was rejected with
write_scope_conflictuntil the old lease expired or another turn repaired it.This change verifies that the newest Turn bound to the source Todo has complete refresh, quota-spend, settlement-identity, and vision-checkpoint evidence, then atomically releases that exact source lease and acquires the target execution. It fails closed for incomplete or superseded Turns, ambiguous conflicts, another owner, repository mismatch, or proof drift.
The branch is temporarily stacked on #8948, which fixes a base/head CLI-output canary environment leak required for trustworthy premerge validation. Once #8948 lands, this PR's product diff remains the single lease-handoff commit.
Validation:
node --no-warnings --experimental-sqlite --experimental-strip-types --test tests/control_plane_ts/settled_execution_switch.test.ts tests/control_plane_ts/local_settled_execution_switch.test.ts tests/control_plane_ts/managed_claim_execution_conformance.tsuv run --offline --extra test pytest -q tests/test_cli_argument_diagnostics.py(108 passed)scripts/loopx canary premerge --from-git-diff --git-diff-base origin/main(19/19 selected checks passed)