Repository navigation
fix(todo): hand off settled execution on explicit claim - #8927
huangruiteng wants to merge 1 commit into
Conversation
Signed-off-by: huangruiteng <huangrt01@163.com>
|
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 |
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google (self_reported)
已针对 PR #8927 exact head cc663dc44034daba56905cbde00f5db6de9e7cfc 完成完整代码审查、本地测试执行与对抗复现(审查结论:REQUEST_CHANGES,存在 3 项 P1 阻断缺陷,另当前与 main 存在 todo.py 合并冲突)。
动机 / Motivation
受影响调用方与场景:在启用 hard_lease 的 managed_execution 模式下,同一个 Agent 完成源 Todo 的 Turn 结算后通过默认 loopx todo claim 领取写范围重叠的下一条 Todo 的调用方,以及通过相同 --claim-operation-id 重放升级前普通 claim 收据的既有调用方。
修改前(68fe1788518e7edbf912638dcc421e17b0c9bc31):即便源 Todo 的最新绑定 Turn 已完成写回与配额扣减,只要源 Todo 仍保持 open 且持有重叠的 active hard lease,调用方直接执行 loopx todo claim 就会因 write_scope_conflict 被拒绝,必须额外手动释放旧租约。修改后(cc663dc44034daba56905cbde00f5db6de9e7cfc):由默认 todo claim(无显式 lease key/version 时)携带 allow_settled_execution_switch=True,经 verifySettledExecutionSwitch 核验源 Turn 结算后在同一权威 CAS 事务中原子释放源租约并获取目标租约,但当前实现存在 3 项 P1 正确性/兼容性缺陷。
可观测结果:串行正常已结算切换、多冲突源拒绝与 lost-ack 恢复在 File/SQLite 契约测试(421 TS tests passed)与 272 项 Python 测试通过;但独立对抗复现确认:(1)当源 Turn 在 semantic_closeout 缺失有效 vision_checkpoint(satisfied=false、replay_phase="open")时,claimLocalCoordinationTodo 仍返回 applied 并错误释放源租约;(2)通过默认 CLI 双标志重放升级前普通 claim 收据会误报 coordination_operation_identity_mismatch;(3)rollout 日志核验与权威 CAS 提交之间缺少并发栅栏。
非目标边界:本 PR 不改动显式传入 --task-lease-idempotency-key 或 --task-lease-expected-version 时的校验路径,不扩展 source_session_v1 / goal_ref 协调租约绑定,也不修改隐式调度选择或已到期租约接管规则。
改动思路 / Approach
在原有单边获取入口 prepareClaimExecution 与 executeCoordinationTodoClaim 上扩展可选切换意图与证明回调,把“最新绑定 source Turn 已结算”的本地读取封装在纯 TS 模块 settled_execution_switch.ts 中,仅在单源同 Agent 同仓库冲突时验证证明并向同一 provider CAS 传入两条 lease_upsert 变更。
当前 PR 边界:将显式切换策略与证明核验保留在协调与结算域既有 owner(claim_execution.ts、todo_claim.ts、settled_execution_switch.ts),Python CLI 与 mutation_api.py / local_authority.py 仅透传布尔开关 allow_settled_execution_switch,不新增手工同步的 ready 状态或第二套租约表;但当前 settled_execution_switch.ts 的准入判断未对齐 replay_phase === "settled"、未覆盖跨日志并发,且 todo_claim.ts 兼容分支未同步清理新字段。
具体改动 / Changes
本 diff 覆盖 11 个文件(+764 / -12 行,含新增 settled_execution_switch.ts 及 2 个 TS 测试文件)。因无独立书面 RFC 规范,对照既有结算与租约恢复契约(settlement_readback.ts、todo_claim.ts)评估:HARD-LEASE-ATOMIC-EXECUTION-SWITCH 部分实现(串行原子切换与多源拒止通过,但 vision_checkpoint 闭环门禁与并发栅栏未满足)、PLAIN-CLAIM-REPLAY-COMPAT 未满足(默认 CLI 双标志重放普通 claim 收据失败)。
关键代码讲解
handle_todo_command、mutation_api.py:304,379、local_authority.py:166,195-199、local_authority_runtime.ts:1062-1129:在未显式传入--task-lease-idempotency-key/--task-lease-expected-version的同 Actortodo claim上同步启用manage_execution=True与allow_settled_execution_switch=True,非 v2 请求或非法布尔类型均被拒绝。verifySettledExecutionSwitch:经latestBoundSourceTurn取最新绑定turn_instance_id,调用readQuotaSettlementFromSnapshot核验found === true、settlementOk、progress.state === "settled"与replan_obligation_id == null,但遗漏了readback.replay_phase === "settled"(导致未过vision_checkpoint的 Turn 被错判为可释放)。prepareClaimExecution:仅在write_scope_conflict、conflict_indexes.length === 1、同 owner/active/effective、同非空task_repository(大小写不敏感)时校验switchProof并生成releasedTaskLeaseRecord(sourceLease, input.now);任何多源、外人租约、不同仓库或证明字段不匹配均抛出ClaimExecutionSwitchRejected。executeCoordinationTodoClaim、todo_claim.ts:759-805:把releasedSourceLease与目标lease放入同一mutations数组做 CAS 提交,但在recoverProof第 524-525 行的老旧普通claim兼容分支仅删除legacyIntent.manage_execution而未删除legacyIntent.allow_settled_execution_switch。
对主干的风险 / Risks
在 exact head cc663dc44034daba56905cbde00f5db6de9e7cfc 上确认以下 3 项 P1 阻断缺陷 与合并冲突:
- [P1 / Blocking]
verifySettledExecutionSwitch遗漏replay_phase === "settled"/vision_checkpoint校验(settled_execution_switch.ts:99-110):当源 Turn 在delivery_boundary="semantic_closeout"下提交了vision_checkpoint: {required: true, satisfied: false}时,实测readback.progress.state == "settled"而readback.replay_phase == "open";但claimLocalCoordinationTodo(..., allow_settled_execution_switch: true)仍返回status: "applied", execution_switch: true并释放了未闭环源 Todo 的 hard lease。最小修复:要求readback.replay_phase === "settled"并补充vision_checkpoint.satisfied === false负例测试。 - [P1 / Blocking] 默认 CLI 双标志重放升级前普通
claim收据必定失败(todo_claim.ts:522-535):todo.py:687-690默认同时传manage_execution=True与allow_settled_execution_switch=True;todo_claim.ts:524-525在回退manage_execution: false时仅删除legacyIntent.manage_execution而未删除legacyIntent.allow_settled_execution_switch。实测对既有的manage_execution=false收据以双标志重放直接返回failed coordination_operation_identity_mismatch(仅传manage_execution=true时才通过replayed)。最小修复:在todo_claim.ts:525同时delete legacyIntent.allow_settled_execution_switch;,并在managed_claim_execution_conformance.ts补齐双标志重放测试。 - [P1 / Blocking] rollout 日志结算校验与协调域 CAS 提交之间缺少跨文件并发栅栏(
settled_execution_switch.ts:49-93、todo_claim.ts:795-820):store.commitAuthority仅对协调存储头做expected_provider_revisionCAS,无法感知验证后提交前并发写入rollout-event-log.jsonl的新 source Turn 绑定,仍会让旧证明释放刚启动新 Turn 的源租约。此外 PR 当前与main在loopx/cli_commands/todo.py存在合并冲突(mergeable=CONFLICTING),且作者后续开启的 #8941 已推进同类修复;待统一修复并发栅栏、上述两项 P1 并变基后再复审。
语义与 CI 对齐
- 复用既有硬租约生命周期与结算读模型;新引入的
todo_settled_execution_switch_proof_v0与settled_execution_switch_*错误码通过semantic-vocabulary-drift-smoke.py(premerge quick通过),但todo_claim.ts兼容分支行为与 CLI 默认双标志发生实际冲突。 - 本地与 CI 验证明细(exact head
cc663dc44034daba56905cbde00f5db6de9e7cfc):- PASS
ruff check(4 个 Python 修改文件):All checks passed!;mypy:17 个源文件 0 错误;npm run typecheck:control-plane:0 错误。 - PASS 定向 TS 测试(
settled_execution_switch.test.ts、local_settled_execution_switch.test.ts、managed_claim_execution_conformance.test.ts、file_authority_store.test.ts、sqlite_authority_store.test.ts):421 passed(0 failed)。 - PASS 定向 Python 测试(6 个 CLI/协调单测文件):
272 passed in 53.57s;canary premerge --tier quick:ok=true, selected=3, failures=0;loopx check --scan-path(11 文件):errors=0, warnings=0。 - FAIL(独立对抗复现):Bug 1(
vision_checkpoint.satisfied=false错误返回applied/execution_switch: true)与 Bug 2(双标志重放普通claim收据返回failed coordination_operation_identity_mismatch)均稳定复现。 - DIAGNOSTIC(基线既有失败):
tests/control_plane_ts/content_digest_single_owner.test.ts的 2 项失败(compaction_memory.ts:29与settlement_readback.ts)在干净baseRefOid68fe1788518e上以完全相同的15 pass / 2 fail复现,非 PR #8927 引入(远端typescript-core (3/3)失败即为此因)。
- PASS
我的整体评价 / Verdict
- Long-horizon 影响:
regression— 未满足vision_checkpoint的源 Turn 或在核验与提交间隙新绑定的源 Turn 仍可能被提前释放 hard lease,同时打破升级前普通claim收据从默认 CLI 的幂等重放。 - User-experience 影响:
not_applicable— CLI 与协调后台契约变更,未改动桌面或网页界面,visual_review为not_applicable。 - 可观测语义 / 复用 / 词表:
observable_semantics为unintended_drift(上述 P1 门禁漏放与旧收据重放回归),repository_reuse为reused,default_off_isolation为isolated(allow_settled_execution_switch仅对默认显式同 Actor 自领取生效,显式 lease key/version 保持隔离),authority_semantics为aligned,semantic_alignment为aligned(candidate_decision="reuse_existing"),code_volume为necessary(compatibility_assessment.decision="retain"),change_proportionality为proportionate(architecture_assessment.decision="retain")。
整体设计复用既有租约与结算边界是合理的,但 exact head cc663dc44034daba56905cbde00f5db6de9e7cfc 存在上述 3 项 P1 阻断缺陷及 main 合并冲突,予以 REQUEST_CHANGES。
English verdict: REQUEST_CHANGES at exact head cc663dc; confirmed 3 blocking P1 issues—verifySettledExecutionSwitch ignores replay_phase==='settled' allowing unsatisfied vision_checkpoint Turns to release active hard leases, todo_claim.ts legacy plain-claim replay omits deleting allow_settled_execution_switch causing coordination_operation_identity_mismatch under default CLI flags, and the rollout-log check vs authority CAS lacks concurrency fencing (plus PR conflicts on todo.py; content_digest_single_owner.test.ts 2 failures reproduce identically on clean base 68fe178).
An agent that explicitly moves from one settled open Todo to another can still be blocked by the first Todo's active hard lease when their write scopes overlap. This change lets only an explicit managed
todo claimatomically release that single settled same-agent source lease and acquire the target lease under the same authority CAS.The switch fails closed unless the source is unique, belongs to the same agent and repository, overlaps the target write scope, and its latest bound Turn has complete writeback and quota settlement receipts. Implicit scheduler claims, unsettled or newer Turns, foreign owners, stale lease identities, unrelated repositories, and multiple conflict sources remain rejected. The durable receipt includes the released source identity so replay and lost-ack recovery do not repeat the transition.
Validation:
git diff --checkpassedcontent_digest_single_owner.test.tsfailures reproduce unchanged on cleanmain@68fe1788518e