Repository navigation
fix(workspace): explain missing cross-repository binding - #8926
Conversation
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google · self_reported
动机 / Motivation
在跨仓库协作场景中执行任务、但所选 Todo 遗漏绑定 --task-repository 时,需要在运行 loopx quota should-run 时立即看清“是补齐跨仓库标识还是切换 worktree”的 Peer Agent 与人类维护者。
修复前,当 Peer 在已处于目标外部仓库的独立工作树(foreign_git_worktree)中运行,但 Todo 尚未设置 task_repository 时,build_agent_workspace_guard 会回退采用 Goal 默认仓库并仅提示泛化的“create or switch to an independent git worktree/branch”,使真正的跨仓库遗漏与工作目录错误无法区分;修复后,PR 仅调整了 loopx/control_plane/agents/workspace_guard.py 的 required_action 字符串以补充 --task-repository <credential-free-git-identity> 说明,虽然传统 JSON/Markdown 输出与 recommended_action 已同步更新,但在 loopx 主力使用的 Codex App 渐进上下文入口(--codex-app --context-delivery on -> --initial-read)及 execution_obligation / interaction_contract 契约投影中,Caller 仍只能看到旧的泛化提示而完全看不到新说明。
在精确头 413c5cc9366c524bca4e8f80cc13f4c058b13e0d 上,目标 Python 测试(155 passed + 21 passed)、ruff、mypy 与 91 项工作区相关 TS 测试均通过,且 CLI JSON/Markdown 及端到端 todo update --task-repository 恢复流可实测跑通;然而,真实 CLI --codex-app --context-delivery on 实测复现表明,首屏 --initial-read 选段(INITIAL_CONTEXT_DECISION_FIELDS)不包含 workspace_guard 或 recommended_action,且 execution_obligation.contract_obligation、interaction_contract.agent_channel.primary_action 与 cli_channel.next_cli_actions 三处均硬编码返回旧文案。
本 PR 范围限定于澄清跨仓库未绑定场景下的 agent_workspace_repair 提示文案并保留原有仓库识别逻辑,不放宽外部仓库写入隔离约束,也不直接修改远端旧基线 68fe1788518e 上的 compaction_memory.ts 测试。
改动思路 / Approach
入口为 loopx/control_plane/agents/workspace_guard.py:524-548 中的 build_agent_workspace_guard,上游依据 selected_todo.task_repository 与 goal.repo 判断 current_workspace == "foreign_git_worktree",下游依次流向 decision_summary.py(recommended_action)、quota_markdown.py 与 turn_envelope.ts。就修改点本身而言,复用既有 workspace_guard 所有者而不新增状态字段的思路十分克制(正向隔离与 todo update --task-repository 恢复均可闭环,且未引入凭据/路径泄漏);但同一业务提示在运行时存在多处平行投影:turn_envelope.ts:2343-2346 的 INITIAL_CONTEXT_DECISION_FIELDS 未投影 workspace_guard / recommended_action,且 execution_obligation.py:40-44、interaction_contract.py:1008-1012 与 interaction_contract.ts:278 对 AGENT_WORKSPACE_REPAIR 模式硬编码输出旧字符串,使 PR 试图解决的首屏引导失效问题在渐进上下文与交互契约主路径上依然存在。
架构判断:Updating workspace_guard.py required_action alone leaves execution_obligation, interaction_contract (Python and TS), and Codex App initial progressive reads projecting the hardcoded generic worktree message.
当前边界:Modifies only loopx/control_plane/agents/workspace_guard.py (+9/-4) and unit test tests/control_plane/test_workspace_git_fact_reads.py (+22/-0), without propagating foreign-worktree remediation to execution_obligation / interaction_contract / INITIAL_CONTEXT_DECISION_FIELDS or integration-testing build_quota_should_run.
具体改动 / Changes
- 规范来源:无独立 RFC(
no_spec),以 PR 问题陈述及quota should-run首屏 /interaction_contract一致性契约为审查依据。- 跨仓库遗漏
--task-repository提示分流 -> 在workspace_guard.py+recommended_action中已实现,但渐进上下文--initial-read与execution_obligation/interaction_contract仍输出旧泛化文本,且文案未明示命令动词todo update。
- 跨仓库遗漏
关键代码讲解
build_agent_workspace_guard(loopx/control_plane/agents/workspace_guard.py:524-548):当not task_repository and current_workspace == "foreign_git_worktree"时将required_action切换为--task-repository <credential-free-git-identity>说明;未读取remote.origin.url亦未拼接本地路径或敏感信息,已设task_repository但目录不匹配时仍保持原独立 worktree 提示。但提示未包含子命令名(todo update),调用方需自行推断--task-repository应传给todo update。- 被遗漏的平行消费者:
loopx/control_plane/quota/turn_envelope.ts:2343-2346(INITIAL_CONTEXT_DECISION_FIELDS)、loopx/control_plane/work_items/execution_obligation.py:40-44、loopx/control_plane/work_items/interaction_contract.py:1008-1012与loopx/control_plane/work_items/interaction_contract.ts:278。这四处分别构成了--codex-app --context-delivery on首屏--initial-read与统一交互契约的实际读取面,目前在相同跨仓库场景下均继续输出旧的"create or switch to an independent worktree/branch"文本。 test_foreign_worktree_explains_missing_cross_repository_binding(tests/control_plane/test_workspace_git_fact_reads.py:128-144):单测使用git init构造的普通外部仓库直接调用build_agent_workspace_guard,未覆盖task_repository已设置却不匹配的负例,也未经过build_quota_should_run与--context-delivery on首屏集成校验。
对主干的风险 / Risks
代码本身未破坏原有隔离边界与凭据脱敏安全,但精确头 413c5cc9366c524bca4e8f80cc13f4c058b13e0d 存在两项需要补齐后再合入的体验与契约缺口:
- [F1 · P1 阻塞] Codex App 首屏渐进上下文(
--initial-read)与交互契约(execution_obligation/interaction_contract)仍显示旧的泛化 worktree 文案:- 触发场景:Peer 在外部仓库 worktree 执行
loopx quota should-run --codex-app --context-delivery on并按契约运行first_read_command(--initial-read)或读取turn_envelope.action.primary_action/next_cli_actions时。 - 实测结果:
first_read_command的INITIAL_CONTEXT_DECISION_FIELDS不包含workspace_guard与recommended_action(turn_envelope.ts:2343-2346),同时execution_obligation.py:40-44、interaction_contract.ts:278与interaction_contract.py:1008-1012均硬编码旧字符串,导致目标调用方在主路径首屏依然看不到任何--task-repository引导;此外建议在文案中明确loopx todo update --task-repository <credential-free-git-identity>,降低猜测成本。
- 触发场景:Peer 在外部仓库 worktree 执行
- [F2 · 非阻塞 P2 建议] 补齐集成测试与已设置
task_repository不匹配负例:- 建议在
tests/control_plane/增加通过build_quota_should_run/ progressive-context 首屏断言新提示可达,以及task_repository已绑定另一仓库时继续要求切换独立 worktree 的负向用例。
- 建议在
- 远端 CI 诊断说明:远端
typescript-core (3/3)失败于旧基线68fe1788518e的compaction_memory.ts与缺失settlement_readback.ts(origin/main#8910/#8928之前的状态,与本 PR 改动正交;基于最新main变基后即可消除),kernel-static-checks、kernel-contracts、browser (1/3)-(3/3)与stage2c-correctness-e2e均已通过。
| 验证项 | 状态 | 实跑结果(exact head 413c5cc9366c524bca4e8f80cc13f4c058b13e0d) |
|---|---|---|
目标 workspace_guard / quota / cli Pytest 套件 |
PASS | 155 passed in 35.28s + 21 passed, 250 deselected in 38.03s |
ruff & mypy & TS 控制面单测(91 项) |
PASS | All checks passed!;mypy 0 errors;TS 91 passed, 0 failed |
真实 CLI --codex-app --context-delivery on --initial-read 复现 |
FAIL(暴露 F1) | --initial-read 与 primary_action/next_cli_actions/contract_obligation 均仅输出旧 worktree 文案 |
远端 GitHub CI(typescript-core (3/3) / checks) |
FAIL(diagnostic) | 基线 68fe1788518e 缺 #8910/#8928(与改动正交,变基至 main 可解);kernel-static-checks 与 stage2c 已过 |
我的整体评价 / Verdict
Inspected all 2 changed files in PR #8926 (workspace_guard.py and test_workspace_git_fact_reads.py) plus downstream projection owners (decision_summary.py, execution_obligation.py, interaction_contract.py/.ts, turn_envelope.ts); backend quota/CLI contract only, zero rendered UI components modified. unverified_scope: none.
识别“跨仓库未绑定 --task-repository 时误导为切换 worktree”这一痛点非常准确,且 PR 本身的凭据安全与 foreign_git_worktree 条件控制严格。但由于未将新指引同步透传到 execution_obligation、interaction_contract(Python/TS)及 --initial-read 首屏字段(INITIAL_CONTEXT_DECISION_FIELDS),导致现代 App / 渐进上下文主路径上的调用方依然只收到旧提示,未能真正消除所描述的阻塞,且 decision_text_assessment 与 user_experience 均有待补齐。请将 workspace_guard.required_action 透传到上述交互/首屏契约出口、点明 todo update --task-repository 并补充一条集成负例后重提审查;同时顺手 rebase 到最新 main 即可解决旧基线导致的 typescript-core 失败。结论:REQUEST_CHANGES。
English verdict: REQUEST_CHANGES
Signed-off-by: huangruiteng <huangrt01@163.com> Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
413c5cc to
703324e
Compare
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent (Gemini, Google DeepMind, self_reported)
基于 exact head 8926@703324e219dfff11ed730b6a8abc88f0e69a5865(base origin/main@9af4caa72e)对 PR #8926(修复先前回顾 5944247962 在 413c5cc936 指出的 [F1]、[F2] 与旧基线问题)的完整复审与全套本地验证,给出 APPROVE 结论。
动机 / Motivation
在跨仓库多 Agent 协作场景中认领并执行外部仓库 Todo、却因该 Todo 遗漏设置 --task-repository 而触发工作区保护的 Peer Agent 与人类维护者。
改动前,Peer 在外部仓库独立 worktree 中运行 quota should-run(含 --codex-app --context-delivery on 首屏 --initial-read),workspace_guard 因 Todo 缺省回退至 goal.repo 而将外部仓库判定为 foreign_git_worktree,但最初及旧版 413c5cc936 在 execution_obligation、interaction_contract(Python/TS)和渐进上下文首屏选段中仍硬编码或截断为泛化文案“create or switch to an independent git worktree/branch”,导致调用方无法分辨是“Todo 缺少跨仓库绑定”还是“工作目录本身错误”;改动后(703324e219 基于 9af4caa72e 变基修复 [F1]/[F2]),由 workspace_guard_missing_task_repository 统一判定条件并在 workspace_guard、execution_obligation、interaction_contract(Python/TS primary_action 与 next_cli_actions)及 --initial-read 首屏选段同步给出 loopx todo update --task-repository <credential-free-git-identity> 修复指引,同时对已设且不匹配的 task_repository 负例严格保留原工作树迁移提示。
真实 SQLite CLI 参数化集成测试 test_foreign_worktree_progressive_initial_read_surfaces_missing_binding_guidance 证明在 --codex-app --context-delivery on 模式下读取 first_read_command 首屏即可同时在 /workspace_guard.required_action、/execution_obligation.contract_obligation、/interaction_contract/agent_channel/primary_action 与 cli_channel/next_cli_actions 获取 todo update --task-repository <credential-free-git-identity>,并在 task_repository 非空但不匹配时 100% 保持原泛化切换工作树提示。
非目标边界:本 PR 仅澄清跨仓库未绑定时的修复与切换工作树二选一引导并打通渐进上下文首屏可见性,不放宽外部仓库写入隔离约束,也不更改 --task-repository 存储与校验逻辑。
相比“不做任何修改”会让跨仓库协作继续反复陷入误建 Goal worktree 的无效往返,本 PR 以不足百行生产代码关闭了传统 JSON/Markdown 与现代渐进上下文(--initial-read)之间最后一段提示断层。
改动思路 / Approach
入口为 loopx/control_plane/agents/workspace_guard.py:451 的 build_agent_workspace_guard,结合 selected_todo.task_repository(若缺省则回退至 goal.repo)评估当前工作目录。新增纯判定辅助函数 workspace_guard_missing_task_repository(workspace_guard.py:439)作为单一事实来源,明确只在“已位于 foreign_git_worktree、引用来源为 goal.repo、且 task_repository 为空”时启用两条分支引导,避免 execution_obligation、Python/TS interaction_contract、以及 progressive_context 各自重复推导条件:
- 下游消费链路
should_run_packet.py:1431将prepared.workspace_guard传入execution_obligation.py:14; primary_action.py:111提取workspace_repair_action,并由interaction_contract.ts:278在EffectiveAction.AGENT_WORKSPACE_REPAIR时优先消费,保留原字符串作精确兜底;interaction_contract.py:1011根据同一个谓词组装带完整--goal-id/--todo-id的todo update --task-repository首步建议;turn_envelope.ts:2343将workspace_guard纳入INITIAL_CONTEXT_DECISION_FIELDS(仅在决策对象存在该键时选中),同时progressive_context.ts:997在AGENT_WORKSPACE_REPAIR场景补齐cli_channel准入与可执行下一步字段到首屏--initial-read。
架构评估结论:Reuse the canonical workspace_guard owner via workspace_guard_missing_task_repository as the single predicate, forward its wording through existing typed projections (execution_obligation, primary_action, interaction_contract), and include workspace_guard plus cli_channel admission fields in first-read progressive delivery for AGENT_WORKSPACE_REPAIR without introducing any new persisted state or protocol field. 当前边界:Complete, self-contained remediation and progressive-first-read wiring across workspace_guard, execution_obligation, interaction_contract (Python & TS), turn_envelope/progressive_context, and real-CLI integration tests at 8926@703324e219.
具体改动 / Changes
全部变更涉及 9 个文件(8 个运行时与交互契约文件 +91 / -14,1 个测试文件 +192 / -0),无独立 RFC(spec_basis: no_spec,以问题陈述与先前回顾 5944247962 [F1]/[F2] 为依据,两项均已在当前 exact head 关闭):
关键代码讲解
workspace_guard_missing_task_repository与build_agent_workspace_guard(loopx/control_plane/agents/workspace_guard.py:439-565):前置集中判定current_workspace == "foreign_git_worktree" and repository_source == "goal.repo" and not task_repository。当跨仓库工作因 Todo 未设置task_repository而落入默认仓库回退时,required_action明确写出loopx todo update --task-repository <credential-free-git-identity>或新建 Goal 仓库独立 worktree 并重跑quota should-run;不拼接敏感 URL/凭据,且当task_repository已显式指定却与当前目录不匹配时完全维持原有独立 worktree 迁移提示。build_execution_obligation(loopx/control_plane/work_items/execution_obligation.py:14-60)与should_run_packet.py:274,1431:在recommended_mode == "repair_agent_workspace"分支通过同一谓词复用workspace_guard["required_action"]作为contract_obligation,不再硬编码笼统的共享工作区文案,从而消除execution_obligation与workspace_guard语义分叉。_admitted_interaction_next_cli_actions(loopx/control_plane/work_items/interaction_contract.py:1011-1039)、primary_action.py:111-115与selectPrimaryActionInstruction(loopx/control_plane/work_items/interaction_contract.ts:278-281):前后端同源读取workspace_repair_action/workspace_guard_missing_task_repository,在cli_channel.next_cli_actions中带出正确--goal-id/--todo-id的todo update --task-repository <credential-free-git-identity>命令模板,并确保非跨仓库回退场景精确返回既有的泛化字符串。turnPlanInspectionPaths(loopx/control_plane/quota/turn_envelope.ts:2343-2353)与initialContextReadGroups(loopx/control_plane/quota/progressive_context.ts:991-1000):将workspace_guard(按Object.hasOwn(decision, "workspace_guard")按需过滤,未触发隔离时保持首屏零膨胀)及AGENT_WORKSPACE_REPAIR所需的cli_channel准入字段纳入--initial-read首屏,从根本上解决 Codex App / Antigravity 首屏盲区。
对主干的风险 / Risks
workspace_guard_missing_task_repository 将分支严格收敛在三个联合条件(foreign_git_worktree + repository_source == "goal.repo" + not task_repository),不会放宽任何跨仓库写入拦截,也不会改变非 AGENT_WORKSPACE_REPAIR 场景的 --initial-read 选段(Object.hasOwn(decision, "workspace_guard") 显式过滤)。对于已设置且不匹配的 task_repository,前后端与真实 CLI 集成负例均验证仍保留原工作树迁移提示;此前 413c5cc936 上的 [F1] 与 [F2] 均已彻底关闭,且 origin/main@9af4caa72e 变基后旧基线 TS 故障已消除。唯一外部待完成项为本次 force-push 后的远端 GitHub Actions 仍在排队/运行中,不影响基于全套本地真实环境测试的代码批准结论,但合入前仍遵循既定门禁。
| 验证项 | 状态 | 实跑结果(exact head 8926@703324e219dfff11ed730b6a8abc88f0e69a5865,base 9af4caa72e) |
|---|---|---|
| TypeScript 类型检查与 TS 控制面测试 | PASS | npm run typecheck:control-plane 通过(rc=0);Node TS 单测 87 passed + 66 passed(0 失败) |
Python 静态检查(mypy + ruff) |
PASS | mypy 17 个文件 0 问题;所有改动文件 ruff check All checks passed! |
pytest tests/control_plane/test_workspace_git_fact_reads.py |
PASS | 11 passed(含单元正/负例与真实 SQLite CLI --codex-app --context-delivery on 首屏集成双参数用例) |
pytest tests/control_plane/test_quota_settlement_cli.py -k "workspace or foreign" & test_context_first_read.py |
PASS | 15 passed, 195 deselected in 30.98s;test_context_first_read.py 160 passed, 2 deselected |
| 控制面 Smoke 与 Semantic Drift 检查 | PASS | peer-agent-workspace-guard-smoke.py (rc=0)、quota-spend-workspace-causality-smoke.py (ok)、semantic-vocabulary-drift-smoke.py (ok) |
canary premerge --tier quick & 公开边界扫描 |
PASS | ok: true, failures: 0, manual_holds: 0; loopx check 9 文件 errors: 0, warnings: 0 |
远端 GitHub CI(703324e219 诊断行) |
UNVERIFIED(diagnostic) | 刚随精确头排队执行(Sign-off 与 Summary 已通过);由本地全量同构套件覆盖当前不变量 |
我的整体评价 / Verdict
CLI/control-plane quota guard and progressive context projection change across Python/TS modules and tests with zero UI or rendered layout changes. unverified_scope: none.
在长程效果(long_horizon)上,跨仓库未绑定时的误导停滞与渐进上下文首屏丢失均被根除,Agent 可在首屏一次性分辨“绑定 --task-repository”或“切换工作树”并快速恢复推进,不会污染已绑定或普通 NORMAL_RUN 轨迹;在用户体验(user_experience)上,前后端提示动词 loopx todo update --task-repository <credential-free-git-identity> 与具体 --goal-id/--todo-id 参数清晰统一,无需猜测命令语法,且未引入任何新持久化字段、环境开关或破坏性兼容迁移(未新增任何状态枚举,已通过 semantic-vocabulary-drift-smoke 验证)。全部必需证据与回归检查均在 exact head 703324e219dfff11ed730b6a8abc88f0e69a5865 通过,正式给出 APPROVE。
English verdict: APPROVE
Merge Decision Record (
|
A peer doing legitimate cross-repository work could receive only a generic “move to an independent worktree” instruction when the selected Todo omitted
task_repository. Because the guard fell back to the Goal repository, a valid independent worktree from the intended repository was classified as foreign without explaining how to bind--task-repositoryacross both full CLI outputs and Codex App / Antigravity progressive initial reads.Rebased onto
origin/main(9af4caa72e), resolving prior review[F1]/[F2]on413c5cc936at exact head703324e219:workspace_guard.py: Addsworkspace_guard_missing_task_repository(guard)and clarifies the Goal-repository fallbackrequired_actionto runloopx todo update --task-repository <credential-free-git-identity>, while leaving explicittask_repositorymismatches on the generic worktree-move instruction.execution_obligation.py&should_run_packet.py: Passesworkspace_guardintobuild_execution_obligationsocontract_obligationsurfaces the missing cross-repository remediation text only whenworkspace_guard_missing_task_repository(workspace_guard)holds.primary_action.py,interaction_contract.py,interaction_contract.ts: Projectsworkspace_repair_actionthroughprimary_action_instruction_factsand updates_admitted_interaction_next_cli_actionsso bothinteraction_contract.agent_channel.primary_actionandinteraction_contract.cli_channel.next_cli_actionsexplaintodo update --task-repositorywhile preserving exact fallback strings for ordinary workspace repair.turn_envelope.ts&progressive_context.ts: Includes"workspace_guard"inINITIAL_CONTEXT_DECISION_FIELDS(filtered cleanly when absent inturnPlanInspectionPaths) and includescli_channeladmission fields (next_cli_actions,spend_*) in the progressive opening wheneffective_action == "agent_workspace_repair".tests/control_plane/test_workspace_git_fact_reads.py): Covers both unit fallback vs. explicit mismatchedtask_repositorynegative checks and end-to-end SQLite--codex-app --context-delivery onprogressive--initial-readverification.Verification (Exact Head
703324e219on Base9af4caa72e)npm run typecheck:control-plane: passed (rc=0)node --experimental-strip-types --test tests/control_plane_ts/interaction_execution_decision.test.ts tests/control_plane_ts/context_delivery.test.ts tests/control_plane_ts/quota_run_decision.test.ts tests/control_plane_ts/turn_envelope.test.ts:87 passed+66 passed(0failed)uv run --extra test python -m mypy(17 source files) &ruff checkon all changed Python files:0issuesuv run --extra test python -m pytest -q tests/control_plane/test_workspace_git_fact_reads.py:11 passed in 4.24suv run --extra test python -m pytest -q tests/control_plane/test_quota_settlement_cli.py -k "workspace or foreign":15 passed, 195 deselected in 30.98sexamples/control_plane/peer-agent-workspace-guard-smoke.py&examples/control_plane/quota-spend-workspace-causality-smoke.py: both passeduv run --extra test loopx canary premerge --tier quick --from-git-diff --git-diff-base origin/main:passed(ok=true, failures=0, manual_holds=0, includingmodule_ceiling_colocation& 3 selected canaries)loopx check --scan-path ...across all 9 changed files:errors=0, warnings=0