Repository navigation
refactor(control-plane): apply 3-layer write_scope subtraction convergence - #9256
Conversation
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google · self_reported
Request changes conclusion (author-owned PR; GitHub blocks formal self-review)
动机 / Motivation
受影响调用方与操作者:本变更影响读取 LoopX 决策首屏上下文(quota should-run 与 context-read)的 Agent Host、配置目标白名单(goal_boundary.write_scope)与已审批边界(checkpointed_boundary_authority)的维护者,以及在多 Agent 场景下调用任务租约(task-lease acquire)和自适应子任务分发(adaptive_children)的协同执行方。
改造前后的具体场景:在旧路径中,只要某个 Goal 同时配置了宽泛前缀和大量细粒度子路径,或者每个 Todo 都带有冗长的路径范围列表(required_write_scopes,即每个任务声明的可写路径范围):(1) goal_boundary.write_scope 与 checkpointed_boundary_authority.active_write_scope 会把已被覆盖的子路径和审批列表原样堆入首屏,迫使控制信息挤出首页预算;(2) 每个摘要与动作候选里的 required_write_scopes 不仅膨胀上下文体积,还会让 projection_repair 在 Goal 已覆盖仓库根或任务绑定外部仓库时误触发边界修复阻断,而多 Agent 隔离检查也以路径范围存在与否为前提;(3) 多 Agent 在独立 Git worktree 并行工作时,仅因路径范围重叠就会在 task-lease acquire 阶段被 write_scope_conflict 硬拒绝。改造后,Layer 1 在源头折叠被宽前缀覆盖的本地子路径并将已审批数组延迟到按需 context-read;Layer 2 默认从 agent_todo_summary、selected_todo、capability_gate 与 action_portfolio 移除 required_write_scopes,改为基于 action_kind 与 task_repository 判定隔离与边界修复;Layer 3 退场 write_scope_conflict 硬阻断,将租约互斥收敛到物理 checkout 冲突(workspace_lease_conflict)。
可观测改进:在确切提交 bbbdb3085f53ab0261953361447f70b30c03831a 的本地实测中:fold_write_scope_subpaths 可将包含 ** 与子路径的本地白名单折叠为精简前缀,在剔除冗余本地子路径的同时保留凭证路径与跨仓库绝对路径;prepareInitialOpening 与 progressivePreparationScopes 在保留 active_count 与 inactive_count 计数摘要的前提下将 active_write_scope 与 entries 移出首屏;decideTaskLeaseAcquire 与 admitAdaptiveChildren 允许不同工作目录或不同所有者在重叠 write_scopes 下继续获取租约与分配子任务。
非目标:本 PR 不从 Todo 规范存储或 todo list 显式读取中删除 required_write_scopes;不在 checkpointed_boundary_authority.active_write_scope 与 coordination.write_scope 之间做跨边界折叠;不引入跨 Goal 全局物理文件锁;也不在本 PR 内直接改写待整合 PR #8941。
剩余缺口:在确切头 bbbdb3085f53ab0261953361447f70b30c03831a 仍存在两项阻塞问题:其一,settlement_cli.py 与 workspace_guard.py 仍向 build_delivery_workspace_causality 传入已裁剪掉 required_write_scopes 的 selected_todo 投影,导致同时声明 required_write_scopes 与 same_agent_non_delivery 的任务绕过工作区校验,并使仅声明 required_write_scopes 的任务被错误记为 unknown;其二,本 PR 修改的 docs/reference/required-work-context.md 第 349 至 355 行及第 384 至 388 行仍在指引迁移后从捕获读取已删除的 /selected_todo/required_write_scopes。
改动思路 / Approach
本 PR 采用“源头减法 + 分层所有权收敛”的架构路径,整体沿着既有的配置归一、首屏渐进读、边界修复、结算因果与租约裁决所有者推进,没有另起平行的状态裁剪层或新的外围截断胶水(reusing existing owners configuration.py, progressive_context.ts, projection_repair.py, task_lease_acquire_decision.ts)。
| 层级 | 变更前基线 (7fb1c851...) |
变更后确切头 (bbbdb308...) |
关键边界与实测状态 |
|---|---|---|---|
| Layer 1 源头折叠与延迟 | goal_boundary.write_scope 全量展开子路径;cba.active_write_scope 与 entries 常驻首屏 |
fold_write_scope_subpaths 按 goal_repo 折叠被 **/dir/** 覆盖的本地子路径;prepareInitialOpening 仅在首屏保留计数并将数组延迟到 context-read |
凭证段/后缀与外部绝对路径保持不折叠;withLinkedObservedRemainder 修复多 detail 热复用丢失问题(源读+实测 PASS) |
| Layer 2 默认去投影与守卫简化 | agent_todo_summary、selected_todo、capability_gate、action_portfolio 均默认携带 required_write_scopes |
默认从上述投影移除 required_write_scopes;projection_repair 在覆盖仓库根或绑定 task_repository 时跳过修复并借助 raw_agent_todo_summary 兜底;workspace_guard 改看 action_kind + task_repository |
遗漏消费端:settlement_cli.py:459 与 workspace_guard.py:245 仍喂入精简后的 selected_todo,实测触发 same_agent_non_delivery 绕过与 unknown 降级(CLI 对照 FAIL) |
| Layer 3 租约互斥收敛 | decideTaskLeaseAcquire 与 admitAdaptiveChildren 按重叠路径拒绝(write_scope_conflict);todo claim 附带 thin_claim_overlap_advisories |
收敛为 Todo 所有权 + 同物理 checkout 互斥(workspace_lease_conflict),允许重叠范围并行获取租约;清理 todo.py 冗余通知逻辑(-68 行) |
保留显式 write_scopes 写入与覆盖率函数以兼容历史读取;残留少量未接线变量(CLI 对照 PASS) |
注:上表基于 7fb1c851ade04fd31a21f395f0447ca832d2aeb5 与 bbbdb3085f53ab0261953361447f70b30c03831a 的源码审计(fold_write_scope_subpaths、prepareInitialOpening、build_boundary_projection_repair_hint、selected_todo_projection、quota_rollout_details、observe_goal_delivery_workspace_isolation、decideTaskLeaseAcquire、admitAdaptiveChildren)及受控 CLI 对比探测,表格本身为结构说明而非独立覆盖率证明。
架构与比例评估:就三层减法架构本身而言,把折叠放在配置与边界入口、把延迟读取放在 TypeScript 渐进上下文所有者、把互斥语义收口于租约裁决所有者,同时只在 projection_repair.py 与 task_orchestration_admission.py 保留受控原始查询,实现了不变量、策略与投影的清晰分离,但必须修复 settlement_cli.py 与 workspace_guard.py 消费裁剪后 selected_todo 导致的因果绕过。当前 PR 边界聚焦 Goal 白名单折叠、首屏上下文减负、边界误报消除和租约目录锁收敛,不删除规范存储中的范围声明,也不触碰外部集成 PR #8941。
具体改动 / Changes
本 PR 共变更 58 个文件(+873 / -601 行):生产代码 25 个文件(+470 / -220)、测试与夹具 29 个文件(+344 / -309)、文档 3 个文件(+53 / -70)及示例冒烟脚本 1 个文件(+6 / -2)。主要热点集中在 loopx/control_plane/coordination/configuration.py(+195/-7)、loopx/control_plane/quota/progressive_context.ts(+61/-45)、loopx/cli_commands/todo.py(+0/-68)、loopx/control_plane/quota/projection_repair.py(+62/-1)、loopx/control_plane/quota/turn_envelope.ts(+21/-24)及 loopx/control_plane/quota/task_orchestration_admission.py(+33/-1)。
规范依据(spec_basis):no_spec(spec_source: none)。代码库中不存在预先写定本“三层 write_scope 减法收敛”重构的独立 RFC;docs/reference/canonical-lease-renew.md 与 docs/reference/required-work-context.md 均在本 PR 内与实现一并修改,因此不能作为独立于补丁的前置验收规范,交付判断完全基于 problem_context 与既有运行时不变量(例如 test_non_delivery_policy_cannot_override_repository_write_contract)。
关键代码讲解
fold_write_scope_subpaths(loopx/control_plane/coordination/configuration.py:116-194):在配置与边界投影层去重并折叠已被**、/**或某确定父前缀dir/**覆盖的本地路径(包括解析goal_repo前缀对应的仓库内绝对路径)。关键不变量由_is_sensitive_or_unfoldable(loopx/control_plane/coordination/configuration.py:70-87)保护:含..、~、;、_CREDENTIAL_SCOPE_SEGMENTS(如.ssh、secrets)或_CREDENTIAL_FILE_SUFFIXES(.key/.pem等)的条目直接标记为不可折叠,仓库外绝对路径仅能在同为外部显式dir/**时折叠,且带 glob 元字符的父茎不参与前缀吞并。loopx/boundary_authority.py复用了该函数在active_write_scope内部独立折叠,不与coordination.write_scope交叉折叠,从而保住持久化审批记录。prepareInitialOpening(loopx/control_plane/quota/progressive_context.ts:775-847):重构渐进首屏拆分逻辑,不再依赖scope是否存在才寻找goal_boundary,而是主动检查checkpointed_boundary_authority(校验schema_version === "checkpointed_boundary_authority_v0"及整型计数)。当存在非空active_write_scope或entries时,将checkpointed_boundary_authority展开为轻量标量键留在首屏,并把两个数组指针加入details以供context-read --select按需拉取;配合withLinkedObservedRemainder校验openingSplit.details全集,避免/goal_boundary/write_scope热复用后遗漏未复用的 CBA 数组。build_boundary_projection_repair_hint(loopx/control_plane/quota/projection_repair.py:224-335):在判断required_write_scope_missing_from_goal_boundary修复前,通过_lookup_raw_todo(raw_agent_todo_summary, ...)补回被默认投影裁掉的required_write_scopes与task_repository。当task_repository非空或_goal_boundary_covers_repo_root为真(即边界已包含**、/**、.或goal_repo根)时直接返回None,不再打断正常交付轮次;若边界确实窄于本地子路径(如docs/**vsprivate/**),仍可靠触发boundary_projection_repair。selected_todo_projection(loopx/control_plane/quota/selected_todo_projection.py:10-58):从SELECTED_TODO_COMPACT_FIELDS移除"required_write_scopes",同时保留"continuation_policy"、"task_repository"与"required_capabilities"。这达到了减小selected_todo载荷的目的,但也把“只剩半截写入契约的投影对象”传给了下游仍在调用build_delivery_workspace_causality的settlement_cli.py与workspace_guard.py(见风险节阻塞项)。decideTaskLeaseAcquire(loopx/control_plane/work_items/task_lease_acquire_decision.ts:677-766):移除write_scope_conflict对其他有效租约的阻断分支,仅在workspace !== null && sameLeaseCheckout(workspace, other.write_workspace)时返回conflict/workspace_lease_conflict(同时保留todo_lease_conflict、CASversion_mismatch、lease_repository_mismatch、lease_workspace_repository_mismatch与idempotency_key_reuse校验,并将nextLease.write_scopes仍经comparisonWriteScopes写入以维持现有结构兼容)。
对主干的风险 / Risks
阻塞性发现(Blocking Findings)
-
Blocking / High —
quota_rollout_details与observe_goal_delivery_workspace_isolation消费裁剪后的selected_todo,破坏工作区因果校验与same_agent_non_delivery防绕过不变量- 触发条件与路径:当 Todo 声明了
required_write_scopes(如docs/**),但未设置task_repository且required_capabilities未包含filesystem_write时:selected_todo_projection(loopx/control_plane/quota/selected_todo_projection.py:10-36)移除了required_write_scopes却保留了continuation_policy。loopx/control_plane/quota/settlement_cli.py:445-460(quota_rollout_details)与loopx/control_plane/agents/workspace_guard.py:235-268(observe_goal_delivery_workspace_isolation,由loopx/control_plane/quota/should_run_packet.py:1713调用)直接把该裁剪后的selected_todo传给build_delivery_workspace_causality。
- 实测风险结果:在以
7fb1c851ade04fd31a21f395f0447ca832d2aeb5与bbbdb3085f53ab0261953361447f70b30c03831a对照同一真实夹具的 CLI 探测中:- 越权绕过场景(Todo 同时设置
required_write_scopes=docs/**与continuation_policy=same_agent_non_delivery):基线将quota_should_run事件落盘为delivery_workspace_requirement="required"(declared_repository_or_write_contract),而当前头却翻转为"not_required"(explicit_non_delivery_without_repository_writes),且delivery_workspace_isolation退化为{}。进入loopx/state_refresh.py:1303时因workspace_requirement == "not_required"跳过工作区快照抓取与隔离校验,进入loopx/control_plane/quota/slot_accounting.py:286(仅修复空/unknown)及:487时也跳过修补并允许无工作区直接记账消费,直接击穿了tests/control_plane/test_delivery_workspace_causality.py:70-83与loopx/control_plane/quota/settlement_workspace_causality.ts:244-256所保护的安全不变量。 - 未设策略场景(Todo 仅设置
required_write_scopes=src/**):quota_should_run事件与loopx/state_refresh.py:1451写入runs/index.jsonl的记录均由"required"降级为"unknown"(todo_write_contract_not_explicit)。
- 越权绕过场景(Todo 同时设置
- 最小修复与回归测试:仿照
loopx/control_plane/quota/projection_repair.py:262-269的做法,在裁剪前用完整原始 Todo(如从prepared/agent_todos按todo_id找回原始记录,或提前在should_run_packet.py计算并传递未裁剪字段)驱动quota_rollout_details与observe_goal_delivery_workspace_isolation内的build_delivery_workspace_causality;新增一条集成回归测试,覆盖required_write_scopes=["loopx/**"]+continuation_policy="same_agent_non_delivery"走完quota should-run -> refresh-state -> quota spend-slot仍必须强制要求"required"而不允许绕过。
- 触发条件与路径:当 Todo 声明了
-
Blocking / Medium —
docs/reference/required-work-context.md与当前捕获格式自相矛盾,误导迁移场景读取不存在的指针- 位置与触发:本 PR 修改了
docs/reference/required-work-context.md:211-214与loopx/control_plane/quota/turn_envelope.ts:1333-1383、loopx/control_plane/quota/selected_todo_projection.py:10-36,明确在捕获的selected_todo及progressivePreparationScopes中删除了/selected_todo/required_write_scopes。但同一文件docs/reference/required-work-context.md:349-355(英文)与L384-L388(中文)仍明文指示:“Large Goal and selected Todo write scope lists are available from the same capture at/goal_boundary/write_scopeand/selected_todo/required_write_scopes” / “可从同一捕获按/goal_boundary/write_scope和/selected_todo/required_write_scopes读取”。 - 最小修复:同步更新该中英文两段,删除已失效的
/selected_todo/required_write_scopes捕获指针,明确仅/goal_boundary/write_scope位于捕获中,若工作树迁移需核对 Todo 范围则于迁移后通过todo list读取(与第 211–214 行保持一致)。
- 位置与触发:本 PR 修改了
非阻塞观察(Non-Blocking / Follow-up)
selectedWorkLaunchBasis遗失写入范围变化敏感度(loopx/control_plane/quota/turn_envelope.ts:910-918):selectedWorkLaunchBasis仍对selected.required_write_scopes ?? []计算摘要,而在selected_todo省略该字段后该项恒为[];若两次探测间仅修改了 Todo 的required_write_scopes,loopx/cli_commands/turn_decision.py:443不会触发current_turn_work_changed重试。若仍希望在宿主启动门保护范围变更,需基于原始 Todo 字段或显式确认其已退场。- 可顺手清理的死代码(Follow-up):
loopx/control_plane/quota/adaptive_children.ts:10留有未使用的evaluateQuotaSchedulingWriteScopesOverlap导入;loopx/capabilities/explore/todo_branch_plan.py:438,519留有只写不读的selected_scopes;task_lease_acquire.ts、claim_execution.ts、todo_claim.ts及cli_commands/task_lease.py仍保留永远为空的integration_overlap_advisories透传分支;resume_planning.ts:38,44仍投影required_write_scopes(靠下游quota_summary.py剥离)。此外loopx/configure_goal.py:704在参数解析阶段不带goal_repo调用一次normalize_goal_write_scope,随后在:1279-1298再带goal_repo二次折叠,功能无错但可进一步合并。 - 范围适配、权限边界与隔离评估(
scope_fit/authority_semantics/default_off_isolation/domain_neutrality/guidance_vs_obligation):本 PR 全部改动均挂载于configure-goal、quota should-run、context-read、task-lease acquire等真实生产入口,无孤立仅测试函数;公共协议命名(task_lease_v0、workspace_lease_conflict、quota_selected_todo_v0、delivery_workspace_causality_v0)未伪造跨 Goal 全局锁或独立多 Agent 选举语义(authority_semantics: aligned);--context-delivery off对 Page-0 CBA 延迟路径保持隔离(default_off_isolation: isolated),但 Layer 2 移除required_write_scopes属于全局默认变更(已导致上述结算因果缺口);规则均为类型化字段与路径归一化驱动(非子串匹配),文案保持领域中性(domain_neutrality),提示与强制动作的边界清晰(guidance_vs_obligation)。
语义与 CI 对齐
- 词汇与契约对齐(
semantic_alignment):本 PR 复用现有词汇workspace_lease_conflict替代退场的write_scope_conflict,examples/semantic-vocabulary-drift-smoke.py本地执行 PASS,没有新增未注册状态词汇。然而,由于quota_selected_todo_v0在默认投影中移除了required_write_scopes,导致同一契约链上的下游消费者delivery_workspace_causality_v0(settlement_cli.py:459、workspace_guard.py:245)和文档契约(docs/reference/required-work-context.md:352,386)出现 契约破坏(violated),需按阻塞项 1 与 2 修复后重跑上述对照探测与tests/control_plane/test_delivery_workspace_causality.py、tests/control_plane/test_quota_settlement_cli.py验证。 - CI 策略与 Pre-merge 状态(
wait_for_ci: false):按仓库与评审策略不等待或轮询远端 GitHub Actions CI。本地uv run --extra test loopx ... canary premerge --from-git-diff --git-diff-base origin/main执行 4 项直接检查 + 10 项 catalog canaries + 8 项 risk-profile smokes + 58 文件公私边界扫描全部 PASS(0 失败,0 私密泄露);唯一令canary premerge整体返回ok: false的原因是远端origin/main已推进到bbd26838366cf03b371f5a2308833e03d1e1229b,使先前基于7fb1c851ade04fd31a21f395f0447ca832d2aeb5签发的 CQR 收据cqr_63d728bce1633b3a6d77状态变为stale_receipt(修复阻塞项后应针对最新基底重新 prepare 并签发 CQR)。
本地验证矩阵(validation_matrix)
| 用例 / 检查 | 命令与范围 | 状态 | 结果摘要 | 必须 |
|---|---|---|---|---|
changed_invariant_positive |
受控基线与当前头 loopx quota should-run / task-lease acquire CLI 对照探测 + node --experimental-strip-types -e(decideTaskLeaseAcquire 与 admitAdaptiveChildren) |
PASS | Layer 1 将 4 项折叠为 ["**", "secrets/key.pem"];Layer 3 在重叠 docs/** vs docs/a.md 下由基线 write_scope_conflict(rc=1)变为 ok: true(rc=0),admitAdaptiveChildren 准入子任务 |
是 |
material_negative_or_failure |
同上对照探测中 todo_docs(required_write_scopes=docs/** + continuation_policy=same_agent_non_delivery)与 todo_src(仅 required_write_scopes=src/**)经 quota should-run |
FAIL | 基线两者均写入 delivery_workspace_requirement="required",头部错误翻转为 "not_required"(explicit_non_delivery_without_repository_writes)与 "unknown",且 delivery_workspace_isolation 被清空 |
是 |
repository_required_checks (TypeScript + MJS) |
npm run typecheck:control-plane;node --experimental-strip-types --test tests/pi_goal_loop_runtime.test.mjs ...(383 项)+ --experimental-sqlite 运行相关 13 个 TS 套件(214 项) |
PASS | typecheck 通过;382 pass / 0 fail / 1 skip(PostgreSQL 未配置);额外 214 pass / 0 fail / 0 skip |
是 |
repository_required_checks (Python 静态与测试) |
ruff check(变更 .py);mypy(17 配置源文件);pytest -n auto(13 个变更测试文件 737 项)+ pytest(10 个变更与因果测试文件 614 项) |
PASS | ruff 与 mypy 均 0 错误;737 passed;613 passed, 1 skipped(test_cli_output_budget.py:2013 因临时目录长度跳过 depth-12 布局) |
是 |
repository_required_checks (Canary Premerge & 公私边界) |
loopx canary premerge --from-git-diff --git-diff-base origin/main + rg 扫描本地路径前缀 |
FAIL (CQR stale) | 直接检查 6/6、Catalog 10/10、Risk Profile 8/8、公私边界 58 文件、RFC 双语检查全部 PASS;仅因 origin/main 前移导致 cqr_63d728bce1633b3a6d77 为 stale_receipt |
是 |
诊断对照:content_digest_single_owner.test.ts |
node --no-warnings --experimental-sqlite --experimental-strip-types --test tests/control_plane_ts/content_digest_single_owner.test.ts |
FAIL (pre_existing_unrelated) |
16 pass / 1 fail(:911:1 缺失 execution_loss_closeout_record.ts);已验证 7fb1c851... 基线同样引入 BARE_SHA256_PATTERN 且未进固定名单,与本 PR 无因果关系 |
否 |
我的整体评价 / Verdict
-
结果影响判断(
problem_context.outcome_impact):long_horizon:regression(退化)。尽管 Layer 1 折叠/首屏减重与 Layer 3 退场目录重叠冲突有效减少了上下文噪声和误阻断,但 Layer 2 在裁剪selected_todo.required_write_scopes时未同步更新settlement_cli.py:459与workspace_guard.py:245,使得包含same_agent_non_delivery与required_write_scopes的 Todo 在长程执行链(quota should-run -> refresh-state -> spend-slot)上跳过工作区抓拍与隔离校验并可完成记账消费,属于确定的跨回合约束绕过。user_experience:regression(退化)。一方面docs/reference/required-work-context.md:349-355,384-388在工作树迁移指引中仍指向已不存在的/selected_todo/required_write_scopes,导致依赖文档排查范围的交互回合受阻;另一方面仅声明required_write_scopes的 Todo 在quota_should_run与运行记录中的诊断因果信息退化为unknown(todo_write_contract_not_explicit)。user_experience.visual_review:not_applicable(unverified_scope: none)。本 PR 58 个变更文件仅覆盖控制面 TS/Python 运行时、CLI 投影、参考文档与测试夹具,未触及任何前端/仪表盘视图渲染,因此视觉人工检查不适用且无未验证视觉范围(unverified_scope: none)。
-
可观测语义与体量评估(
observable_semantics/code_volume/change_proportionality):通过向7fb1c851ade04fd31a21f395f0447ca832d2aeb5与bbbdb3085f53ab0261953361447f70b30c03831a提交完全相同的测试夹具并经真实loopxCLI 执行对照,observable_semantics判定为unintended_drift:Layer 1 折叠与 Layer 3 租约行为按预期演进,但 Layer 2 对selected_todo的字段裁剪破坏了delivery_workspace_causality_v0消费者对“非交付策略不能覆盖显式写范围”的不变量保证。整体变更体量(58 文件+873/-601)与重构目标是相称的(code_volume: necessary,兼容性决策为在主体契约retain历史todo list与task_orchestration_admission原始读取的同时,将adaptive_children.ts未使用导入等死代码清理列为follow_up;change_proportionality: proportionate,architecture_assessment: retain)。权限语义(authority_semantics: aligned)及渐进读开关隔离(default_off_isolation: isolated)均成立。 -
词汇与合规归类:本 PR 复用既有词汇(
reuse_existing,semantic-vocabulary-drift-smoke.pyPASS),未创造平行协议名,但因消费者断链构成契约违规(semantic_alignment: violated);修复settlement_cli.py、workspace_guard.py与docs/reference/required-work-context.md,补齐same_agent_non_delivery + required_write_scopes回归测试并针对最新origin/main重新刷新 CQR 收据后,即可重新发起 exact-head 复审。当前确切头bbbdb3085f53ab0261953361447f70b30c03831a未达到合入标准。
English verdict: REQUEST_CHANGES — Fix the build_delivery_workspace_causality bypass/downgrade in settlement_cli.py and workspace_guard.py (which read selected_todo without required_write_scopes) and remove the stale /selected_todo/required_write_scopes pointer from docs/reference/required-work-context.md.
bbbdb30 to
a5c3ab6
Compare
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Request changes conclusion (author-owned PR; GitHub blocks formal self-review)
动机 / Motivation
分配 Goal 工作的维护者需要压缩首读内容,同时保留已有写入范围的实际含义。 基线直接把既有的精确范围与 glob 传给同一个 typed coverage owner。 File 和 SQLite 的正常 CLI 读取显示,已声明的 plans 与 plans/** 在当前头被折为单独的 plans/**。现有覆盖判断允许前者覆盖字面 plans,但后者只能匹配带斜杠的路径。需要精确 plans 的同一 Todo 因此从 normal_run 变为 boundary_projection_repair。 当前候选在配置、CBA 和 incoming Goal boundary 组合处折叠 scope,然后让原 coverage 走压缩后的值。 本轮仅验证源码 CLI 和隔离状态,不执行跨主机资源迁移、远端 CI 或合并。
改动思路 / Approach
三处改动分别处理 scope 集合、选中 Todo 展示、租约冲突。保留 scope 投影和执行资格之间的区分。 折叠前后,既有 matcher 对所有已授权的普通路径应给出同一结果。按已验证工作树组织租约属于单独的显式行为改动。 以实际规范化后的 matcher 判定包含关系,避免维护一个只按字符串前缀猜测覆盖的语义。
具体改动 / Changes
逐项检查当前头 a5c3ab6 和 merge base d380526,62 个文件,+1165/-619。配置和 CBA 折叠、渐进首读、Todo 展示字段、现有收尾和租约行为分别核对。范围压减应通过内容同义,而租约规则变更需按新说明验收。 评审依据为 d380526。 目标规范
关键代码讲解
_prefix_covers把仅名称与带斜杠的后代集合理解为同一覆盖。 折叠_registry_boundary_projection将失真的列表直接交给正常 scope 观察。 投影schedulingWriteScopeAllowed的既有 fnmatch 保留实际斜杠语义。工作树 lease 冲突是另一决策。 覆盖 · 租约scope-language-parity当前失效。workspace-causality已增加经原 CLI 作用的回归。
对主干的风险 / Risks
[P2] 折叠移除了目录自身的精确写入范围。 File 和 SQLite 的正常 CLI 读取显示,已声明的 plans 与 plans/** 在当前头被折为单独的 plans/**。现有覆盖判断允许前者覆盖字面 plans,但后者只能匹配带斜杠的路径。需要精确 plans 的同一 Todo 因此从 normal_run 变为 boundary_projection_repair。 删除候选 scope 前,复用已有语义覆盖规则证明被保留模式覆盖它。至少保留父目录的精确授权项,并加上基线/当前头两个存储的正常 CLI 回归。 两端每个案例均未消耗业务额度。该回归阻塞已正常工作的任务。
子路径 plans/draft.md 在两个修订和两个存储都可推进;未覆盖的 elsewhere/draft.md 均继续报告正常范围缺口。 当前补丁为原 scope-only 工作区因果路径补了回归测试,涵盖非交付策略、外部工作区拒绝及正常结算。新测与变更前的精确 scope 失败是独立路径。 独立运行 Python(538 passed)、TypeScript(359 通过,1 跳过),类型检查和 Ruff 通过。预合并 6 项直接检查、19 项选中检查通过。 未运行真实 PostgreSQL、桌面安装或远端 CI。预合并资格状态为 quality_receipt_missing。
我的整体评价 / Verdict
请求修改。三处改动分别处理 scope 集合、选中 Todo 展示、租约冲突。保留 scope 投影和执行资格之间的区分。 折叠前后,既有 matcher 对所有已授权的普通路径应给出同一结果。按已验证工作树组织租约属于单独的显式行为改动。 现有 coverage 决策仍为权威,当前压缩后的列表改变了它收到的授权集合。 保留上次评审关注的工作区因果验证,再修正折叠的覆盖判断。 变更位于 CLI 和技术参考。
English verdict: REQUEST_CHANGES at a5c3ab6. Preserve explicit directory-root grants. A descendant glob alone cannot satisfy the original literal scope, and both File and SQLite now incorrectly route that Todo to boundary repair.
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google · self_reported
Request changes conclusion (author-owned PR; GitHub blocks formal self-review)
针对 PR #9256 精确提交 a5c3ab6d3d32a9f724572a69d0180bb64b477ced(基于 d38052695c2c8a2e67cdb2c1eb6f4c6651eabd4d)的独立代码审查与本地实测已完成。虽然该提交明确修复了前一轮评审意见中的结算因果丢失与文档失效指针问题,且 Layer 1(路径折叠、CBA 延后与多细节热复用)与 Layer 3(同工作区独占与告警胶水清理)整体成立,但独立验证发现两处影响跨轮交付与安全门控的 P1 阻塞回归:build_agent_workspace_guard 移除了 required_write_scopes 隔离触发导致 quota should-run 与 refresh-state 自相矛盾,以及 selectedWorkLaunchBasis 读取已被裁减的 selected_todo.required_write_scopes 导致原生启动防漂移检查在 tests/control_plane/test_host_current_admission.py 4 个 write_scope 用例全部失败。
动机 / Motivation
当目标(Goal)配置了上百条局部路径白名单、历史检查点边界授权(CBA)条目以及带 required_write_scopes 的待办任务(Todo)时,执行前置检查的协调调度器(quota should-run)、首屏渐进上下文读取器(context-read)、跨轮工作区护栏(build_agent_workspace_guard)、以及原生 Turn 启动复核器(turn_decision / selectedWorkLaunchBasis)都会直接读取或依赖这些写作用域契约。
此前主干依赖首屏截断与 required_write_scopes 默认全量投影,导致边界清单和摘要在多边界 Goal 中膨胀到数百 KB 并在 task_lease 认领时因路径重叠误报冲突;本次收敛改为在配置与边界投影层折叠冗余子路径、将 cba.active_write_scope 移出第 0 页并改为按需读取、把 required_write_scopes 从摘要默认投影中减去、并把租约互斥收口到同一工作区检出(workspace_lease_conflict)。然而在实际运行中,虽然此前审查指出的结算因果读取和文档指针问题已在 a5c3ab6d3d 修复,实测仍有两处核心链路因字段被减去后未同步接入原始写契约而退化:同一多 Agent Git 仓库场景下 quota should-run --begin-turn 对仅声明 required_write_scopes 且 action_kind=validate 的 Todo 放行 normal_run(workspace_guard=null),随后在 todo complete 后执行 refresh-state 时却因缺少独立 worktree 被拒;同时规划期到启动期之间若通过 todo update --required-write-scope 修改写作用域,启动复核的 selectedWorkLaunchBasis 仍读取被置空的 selected.required_write_scopes,导致 test_host_current_admission.py 全部 4 个 write_scope 用例未能拦截变更并直接放行启动。
验证结果表明,Layer 1 路径折叠、CBA 首屏延后与多细节指针热复用、Layer 2 quota_rollout_details / observe_goal_delivery_workspace_isolation 原始写契约回溯,以及 Layer 3 同工作区租约互斥和文档指针迁移均可在目标用例中正常工作并显著缩减首屏体积;但在当前提交 a5c3ab6d3d32a9f724572a69d0180bb64b477ced 上,build_agent_workspace_guard 的隔离判定退化与 selectedWorkLaunchBasis 的写作用域漂移盲区仍会导致跨轮交付卡死和陈旧工作范围越权启动。
边界与非目标:本 PR 不改动原生 todo list 与底层持久化写契约中 required_write_scopes 的校验和存储语义,不改变 PostgreSQL 权威存储架构,也不强行重写下游能力模块(如 explore 分支规划器)内部仍合法读取原始 required_write_scopes 的逻辑,同时不顺带修改历史书籍章节或与本 PR 无关的基准脚本。
改动思路 / Approach
本 PR 采用“源头减法收敛”替代首屏字符串截断,将写作用域管理拆成三个层次推进:
- Layer 1(边界去重与 CBA 首屏延后):在配置写入与边界组装入口(
loopx/control_plane/coordination/configuration.py、loopx/configure_goal.py、loopx/control_plane/quota/goal_boundary.py、loopx/boundary_authority.py)通过fold_write_scope_subpaths折叠被**、/**或dir/**覆盖的子路径,同时排除外部绝对路径跨仓错误折叠以及.ssh/密钥等敏感片段;在loopx/control_plane/quota/turn_envelope.ts和loopx/control_plane/quota/progressive_context.ts将goal_boundary.checkpointed_boundary_authority.active_write_scope移至按需context-read,并用openingSplit.details修复热复用多细节指针时的遗漏问题。 - Layer 2(摘要字段默认关闭与契约回溯):把
required_write_scopes从context_projection.ts、quota_summary.py、selected_todo_projection.py、action_portfolio.ts与默认planning_inventory.ts投影中移出;通过selected_todo_projection.py新增的lookup_raw_todo/resolve_selected_todo_write_contract为observe_goal_delivery_workspace_isolation、settlement_cli.py(quota_rollout_details与心跳结算对账)和projection_repair.py(通过lookup_raw_todo)恢复完整写契约。但在同一层的消费边界上,本 PR 未将相同的原始写契约解析同步接入build_agent_workspace_guard与turn_envelope.ts:selectedWorkLaunchBasis,反而改写了_peer_work_requires_isolated_workspace判定与对应单元测试,引发了跨调用方契约断裂。 - Layer 3(租约互斥收口与胶水拆除):
task_lease_acquire_decision.ts/task_lease_acquire.ts将并发租约互斥从按路径交集比对收口为同一检出工作区互斥(workspace_lease_conflict),同步拆除todo.py中 68 行内联冲突告警拼接并对齐参考文档。
flowchart LR
subgraph L1["Layer 1 源头折叠与按需读取 (已验证)"]
C1["coordination.write_scope / CBA"] --> F["fold_write_scope_subpaths"]
F --> P0["Page 0 保留 compact summary"]
F --> CR["context-read 按需读取 active_write_scope"]
end
subgraph L2["Layer 2 默认减法投影与调用方断裂 (含 P1 回归)"]
RAW["原始 agent_todos (含 required_write_scopes)"] --> COMP["selected_todo 默认省略 required_write_scopes"]
RAW --> RES["resolve_selected_todo_write_contract"]
RES --> OBS["observe_goal_delivery_workspace_isolation & settlement_cli -> required (正常)"]
COMP --> WG["build_agent_workspace_guard (未回溯写契约 -> 误放行 normal_run)"]
OBS --> RS["refresh-state (要求独立 worktree -> 报错阻塞)"]
COMP --> LB["turn_envelope.selectedWorkLaunchBasis (读到 [] -> 漏检 write_scope 修改)"]
end
(注:上图为基于 exact head a5c3ab6d3d32a9f724572a69d0180bb64b477ced 源码关系绘制的示意流图,未单独做图形渲染校验,相关运行结论以前述及下文实测结果为准。)
架构边界评估与取舍:三层减法架构本身边界清晰且符合按源头减法收敛方向:Layer 1 fold_write_scope_subpaths(策略归并)与 normalize_required_write_scopes 因 Goal 通配符与 Todo 相对路径词表不同而分离合理,progressive_context.ts 与 turn_envelope.ts 将 CBA 活跃作用域改为按需 context-read 指针并修复 withLinkedObservedRemainder 多详情复用亦属低成本纯投影减法;Layer 2 的失败不在于方向本身,而在于减法后仅修复了 observe_goal_delivery_workspace_isolation 与结算回放路径,遗漏了同一不变式链路上的 build_agent_workspace_guard 和 selectedWorkLaunchBasis(决策不变量调用方);Layer 3 将 task_lease 硬互斥收口为工作区检出独占并清理 -68 行告警拼接属正向减法。因此必须在当前 PR 边界内补齐两处决策调用方对原始写契约摘要的接入,而不是引入新的投影字段。
当前 PR 边界判定:当前 PR 已覆盖 Layer 1 路径折叠与 CBA 延后读取、Layer 2 摘要投影减法及结算因果回溯、Layer 3 task_lease 同工作区互斥与 -68 行胶水清理及文档同步;但在放行合并前,本 PR 必须补齐两项同一边界内的阻塞修复:build_agent_workspace_guard 接入 resolve_selected_todo_write_contract 并恢复 required_write_scopes 隔离门控,以及 selectedWorkLaunchBasis 在规划与启动复核两侧同步纳入原始写作用域摘要,确保 tests/control_plane/test_host_current_admission.py 全部参数化用例恢复通过。至于 should_run.py 传入 raw_agent_todo_summary 时未回退到 project_asset.agent_todos、work_requirements.ts 对裸仓库根路径的处理差异、todo_branch_plan.py 死变量与残余 integration_overlap_advisories 空传递透传,均可在合并后作为独立小清理跟进。
具体改动 / Changes
本次 exact head a5c3ab6d3d32a9f724572a69d0180bb64b477ced 相对于 d38052695c2c8a2e67cdb2c1eb6f4c6651eabd4d 的变更分类统计如下:
- 生产代码(production):29 个文件,+576 / -228 行;热点集中在
loopx/control_plane/coordination/configuration.py(+195/-7)、loopx/control_plane/quota/progressive_context.ts(+61/-45)、loopx/control_plane/quota/selected_todo_projection.py(+82/-1)、loopx/cli_commands/todo.py(+0/-68)、loopx/control_plane/quota/projection_repair.py(+48/-1)、loopx/control_plane/quota/turn_envelope.ts(+21/-24)与loopx/control_plane/quota/task_orchestration_admission.py(+33/-1)。 - 测试与示例(tests_or_fixtures):30 个文件(含 1 个 smoke),+527 / -311 行。
- 公开文档(docs):3 个文件(
docs/reference/canonical-lease-renew.md、docs/reference/required-work-context.md、loopx/pi_goal_mode/README.md),+62 / -80 行。 - 总计:62 个文件,+1,165 / -619 行。
前轮评审闭环核验(对比 bbbdb3085f 上的 #pullrequestreview-6011450700):
- 已解决 — 结算因果丢失:
settlement_cli.py(reconcile_existing_heartbeat_receipt与quota_rollout_details)与quota.py/quota_should_run.py已补入status_payload与resolve_selected_todo_write_contract;test_required_write_scopes_preserves_causality_and_workspace_proof_end_to_end与独立 SQLitehard_lease重放实测均正确返回requirement="required"。 - 已解决 — 文档失效指针:
docs/reference/required-work-context.md第 349–355 行及 384–388 行已清除/selected_todo/required_write_scopes,改为/goal_boundary/write_scope与todo list。 - 规范基线说明:经核查当前仓库对应表面,本次 3 层减法收敛无独立书面规范或已接受 RFC 逐条映射(
no_spec,spec_source: none),以现有主干运行契约、不变量及控制面测试作为验收依据。
关键代码讲解
-
fold_write_scope_subpaths(loopx/control_plane/coordination/configuration.py:116)
负责在持久化与边界构建前折叠重复及被宽泛前缀覆盖的write_scope。函数先规范化斜杠与./前缀、识别敏感路径(如.ssh、.key)及跨仓外部绝对路径(_is_sensitive_or_unfoldable),再将库内路径映射为相对表达(_to_repo_relative);仅当同为外部绝对路径且父前缀显式以/**结尾并覆盖子路径时才折叠外部条目,库内则由**/dir/**归并子路径并保留敏感条目与原始拼写顺序。调用证据覆盖configure_goal.py、goal_boundary.py与boundary_authority.py;其中当write_scope同时含裸/repo根路径时_to_repo_relative返回**,与 TS 侧work_requirements.ts仅剥离prefix + "/"存在轻微边界差异(非阻塞)。 -
resolve_selected_todo_write_contract(loopx/control_plane/quota/selected_todo_projection.py:203)
Layer 2 修复结算与隔离观测丢失写契约的核心辅助函数。输入紧凑版selected_todo与可变长原始agent_todos摘要序列;当selected_todo缺少required_write_scopes时,调用lookup_raw_todo(同时扫描分组列表和task_orchestration_authority.candidate_items)按归一化todo_id找回原始条目,仅向拷贝对象补回required_write_scopes、task_repository、required_capabilities与continuation_policy。当前已被observe_goal_delivery_workspace_isolation(workspace_guard.py:250)与settlement_cli.py:469(quota_rollout_details与心跳对账)调用(projection_repair.py:248则直接调用lookup_raw_todo),但尚未被同一文件体系中的build_agent_workspace_guard与 TS 启动检查调用。 -
_peer_work_requires_isolated_workspace与build_agent_workspace_guard(loopx/control_plane/agents/workspace_guard.py:388,462)
负责在quota should-run阶段决定多 Agent Git Goal 下的 Peer 是否必须切换到独立 worktree 才能常规交付。主干基线原本包含if candidate.get("required_write_scopes"): return True;本 PR 将其替换为task_repository与PEER_WRITE_ACTION_KINDS动作前缀判断,且build_agent_workspace_guard未通过resolve_selected_todo_write_contract回查原始required_write_scopes。一旦 Peer Todo 采用action_kind=validate并携带required_write_scopes=["docs/**"],build_agent_workspace_guard返回None放行normal_run,而同文件第 235 行的observe_goal_delivery_workspace_isolation与state_refresh.py仍坚持要求独立 worktree,造成同一轮内前门放行、后门refresh-state报错的阻塞冲突。 -
selectedWorkLaunchBasis(loopx/control_plane/quota/turn_envelope.ts:910)
分别在规划封包(L1546)和原生启动前复核(L849)为选中 Todo 生成工作定义指纹(canonicalHash),供turn_decision.py:443-444校验规划到启动期间任务是否被篡改(current_turn_work_changed)。函数读取selected.required_write_scopes ?? [];由于 Layer 2 从quota_summary.py、context_projection.ts与selected_todo_projection.py移除了required_write_scopes,规划和复核两侧同时读到空数组[],令todo update --required-write-scope的变更在file/sqlite与exec/operation全部 4 条宿主通道上完全逃逸。 -
progressivePreparationScopes(loopx/control_plane/quota/turn_envelope.ts:1333)与prepareInitialOpening/withLinkedObservedRemainder(loopx/control_plane/quota/progressive_context.ts:775)
负责决定哪些高字节写作用域数组从第 0 页剥离为按需读取提示。修改前仅在准备/修复分支触发,且withLinkedObservedRemainder未把全部剩余详情指针统一挂入openingSplit.details,导致热复用/goal_boundary/write_scope时 CBA 数组回流到第 0 页;修改后只要存在非空cba.active_write_scope即将其挂入独立context-read详情指针并保留紧凑计数,已通过多组参数化大作用域/热复用测试校验。
对主干的风险 / Risks
阻塞发现(Findings First)
-
[P1 / Blocking]
build_agent_workspace_guard隔离门控退化与refresh-state自相矛盾- 触发条件:多 Agent Git Goal 下,
action_kind=validate且显式声明required_write_scopes=["docs/**"]的 Todo 在规范主仓库检出目录运行quota should-run --begin-turn。 - 代码路径:
loopx/control_plane/agents/workspace_guard.py:388-414,462-505未接入resolve_selected_todo_write_contract并删除了required_write_scopes判据;对照observe_goal_delivery_workspace_isolation(L235-277)与loopx/state_refresh.py:1293-1356;且tests/control_plane/test_workspace_git_fact_reads.py:129-136改写了原断言。 - 观测结果:实时 SQLite CLI 复现显示
quota should-run --begin-turn放行normal_run(workspace_guard=null)的同时输出peer_independent_worktree_required=true与causality.requirement="required",随后todo complete后执行refresh-state以退出码 1 失败。 - 最小修复:在
build_agent_workspace_guard接入resolve_selected_todo_write_contract并传全project_asset.agent_todos回退,恢复_peer_work_requires_isolated_workspace对required_write_scopes的隔离判定,并恢复test_workspace_git_fact_reads.py对 worktree 解析的校验。
- 触发条件:多 Agent Git Goal 下,
-
[P1 / Blocking]
selectedWorkLaunchBasis因读取空字段而丧失写作用域漂移拦截- 触发条件:Turn 规划生成
selected_work_basis后、宿主启动前执行todo update --required-write-scope docs/evidence/**。 - 代码路径:
loopx/control_plane/quota/turn_envelope.ts:910-918,849,1546依赖selected.required_write_scopes ?? [],而quota_summary.py:42-45,132-135、context_projection.ts:209,252与selected_todo_projection.py:20-23已省略该字段;loopx/cli_commands/turn_decision.py:434-444依赖该指纹拒绝陈旧启动。 - 观测结果:执行
tests/control_plane/test_host_current_admission.py复现 4 failed, 20 passed:write_scope在exec/operation×file/sqlite全部 4 个组合下均未能触发current_turn_work_changed,直接放行启动并写出了模型运行痕迹。 - 最小修复:在不恢复首屏
selected_todo.required_write_scopes原数组的前提下,在规划与启动复核入口补全原始写契约摘要(如required_write_scopes_sha256)并注入selectedWorkLaunchBasis的canonicalHash输入中。
- 触发条件:Turn 规划生成
非阻塞清理建议(P3):loopx/control_plane/quota/should_run.py:349-361 传入 build_boundary_projection_repair_hint 时应补充 project_asset.agent_todos 回退(task_orchestration_admission.py:37-60 的 _raw_write_scopes_by_todo_id 亦可收敛复用 lookup_raw_todo);configuration.py:90-100 与 work_requirements.ts:13-28 对裸 /repo 根目录需对齐;另 todo_branch_plan.py:438,519 死变量 selected_scopes、projection_repair.py:251-254 冗余解包与 task_lease_acquire.ts / todo_claim.ts 空 integration_overlap_advisories 透传可后续清理。
负向路径追踪与测试矩阵
- 正/负向路径对比:正常单/多边界 Goal 在按需加载
cba.active_write_scope、保留quota_rollout_details因果、同一检出workspace_lease_conflict冲突以及独立 worktree 内implement任务均跑通;负向路径下,action_kind=validate携带required_write_scopes在主仓库跳过workspace_guard并卡死于refresh-state,以及规划后更新--required-write-scope静默穿透启动门控,均无自动重试恢复。 - 比例性与作用范围评估:整体 3 层减法逻辑有清晰生产调用点(非纯测试脚手架),
task_lease退回检出独占降低了误拦成本,但 Layer 2 减法在没有同步迁移两个安全不变量读取方的情况下合并会引入直接运行时回归。
| 验证维度 | 命令或路径 | 结果 | 说明 |
|---|---|---|---|
| 实测端到端反例(SQLite) | quota should-run --begin-turn -> todo complete -> refresh-state(validate + required_write_scopes) |
FAIL | 前门放行 normal_run(workspace_guard=null)且声明 peer_independent_worktree_required=true,refresh-state 退出码 1 失败 |
| 原生启动防漂移套件 | uv run --extra test python -m pytest tests/control_plane/test_host_current_admission.py |
FAIL | 4 failed, 20 passed(全部 4 个 write_scope 变更组合失败,task_text/progress_note 通过) |
| 结算因果与工作区验证 | uv run --extra test python -m pytest tests/control_plane/test_quota_settlement_cli.py -k test_required_write_scopes_preserves_causality_and_workspace_proof_end_to_end + 4 个工作区测试文件 |
PASS | 1 + 45 用例全部通过,SQLite 重放反例正确保留 requirement="required" |
| 控制面 TypeScript 类型检查与单元测试 | npm run typecheck:control-plane;变更 TS/MJS 14 套件 + 扩展 43 / 4 / 14 套件 |
PASS | typecheck 通过;14 变更套件 494 pass / 0 fail / 1 skip;43 扩展套件 645 pass / 0 fail / 31 skip;4 选路/上下文套件 83 pass;14 边界/作用域套件 213 pass / 0 fail / 1 skip(PostgreSQL 用例按既定策略跳过) |
| 变更 Python 全量套件扫描 | 15 个变更控制面/租约 pytest 文件(759 用例)及隔离单测复跑 | PASS | 批跑 758 passed、1 失败(test_context_first_read::test_ready_opening_keeps_controls_readable_with_a_large_write_scope[290-12000-0-0-file-True] 因共用 --basetemp 并发清退触发 FileNotFoundError);该单测随后在独立 --basetemp 复跑 PASS(1 passed in 7.70s),另 test_quota_boundary_projection_selection.py 10 passed |
| 静态检查与标准预合并门禁 | ruff check(17 .py)、mypy(17 .py)、canary premerge、核心 smokes(含 peer-agent-runtime-v1-smoke.py 等) |
PASS | 代码静态与 19/19 执行类门禁全部通过(canary premerge 总门禁报告 quality_stale_receipt,因远端 origin/main 已前进至 016791c95a 导致旧 CQR 基准指纹失效) |
语义与 CI 对齐
- 共享契约违规(
semantic_alignment = violated):本 PR 复用既有词表(examples/semantic-vocabulary-drift-smoke.py通过),未引入未登记状态值;但默认删除selected_todo.required_write_scopes改变了quota_summary/selected_todo/context_projection共享输出契约,而未对全部消费方执行契约对齐——直接破坏了turn_envelope.ts:selectedWorkLaunchBasis(current_turn_work_changed语义契约)与workspace_guard.py:_peer_work_requires_isolated_workspace(多 Agent 隔离契约)。需按上述最小修复补齐两处消费方,并重跑uv run --extra test python -m pytest tests/control_plane/test_host_current_admission.py tests/control_plane/test_workspace_git_fact_reads.py。 - CI 策略说明:依据目标仓库当前配置(
wait_for_ci: false,ci_policy: "not_consulted"),本审查未轮询或等待远端 GitHub Actions CI,上述结论全部基于提交a5c3ab6d3d32a9f724572a69d0180bb64b477ced的本地独立复现与验证。
我的整体评价 / Verdict
综合判断 Request changes conclusion (author-owned PR; GitHub blocks formal self-review):PR #9256 在架构方向与减法收敛收益上非常明确(显著压缩 goal_boundary、CBA 第 0 页体积与 todo.py 胶水代码),也确实修复了前轮指出的 quota_rollout_details 因果丢失与文档指针问题;但从控制面长程交付与安全门控来看,仍存在必须修复的回归:
- 交付维度判定:
long_horizon = regression、user_experience = regression(Agent 在主仓库被放行执行后会在refresh-state卡死,且规划后修改required_write_scopes可绕过启动拦截);visual_review = not_applicable(PR #9256 仅修改控制面 TypeScript/Python 核心逻辑、CLI 投影与工作区守卫、参考文档和自动化测试(共 62 个文件),未改动前端 UI 页面、渲染视图或视觉样式,因此不适用页面截图/视觉审查。 未验证范围:无(本次变更不包含任何渲染 UI 表面))。 - 契约与语义评估:
observable_semantics = unintended_drift、default_off_isolation = not_isolated(required_write_scopes默认关闭泄漏到未适配调用方,破坏基线行为)、authority_semantics = aligned(workspace_lease_conflict命名与实际检出作用域独占权限一致,未虚构跨仓库授权)、semantic_alignment = violated(基于复用现有词表但破坏了共享契约消费端)、code_volume = necessary(兼容策略compatibility_assessment = retain)。 - 复核前置条件:作者在修复
build_agent_workspace_guard与selectedWorkLaunchBasis后,须提交新 head 并完成以下本地复验再提请复核:uv run --extra test python -m pytest tests/control_plane/test_host_current_admission.py tests/control_plane/test_workspace_git_fact_reads.py tests/control_plane/test_delivery_workspace.py tests/control_plane/test_quota_settlement_cli.py tests/control_plane/test_context_first_read.py、npm run typecheck:control-plane与loopx canary premerge --from-git-diff --git-diff-base origin/main。 - 残余风险与精确头:当前评审结论严格绑定 exact head
a5c3ab6d3d32a9f724572a69d0180bb64b477ced;此外部分 PostgreSQL 集成用例在本机按既有策略跳过(skipped),以及canary premerge因origin/main已推进需重新刷新 CQR 凭证。
English verdict: REQUEST_CHANGES — resolve the build_agent_workspace_guard write-contract regression and the selectedWorkLaunchBasis write_scope launch-drift regression (4 failing cases in tests/control_plane/test_host_current_admission.py) at a fixed follow-up head before merging.
…gence Layer 1 folds redundant coordination.write_scope and cba.active_write_scope entries using quota.write_scope_coverage semantic proof (preserving exact directory grants like plans alongside plans/**, external/credential boundaries, and --harden compatibility) and moves cba.active_write_scope off page-0 first read into on-demand context-read. Layer 2 stops projecting required_write_scopes into agent_todo_summary, selected_todo, capability_gate, and action_portfolio by default, disables required_write_scope_missing_from_goal_boundary repair when Goal covers repo root or task_repository is bound, and preserves raw Todo write contracts for delivery workspace causality, workspace_guard isolation, and selectedWorkLaunchBasis launch drift checks. Layer 3 stops collecting/checking per-path write_scope_conflict blocks across task_lease_acquire, adaptive_children, coordination, and todo_branch_plan while returning leases to Todo ownership + same-workspace locking, retiring thin claim overlap advisories, and reclaiming page-0 truncation glue. Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
a5c3ab6 to
29def33
Compare
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google · self_reported
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
针对 PR #9256 在确切提交 29def33edc8b560c26c355a18e31a95383fca6a4(基线 b375539271b4cb9f34386a77211a944ce6e05ffe)的独立代码审查与全量本地实测已完成。本轮复审逐项核验了此前三轮审查(6011450700、6011813597 / 行内线程 PRRT_kwDOStEbEs66i218、6011872706)提出的全部阻塞点,以及跨三层收敛的完整基线到当前头变更:所有此前阻塞问题均已在当前确切头修复闭环,未发现新的阻塞性回归或公私边界泄露。
动机 / Motivation
受影响调用方与操作者为读取 quota should-run、context-read 与原生 Turn 启动上下文的 Agent Host、配置目标白名单与已审批边界的 Goal 维护者,以及在多 Agent 独立 Git worktree 中并发领取 task-lease 或分发子任务的协同执行方。
改造前在基线提交 b375539 下,同一 Goal 同时配置通配符与子路径及多条 Todo 写范围时,首屏会堆入冗余边界列表与已审批数组、在覆盖仓库根或绑定外部仓库时误触发边界修复,且不同 Git worktree 仅因写范围重叠即被 write_scope_conflict 阻断或产生冗余冲突提示;改造后在确切提交 29def33 上,配置与边界入口自动折叠被宽前缀覆盖的本地子路径同时保留精确目录根授权如 plans 与敏感路径,首屏仅保留 CBA 计数摘要而将 active_write_scope 延后到按需读取,默认摘要不再投影 required_write_scopes 但结算因果、工作区守卫与启动防漂移检查均回溯完整写契约,同时任务租约冲突收敛为 Todo 归属与同一物理 checkout 独占。
在确切提交 29def33 的本地 CLI 与单测实测中:fold_write_scope_subpaths 证明后折叠冗余子路径并在 File 与 SQLite 正常路径保留 plans 与 plans/** 的斜杠语义区分;prepareInitialOpening 与 withLinkedObservedRemainder 将 active_write_scope 与 entries 移出首屏同时保留计数摘要且不破坏 --context-delivery off 视图;resolve_selected_todo_write_contract 与 selectedTodoRequiredWriteScopes 恢复了 same_agent_non_delivery 工作区约束、主仓 checkout 拦截与启动期写范围漂移拒绝;decideTaskLeaseAcquire 与 admitAdaptiveChildren 允许不同 worktree 重叠写范围并发推进并在同 checkout 冲突时返回 workspace_lease_conflict。
本 PR 不从权威 Todo 存储或 todo list 显式读取中删除 required_write_scopes,不在 checkpointed_boundary_authority.active_write_scope 与 coordination.write_scope 之间做跨边界折叠,不引入跨 Goal 全局物理文件锁,也不在本 PR 内直接修改其他开放 PR 的分支代码。
之所以需要这一三层源头减法而不只是继续在终端层做字符串截断:此前补丁叠加在 todo.py 与首屏裁剪层上,既无法消除 goal_boundary.write_scope 与 cba.active_write_scope 的源头膨胀和 projection_repair 对仓库根覆盖的误报,也让跨 worktree 的并发任务因为静态路径 glob 重叠而被不必要地串行化;同时本 PR 保留规范存储中的 required_write_scopes 并让全部安全/因果消费方回溯完整写契约,确保减负不牺牲任何既有执行隔离不变量。
改动思路 / Approach
本 PR 沿着 LoopX 既有的配置归并、TypeScript 渐进上下文拆页、结算工作区因果、工作区守卫、Turn 启动契约与硬租约决策边界推进,在源头消除冗余投影与过期互斥规则:
| 收敛层级 | 变更前基线 (b3755392...) |
变更后确切头 (29def33e...) |
关键不变量与实测状态 |
|---|---|---|---|
| Layer 1 源头折叠与延后 | normalize_goal_write_scope 仅拆分去重;cba.active_write_scope 与 entries 留驻第 0 页 |
fold_write_scope_subpaths 经 quota.write_scope_coverage 语义证明后折叠冗余子路径;prepareInitialOpening 与 withLinkedObservedRemainder 延后 active_write_scope 与 entries 仅留计数 |
保留 plans 与 plans/** 差异、跨仓外部路径、凭据目录及裸仓库根;--context-delivery off 视图不变(PASS) |
| Layer 2 默认去投影与回溯 | agent_todo_summary、selected_todo、capability_gate、action_portfolio 默认内联 required_write_scopes;覆盖仓库根或绑定 task_repository 易触发边界修复 |
默认摘要省略 required_write_scopes;projection_repair 对仓库根与外部仓库跳过误报;resolve_selected_todo_write_contract 与 selectedTodoRequiredWriteScopes 为因果、守卫与启动复核提供完整写契约 |
same_agent_non_delivery 无法绕过工作区校验,主仓 checkout 阻断与启动期 write_scope 漂移检测在 File/SQLite 恢复通过(PASS) |
| Layer 3 租约互斥收口与去胶水 | decideTaskLeaseAcquire 与 admitAdaptiveChildren 按静态路径交集返回 write_scope_conflict;todo.py 维护 68 行 overlap 详情胶水 |
租约互斥收口为 Todo 归属与同一物理 checkout 独占(workspace_lease_conflict),停止默认采集 write_scopes 并删除 todo.py 68 行胶水与对齐参考文档 |
独立 Git worktree 重叠写范围并发领取成功,同工作区冲突精准拒绝(PASS) |
flowchart LR
subgraph L1["Layer 1 源头折叠与首屏延后"]
CFG["configure_goal / goal_boundary / boundary_authority"] --> FOLD["fold_write_scope_subpaths (经 quota.write_scope_coverage 证明)"]
FOLD --> P0["Page 0 仅保留 count 摘要"]
FOLD --> CR["context-read 按需读取 active_write_scope"]
end
subgraph L2["Layer 2 默认减法投影与不变量回溯"]
RAW["原始 agent_todos / work_context.sources"] --> COMP["selected_todo 默认省略 required_write_scopes"]
RAW --> RES["resolve_selected_todo_write_contract & selectedTodoRequiredWriteScopes"]
RES --> GUARD["observe_goal_delivery_workspace_isolation / build_agent_workspace_guard / settlement_cli / selectedWorkLaunchBasis"]
end
subgraph L3["Layer 3 租约互斥收敛"]
LEASE["decideTaskLeaseAcquire & admitAdaptiveChildren"] --> WT["Todo 归属 + 同物理 checkout 独占 (workspace_lease_conflict)"]
end
(注:上图依据确切头 29def33edc8b560c26c355a18e31a95383fca6a4 源码调用关系绘制,仅作结构示意;运行与隔离结论以下文实测结果为准。)
架构评估与 PR 边界:把 Goal 白名单折叠收敛在协调配置与边界出口、把 CBA 首屏按需延后放在 progressive_context 与 turn_envelope、把默认 Todo 摘要字段减法放在既有投影层同时通过共享解析器为结算因果/守卫/启动校验回溯完整写契约、并把任务租约互斥收口回 Todo 所有权与物理 checkout 独占,实现了不变量、策略、IO 与投影的清晰分层,避免了新的平行状态层。当前 PR 边界覆盖三层减法收敛、全链路写入契约回溯(含 File 与 SQLite 的精确目录授权保留、工作区守卫与启动期写范围漂移拦截)及对应参考文档对齐;保留显式 todo list 规范读取与仅读不用的空 overlap 透传字段作为安全非阻塞后续清理,不改动外部开放 PR 的分支内容。
具体改动 / Changes
相对于基线 b375539271b4cb9f34386a77211a944ce6e05ffe,确切头 29def33edc8b560c26c355a18e31a95383fca6a4 共修改 63 个文件(+1,409 / -623 行):
- 生产代码(production):29 个文件,
+621 / -233行;热点集中在loopx/control_plane/coordination/configuration.py(+220 / -7)、loopx/control_plane/quota/progressive_context.ts(+61 / -45)、loopx/control_plane/quota/selected_todo_projection.py(+82 / -1)、loopx/cli_commands/todo.py(+0 / -68)、loopx/control_plane/quota/turn_envelope.ts(+40 / -25)、loopx/control_plane/quota/projection_repair.py(+49 / -1)、loopx/control_plane/agents/workspace_guard.py(+31 / -5)、loopx/boundary_authority.py(+24 / -4)、loopx/configure_goal.py(+19 / -6)与loopx/control_plane/quota/settlement_cli.py(+20 / -1)。 - 测试与示例(tests_or_fixtures):31 个文件(含 1 个 smoke 示例),
+726 / -310行。 - 公开文档(docs):3 个文件(
docs/reference/canonical-lease-renew.md、docs/reference/required-work-context.md、loopx/pi_goal_mode/README.md),+62 / -80行。
规范依据(spec_basis):no_spec(spec_source: none)。仓库中不存在独立于本 PR 之外、预先规定本次三层 write_scope 减法收敛的已接受 RFC;docs/reference/canonical-lease-renew.md 与 docs/reference/required-work-context.md 随代码一并更新,故不作为独立前置验收标准,评审依据建立在 problem_context 与既有运行时安全/准入不变量之上。
此前各轮评审意见在 29def33edc8b560c26c355a18e31a95383fca6a4 的逐项核验闭环:
- 线程
PRRT_kwDOStEbEs66i218(6011813597—configuration.py目录根精确授权折叠):已解决。fold_write_scope_subpaths现调用quota.write_scope_coverage证明每次非精确消除;实测["plans", "plans/**"]保留两项(covered: [False]for"plans"vs["plans/**"]),而"plans/"与"plans/draft.md"可被安全折叠;tests/control_plane/test_write_scope_coverage.py::test_real_cli_preserves_exact_directory_grant_alongside_descendant_glob在 File 与 SQLite 6/6 参数用例全通过。 - 评审
6011872706阻塞项 1(workspace_guard.pyrequired_write_scopes工作区隔离):已解决。build_agent_workspace_guard与_peer_work_requires_isolated_workspace现通过resolve_selected_todo_write_contract回溯goal.agent_todos、project_asset.agent_todos与raw_agent_todo_summary(由should_run.py传入),恢复了仅声明required_write_scopes且action_kind=validate的 Peer Todo 在主仓库 checkout 的阻断;test_required_write_scopes_blocks_canonical_git_checkout_on_file_and_sqlite(File/SQLite)、test_workspace_git_fact_reads.py(11/11)及无selected_todo回退探测全通过。 - 评审
6011872706阻塞项 2(turn_envelope.tsselectedWorkLaunchBasis启动期防漂移):已解决。新增selectedTodoRequiredWriteScopes从interaction_contract.agent_channel.work_context.sources中读取source === "selected_todo"的content.todo.required_write_scopes(再回退selected_todo);tests/control_plane_ts/turn_envelope.test.ts与tests/control_plane/test_host_current_admission.py全部 24/24 用例(含 File/SQLite × exec/operation 的write_scope变更拦截)全通过。 - 评审
6011450700(结算因果丢失与文档失效指针):已解决。settlement_cli.py(quota_rollout_details与reconcile_existing_heartbeat_receipt)及workspace_guard.py(observe_goal_delivery_workspace_isolation)均已通过resolve_selected_todo_write_contract恢复写契约,test_required_write_scopes_preserves_causality_and_workspace_proof_end_to_end通过;docs/reference/required-work-context.md已全部清理/selected_todo/required_write_scopes残留引用。
关键代码讲解
fold_write_scope_subpaths(loopx/control_plane/coordination/configuration.py:125-218)
在配置入口(configure_goal.py)、边界投影(goal_boundary.py)和 CBA 摘要(boundary_authority.py)执行语义折叠。先清洗斜杠与./**,再通过_is_sensitive_or_unfoldable将含..、~、;、凭据目录段(如.ssh、secrets)、凭据后缀(.key/.pem等)及裸仓库根<goal_repo>标记为不可折叠,并按is_external_abs极性隔离仓库内路径与跨仓绝对路径;随后对**与无通配符茎的dir/**候选构建覆盖证明批次,调用_prove_write_scope_coverage(即 TS 侧quota.write_scope_coverage/schedulingWriteScopeAllowed)逐条核验覆盖关系后才删除被覆盖项,从而严格区分精确目录授权plans与子路径通配符plans/**。prepareInitialOpening与withLinkedObservedRemainder(loopx/control_plane/quota/progressive_context.ts:448-464,775-847)
将goal_boundary.checkpointed_boundary_authority.active_write_scope与entries从第 0 页拆出到按需context-read详情列表,首屏仅保留active_count、inactive_count与schema_version;同时让withLinkedObservedRemainder校验openingSplit.details的全集复用状态,修正了/goal_boundary/write_scope热复用后遗漏其余 CBA 详情指针的隐患。开启开关完全受渐进读取路由控制,--context-delivery off视图保持原样。resolve_selected_todo_write_contract与build_agent_workspace_guard(loopx/control_plane/quota/selected_todo_projection.py:203-228、loopx/control_plane/agents/workspace_guard.py:235-280,388-516)
SELECTED_TODO_COMPACT_FIELDS移除required_write_scopes后,resolve_selected_todo_write_contract复用lookup_raw_todo从传入的未裁剪agent_todos摘要序列(按归一化todo_id)补回required_write_scopes、task_repository、required_capabilities与continuation_policy。observe_goal_delivery_workspace_isolation、settlement_cli.quota_rollout_details与build_agent_workspace_guard统一消费该解析结果,且_peer_work_requires_isolated_workspace先豁免continuous_monitor再检查task_repository、required_write_scopes与写动作前缀,从而在保持selected_todo紧凑的同时守住隔离与因果不变量。selectedTodoRequiredWriteScopes与selectedWorkLaunchBasis(loopx/control_plane/quota/turn_envelope.ts:908-936)
在生成启动指纹selected_work_basis时,由于第 0 页selected_todo已默认省略required_write_scopes,selectedTodoRequiredWriteScopes优先从interaction_contract.agent_channel.work_context.sources中提取source === "selected_todo"对应的content.todo.required_write_scopes(interaction_contract.ts:1062-1088会在引用去重时自动保留selected_todo投影中缺失的字段),否则回退到selected_todo.required_write_scopes ?? [],使todo update --required-write-scope在规划后仍可触发current_turn_work_changed阻断。decideTaskLeaseAcquire(loopx/control_plane/work_items/task_lease_acquire_decision.ts:733-765)
删除基于writeScopesOverlap的跨 worktree 阻断与integration_overlap_advisories计算,保留todo_lease_conflict、CAS 版本校验、lease_repository_divergence/lease_workspace_repository_mismatch校验,并将并发租约冲突条件精确收敛为workspace !== null && sameLeaseCheckout(workspace, other.write_workspace)返回workspace_lease_conflict;同时claim_execution.ts与todo_claim.ts默认写入write_scopes: []但继续验证并传递write_workspace。
对主干的风险 / Risks
无阻塞性发现(No blocking findings):在确切头 29def33edc8b560c26c355a18e31a95383fca6a4 上,此前轮次指出的精确目录折叠、结算因果、工作区守卫、启动期漂移与文档失效指针问题均已修复且通过独立验证。
非阻塞观察与后续清理(Non-blocking Follow-ups)
- 残余空列表透传:
claim_execution.ts:131-134、todo_claim.ts:505,718、task_lease_acquire.ts:148与cli_commands/task_lease.py:81仍保留了overlapAdvisories/integration_overlap_advisories透传分支,但在advisoryIndexes: []下恒为空且不输出线缆字段;可在后续清理中顺手移除。 - 下游已剥离字段的兼容投影:
loopx/control_plane/todos/resume_planning.ts:38,44在compactFields仍保留required_write_scopes(已在注释中标明为既有兼容表现层,实际在quota_summary.py下游已省略)。 - 辅助诊断无
goal_repo参数:run_history.py:47与issue_fix/cli.py:239调用checkpointed_boundary_authority_summary(coordination)未传goal_repo,仅意味<goal_repo>/...绝对路径在历史诊断投影中不转为相对路径折叠,不影响运行门控。 - 跨 PR 协作边界:PR 正文已显式提醒待合入 PR
#8941需在集成时将claim_execution.ts中的"write_scope_conflict"检查同步为"workspace_lease_conflict",清晰且低耦合。 - 范围适配、隔离、权限与状态规则检查(
scope_fit/default_off_isolation/authority_semantics/typed_state_rule/domain_neutrality/behavior_change_disclosure/guidance_vs_obligation):所有新增/修改逻辑均由configure-goal、quota should-run、context-read、refresh-state、spend-slot与task-lease真实生产链路调用,无孤立仅测试函数;--context-delivery off对渐进 CBA 延迟完全隔离,而默认关闭required_write_scopes投影的全局行为变更已在参考文档与测试更新中显式披露;公共命名workspace_lease_conflict与实际物理 checkout 独占范围一致;判断逻辑全部基于类型化词表与quota.write_scope_coverage,提示文案保持领域中性,建议与强制门控边界清晰。
语义与 CI 对齐
- 词汇与契约对齐(
semantic_alignment = aligned、candidate_decision = reuse_existing):本 PR 复用既有已注册状态词汇workspace_lease_conflict替代退场的write_scope_conflict,examples/semantic-vocabulary-drift-smoke.py本地执行 PASS,无未登记词表或跨运行时分裂。随selected_todo默认省略required_write_scopes受影响的下游契约消费端(settlement_cli.py、workspace_guard.py、projection_repair.py、task_orchestration_admission.py、turn_envelope.ts)与参考文档均已在当前头完成契约对齐。 - CI 策略说明(
wait_for_ci: false,ci_policy: "not_consulted"):按仓库与 Goal 评审策略未查询或等待远端 GitHub Actions CI;所有结论均基于当前确切头29def33edc8b560c26c355a18e31a95383fca6a4的本地独立全量验证。
本地验证矩阵(validation_matrix)
| 检查项目 | 命令 / 验证路径 | 状态 | 结果摘要 | 必须 |
|---|---|---|---|---|
changed_invariant_positive |
test_coordination_configuration.py + test_write_scope_coverage.py(55 items)+ test_context_first_read.py + test_task_lease_cli.py + test_canonical_lease_scopes.py + test_quota_settlement_cli.py + SQLite 实机 CLI 探针 |
PASS | fold_write_scope_subpaths 保留 plans 与 plans/**、凭据与跨仓边界;CBA 第 0 页延后与 --context-delivery off 隔离成立;独立 worktree 重叠写范围并发拿租约成功,因果校验保持 required |
是 |
material_negative_or_failure |
test_host_current_admission.py(24 items)+ test_workspace_git_fact_reads.py(11 items)+ test_quota_settlement_cli.py -k test_required_write_scopes_(3 items)+ SQLite 同 checkout 冲突探针 |
PASS | 仅声明 required_write_scopes 的 validate 任务在 File/SQLite 主仓 checkout 均被拦截(agent_workspace_repair);规划后改写 required_write_scopes 在 exec/operation 均被 current_turn_work_changed 拒绝;同物理 worktree 租约冲突返回 workspace_lease_conflict |
是 |
repository_required_checks (TypeScript + MJS) |
npm run typecheck:control-plane + node --no-warnings --experimental-sqlite --experimental-strip-types --test(覆盖全部变更/相关 TS 套件 + authority_store.test.ts + sqlite_authority_store.test.ts + tests/pi_goal_loop_runtime.test.mjs) |
PASS | typecheck 通过;TS/MJS 实测共 1,790 passed, 0 failed(31 skipped 为未配置本机 PostgreSQL 实例的既有集成用例) |
是 |
repository_required_checks (Python 静态与测试) |
uv run --extra test mypy + uv run --extra test ruff check(全部变更 .py)+ pytest(24 个控制面与租约测试套件) |
PASS | mypy(17 源文件)0 错、ruff 0 错;24 个 Python 测试套件共 1,175 passed, 0 failed |
是 |
repository_required_checks (Pre-merge & Smokes) |
scripts/check_rfc_bilingual.py + Goal-bound loopx canary premerge --from-git-diff --git-diff-base origin/main + 4 个核心 smoke 脚本 |
PASS | gate.status = passed(merge_gate_passed = true:direct_checks 4/4、python_compile 1/1、catalog_canaries 10/10、risk_profile_smokes 8/8、public_boundary 1/1 零私密泄露);4 个独立 smoke 全通过 |
是 |
我的整体评价 / Verdict
综合判断 Approval conclusion (author-owned PR; GitHub blocks formal self-approval):PR #9256 在确切头 29def33edc8b560c26c355a18e31a95383fca6a4 完整交付了三层 write_scope 减法收敛,并已扎实闭环了前序各轮发现的全部实现与文档缺陷:
- 交付效果评估(
problem_context.outcome_impact):long_horizon = improved:源头白名单折叠与 CBA 第 0 页延迟显著降低了多边界 Goal 首屏与 Turn 负载压力,projection_repair不再因仓库根或外部仓库误阻断,工作区守卫、结算因果与启动期写范围防漂移检查在 File/SQLite 全链路保持完整不变量,同时跨 worktree 并行租约不再被静态 glob 重叠卡死。user_experience = improved:quota should-run、context-read与task-lease输出更紧凑且与docs/reference/required-work-context.md、docs/reference/canonical-lease-renew.md描述一致;todo list继续保留完整原始required_write_scopes供按需排查。visual_review = not_applicable:PR #9256 仅改动控制面 TypeScript/Python 逻辑、CLI 投影与工作区守卫、参考文档及测试(63 个文件),不涉及任何前端渲染视图或视觉样式。未验证范围:无(本次变更不包含渲染 UI 表面)。
- 契约、复用与体量评估:
observable_semantics = intentional_change_validated、repository_reuse = reused(复用quota.write_scope_coverage、新增共享resolve_selected_todo_write_contract并沿用既有progressive_context与租约状态机所有者)、code_volume = necessary(compatibility_assessment = retain,保留todo list规范读取与空列表契约兼容并清理 68 行胶水)、change_proportionality = proportionate(architecture_assessment = retain)、default_off_isolation = isolated、authority_semantics = aligned、semantic_alignment = aligned(reuse_existing)。 - 残余风险与精确头:本评价严格绑定确切头
29def33edc8b560c26c355a18e31a95383fca6a4;残余风险仅限于本机未连接 PostgreSQL 实例导致 31 项 TS 集成用例按既有策略skipped(File 与 SQLite 默认权威路径已完整实测通过),以及前述几处无害的非阻塞死代码清理建议。合入前仍需按维护者权限走完线程关闭与--check-merge-readiness。
English verdict: APPROVE — verified 3-layer write_scope subtraction convergence, exact directory-root folding preservation, workspace guard/causality/launch-basis write-contract parity, and all local checks at exact head 29def33.
…traction-20261122 Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
…ions 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-astra · OpenAI · runtime_reported · xhigh
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
在同一个 Goal 下分工、认领 Todo 并从工作区开展修改的 Agent。 两个工作项声明相同的相对路径,旧版可能拦住第二个持有人,即使它有自己的工作区。 独立工作区可以并行;同一已验证工作区仍互斥。同仓库 Todo 超出 Goal 的范围会获得具体缺失路径。 本次评审覆盖调度与租约接口。未衡量真实模型的长期效率。
改动思路 / Approach
工作区互斥由原有租约决定统一裁决,摘要继续使用同一个 Todo 源数据。 改动限于写范围的压缩、准入、互斥和相关读回。 用户授权、租约持有者和当前工作区可用性分别取证。下一次能够执行的操作取决于原有权威状态;只读文本、过期执行证明或恢复建议都不会扩大可执行范围。
具体改动 / Changes
| 调用位置 | 此提交的行为 |
|---|---|
| build_boundary_projection_repair_hint | 同仓库和未知仓库继续比较,已识别为另一仓库时独立解释路径 |
| evaluateTaskLeaseAcquireDecision | 同 Todo 的活跃执行或同一已验证工作区产生冲突,两个独立 worktree 的路径重合可以并行 |
| lookup_raw_todo | 按原 Todo 身份读回完整路径,保持准入和结算因果 |
核对条目 execution-ownership 与 workspace-isolation。File/SQLite 在允许 src/** 的情况下,选择同仓库 src/report.py 得到 normal_run。 File/SQLite 在仅允许 docs/** 时选择声明 src/report.py 的同仓库任务,得到 boundary_projection_repair、路径缺口及零扣额。 对照用例从正常入口操作隔离的实际提供者,保留操作前后的状态与可见诊断。 验收依据,a4e0d384868c3ec6587df49dcc784679b2301f02
对主干的风险 / Risks
旧头在同仓库未覆盖的路径上给 normal_run;修正后回到 boundary_projection_repair。 独立工作区的判断需要已验证的物理身份。缺少这项身份的历史租约只保证其 Todo 的执行归属,不能承诺同目录排他。显式取得的路径和历史回执仍可读,日常自动认领保留 Todo 源声明,简表默认不携带路径数组。主分支最容易出现的回归是把缺少有效身份当成授权,或在遭遇并发后反复要求用户干预。写范围与租约定向 Python 验证 297 项通过。TypeScript 与宿主投影测试 370 项通过、1 项跳过。PostgreSQL 等真实提供者组合验证先有两项仍期待在摘要中看到完整路径;修正为同时检查摘要省略与原始记录后,两项均通过,其余 572 项已通过。最终提交的标准 premerge 选中 19 项,零失败,RFC 成对检查通过。 历史回执与新的执行机会分别按原身份处理。未把按策略跳过的远端 CI 或未运行的正式模型当作验收证据。
我的整体评价 / Verdict
精确提交 a4e0d384868c3ec6587df49dcc784679b2301f02 的评审包含 65 files, +1459/-659。工作区互斥由原有租约决定统一裁决,摘要继续使用同一个 Todo 源数据。 操作者可以从真实拒绝原因和有效租约判断下一步,独立任务可以继续推进。后续安装版本是否包含该改动需要单独读回,离线评审结果也不等于真实用户的长期收益。
English verdict: APPROVE. The reviewed head satisfies the scoped ownership and recovery contract under the tested local providers.
Summary
Implements the three-layer
write_scopesubtraction convergence across TypeScript control-plane owners, Python runtime/CLI adapters, reference docs, and test suites—replacing first-screen truncation glue from #9078, #9106, and #9086 with structural subtraction at the source.1. Layer 1 — Fold Goal Whitelists & Defer
cba.active_write_scopeloopx/control_plane/coordination/configuration.py,loopx/control_plane/quota/goal_boundary.py,loopx/boundary_authority.py,loopx/configure_goal.py): Fold subpaths covered by broad prefixes (**,/**,dir/**) insidecoordination.write_scopeand internally withincheckpointed_boundary_authority.active_write_scope, proving every non-exact elimination against the normalized coverage owner (quota.write_scope_coverage/schedulingWriteScopeAllowed) so exact directory-root grants such asplansremain alongside descendant globs likeplans/**(both require distinct slash semantics), while preserving external-repository boundaries, sensitive credential directories, bare<repo>alignment withprojectGoalWriteScopes, and--hardenpolicy compatibility.loopx/control_plane/quota/progressive_context.ts,loopx/control_plane/quota/turn_envelope.ts): Movegoal_boundary.checkpointed_boundary_authority.active_write_scopeoff Page 0 /required-context.jsoninto on-demandcontext-read --select /goal_boundary/checkpointed_boundary_authority/active_write_scope, retaining compactactive_count/inactive_countsummary counts on the opening surface.loopx/control_plane/quota/progressive_context.ts): UpdatewithLinkedObservedRemainderto track all deferred detail pointers inopeningSplit.detailsso warm reuse of/goal_boundary/write_scopeno longer leaves un-reused CBA arrays stranded on Page 0.2. Layer 2 — Default-Off
required_write_scopes& Retire False-Positive Gateloopx/control_plane/todos/context_projection.ts,quota_selection.ts,quota_summary.py,selected_todo_projection.py,work_items/action_portfolio.ts,work_items/planning_inventory.ts): Stop projectingrequired_write_scopesintoagent_todo_summary,selected_todo,capability_gate, andaction_portfolioby default (while using sharedlookup_raw_todoforadaptive_childrenchild-lane isolation intask_orchestration_admission.py).loopx/control_plane/quota/selected_todo_projection.py,projection_repair.py,agents/workspace_guard.py,quota/should_run.py,quota/should_run_packet.py,quota/settlement_cli.py,quota/turn_envelope.ts,cli_commands/quota.py,cli_commands/quota_should_run.py):lookup_raw_todoandresolve_selected_todo_write_contractsobuild_agent_workspace_guard,observe_goal_delivery_workspace_isolation,build_boundary_projection_repair_hint, andquota_rollout_details/ settlement readback observe uncompactedrequired_write_scopes(preservingrequired_write_scopesworktree isolation gating in_peer_work_requires_isolated_workspaceand canonical checkout fail-closed behavior across File & SQLite without re-exposingrequired_write_scopesonselected_todo).selectedWorkLaunchBasisinloopx/control_plane/quota/turn_envelope.tsto readrequired_write_scopesfrominteraction_contract.agent_channel.work_context.sources(selected_todosource) when omitted fromselected_todo, preserving pre-launchcurrent_turn_work_changeddrift rejection across File & SQLite (tests/control_plane/test_host_current_admission.py).loopx/control_plane/quota/projection_repair.py,should_run.py): Disablerequired_write_scope_missing_from_goal_boundaryauto-repair whengoal_boundary.write_scopealready covers the Goal root or when the selected Todo bindstask_repository.3. Layer 3 — Retire
task_leasewrite_scope_conflictHard Blocks & Reclaim Glueloopx/control_plane/work_items/task_lease_acquire.ts,task_lease_acquire_decision.ts,coordination/claim_execution.ts,coordination/task_lease_acquire.ts,coordination/todo_claim.ts,quota/adaptive_children.ts,capabilities/explore/todo_branch_plan.py): Returntask_leaseacquisition to Todo ownership + same-checkout/worktree (sameLeaseWorkspace) exclusivity (workspace_lease_conflict), stopping default per-pathwrite_scopescollection andwrite_scope_conflictrejections.#9078/#9106/#9086glue & align docs (loopx/cli_commands/todo.py,todo_argument_validation.py,docs/reference/canonical-lease-renew.md,docs/reference/required-work-context.md,loopx/pi_goal_mode/README.md): Retire_thin_claim_overlap_advisoriesand inline claim-overlap detail wiring (-68net lines inloopx/cli_commands/todo.py), relocate active boundary/Todo read instructions off/selected_todo/required_write_scopesonto/goal_boundary/write_scopeandtodo listin both English and Chinese reference prose, and keep a clean boundary with open PR#8941(note for#8941: align itsclaim_execution.tscheck from"write_scope_conflict"to"workspace_lease_conflict"when integrating alongside this PR).Empirical Measurements (Representative Multi-Boundary Snapshot at
29def33edc, Before vs. After)goal_boundary.write_scopeitemsgoal_boundary.write_scopecompact JSONgoal_boundarysection inrequired-context.jsoncba.active_write_scope(7 active, 1 inactive) on Page 0 /required-context.jsontruefalse(context-read392 B, 7 entries)agent_todo_summaryrequired_write_scopeskey occurrencesagent_todo_summarycompact JSONrequired-context.jsontotal bytesprojection.jsontotal bytesfirst_read_command(total_bytes)--turn-envelopetotal JSON (boundaryfield)origin/main..HEAD): 63 files changed, 1,409 insertions(+), 623 deletions(-) (loopx/: 30 files changed, 622 insertions(+), 234 deletions(-);loopx/cli_commands/todo.py: 0 insertions(+), 68 deletions(-)).Verification (All Run on Current Head
29def33edc8b560c26c355a18e31a95383fca6a4)loopx canary premerge --from-git-diff --git-diff-base origin/main: passed (selected=19, failures=0:python_compile1/1,catalog_canaries10/10,risk_profile_smokes8/8,public_boundary1/1, plus 6 direct checks; Goal-bound CQR receiptcqr_3da5d0222b8129bd0440valid).npm run typecheck:control-plane: passed.uv run --extra test mypy(17 configured Python source files): passed.uv run --extra test ruff check(all changed.pyfiles): passed.examples/semantic-vocabulary-drift-smoke.py,examples/control_plane/task-orchestration-smoke.py,examples/control_plane/task-lease-runtime-smoke.py,examples/control_plane/quota-projection-repair-state-machine-smoke.py): passed.node --experimental-strip-types --test:action_portfolio,adaptive_children,claim_contention_conformance,lease_acquisition_conformance,local_authority_runtime,managed_claim_execution_conformance,progressive_context*,quota_settlement_readback,settlement_workspace_causality,task_lease*,todo*,turn_envelope,write_scope_coverage,tests/pi_goal_loop_runtime.test.mjs): 1,026 passed, 0 failed, 31 skipped (PostgreSQL integration cases).quota_selection,quota_run_decision,context_projection_root,context_selection,settlement_workspace_causality,write_scope_coverage): 139 passed, 0 failed.pytestacross all 30 control-plane & lease suites (1,323 passed, 0 failed):-n 6:test_quota_settlement_cli,test_quota_authority_settlement_journey,test_context_first_read,test_quota_action_portfolio,test_quota_cli_projection,test_quota_should_run_parity,test_machine_guard_context_contract,test_progressive_context_entrypoints,test_progressive_native_context,test_delivery_workspace*,test_cli_output_budget,test_write_scope_coverage,test_task_orchestration_admission,test_quota_boundary_projection_selection,test_coordination_configuration,test_goal_boundary_resolution,test_goal_local_write_admission,test_workspace_git_fact_reads): 891 passed, 0 failed (includes new File & SQLite CLI regressions for["plans", "plans/**"]exact directory-root grants andrequired_write_scopescanonical checkout blocking).test_host_current_admission[all 24/24 incl. File & SQLitewrite_scopedrift],test_canonical_claim_execution_proof,test_canonical_lease_scopes,test_task_lease_cli,test_todo_claim_argument_recovery,test_todo_list_thin,test_adaptive_child_admission_characterization,test_explore_resource_portfolio,test_task_lease_worktree,test_pi_goal_mode): 432 passed, 0 failed.