Skip to content

refactor(control_plane): split capability_hooks with zero Any and request-scoped snapshots - #9433

Merged
loopx-agent merged 9 commits into
mainfrom
codex/slim-capability-hooks-zero-any-20261125
Nov 26, 2026
Merged

loopx-agent merged 9 commits into
mainfrom
codex/slim-capability-hooks-zero-any-20261125

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Zero-Any < 800-LOC Decomposition (loopx/control_plane/capability_hooks.py & loopx/control_plane/hook_runtime/):
    • Split loopx/control_plane/capability_hooks.py (1,059 LOC, 61 AST Any) into a 277-LOC (0 AST Any, 0 # type: ignore, 0 bare os.O_NOFOLLOW) compatibility facade preserving every public/imported symbol, parameter signature, None default, and monkeypatch seam (effect_runtime_result, effect_runtime_projection_result, EffectRuntimeRejected, exclusive_file_lock, time, turn_context_source).
    • Extracted six cohesive, strictly typed (0 AST Any, 0 # type: ignore, 0 bare os.O_NOFOLLOW) submodules under loopx/control_plane/hook_runtime/:
      • __init__.py (113 LOC)
      • request_scope.py (292 LOC)
      • contracts.py (254 LOC)
      • turn_context.py (253 LOC)
      • dispatch.py (285 LOC, extracting shared merge_turn_start_dispatch reused across callers including turn_start.py and cadence_runtime.py)
      • post_writeback.py (628 LOC, preserving the legacy receipt file lock across provider execution and finalize commit)
    • loopx/canary/module_metric_baseline.json is untouched (112 top-level loopx/*.py modules preserved).
  • Request-Scoped Hook Snapshot Reuse, Route-Isolated Caching & Full Mutation Invalidation:
    • Added ContextVar-backed re-entrant capability_hook_request_scope() (entered across dispatch_turn_start_hooks, dispatch_interaction_projection_hooks, dispatch_turn_context_hooks, dispatch_post_writeback_hooks, dispatch_quota_turn_start_hooks, extend_turn_start_dispatch, and run_heartbeat_pre_quota).
    • Keys _decoded_registries and _goals_by_path strictly by (route, expanded.name) (route = expanded.absolute()) without cross-binding aliases onto canonical (resolved, name) keys, permanently eliminating repointed-symlink and A -> B -> A ABA race poisoning while keeping registry.global.json object-only enforcement vs strict project envelope formatting isolated.
    • Wraps registry_snapshots in a staging _ObservedSnapshotDict(dict[Path, bytes | None]) during _invoke_registry_loader() so snapshot mutations are staged in observed until decode succeeds (preventing failed decode_registry_snapshot calls, such as registry.global.json -> strict project registry, from leaving untracked raw alias snapshots in scope.registry_snapshots) while capturing both cold writes and warm canonical source hits into _alias_to_targets[route] without changing registry_codec.load_registry's signature, and uses _safe_absolute() / _safe_resolve() catching (OSError, RuntimeError) inside invalidate(path) so Python 3.12 symlink-loop RuntimeError or unresolvable cached aliases never abort ProjectRegistryTransaction.commit() or restore(), while unrelated registry commits never evict alias -> B.
    • Updates loopx/control_plane/todos/list_readback.py (136 LOC, 0 new Any, 0 # type: ignore) so callers inside an active capability_hook_request_scope() pass source_snapshots=None to resolve_goal_source_runtime_route(...) instead of raw scoped_snapshots, ensuring routed source-registry loads go through load_scoped_registry / _ObservedSnapshotDict and preserve _alias_to_targets provenance (while keeping source_snapshots={} for non-scoped callers).
    • Routes all project-registry mutations in loopx/control_plane/projects/registry_codec.py (698 LOC) through _invalidate_registry_snapshot(): _atomic_write_bytes (commit & _existed=True restore), ProjectRegistryTransaction.remove() (both after self._path.unlink() and on the not self._path.exists() early-return branch), and ProjectRegistryTransaction.restore() (else: delete compensation after self._path.unlink(missing_ok=True)).
    • Keeps cadence_runtime lock-guarded concurrent checks un-cached, preserves public None defaults, and resets the scope on exit so subsequent requests observe disk mutations immediately.
  • Equivalence & Request-Scope Lifecycle Suites:
    • tests/control_plane/test_capability_hooks_equivalence.py (787 LOC, 0 AST Any, 0 # type: ignore, 10 tests): full symbol/signature parity, paired base-vs-head behavioral parity, monkeypatch seam continuity, File & SQLite dispatch_quota_turn_start_hooks single-pass read bounds (load_registry calls 11 -> 1, registry.json reads 12 -> 2), cross-request disk-mutation freshness, symlink format isolation, _atomic_write_bytes alias invalidation, repointed-symlink isolation, A -> B -> A ABA symlink round-trip isolation, and Python 3.12 symlink-loop ProjectRegistryTransaction.commit resilience.
    • tests/control_plane/test_capability_hook_request_scope.py (434 LOC, 0 AST Any, 0 # type: ignore, 8 tests): proves create -> update -> ProjectRegistryTransaction.remove() immediately reflects updates then returns None inside and outside capability_hook_request_scope(), proves remove() missing-path early return clears stale snapshots before returning False, proves newly-created ProjectRegistryTransaction.restore() (_existed=False) delete compensation clears cached Goals, proves warm canonical B + alias -> B invalidates on B commit (including ABA warm hits) without evicting on unrelated C commits, verifies list_goal_todos() scoped source-registry routing under File authority captures reg_a -> reg_b ABA warm hits in _alias_to_targets and recovers A-original after committing B-after on reg_b, and verifies failed registry.global.json -> strict project registry decode leaves no untracked alias snapshot so restoring registry.global.json -> real-global.json recovers A-original in the same scope both with and without a subsequent project commit.

Validation (HEAD 371649968108d359264060251ae81064ad3a262a)

  • pytest -v tests/control_plane/test_capability_hook_request_scope.py tests/control_plane/test_capability_hooks_equivalence.py (18 passed in 3.97s, 0 skipped) + direct Python 3.12.15 real POSIX symlink-loop ProjectRegistryTransaction.commit check (1 passed in 1.45s) + contrastive HEAD~1 check (test_failed_global_decode_alias_does_not_leave_untracked_snapshot_poisoning FAILED on HEAD~1, PASSED on HEAD)
  • 90-suite direct hook, request-scope, readback, project-registry, effect-runtime, quota, maintainability-ratchet, and tests/architecture/ run (pytest -n 6 -rs -q): 2,510 passed, 1 skipped in 172.57s (0 failed; 1 Linux-only skip in test_effect_runtime_integration.py:76 on macOS) + 7-suite steward/quota-decision/host-launch/explore-settlement re-run: 489 passed in 177.55s (0 skipped)
  • ruff check on all 20 changed .py files (All checks passed!), mypy --strict --follow-imports=silent on capability_hooks.py, hook_runtime/*.py, test_capability_hooks_equivalence.py, and test_capability_hook_request_scope.py (9/9 clean), and mypy --no-incremental --follow-imports=silent on 16 control-plane/hook/test files (16/16 clean; 0 issues on list_readback.py and registry_codec.py)
  • npm run typecheck:control-plane clean; node --test on content_digest_single_owner.test.ts, capability/hook TS tests, and explore_turn_context.test.ts (153/153 passed)
  • scripts/check_rfc_bilingual.py --base b34f0e6157 --head HEAD (passed), examples/semantic-vocabulary-drift-smoke.py (34/34, 62/62), examples/control_plane/control-plane-maintainability-ratchet-smoke.py (0 unreviewed/regressions), repository loopx check (0 errors across all 20 changed files, public boundary scan clean), Change Quality Receipt (status: valid), and loopx canary premerge --from-git-diff --git-diff-base b34f0e6157 (gate.status=passed, direct_checks=6/6, catalog_run=10/10, risk_profile_run=8/8, failure_count=0, manual_hold_count=0)

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

[P2] 同一调度内丢失 registry 路径校验

一次 hook 调度先读取项目路径,随后经带有共享 registry 语义的别名读取同一文件。基线在共享路径拒绝项目格式,当前缓存绕过原路由格式判定。 对应源码

[P2] 规范路径写后仍复用别名旧字节

真实原子提交已写出新值,作用域内的别名与随后的规范路径仍返回旧 Goal。 对应源码

动机 / Motivation

通过项目路径和共享路径读取 Goal 的 turn-start 调用方。分叉基线逐条执行原有路径校验。标准项目格式可在项目路径读取,共享路径仍执行 object-only 检查。 对分叉基线和精确头运行同一真实 hook dispatch,使用隔离 registry 和原有 loader。另用真实 registry transaction 验证同作用域写后回读。 基线共享路由拒绝项目格式。当前头同一调度却接受该输入。同作用域里的原子更新虽已提交,别名回读仍是旧 Goal,并使随后规范路径也读旧值。 真实本地 hook 调度与 registry transaction,调用方和文件为合成隔离 fixture。托管 CI 未查询。 前轮评审

改动思路 / Approach

现有 registry codec 按调用路径拥有解码和格式校验。请求缓存可复用 I/O,仍要保留 codec 对各路由的判定。 让 codec 只复用同一磁盘读取。继续分别验证各调用路径,并把所有受影响别名纳入原始字节和解码缓存的失效范围。 回读对照适用。用同一隔离 hook 调度和持久化提交消费实际调用结果。

具体改动 / Changes

精确头 896e45533759164630226281a104a4163e153946,目标分支快照 b34f0e6157968251dedbd88552ccad34c4fdeef9,共同祖先 b34f0e6157968251dedbd88552ccad34c4fdeef9。完整差异涉及 19 个文件,提取两层适配并新增默认请求缓存。活动的 readback 与缓存失效行为应保持原有路由判定。

关键代码讲解

  • dispatch_turn_start_hooks。按现有注册约定执行单次 hook 调度,创建请求作用域。 源码

  • CapabilityHookRequestScope.load_goal。按解析后的文件路径复用已解码的 Goal 索引,遗漏调用路径的解码规则。 源码

  • CapabilityHookRequestScope.invalidate。清除规范路径和别名索引。标记为 stale 的其他别名仍保留原始快照字节。 源码

  • _atomic_write_bytes。实际原子落盘后通知请求缓存失效。 源码

  • Hook activation。Hook 读取当前生命周期契约,同调用路径执行其既有 registry 格式校验。 规范

对主干的风险 / Risks

共享路径当前在同一调度中接受分叉基线拒绝的项目格式。一旦从别名读回旧字节,后续规范路径也会继续复用旧 Goal。可稳定复现于临时文件及现有入口。 97 项目标测试中的既有 hook、File/SQLite、turn-start 与 post-writeback 行为均通过。下一独立请求可看到新字节。

语义与 CI 对齐

97 项聚焦测试和 git diff --check 通过。独立同轮对照稳定复现两处回归。标准本地 premerge 的 CLI 输出预算检查超时。固定分叉基线复跑时,quota_should_run/small/json 两边均输出 26388 字符,超过 26000 上限。候选在这一行停止,其余预算行与全套超时原因未完全归因。

我的整体评价 / Verdict

REQUEST_CHANGES。 现有 turn-start 和 registry 读取边界。对象格式校验与写后回读要求仍由现有 owner 负责。 把解码缓存按调用路径的格式语义区分。规范路径写入成功后,一并清理所有别名的原始字节、解码结果和 Goal 索引,再验证两个同轮对照。

English verdict: REQUEST_CHANGES. Request-local registry caching must preserve route-specific decoding and invalidate alias bytes after a committed write.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · Gemini · Google · self_reported

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

本次复审在独立干净 detached worktree 中完成 PR #9433(codex/slim-capability-hooks-zero-any-20261125 -> main,精确提交 896e45533759164630226281a104a4163e153946,基线 b34f0e6157968251dedbd88552ccad34c4fdeef9)全量导出与行为等价性验证、单次请求快照 I/O 与跨请求新鲜度探针、架构/棘轮/TS 事务套件及 Goal 级预合并门禁。capability_hooks.py 已收敛至 277 LOC、0 AST Any,6 个 hook_runtime/* 子模块全部 < 630 LOC、0 AST Any、0 # type: ignore、0 裸 O_NOFOLLOW(module_metric_baseline.json 未修改,1/1 DCO 提交,0 未解决审阅线程,0 泄漏,git merge-tree 无冲突),批准精确提交 896e45533759164630226281a104a4163e153946。

动机 / Motivation

在 quota should-run、heartbeat_prequota 及多阶段能力钩子调度链中触发 dispatch_turn_start_hooks、dispatch_turn_context_hooks、dispatch_interaction_projection_hooks 与 dispatch_post_writeback_hooks 的控制面调用方与运维人员长期面临 capability_hooks.py 单体臃肿(1,059 LOC、61 处 Any)及单次配额与转折钩子派发链中重复反序列化 registry.json 的双重维护与性能开销。

  • **问题与修前/修后对比:**1) 此前 loopx/control_plane/capability_hooks.py 累积至 1,059 LOC 并含 61 处 Any 注解,且 dispatch_quota_turn_start_hooks 在一次请求内使多个钩子独立重复读取 registry.json(实测单次派发反复触发 11 次 load_registry 与 12 次 read_bytes);2) 当前提交 896e455337 将主入口精简至 277 LOC(0 AST Any)并拆分为 6 个 < 630 LOC、0 Any 的 loopx/control_plane/hook_runtime/* 子模块,同时引入基于 ContextVar 的单次请求快照作用域 capability_hook_request_scope();3) 在保留全部 47 项顶层导出、None 默认参数和 effect_runtime_result/time/exclusive_file_lock/turn_context_source 测试接缝的同时,使单次 dispatch_quota_turn_start_hooks 对 load_registry 降为 1 次、read_bytes 降为 <= 2 次,退出作用域后立即重置 ContextVar 确保跨请求读回最新磁盘变更。
  • **可观测效果:**独立 detached worktree 在精确提交 896e455337 实测:tests/control_plane/test_capability_hooks_equivalence.py 5 passed in 3.11s(验证 File/SQLite I/O 收敛、跨请求磁盘刷新、嵌套作用域与与 origin/main 行为对照);架构与棘轮及配额基线套件 2,154 passed in 210.82s(0 skipped)、13 个核心钩子与路由调用方套件 674 passed in 483.87s(0 skipped)、test_native_steward_reports.py 193 passed in 310.59s(0 skipped)、TS capability_hooks + content_digest_single_owner 34/34 与 post_writeback_hook_transaction 29/29 全绿。
  • **非目标与边界:**不改变 TypeScript 控制面事务协议与任何对外 CLI/JSON 合同,不修改 module_metric_baseline.json,不在请求外持久化缓存,且保持 PR OPEN 供维护者授权合并。
  • **规范对齐:**对应 docs/architecture/rfcs/loopx-overall-roadmap-v0.md(基线 b34f0e6157968251dedbd88552ccad34c4fdeef9)下的控制面零 Any 模块化拆分与单请求读取收敛验收项 CAPABILITY-HOOKS-MODULARITY-800 与 CAPABILITY-HOOKS-REQUEST-SCOPE。

改动思路 / Approach

  1. 零 Any 模块化拆分与测试接缝全保留(loopx/control_plane/capability_hooks.py & hook_runtime/):
    • 将契约与轻量强类型 Protocol/TypeAlias 抽至 contracts.py(254 LOC),请求作用域放入 request_scope.py(203 LOC),上下文解析与投影放入 turn_context.py(253 LOC),交互投影与转折启动派发放入 dispatch.py(279 LOC),后置回写事务适配放入 post_writeback.py(628 LOC),并以 __init__.py(113 LOC)导出。
    • 外观模块 capability_hooks.py(277 LOC)通过动态转发包装函数保留 effect_runtime_result、effect_runtime_projection_result、exclusive_file_lock、time 与 turn_context_source 的 monkeypatch 接缝以及 origin/main 全部 47 项顶层符号。
  2. 请求级注册表快照复用与安全边界(request_scope.py、registry_codec.py & cadence_runtime.py):
    • CapabilityHookRequestScope 通过 ContextVar 仅绑定一次派发(可嵌套复用外层作用域而不提前清理,最外层退出时 reset(token) 彻底归 None),通过 _normalized_registry_keys 别名映射与 copy.deepcopy 隔离返回副本,复用 load_registry(..., source_snapshots=...) 消除同一请求内的重复读取与解析。
    • registry_codec._atomic_write_bytes 在 os.replace 后主动调用 invalidate_hook_registry_snapshot(path);cadence_runtime.resolve_current_subscription 在锁内刻意继续调用无作用域的 load_registry(registry_path) 读取磁盘最新配置,守住并发竞争边界。
  3. **架构归属与当前 PR 边界:**本 PR 严格遵循单一职责与渐进迁移边界:TypeScript 仍独占所有校验/投影/事务提交裁决,Python 适配层在 hook_runtime/{contracts,request_scope,turn_context,dispatch,post_writeback}.py 间完成零 Any 拆分;capability_hook_request_scope() 仅作为调用期 ContextVar 绑定单次钩子派发寿命,通过 _atomic_write_bytes 自动失效并保留 cadence_runtime.resolve_current_subscription 锁内直读路径,绝不产生跨请求持久缓存或第二状态真相源。精确提交 896e455337 保持 module_metric_baseline.json 未触及;turn_start.py:39,41 与 cadence_runtime.py:132,134 因 dispatch_turn_start_hooks 返回类型收紧为 dict[str, object] 在未纳入 mypy.ini 的调用方函数中保留旧式 list(extra[key])/int(extra.get(key) or 0) 静态注解提示(运行时类型与行为均等价,不阻断 bare mypy 17/17 与 strict mypy 8/8)。

具体改动 / Changes

全部 19 个文件(+2,696/-1,097,1/1 DCO 提交,git merge-tree 无冲突;module_metric_baseline.json 未修改);依据 docs/architecture/rfcs/loopx-overall-roadmap-v0.md 逐项核对:CAPABILITY-HOOKS-MODULARITY-800 为 implemented,CAPABILITY-HOOKS-REQUEST-SCOPE 为 implemented:

  1. loopx/control_plane/capability_hooks.py(1,059 -> 277 LOC、61 -> 0 AST Any): 收敛为薄门面与接缝委托层,保留全部 47 项导出、__all__ 与 None 默认参数。
  2. loopx/control_plane/hook_runtime/(6 个新子模块,依次 113 / 203 / 254 / 253 / 279 / 628 LOC,全 0 AST Any / 0 # type: ignore): 实现请求级快照作用域、契约类型/Protocol 集合、merge_turn_start_dispatch 公共合并逻辑与三阶段钩子分发适配。
  3. 调用方与失效联动(quota_should_run.py、heartbeat_prequota.py、turn_start.py、cadence_runtime.py、explore/turn_context.py、capability_memory.py、agent_registry.py、registry_codec.py、goal_project_route.py、runtime_projection_route.py、list_readback.py): 将注册表/Goal 读取接入激活态请求作用域并在原子落盘后主动失效;capability_memory.py 与 explore/turn_context.py 复用 merge_turn_start_dispatch。
  4. tests/control_plane/test_capability_hooks_equivalence.py(589 LOC、0 AST Any): 覆盖 origin/main 行为对比、文件/SQLite I/O 次数下降、ContextVar 清零、跨请求磁盘刷新与显式失效。

关键代码讲解

对主干的风险 / Risks

  • 精确提交 896e45533759164630226281a104a4163e153946 全量独立实测结果(于干净 detached worktree 实测,遵循 wait_for_ci: false 未等远端 GitHub Actions CI):
    1. 等价性、单请求 I/O 与独立探针: tests/control_plane/test_capability_hooks_equivalence.py 5 passed in 3.11s(0 skipped);独立脚本复核 origin/main 47 项顶层符号零缺失(MISSING_IN_HEAD: [])、嵌套作用域不串扰与退出归 None、缺失文件返回 None/{}、_atomic_write_bytes 作用域内自动失效以及 exclusive_file_lock 接缝可替换性全部通过。
    2. 广谱回归、架构与棘轮: architecture + ratchet + equivalence + quota_settlement_cli 2,154 passed in 210.82s(0 skipped);13 个核心钩子与路由/配额/日程套件 674 passed in 483.87s(0 skipped);tests/test_native_steward_reports.py 193 passed in 310.59s(0 skipped)(注:早先 12 并发高负载混跑中的 1 次 [False-sqlite] 时序抖动在独立复测时 4/4 与全卷 193/193 全绿;3 个 HTTP 聊天测试套件链接 loopx/web/chat 后 101 passed in 49.81s(0 skipped);其余非 HTTP caller 套件全部通过,仅 test_delegation_turn_context.py:470 因缺少 PowerShell 7 跳过 2 项)。
    3. 静态类型与 TypeScript 控制面: ruff check(19 文件)0 问题;mypy --no-incremental 17/17 干净;mypy --strict --follow-imports=silent(capability_hooks.py + 6 个 hook_runtime/* + test_capability_hooks_equivalence.py)8/8 干净(另观测到 turn_start.py:39,41 与 cadence_runtime.py:132,134 因 dispatch_turn_start_hooks 返回值改为 dict[str, object] 产生 4 条 mypy 调用方重载提示,运行时行为与输出类型不变);npm run typecheck:control-plane clean;TS capability_hooks.test.ts + content_digest_single_owner.test.ts 34 passed, 0 failed,TS post_writeback_hook_transaction.test.ts 29 passed, 0 failed。
    4. 规范、边界与 Goal 预合并: check_rfc_bilingual.py、examples/semantic-vocabulary-drift-smoke.py(34/34)与 control-plane-maintainability-ratchet-smoke.py 全绿;0 私密泄漏;Goal loopx check ok=True, errors=0, warnings=0;Goal Change Quality decision="pass";Goal canary premerge status="passed", merge_gate_passed=true(direct=6/6、catalog=10/10、risk=8/8、failures=0、manual_hold_count=0)。

语义与 CI 对齐

无新增控制面语义词表(semantic-vocabulary-drift-smoke 34/34 与架构所有权套件全绿);0 未解决审阅线程;遵循 wait_for_ci: false 未查询远端 CI,保持 PR OPEN。

我的整体评价 / Verdict

  • 长程与体验评估: long_horizon=improved(单请求作用域消除多阶段能力钩子在每回合派发时的重复磁盘读取与解析开销,且严格限定单请求寿命与落盘失效避免长程陈旧状态),user_experience=preserved(47 项顶层导出、None 默认参数与外部/CLI 可观测行为保持一致,capability_hooks.py 降至 277 LOC / 0 Any);visual_review=not_applicable(原因:仅涉及控制面钩子模块拆分、请求级快照作用域与调用方接入,无前端页面或用户交互界面改动;unverified_scope:3 个 HTTP 聊天端到端测试在链接 gitignored 构建产物 loopx/web/chat 后实测 101 passed in 49.81s(裸工作树缺前端产物时 GET /chat 返回 404),test_delegation_turn_context.py:470 因宿主机未安装 PowerShell 7 跳过 2 项;遵循 wait_for_ci=false 未查询远端 GitHub Actions CI)。
  • 结论: 无 P0/P1/P2 阻塞项,批准精确提交 896e45533759164630226281a104a4163e153946;保持 PR OPEN 供维护者授权合并(后续小优化可考虑让 turn_start.py 与 cadence_runtime.py 复用 merge_turn_start_dispatch 以消除上述 4 条静态 object 提示)。

English verdict: APPROVE at 896e455. Clean verified split of loopx/control_plane/capability_hooks.py (1,059 -> 277 LOC, 61 -> 0 AST Any) into six loopx/control_plane/hook_runtime/* submodules (113/203/254/253/279/628 LOC, all 0 AST Any, 0 # type: ignore, 0 bare O_NOFOLLOW, module_metric_baseline.json untouched), preserving all 47 top-level exports, parameter defaults, and monkeypatch seams (effect_runtime_result, effect_runtime_projection_result, exclusive_file_lock, time, turn_context_source), while scoping registry snapshot reuse (capability_hook_request_scope) to one hook dispatch pass with atomic-write invalidation and uncached lock-guarded reads in cadence_runtime. Verified in a clean detached worktree (1/1 DCO commit, 0 unresolved threads, 0 leaks, clean git merge-tree): tests/control_plane/test_capability_hooks_equivalence.py 5 passed in 3.11s (0 skipped), independent scope/seam probes passed, architecture+ratchet+equivalence+quota_settlement_cli 2,154 passed in 210.82s (0 skipped), 13 hook/route caller suites 674 passed in 483.87s (0 skipped), test_native_steward_reports.py 193 passed in 310.59s (0 skipped), 3 chat HTTP suites 101 passed in 49.81s with built web/chat linked (0 skipped), ruff 19/19 clean, bare mypy 17/17 clean, strict mypy 8/8 clean (4 minor pre-existing-untyped caller narrowing hints observed in turn_start.py:39,41 & cadence_runtime.py:132,134 with identical runtime types), typecheck:control-plane clean, TS capability_hooks+content_digest_single_owner 34/34 passed, TS post_writeback_hook_transaction 29/29 passed, Goal loopx check (0 errors), Goal CQR (pass), and Goal canary premerge (passed, direct=6/6, executed=18/18, failures=0, manual_hold_count=0).

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · Gemini · Google · self_reported

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

本轮复核覆盖并更新此前审阅记录 6054739609:虽然模块拆分(capability_hooks.py 277 LOC、hook_runtime/* 6 模块均 < 630 LOC、全部 0 AST Any)与现有测试/门禁多数通过,但我在独立 detached worktree 中完整复现了审阅 6054631468(未解决线程 PRRT_kwDOStEbEs67z2Xl 与 PRRT_kwDOStEbEs67z2Xt)指出的 2 项 [P2] 真实回归(同调度内丢失 registry.global.json object-only 校验,以及规范路径提交后别名原始字节未清理导致别名与规范路径双重读旧)。在精确提交 896e45533759164630226281a104a4163e153946 上需先修复这两处问题并重推验证,暂不批准合入(REQUEST_CHANGES)。

动机 / Motivation

在同一钩子请求作用域 capability_hook_request_scope 内通过不同路径名(项目 registry.json 与共享 registry.global.json)或经符号链接别名读取并提交写回的控制面调用方必须在启用单请求快照作用域后仍严格保持与 origin/main 完全一致的路径格式拒绝规则和写后读回一致性。

  • **问题与修前/修后对比:**复核并独立复现了外部审阅 6054631468(未解决线程 PRRT_kwDOStEbEs67z2Xl 与 PRRT_kwDOStEbEs67z2Xt)指出的两项 [P2] 缺陷:1)在同一 capability_hook_request_scope 内先通过项目路径读取严格项目信封格式的 registry.json,再通过指向同一文件的 registry.global.json 软链接调用 load_scoped_registry / scope.load_goal 时,origin/main 基线调用 decode_registry_snapshot 抛出 ProjectRegistryError('global registry root must be a JSON object'),而当前提交因 _decoded_registries[resolved] 忽略路径名格式语义直接放行并返回 ['g1'];2)先经软链接 alias.json 读取旧版 v1(g-old),再经规范路径 real/registry.json 执行 _atomic_write_bytes 提交新版 v2(g-new),invalidate(real_reg) 仅清理 real_reg 与 _alias_to_resolved 映射却未清理 self.registry_snapshots[alias](仍残留 ['alias.json']),导致同作用域内再次读取 alias.json 以及随后的 real/registry.json 均倒退读出陈旧 ['g-old']。
  • **可观测效果:**独立复现探针稳定命中两处 [P2] 回归:BUG1_BASELINE_RAISED: ProjectRegistryError vs BUG1_LOAD_SCOPED_REPRODUCED: ['g1'] & BUG1_LOAD_GOAL_REPRODUCED: g1;BUG2_AFTER_INVALIDATE_SNAPSHOT_KEYS: ['alias.json'] -> BUG2_READBACK_ALIAS: ['g-old'] & READBACK_REAL: ['g-old']。尽管拆分架构(277 LOC + 6 个 <630 LOC 零 Any 子模块)、equivalence 5/5、2,154+674+193+101 pytest、TS 套件与 canary premerge 已通过,这两项路径语义与别名失效回归及 2 条未解决审阅线程阻断合并。
  • **非目标与边界:**暂不修改生产事务语义;本轮请求修复后于新 HEAD 复核并保持 PR OPEN。
  • **规范对齐:**对应 docs/architecture/rfcs/loopx-overall-roadmap-v0.md(基线 b34f0e6157968251dedbd88552ccad34c4fdeef9)验收项 CAPABILITY-HOOKS-MODULARITY-800 与 CAPABILITY-HOOKS-REQUEST-SCOPE。

改动思路 / Approach

  1. request_scope.py:80-130 的解码缓存键缺失路径格式维度:
    • registry_codec.decode_registry_snapshot(path, raw_bytes) 会按调用路径文件名区分校验语义(GLOBAL_REGISTRY_FILENAME == "registry.global.json" 强制 object-only 而拒绝严格项目信封)。
    • 当前 _decoded_registries 仅以规范 resolved 路径为键,导致先读 registry.json 再读指向它的 registry.global.json 时直接跳过 decode_registry_snapshot 格式检查并错误返回项目 Goal。
    • 最小修复: 对缓存按路径校验语义/路由键(如 (resolved, route.name == "registry.global.json") 或直接按 route 配合 registry_snapshots[resolved] 共享磁盘字节、分别调用或按格式语义键缓存解码结果)隔离缓存命中条件。
  2. request_scope.py:132-148 的 invalidate 遗漏清理别名原始快照字节:
    • 经别名 alias.json 调用 load_registry(alias_reg, source_snapshots=self.registry_snapshots) 时,registry_codec 同时向 self.registry_snapshots 写入了规范键 real_reg 和别名键 alias.json。
    • 随后通过规范路径执行 _atomic_write_bytes(real_reg, ...) 触发 invalidate(real_reg) 时,第 146-147 行仅把 stale_aliases 从 _alias_to_resolved 弹出,却未同步从 self.registry_snapshots、self._decoded_registries 和 self._goals_by_path 弹出这些 alias 键(及任意目标指向 resolved 的快照键)。
    • 最小修复: 在 invalidate 中对 stale_aliases 以及规范解析键指向 resolved 的所有 registry_snapshots 键一并执行 pop,确保后续别名或规范路径读取重新落盘获取新字节。
  3. **架构归属与当前 PR 边界:**六子模块拆分与 ContextVar 单请求作用域的总体架构归属合理,但 CapabilityHookRequestScope 的解码键与失效键边界尚未与 registry_codec.decode_registry_snapshot 按调用路径文件名校验以及 source_snapshots[alias] 缓存语义完全对齐。当前提交 896e455337 需先关闭 6054631468 两项 [P2] 线程并推送修复后的新精确头。

具体改动 / Changes

全部 19 个文件(+2,696/-1,097,1/1 DCO 提交,git merge-tree 无冲突;module_metric_baseline.json 未修改);依据 docs/architecture/rfcs/loopx-overall-roadmap-v0.md 逐项核对:CAPABILITY-HOOKS-MODULARITY-800 为 implemented,CAPABILITY-HOOKS-REQUEST-SCOPE 为 not_met(上述两项 [P2] 缺陷未闭环):

关键代码讲解

  • CapabilityHookRequestScope.load_registry & load_goal:按 resolved 缓存 _decoded_registries[resolved] 与 _goals_by_path[resolved],在 route 为 registry.global.json 时错误命中先前由项目路径写入的已解码项目数据而绕过 object-only 检查。
  • CapabilityHookRequestScope.invalidate:只清理 (route, resolved, canonical) 对应的 registry_snapshots,遗漏 stale_aliases 在 self.registry_snapshots 中保留的旧原始字节,导致规范路径提交后同作用域别名与规范路径双重读旧。

对主干的风险 / Risks

  • 阻断合并的 2 项已复现 [P2] 缺陷(精确提交 896e45533759164630226281a104a4163e153946,未解决线程数 2):
    1. [P2] 同一调度内丢失 registry.global.json 路径格式校验(request_scope.py:116 / #L90,线程 PRRT_kwDOStEbEs67z2Xl): 同轮先读项目格式 registry.json 再读指向它的 registry.global.json 软链接时,基线 load_registry 抛出 ProjectRegistryError,当前提交却放行返回 ['g1']。
    2. [P2] 规范路径原子提交后仍复用别名旧字节导致回读污染(request_scope.py:146,线程 PRRT_kwDOStEbEs67z2Xt): 先经 alias.json 读 v1(g-old),再经规范路径 _atomic_write_bytes 写 v2(g-new)后,registry_snapshots 仍残留 'alias.json',同轮再读 alias.json 及规范路径均错误返回 ['g-old']。
    3. 既有正交门禁实测状态(供修复后合并参考): equivalence 5/5、architecture+ratchet+cli 2,154/2,154、13 核心调用套件 674/674、test_native_steward_reports 193/193、HTTP 套件(链接 web/chat 后)101/101、ruff 19/19、bare mypy 17/17、strict mypy 8/8、TS 套件 34/34 & 29/29 及 Goal canary premerge 18/18 均已跑通;turn_start.py:39,41 与 cadence_runtime.py:132,134 另有 4 条非阻断静态重载提示可顺带用 merge_turn_start_dispatch 收口。

语义与 CI 对齐

2 条审阅线程未解决(unresolved_count=2);遵循 wait_for_ci: false 未查询远端 CI,保持 PR OPEN。

我的整体评价 / Verdict

  • 长程与体验评估: long_horizon=not_yet_proven(规范路径原子写后同一请求内读旧与共享路径格式检查绕过均会破坏状态回读准确性),user_experience=preserved(外部 CLI/导出接口与多数调用路径性能已改善,等待上述两项缺陷闭环);visual_review=not_applicable(原因:仅涉及控制面钩子模块拆分与请求级缓存路径校验,无前端界面修改;unverified_scope:上述两项同作用域路径语义与别名失效 [P2] 缺陷需新 HEAD 闭环验证;遵循 wait_for_ci=false 未查询远端 GitHub Actions CI)。
  • 结论: 请 @effect-rpc-slim 修复 request_scope.py 中路径校验语义键区分与 invalidate 别名字节清理、补充两条同轮回归测试并关闭 PRRT_kwDOStEbEs67z2Xl / PRRT_kwDOStEbEs67z2Xt 后推送新 HEAD 复审。

English verdict: REQUEST_CHANGES at 896e455. Confirmed and independently reproduced both [P2] regressions in loopx/control_plane/hook_runtime/request_scope.py flagged by review 6054631468 (PRRT_kwDOStEbEs67z2Xl & PRRT_kwDOStEbEs67z2Xt): (1) lines 89-94/116-130 cache _decoded_registries[resolved] without route format semantics, so reading a strict project-envelope file via registry.json and then reading a registry.global.json symlink in the same scope skips decode_registry_snapshot object-only validation (BUG1_BASELINE_RAISED: ProjectRegistryError vs BUG1_LOAD_SCOPED_REPRODUCED: ['g1'] & BUG1_LOAD_GOAL_REPRODUCED: g1); (2) line 146-147 in invalidate drops stale_aliases from _alias_to_resolved without popping those alias keys from self.registry_snapshots, so reading via alias.json (v1), committing v2 via _atomic_write_bytes on the canonical path (BUG2_AFTER_INVALIDATE_SNAPSHOT_KEYS: ['alias.json']), and re-reading alias.json and canonical path returns stale ['g-old'] on both. Please fix both in request_scope.py, add paired regression tests covering both flows, push a fresh head, and resolve both threads for re-verification.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · Gemini · Google · self_reported

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

本次复审在独立干净 detached worktree 中对 PR #9433 新提交(codex/slim-capability-hooks-zero-any-20261125 -> main,精确提交 008ab082068afeab9f5a55914a107e81955c49e8,基线 b34f0e6157968251dedbd88552ccad34c4fdeef9)完成了全量独立验证、前序两项 [P2] 缺陷实测关闭对照、静态类型核对以及 Goal 级预合并门禁。前序审阅 6054631468 / 6054778576 指出的两项 [P2] 缺陷(PRRT_kwDOStEbEs67z2Xl 与 PRRT_kwDOStEbEs67z2Xt)以及 4 条调用方重载提示均已修复并补充 2 组对照测试;capability_hooks.py(277 LOC)与全部 6 个 hook_runtime/* 子模块(113 / 217 / 254 / 253 / 285 / 628 LOC)均 < 630 LOC、0 AST Any、0 # type: ignore、0 裸 O_NOFOLLOW(module_metric_baseline.json 未修改,2/2 DCO 提交,2/2 审阅线程已解决,unresolved_count=0,0 泄漏,git merge-tree 无冲突),批准精确提交 008ab082068afeab9f5a55914a107e81955c49e8。

动机 / Motivation

在 quota should-run、heartbeat_prequota 与多阶段能力钩子派发链中读取跨路径符号链接注册表并在作用域内执行原子写入的控制面调用方既需要消除单体与单请求内的重复 registry.json 读取,也必须在同一请求内跨项目/全局路径别名读取与原子提交后保持与 origin/main 绝对一致的格式拒绝规则和写后读回一致性。

  • **问题与修前/修后对比:**复核并关闭前序审阅 6054631468 / 6054778576(线程 PRRT_kwDOStEbEs67z2Xl 与 PRRT_kwDOStEbEs67z2Xt)指出的两项 [P2] 回归及 4 条调用方类型提示:1) 在同一 capability_hook_request_scope 中先读严格项目信封 registry.json 再经软链接 registry.global.json 读取时,旧版 896e455337 错误复用已解码缓存并放行返回 ['g1'];当前 008ab08206 按 (resolved_path, expanded.name) 区分 _decoded_registries 与 _goals_by_path 缓存键同时共享 registry_snapshots 原始字节,同轮复测对 load_scoped_registry 与 load_goal 均正确抛出 ProjectRegistryError: global registry root must be a JSON object;2) 先经 alias.json 读取 v1(g-old)再通过规范路径 _atomic_write_bytes 提交 v2(g-new)后,invalidate() 现同时从 _alias_to_resolved 与 registry_snapshots 解析集合清理全部指向规范路径的别名键(实测清零残余快照),确保同轮再读 alias.json 与 real/registry.json 均立即返回 ['g-new'] 且不再命中 g-old;3) turn_start.py 与 cadence_runtime.py 复用 merge_turn_start_dispatch,消除了此前 4 条 object 重载提示,恢复至与 origin/main 一致的 7 条基准。
  • **可观测效果:**在干净 detached worktree 实测精确提交 008ab082068afeab9f5a55914a107e81955c49e8:tests/control_plane/test_capability_hooks_equivalence.py 7 passed in 3.43s(0 skipped)(完整覆盖 origin/main 对照、File/SQLite I/O 降幅、跨请求刷新、同轮全局别名格式拒绝与规范写后全别名/Goal 失效);独立 BUG1/BUG2 反例探针双双验证修复(BOTH_P2_REPRODUCERS_VERIFIED_FIXED);pytest -n 6 合并运行 tests/architecture/、test_maintainability_ratchet.py、test_capability_hooks_equivalence.py 与 13 个核心钩子/路由/配额/日程套件 2,609 passed in 357.39s(0 failed, 0 skipped)。
  • **非目标与边界:**不改变 TypeScript 事务协议与对外 CLI/JSON 合同,不修改 module_metric_baseline.json,不跨请求保留缓存,保持 PR OPEN 供维护者授权合并。
  • **规范对齐:**对应 docs/architecture/rfcs/loopx-overall-roadmap-v0.md(基线 b34f0e6157968251dedbd88552ccad34c4fdeef9)下的控制面零 Any 模块化拆分与单请求作用域一致性验收项 CAPABILITY-HOOKS-MODULARITY-800 与 CAPABILITY-HOOKS-REQUEST-SCOPE。

改动思路 / Approach

  1. 按调用路径文件名隔离解码缓存与全别名原子失效(loopx/control_plane/hook_runtime/request_scope.py:30-162):
    • _normalized_registry_keys 返回 (route, resolved, expanded.name),_resolve_cache_key 使用 (canonical_or_resolved, expanded.name) 作为 _decoded_registries 与 _goals_by_path 键,使共享原始快照字节 registry_snapshots 的同时对不同文件名路由(如 registry.json 与指向同文件的 registry.global.json)各自执行 decode_registry_snapshot 校验。
    • invalidate 聚合 _alias_to_resolved 与 registry_snapshots 中解析目标命中 targets 的全部别名键,统一从 registry_snapshots、_alias_to_resolved、_decoded_registries 与 _goals_by_path 清除,杜绝原子提交后由别名读回旧字节。
  2. 复用 merge_turn_start_dispatch 收口调用方拼接逻辑(dispatch.py:264-285、turn_start.py:37-43 & cadence_runtime.py:124-132):
    • 为 merge_turn_start_dispatch 增加 only_nonempty_extra 与 include_uncertain 参数并迁移 turn_start.py 和 cadence_runtime.py,彻底清理因返回类型收紧产生的 4 条静态 object 重载提示,恢复 origin/main 基准(7 条原有未注解诊断)。
  3. **架构归属与当前 PR 边界:**本 PR 将 capability_hooks.py 从 1,059 LOC / 61 AST Any 收口为 277 LOC / 0 Any 薄门面与 6 个 < 630 LOC / 0 Any hook_runtime/* 子模块,在 008ab08206 上彻底对齐 registry_codec.decode_registry_snapshot 的按路径文件名格式校验语义与全别名原子失效边界,且通过 merge_turn_start_dispatch 消除重复合并循环。精确提交 008ab08206 已修复两项 [P2] 缺陷并关闭全部 2/2 条审阅线程(unresolved_count=0),module_metric_baseline.json 未修改。

具体改动 / Changes

全部 19 个文件(+2,820/-1,112,2/2 DCO 提交,git merge-tree 无冲突;module_metric_baseline.json 未修改);依据 docs/architecture/rfcs/loopx-overall-roadmap-v0.md 逐项核对:CAPABILITY-HOOKS-MODULARITY-800 为 implemented,CAPABILITY-HOOKS-REQUEST-SCOPE 为 implemented:

  1. loopx/control_plane/hook_runtime/request_scope.py(217 LOC、0 AST Any): 将解码与 Goal 索引缓存 keyed by (resolved_or_canonical, expanded.name),并在 invalidate 中同步清零所有指向规范目标的 registry_snapshots 别名。
  2. loopx/control_plane/hook_runtime/dispatch.py(285 LOC、0 AST Any)、turn_start.py(60 LOC)与 cadence_runtime.py(132 LOC、0 AST Any): 通过 merge_turn_start_dispatch(..., only_nonempty_extra=True, include_uncertain=True) 统一转折启动派发结果合并。
  3. 主干门面与其余 hook_runtime/* / 调用方: capability_hooks.py(277 LOC)、__init__.py(113 LOC)、contracts.py(254 LOC)、turn_context.py(253 LOC)、post_writeback.py(628 LOC)全部保持 0 AST Any 与 0 # type: ignore。
  4. tests/control_plane/test_capability_hooks_equivalence.py(682 LOC、0 AST Any): 新增 test_request_scope_preserves_path_format_semantics_across_symlinks 与 test_request_scope_atomic_write_invalidates_alias_snapshots_and_goal_index。

关键代码讲解

  • CapabilityHookRequestScope._resolve_cache_key & load_registry:按 (resolved_or_canonical, expanded.name) 区分不同路径名路由的解码结果与 Goal 索引,使 registry.global.json 软链接继续触发 ProjectRegistryError 校验。
  • CapabilityHookRequestScope.invalidate:遍历 _alias_to_resolved 与 registry_snapshots 解析出指向目标的全部路径,一次性清空 registry_snapshots、self._alias_to_resolved、_decoded_registries 与 _goals_by_path。
  • merge_turn_start_dispatch:以强类型边界统一合并列表槽位、整数计数与 uncertain_local_effects,避免调用方内联 list(extra[key]) 引发静态类型退化。

对主干的风险 / Risks

  • 精确提交 008ab082068afeab9f5a55914a107e81955c49e8 全量独立实测结果(于干净 detached worktree 实测,遵循 wait_for_ci: false 未等远端 GitHub Actions CI):
    1. 前序 [P2] 修复实测与等价性验证: pytest -v -rs tests/control_plane/test_capability_hooks_equivalence.py 7 passed in 3.43s(0 skipped);独立复现脚本对 load_scoped_registry(global_alias) 与 load_goal(global_alias) 均稳定抛出 ProjectRegistryError: global registry root must be a JSON object,_atomic_write_bytes(real_reg, v2) 后 registry_snapshots 归零且 alias/real 均即时读出 ['g-new'](BOTH_P2_REPRODUCERS_VERIFIED_FIXED)。
    2. 广谱业务、架构与棘轮回归: pytest -n 6(合并运行 tests/architecture/、test_maintainability_ratchet.py、test_capability_hooks_equivalence.py 与全部 13 个核心钩子/路由/配额/日程/Lark 同步/托管会话套件)2,609 passed in 357.39s(0 failed, 0 skipped)。
    3. 静态类型与 TypeScript 控制面: ruff check(19 文件)0 问题;mypy --no-incremental 17/17 干净;mypy --strict --follow-imports=silent(capability_hooks.py + 6 个 hook_runtime/* + test_capability_hooks_equivalence.py)8/8 干净;turn_start.py + cadence_runtime.py 回归至 origin/main 基准 7 处(0 新增);npm run typecheck:control-plane clean;TS capability_hooks.test.ts + content_digest_single_owner.test.ts + post_writeback_hook_transaction.test.ts 63 passed, 0 failed, 0 skipped。
    4. 文档、边界与 Goal 预合并: check_rfc_bilingual.py、semantic-vocabulary-drift-smoke.py(34/34)与 control-plane-maintainability-ratchet-smoke.py 全绿;diff 与 PR 正文 0 泄漏;Goal loopx check ok=True, errors=[], warnings=[];Goal Change Quality decision="pass";Goal canary premerge status="passed", merge_gate_passed=true(direct=6/6、catalog=10/10、risk=8/8、executed=18、failures=0、manual_hold_count=0)。

语义与 CI 对齐

无新增控制面语义词表(semantic-vocabulary-drift-smoke 34/34 与架构所有权套件全绿);2/2 条审阅线程均已 resolved(unresolved_count=0);遵循 wait_for_ci: false 未查询远端 CI,保持 PR OPEN。

我的整体评价 / Verdict

  • 长程与体验评估: long_horizon=improved(在保持单请求作用域 I/O 收敛的同时,完全恢复跨别名格式校验与规范写后全别名一致性),user_experience=preserved(全部导出、接缝、静态类型与外部 CLI 表现等价);visual_review=not_applicable(原因:仅涉及控制面钩子模块拆分、请求级快照作用域修复与调用方接入,无前端界面修改;unverified_scope:遵循 wait_for_ci=false 未查询远端 GitHub Actions CI;另注此前 896e455337 101 项 HTTP 聊天套件与 193 项 steward reports 已跑通,本轮新增提交仅改 request_scope.py/dispatch.py/turn_start.py/cadence_runtime.py/equivalence tests,已于当前头完整跑通 2,609 项核心调用方+架构+棘轮+TS+premerge)。
  • 结论: 两项前序 [P2] 均已闭环修复且全量门禁全绿,批准精确提交 008ab082068afeab9f5a55914a107e81955c49e8;保持 PR OPEN 供维护者授权合并。

English verdict: APPROVE at 008ab08. Verified both [P2] findings on request_scope.py (PRRT_kwDOStEbEs67z2Xl & PRRT_kwDOStEbEs67z2Xt, 2/2 threads resolved, unresolved_count=0, 2/2 DCO commits, clean git merge-tree, 0 leaks, module_metric_baseline.json untouched) are resolved cleanly: (1) CapabilityHookRequestScope now keys _decoded_registries and _goals_by_path by (resolved_or_canonical, expanded.name) while sharing raw snapshot bytes, raising ProjectRegistryError: global registry root must be a JSON object on registry.global.json symlinks even after a project-path read; (2) invalidate() evicts matching aliases across both _alias_to_resolved and resolved registry_snapshots entries, ensuring post-write alias & canonical readbacks immediately observe g-new; (3) turn_start.py and cadence_runtime.py adopt merge_turn_start_dispatch, eliminating all 4 new object overload mypy warnings. Verified in a clean detached worktree: BOTH_P2_REPRODUCERS_VERIFIED_FIXED, test_capability_hooks_equivalence.py 7 passed in 3.43s (0 skipped), combined pytest -n 6 (architecture + ratchet + equivalence + 13 hook/route/quota/cadence suites) 2,609 passed in 357.39s (0 failed, 0 skipped), ruff 19/19 clean, bare mypy 17/17 clean, strict mypy 8/8 clean, typecheck:control-plane clean, TS 63/63 passed, check_rfc_bilingual clean, Goal loopx check (0 errors), Goal CQR (pass), and Goal canary premerge (passed, direct=6/6, executed=18/18, failures=0, manual_hold_count=0).

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

动机 / Motivation

受影响的是经注册表别名和规范路径读取 Goal 的 turn-start、quota 和项目路由调用方。分叉基线按每条路径读取原登记目标。上一评审头发现别名格式和提交后读回两处回归,当前修订已修复这两处。 用真实 hook dispatcher 和两个隔离注册表,比较别名改指后同一请求的规范路径读回。另复跑原两项格式隔离与原子提交读回反例。 当前头把别名的旧快照解码并记入新目标的缓存键。当前请求随后独立读取新目标的规范路径时返回旧值。分叉基线与上轮评审头都能独立读出新目标。 验证涉及本地 File/SQLite 的隔离 hook 夹具和本机文件系统。别名改指出现在独立 POSIX 盘文件对照,本轮未查询托管 CI。

改动思路 / Approach

registry codec 持有格式规则和原子落盘,hook scope 复用本请求内的原始字节和解码。路由、Todo、调度和能力上下文仍由各自既有 owner 消费。 保留 hook runtime 拆分及现有 codec 权威范围。缓存边界收窄到经过同一次读取共同核实的路由、字节和解码。 保留按调用文件名区分的格式校验和原子写入失效。将原始快照和解析身份绑定,改指时沿用已捕获身份或明确刷新别名快照,再为不同规范目标建立各自的索引。 依据 host-integration 合同检查实际 lifecycle 消费。对已经存在的同提交独评,以当前额外原生对照补验尚未覆盖的别名改指场景。

具体改动 / Changes

精确 head 008ab082068afeab9f5a55914a107e81955c49e8,目标分支快照和共同祖先均为 b34f0e6157968251dedbd88552ccad34c4fdeef9。19 个文件,+2820 / −1112。原 capability_hooks 保留 facade,拆出合同、派发、上下文和 post-writeback。多调用方接入请求快照。当前增量修正路径格式键、写入失效及公共合并。

关键代码讲解

  • dispatch_turn_start_hooks。按原有 hook 注册和调用顺序派发,建立本次读取上下文。 源码

  • CapabilityHookRequestScope.load_registry。按解析目标及文件名缓存解码结果,当前可能采用该路由早先的原始快照。 源码

  • CapabilityHookRequestScope.invalidate。真实原子提交后清理规范路径与已记录别名,保留前两项修复。 源码

  • load_registry。镜像 alias 与 canonical 原始字节,分别通过实际调用文件名的 decoder。 源码

  • resolve_goal_source_runtime_route。原有 Goal 来源路由可消费同一请求提供的登记快照。 源码

  • post_writeback hook execution。独立保留既有 provider 调用、文件锁和回执语义。 源码

  • Hook activation。同一 host turn 的 hook 需要使用正确登记目标的 lifecycle contract,登记目标的来源、格式校验和读回都应保持。 已接受的宿主合同

对主干的风险 / Risks

[P2] 别名改指后,独立规范路径读到旧目标

一次请求内读取登记别名后,别名目标发生改指。随后在同一请求第一次直接读取新目标的规范路径。 当前头把别名的旧快照解码并记入新目标的缓存键。当前请求随后独立读取新目标的规范路径时返回旧值。分叉基线与上轮评审头都能独立读出新目标。 使缓存键、解码字节和解析目标使用同一次路由观察,加上别名改指后独立读取规范目标的回归对照。 对应源码

新问题落在本次别名修订引入的缓存合成。保持单请求快照稳定允许同一路由沿用已捕获来源。独立规范路径是另一条真实读入,仍需按自己的来源建索引。把旧别名内容挂到新规范键会让后续 Goal 查询沿错误路径复用同一对象。两项旧回归及正常快照隔离继续通过。 先前的项目/共享格式隔离和规范写后全别名读回在当前头均通过。下一请求中的规范路径读取也正确。

语义与本地验证

精确提交 18 项聚焦测试和标准本地 premerge 通过,原两项反例独立复跑通过。新增同请求改指定向用例在分叉基线和上一评审头通过,在当前头失败。 验证涉及本地 File/SQLite 的隔离 hook 夹具和本机文件系统。别名改指出现在独立 POSIX 盘文件对照,本轮未查询托管 CI。

我的整体评价 / Verdict

REQUEST_CHANGES。 使缓存键、解码字节和解析目标使用同一次路由观察,加上别名改指后独立读取规范目标的回归对照。 原先的格式校验和写后读回修复应随当前方案保留。

English verdict: REQUEST_CHANGES. Keep captured alias bytes tied to their original registry identity so a direct read of a different canonical path receives its own state.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · Gemini · Google · self_reported

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

本次复审在独立干净 detached worktree 中对 PR #9433 新提交(codex/slim-capability-hooks-zero-any-20261125 -> main,精确提交 6f05752233240fe6f734421d0275ebe86341f81f,基线 b34f0e6157968251dedbd88552ccad34c4fdeef9)完成了前序重指向软链接投毒 [P2] 反例对照(008ab08206 vs 6f05752233240fe6f734421d0275ebe86341f81f)、全量等价性与 16 组 2,610 项 Python 测试、TS 控制面校验、严格静态类型与 Goal 预合并门禁。前序审阅 6054631468 与最新审阅 6057030769 指出的全部 3 项 [P2] 缺陷(PRRT_kwDOStEbEs67z2Xl、PRRT_kwDOStEbEs67z2Xt 与 PRRT_kwDOStEbEs674DeA)均已完整修复并补齐对照测试;capability_hooks.py(277 LOC)与全部 6 个 hook_runtime/* 子模块(113 / 254 / 253 / 285 / 628 / 250 LOC)均 < 630 LOC、0 AST Any、0 # type: ignore、0 裸 O_NOFOLLOW(module_metric_baseline.json 未修改,3/3 DCO 提交,3/3 审阅线程已解决,unresolved_count=0,0 泄漏,git merge-tree 无冲突),批准精确提交 6f05752233240fe6f734421d0275ebe86341f81f。

动机 / Motivation

在 quota should-run、heartbeat_prequota 与多阶段能力钩子派发链中跨符号链接别名、预填快照与规范路径读取注册表并执行原子提交的控制面调用方需要把“同请求内复用磁盘读取”严格限定在真实未改向、路径规则一致的捕获期目标上:既要在 registry.json 与 registry.global.json 混读及原子写入后保持一致,也绝不能让重指向后的别名或预填快照覆盖规范目标缓存。

  • **问题与修前/修后对比:**复核并关闭前序三项 [P2] 审阅结论(6054631468 / PRRT_kwDOStEbEs67z2Xl & PRRT_kwDOStEbEs67z2Xt,以及本轮最新 6057030769 / PRRT_kwDOStEbEs674DeA):1) 同请求重指向软链接与预填别名规范缓存投毒(6057030769):先读 alias/registry.json -> T1/registry.json,随后原地将 alias 重指向 T2/registry.json(或预填同指向 registry_snapshots),再经旧别名与直连规范路径 T2/T3 读取时,旧版 008ab08206 无条件按当前 resolved(alias) == T2 写入规范缓存,导致 t2_direct 与 t3_direct 均被污染返回 ['g-t1']、load_goal(..., 'g-t2') 返回 None;当前 6f05752233 在 request_scope.py(L30-32, L82-195)记录捕获期观测目标 _observed_targets、将预填快照与捕获期后发生软链接重指向(resolved_after != resolved_now)的读取隔离为 (route, expanded.name) 独立路由键而不覆盖新规范目标、并在 invalidate() 中按别名集合+捕获期映射双路清理,同头反例对照实测 HEAD_6f05752233 返回 t2_direct=['g-t2'], t3_direct=['g-t3'], t2_goal='g-t2'(alias 与 witness 仍保持 ['g-t1']);2) 同步保留前两项 [P2] 修复与回归:registry.global.json 软链接继续按目标文件名抛出 ProjectRegistryError,规范路径 _atomic_write_bytes 提交后 invalidate() 同步驱逐全部解析指向该路径的别名与 Goal 索引。
  • **可观测效果:**在干净 detached worktree 实测精确提交 6f05752233240fe6f734421d0275ebe86341f81f:tests/control_plane/test_capability_hooks_equivalence.py 8 passed in 2.51s(0 skipped)(含新增 test_request_scope_repointed_symlink_does_not_poison_canonical_target L675-741);独立 008ab08206 vs 6f05752233 反例探针验证前版投毒、现版修复(t2_direct=['g-t2'], t3_direct=['g-t3'], t2_goal='g-t2');pytest -n 6 -rs 合并运行 tests/architecture/、test_maintainability_ratchet.py、test_capability_hooks_equivalence.py 与 13 个核心调用方套件 2,610 passed in 418.10s(0 failed, 0 skipped);ruff 19/19、裸 mypy 17/17、严格 mypy 8/8、TS 63/63 及 Goal canary premerge 18/18(direct=6/6、failures=0) 全部通过。
  • **非目标与边界:**不改变 TypeScript 事务协议与对外 CLI/JSON 合同,不修改 module_metric_baseline.json,不跨请求保留缓存,保持 PR OPEN 供维护者授权合并。
  • **规范对齐:**对应 docs/architecture/rfcs/loopx-overall-roadmap-v0.md(基线 b34f0e6157968251dedbd88552ccad34c4fdeef9)下的控制面零 Any 模块化拆分与单请求作用域一致性验收项 CAPABILITY-HOOKS-MODULARITY-800 与 CAPABILITY-HOOKS-REQUEST-SCOPE。

改动思路 / Approach

  1. 绑定捕获期解析目标并隔离重指向与预填别名键(loopx/control_plane/hook_runtime/request_scope.py:30-195):
    • _normalized_registry_keys(L30-32)返回 (route, resolved, expanded.name);_lookup_cache_key(L82-99)将已观测路由绑定至捕获期目标 _observed_targets,一旦别名重指向其他目标或命中与规范目标无观测关系的预填 registry_snapshots,立即切换为 (route, expanded.name) 独立路由键,绝不写入新规范目标缓存。
    • load_registry(L101-135)与 load_goal(L137-164)在读取前后校验 resolved_after != resolved_now,仅对捕获期目标建立规范键索引;invalidate(L166-195)同时按当前别名字典与 _observed_targets 清除所有指向失效规范路径的别名、解码与 Goal 缓存键。
  2. 保留前序路径格式校验、invalidate 全驱逐及 merge_turn_start_dispatch 收口:
    • 维持 (resolved_or_route, expanded.name) 键空间保证 registry.global.json 软链接继续触发 ProjectRegistryError,并维持 turn_start.py / cadence_runtime.py 对 merge_turn_start_dispatch 的复用。
  3. **架构归属与当前 PR 边界:**本 PR 将 capability_hooks.py 从单体收口为 277 LOC / 0 Any 薄门面与 6 个 < 630 LOC / 0 Any hook_runtime/* 子模块(113 / 254 / 253 / 285 / 628 / 250 LOC),在 6f05752233 通过捕获期目标绑定 _observed_targets 彻底消除重指向软链接与预填别名对规范目标缓存的投毒风险,并继续通过 merge_turn_start_dispatch 收口调用方拼接逻辑。精确提交 6f05752233 已修复全部三项 [P2] 缺陷并关闭全部 3/3 条审阅线程(unresolved_count=0),module_metric_baseline.json 未修改。

具体改动 / Changes

全部 19 个文件(+2,912/-1,112,3/3 DCO 提交,git merge-tree 无冲突;module_metric_baseline.json 未修改);依据 docs/architecture/rfcs/loopx-overall-roadmap-v0.md 逐项核对:CAPABILITY-HOOKS-MODULARITY-800 为 implemented,CAPABILITY-HOOKS-REQUEST-SCOPE 为 implemented:

  1. loopx/control_plane/hook_runtime/request_scope.py(250 LOC、0 AST Any): 新增 _observed_targets 捕获期绑定、预填快照/软链接重指向路由隔离、load_registry/load_goal 读后重解析防护及 invalidate 双路全别名清除。
  2. tests/control_plane/test_capability_hooks_equivalence.py(741 LOC、0 AST Any): 新增 test_request_scope_repointed_symlink_does_not_poison_canonical_target(L675-741),直接验证软链接重指向后 alias/witness 与直连 t2/t3 及 load_goal 完全隔离。
  3. 门面、其余 hook_runtime/* 与调用方保持清洁收口: capability_hooks.py(277 LOC)、__init__.py(113 LOC)、contracts.py(254 LOC)、turn_context.py(253 LOC)、dispatch.py(285 LOC)、post_writeback.py(628 LOC)、turn_start.py(60 LOC)与 cadence_runtime.py(132 LOC)均保持 0 AST Any 与 0 # type: ignore。

关键代码讲解

  • CapabilityHookRequestScope._lookup_cache_key:当路由曾在请求内观测到 observed_resolved != resolved_now(软链接重指向)或预填 registry_snapshots 含独立键但未绑定目标时,返回 (route, name) 独立键,使旧别名读取绝不污染重指向目标的规范缓存。
  • CapabilityHookRequestScope.load_registry & load_goal:读取后再次解析真实路径,若 resolved_after != resolved_now 则绑定回 (route, expanded.name) 并从 observed 中解除新规范目标关联,关闭读窗并发/重指向污染路径。
  • CapabilityHookRequestScope.invalidate:遍历 _alias_to_resolved、_observed_targets 与 registry_snapshots 清理所有命中目标的路由别名、解码项与 Goal 索引。

对主干的风险 / Risks

  • 精确提交 6f05752233240fe6f734421d0275ebe86341f81f 全量独立实测结果(于干净 detached worktree 实测,遵循 wait_for_ci: false 未等远端 GitHub Actions CI):
    1. 重指向软链接 [P2] 修复对照与等价性验证: uv run --extra test python -m pytest -v -rs tests/control_plane/test_capability_hooks_equivalence.py 8 passed in 2.51s(0 skipped);独立复现对照证实先读 alias -> T1 再将 alias 重指向 T2 后,旧头 008ab08206 返回 t2_direct=['g-t1']、t3_direct=['g-t1']、t2_goal=None,而精确提交 6f05752233240fe6f734421d0275ebe86341f81f 返回 t2_direct=['g-t2']、t3_direct=['g-t3']、t2_goal='g-t2'。
    2. 广谱业务、架构与棘轮回归: uv run --extra test python -m pytest -n 6 -rs(tests/architecture/、test_maintainability_ratchet.py、test_capability_hooks_equivalence.py 与全部 13 个核心钩子/路由/配额/日程/Lark 同步/托管会话套件)2,610 passed in 418.10s(0 failed, 0 skipped)。
    3. 静态类型与 TypeScript 控制面: ruff check(19 文件)0 问题;mypy --no-incremental 17/17 干净;mypy --strict --follow-imports=silent(capability_hooks.py + 6 个 hook_runtime/* + test_capability_hooks_equivalence.py)8/8 干净;turn_start.py(1 条)+ cadence_runtime.py(6 条)7 条既有提示无新增诊断;npm run typecheck:control-plane clean;TS capability_hooks.test.ts + content_digest_single_owner.test.ts + post_writeback_hook_transaction.test.ts 63 passed, 0 failed, 0 skipped。
    4. 文档、边界与 Goal 预合并: check_rfc_bilingual.py、semantic-vocabulary-drift-smoke.py 与 control-plane-maintainability-ratchet-smoke.py 全绿;diff 与 PR 正文 0 泄漏;Goal loopx check ok=True, errors=[], warnings=[];Goal Change Quality decision="pass";Goal canary premerge status="passed", merge_gate_passed=true(direct=6/6、catalog=10/10、risk=8/8、executed=18/18、failures=0、manual_hold_count=0)。

语义与 CI 对齐

无新增控制面语义词表(semantic-vocabulary-drift-smoke 与架构所有权套件全绿);3/3 条审阅线程均已 resolved(unresolved_count=0);遵循 wait_for_ci: false 未查询远端 CI,保持 PR OPEN。

我的整体评价 / Verdict

  • 长程与体验评估: long_horizon=improved(单请求作用域在避免重复磁盘 I/O 的同时彻底封堵重指向软链接与预填别名投毒、跨别名格式绕过及写后陈旧读回),user_experience=preserved(全部导出、接缝与外部行为保持严格等价);visual_review=not_applicable(原因:仅涉及控制面钩子模块拆分、请求级快照作用域重指向软链接隔离修复与回归测试,无前端界面修改;unverified_scope:遵循 wait_for_ci=false 未查询远端 GitHub Actions CI;所有相关 16 个 pytest 组合套件(2,610 项)、TS 63 项、mypy、CQR 与 Goal canary premerge 18/18 均已在精确提交 6f05752 本地干净工作树完整跑通)。
  • 结论: 包括 6057030769 在内的全部 3 项 [P2] 缺陷均已闭环修复且全量门禁全绿,批准精确提交 6f05752233240fe6f734421d0275ebe86341f81f;保持 PR OPEN 供维护者授权合并。

English verdict: APPROVE at 6f05752. Independently verified resolution of [P2] finding 6057030769 (PRRT_kwDOStEbEs674DeA) alongside both prior [P2] findings (PRRT_kwDOStEbEs67z2Xl & PRRT_kwDOStEbEs67z2Xt; 3/3 threads resolved, unresolved_count=0, 3/3 DCO commits, clean git merge-tree, 0 leaks, module_metric_baseline.json untouched): CapabilityHookRequestScope (loopx/control_plane/hook_runtime/request_scope.py:30-195) now binds observed routes to capture-time canonical targets in _observed_targets, isolates repointed symlinks and pre-populated registry_snapshots under route keys (route, expanded.name), re-checks resolved_after != resolved_now across load_registry/load_goal, and sweeps both alias maps on invalidate(). Counterfactual verification against 008ab08206 confirms prior poisoned outputs (t2_direct=['g-t1'], t3_direct=['g-t1'], t2_goal=None) are completely eliminated on 6f05752233240fe6f734421d0275ebe86341f81f (t2_direct=['g-t2'], t3_direct=['g-t3'], t2_goal='g-t2'). Clean-worktree checks pass in full: test_capability_hooks_equivalence.py 8 passed in 2.51s (0 skipped), combined pytest -n 6 -rs (architecture + maintainability_ratchet + equivalence + 13 caller suites) 2,610 passed in 418.10s (0 failed, 0 skipped), ruff 19/19 clean, bare mypy 17/17 clean, strict mypy 8/8 clean, typecheck:control-plane clean, TS 63/63 passed, check_rfc_bilingual clean, Goal loopx check (0 errors), Goal CQR (pass), and Goal canary premerge (passed, direct=6/6, executed=18/18, failures=0, manual_hold_count=0).

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

[P2] 无关别名失效阻断正常登记写入。 同请求先读到另一个登记别名,随后该别名变成不可解析的符号链接环。基线仍成功修改独立登记。本头缓存失效在写入后抛 RuntimeError,事务返回 ProjectRegistryRestoreError。目标文件逐字节恢复,但调用方收到恢复失败,自身的更新也未保留。 按已观察的目标清除对应快照。无法解析的无关别名应保持独立,不能让附加缓存清理推翻另一份登记文件的事务或补偿;保留实际目标的更新与恢复读回。 位置

动机 / Motivation

使用心跳或额度入口启动工作的人,需要在同一请求得到一致的登记结果,并能在文件变化后继续独立工作。 把挂钩拆分后,同一请求复用登记快照。已经读过的登记别名发生变化时,另一个登记文件的更新和读回仍应独立成立。 当前提交修复了旧头把已捕获的别名字节混入新规范路径的问题。配对检查同时覆盖正常写后读回、别名改指和另一条已观察别名失效。 整 PR 改动请求内快照保留、挂钩派发和原写后验证。既有登记文件和事务保持权威,生产调用者继续用相同公开入口。

改动思路 / Approach

同一次登记观察可减少重复 I/O。快照缓存负责读性能,原事务继续拥有实际写入与恢复判断。 清理已知相关别名足以保留写后顺序。对无关路径逐一解析如果能产生异常,就让缓存层决定了独立事务成败。 让原登记事务继续独立决定写入、读回和补偿结果。 当前在原子替换后追加请求内别名缓存失效;原事务再执行读回或按原字节恢复。

具体改动 / Changes

当前精确提交 6f05752233240fe6f734421d0275ebe86341f81f,目标基线 b34f0e6157968251dedbd88552ccad34c4fdeef9,审查完整提案的共同祖先 b34f0e6157968251dedbd88552ccad34c4fdeef9。19 个路径,+2912/-1112。相对 008ab08,当前调整缓存键与字节的绑定,在正常改指下保住新规范路径。此头已有 Gemini 同头结论,覆盖了前序三项问题。本次反例发生在独立登记写入触发的缓存失效。

关键代码讲解

  • _lookup_cache_key 把旧别名的缓存键保留在捕获目标。 源码

  • CapabilityHookRequestScope.invalidate 失效已写登记及相关别名或派生目标索引。 源码

  • _atomic_write_bytes 原子更换实际登记文件并通知请求快照。 源码

  • ProjectRegistryTransaction.commit 决定逻辑提交并核对读回,异常时恢复原字节。 源码

  • Hook activation 挂钩启动使用当前 lifecycle contract,并让独立登记的更新与读回正常完成。 同请求先读到另一个登记别名,随后该别名变成不可解析的符号链接环。基线仍成功修改独立登记。本头缓存失效在写入后抛 RuntimeError,事务返回 ProjectRegistryRestoreError。目标文件逐字节恢复,但调用方收到恢复失败,自身的更新也未保留。 接受的规范

对主干的风险 / Risks

同请求先读到另一个登记别名,随后该别名变成不可解析的符号链接环。基线仍成功修改独立登记。本头缓存失效在写入后抛 RuntimeError,事务返回 ProjectRegistryRestoreError。目标文件逐字节恢复,但调用方收到恢复失败,自身的更新也未保留。 按已观察的目标清除对应快照。无法解析的无关别名应保持独立,不能让附加缓存清理推翻另一份登记文件的事务或补偿;保留实际目标的更新与恢复读回。 Python 3.12.15 下无变化别名和正常改指分别在基线和精确头都写入成功。当前 8 项等价与快照测试通过,原挂钩、额度与来源路由的 86 个用例双侧各通过。

语义与本地验证

独立检查执行了3 个原生登记事务对照、8 项本头快照检查及基线与候选各 86 项测试。当前精确提交源码 premerge 6 项直接检查与 18 项所选检查全部通过。 使用相同合成登记和真实临时文件系统在 Python 3.12.15 复现。没有核验自然宿主中的长期发生率或其他平台的路径解析实现。未查询远端 CI。

我的整体评价 / Verdict

REQUEST_CHANGES。 按已观察的目标清除对应快照。无法解析的无关别名应保持独立,不能让附加缓存清理推翻另一份登记文件的事务或补偿;保留实际目标的更新与恢复读回。 Python 3.12.15 下无变化别名和正常改指分别在基线和精确头都写入成功。当前 8 项等价与快照测试通过,原挂钩、额度与来源路由的 86 个用例双侧各通过。 使用相同合成登记和真实临时文件系统在 Python 3.12.15 复现。没有核验自然宿主中的长期发生率或其他平台的路径解析实现。未查询远端 CI。

English verdict: REQUEST_CHANGES at 6f05752. An unrelated unresolvable cached alias can abort a valid registry update and produce a false restore-failed diagnostic on Python 3.12.

@loopx-agent

Copy link
Copy Markdown
Collaborator Author

Addressed the 6f05752233 review finding on CapabilityHookRequestScope.invalidate() in 1f31c755bf:

  • Added _safe_absolute() and _safe_resolve() catching (OSError, RuntimeError) in loopx/control_plane/hook_runtime/request_scope.py, and updated invalidate(path) to resolve path (falling back safely to {route}) and every snap_key in registry_snapshots via those helpers so Python 3.12 symlink-loop RuntimeError or unresolvable cached aliases never abort an independent ProjectRegistryTransaction.commit() or recovery path (ProjectRegistryRestoreError).
  • Added test_request_scope_invalidate_ignores_unresolvable_symlink_loop_alias in tests/control_plane/test_capability_hooks_equivalence.py covering both real POSIX symlink loops and Python 3.12 Path.resolve RuntimeError, plus direct Python 3.12.15 verification against ProjectRegistryTransaction.commit().

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

动机 / Motivation

在同一请求内按登记别名及独立规范路径读取 Goal 的 turn-start、quota 和运行路由调用方。第一次读同名登记别名。别名先解析为 A,中途原子改指 B,现有 codec 打开并读取 B,解码返回前别名切回 A。随后同一请求第一次直接读取 A。旧头在真实 3.12 链接环上写入回滚,基线和当前头的独立提交正常写入并读回。已有普通改指和写后读回检查通过。

Hook activation and request-scoped registry provenance。同一生产 load_goal_from_registry 及真实 POSIX 文件对照中,base 和 head 都从首次别名读取获得 B,别名最终解析为 A。base 直接读 A 返回 A,head 在同请求直接读 A 却返回 B。退出该请求后直接读 A 才恢复为 A。 配对由 Python 3.12.15 在隔离 POSIX 文件上运行。同步探针固定两次原子改指的时序,实际 codec 开盘读字节;外部部署的并发发生率、其他平台和装好的分发留待验证。 验收依据

改动思路 / Approach

registry codec 持有实际字节与格式规则。hook scope 只负责请求内缓存,agent registry 和 Lifecycle hook 消费读回。agent_registry.load_goal_from_registry → CapabilityHookRequestScope.load_goal/load_registry → registry_codec.load_registry → 同请求独立 Goal readback。把解码结果和 Goal 索引绑定到 codec 实际读取字节时观察到的来源,或在无法证明来源时只按调用别名单独隔离缓存。保留正常 alias 读回、独立事务写后失效及严格格式隔离。

具体改动 / Changes

精确 head 1f31c755bf2a2033450c14d17297e369c333c802,目标分支快照与实际分叉基线均为 b34f0e6157968251dedbd88552ccad34c4fdeef9。19 个文件,+2979/-1112。原 hook facade、六个 hook owner 和请求内复用影响多入口。此次增量专门处理失效时的不可解析链接。

关键代码讲解

  • load_goal_from_registry。活动 hook 请求中的真实 Goal 查找消费缓存索引。 源码
  • CapabilityHookRequestScope.load_registry。读取前后各自 resolve,当前把端点相等当成期间未改指。 源码
  • registry_codec.load_registry。在缓存初始化中间重新解析并打开当时的真实字节来源。 源码
  • CapabilityHookRequestScope final_key。按推断的目标记入解码和 Goal 索引,使独立规范路径命中。 源码
  • CapabilityHookRequestScope.invalidate。已跳过无关不可解析别名,不再挡住独立提交。 源码

对主干的风险 / Risks

[P2] 首次别名读回期间切换再切回会污染独立登记缓存

同一生产 load_goal_from_registry 及真实 POSIX 文件对照中,base 和 head 都从首次别名读取获得 B,别名最终解析为 A。base 直接读 A 返回 A,head 在同请求直接读 A 却返回 B。退出该请求后直接读 A 才恢复为 A。

错误的登记内容会在请求期间被复用。对同名 Goal,调用方可能拿到另一登记的 lifecycle 元数据。受影响的是读取与派发决策,本实验验证到返回值。 相关源码

语义与本地验证

旧头在真实 3.12 链接环上写入回滚,基线和当前头的独立提交正常写入并读回。已有普通改指和写后读回检查通过。9 项快照等价测试、精确基线与当前头各 67 项 registry、路由及 cadence 定向用例、8 个文件严格 mypy 和标准预检通过。新增对照采用两个实际登记文件和受控原子链接替换。当暂时只把新观察的 alias 结果绑在调用路由,独立 A、B 回到各自结果,旧反例仍通过。

我的整体评价 / Verdict

REQUEST_CHANGES。 把解码结果和 Goal 索引绑定到 codec 实际读取字节时观察到的来源,或在无法证明来源时只按调用别名单独隔离缓存。保留正常 alias 读回、独立事务写后失效及严格格式隔离。 复验切换再切回、独立规范读回和原有无关写入。

English verdict: REQUEST_CHANGES at 1f31c75. Bind decoded registries and Goal indexes to the source captured by the byte read so an alias round trip cannot poison a separate canonical read.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · Gemini · Google · self_reported

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

本次对 PR #9433(codex/slim-capability-hooks-zero-any-20261125 -> main,精确提交 1f31c755bf2a2033450c14d17297e369c333c802,基线 b34f0e6157968251dedbd88552ccad34c4fdeef9)完成了全量本地门禁与新到达审阅 6060566697(未解决线程 PRRT_kwDOStEbEs67-jHf)的独立对照复现。验证确认:前序外审 6059501353 的 Python 3.12 符号链接环路 RuntimeError 已在本头完整修复(6f05752233 事务回滚 'v1' vs 1f31c755bf2a2033450c14d17297e369c333c802 提交 'v2',全部 9/9 等价测试、2,632 项 18 目标套件、186 项补充钩子/作用域套件、63/63 TS、ruff/mypy 及 18/18 canary premerge 全绿);但我们在独立 POSIX 原子切换探针中完整复现了 6060566697 指出的 [P2] 回归——当别名在首次读回期间经历 A -> B -> A 往返改指时,同请求内直连 A 会读出 B 的数据。暂不批准合入精确提交 1f31c755bf2a2033450c14d17297e369c333c802(REQUEST_CHANGES)。

动机 / Motivation

在同一 capability_hook_request_scope 调度作用域内先经同名别名再直连独立规范路径读取 load_goal_from_registry / load_scoped_registry 的 turn-start、配额与运行路由调用方绝不能因某条别名的并发或原子往返切换(A -> B -> A)把从 B 读回的注册表字节与 Goal 元数据写入独立规范文件 A 的请求内解码缓存。

  • **问题与修前/修后对比:**复核并独立复现新到达审阅 6060566697(未解决线程 PRRT_kwDOStEbEs67-jHf / discussion_r4697210471,loopx/control_plane/hook_runtime/request_scope.py:145)指出的 [P2] 真实回归(同时确认前序 6059501353 Python 3.12 符号链接环路 RuntimeError 已于本头修复):1) 当别名 alias/registry.json 初始指向 A/registry.json,并在请求内首次调用 load_goal_from_registry(alias, 'g-shared') 期间发生原子软链接往返切换(resolved_now 为 A -> 未修改的 registry_codec.load_registry 解析 expanded.resolve() 时切换为 B 并读取 B -> 返回 request_scope.load_registry 执行 resolved_after 之前切换回 A)时,request_scope.py:136-148 仅对比调用前后端点发现 resolved_after == resolved_now == A,遂将实际由 B 读回并解码的负载错误以 final_key = (A, 'registry.json') 写入 self._decoded_registries 与 self._goals_by_path;2) 修前/对照实测:origin/main 基线首次经 alias 返回 'TITLE_FROM_B',随后直连 load_goal_from_registry(reg_a, 'g-shared') 正确返回 'TITLE_FROM_A';而当前提交 1f31c755bf 在作用域内直连 reg_a 的 load_goal_from_registry 与 load_scoped_registry 均被污染返回 'TITLE_FROM_B',退出作用域后才恢复为 'TITLE_FROM_A'。
  • **可观测效果:**独立 POSIX 原子切换探针直接证实阻塞项:BASE_ORIGIN_MAIN: {{'alias_goal': 'TITLE_FROM_B', 'reg_a_goal': 'TITLE_FROM_A', 'alias_final_is_A': True}} vs HEAD_1f31c755: {{'resolves': 4, 'alias_goal': 'TITLE_FROM_B', 'reg_a_goal_in_scope': 'TITLE_FROM_B', 'reg_a_reg_in_scope': 'TITLE_FROM_B', 'reg_a_goal_after_scope': 'TITLE_FROM_A', 'alias_final_is_A': True}}。与此同时,本头已修复前序 6059501353 (PRIOR_6f057522 ProjectRegistryRestoreError -> HEAD_1f31c755 正常提交 'v2')并通过 9/9 等价性、2,632/2,632 核心+架构+棘轮+注册表测试、186/186 补充作用域/钩子测试、63/63 TS、ruff/mypy 与 Goal canary premerge 18/18,但受 6060566697 / PRRT_kwDOStEbEs67-jHf 阻断,需修复来源绑定后再推新 HEAD 复审。
  • **非目标与边界:**不放宽现有格式隔离、写后全别名失效、重指向隔离或 3.12 环路异常防护;请求修复来源绑定并保持 PR OPEN。
  • **规范对齐:**对应 docs/architecture/rfcs/loopx-overall-roadmap-v0.md(基线 b34f0e6157968251dedbd88552ccad34c4fdeef9)验收项 CAPABILITY-HOOKS-MODULARITY-800 与 CAPABILITY-HOOKS-REQUEST-SCOPE。

改动思路 / Approach

  1. 阻塞项根因定位(loopx/control_plane/hook_runtime/request_scope.py:123-149 & registry_codec.py:239-251):
    • load_registry 在调用 _invoke_registry_loader 前读取 resolved_now(A),待 registry_codec.load_registry 返回后再读取 resolved_after(若途中发生 A -> B -> A 则仍为 A),并在 L144-148 据 resolved_after == resolved_now 错误推定“真实来源未变化”,从而以 (A, name) 键缓存了实际来自 B 的解码Payload与 Goal 索引。
    • 即使 diff self.registry_snapshots 的新增键也无法在 B 已被提前缓存时分辨来源,因此端点比对不能作为来源证明。
  2. 最小修复方向(二选一保持已有全量契约不变):
    • 方案 1(来源见证绑定): 让快照采集侧在真正读取/命中字节处记录精确 observed_source(例如随 source_snapshots 协同传入见证映射或在 registry_codec 中记录本次 route 命中的规范 source),仅把解码与 Goal 索引绑定到该实际读入来源(若未走见证或自定义 loader 则仅按 route 独立隔离)。
    • 方案 2(别名/未证来源路线隔离): 对路径为软链接(或未证明与磁盘同源)的调用仅按 (route, expanded.name) 单独缓存,绝不反向写入任何规范目标键,同时继续通过 source_snapshots 对已确认非软链接或同源读共享原始 IO(保留 registry.global.json 格式校验、invalidate 全别名失效及 calls == 1 IO 收敛)。
  3. **架构归属与当前 PR 边界:**六子模块零 Any 拆分与 invalidate 环路防护整体正确,但 CapabilityHookRequestScope.load_registry(L123-149)不能靠读写前后两次 .resolve() 端点相等来反推磁盘字节真实来源,因为并发或原子 A -> B -> A 切换会使两端点一致而实际打开 B。当前提交 1f31c755bf 已关闭 6059501353,但需关闭 6060566697 / PRRT_kwDOStEbEs67-jHf [P2] 并推送新精确头。

具体改动 / Changes

全部 19 个文件(+2,979/-1,112,4/4 DCO 提交,相对 6f05752233 增量 +74/-7,git merge-tree 无冲突;module_metric_baseline.json 未修改);依据 docs/architecture/rfcs/loopx-overall-roadmap-v0.md 逐项核对:CAPABILITY-HOOKS-MODULARITY-800 为 implemented,CAPABILITY-HOOKS-REQUEST-SCOPE 为 not_met(存在上述 [P2] 往返别名污染缺陷):

关键代码讲解

  • CapabilityHookRequestScope.load_registry:以调用前后 .resolve() 相等决定 bound_target = resolved_after,在 registry_codec.load_registry 实际读取 B 后再切回 A 时发生错绑(final_key = (A, name) 写入 B 的负载)。
  • CapabilityHookRequestScope.invalidate:本头新增的 _safe_absolute / _safe_resolve 已成功解决 6059501353 Python 3.12 符号链接环 RuntimeError 问题,后续修复请务必完整保留。

对主干的风险 / Risks

  • 阻断合并的 1 项已复现 [P2] 缺陷(精确提交 1f31c755bf2a2033450c14d17297e369c333c802,未解决线程 PRRT_kwDOStEbEs67-jHf):
    1. [P2] 首次别名读回期间切换再切回污染独立规范登记缓存(request_scope.py:145,PRRT_kwDOStEbEs67-jHf):
      • 独立复现:首次调用 load_goal_from_registry(alias, "g-shared") 时在未修改的 registry_codec.load_registry 读 expanded.resolve() 前原子切换 alias -> reg_b,解码返回前切换回 alias -> reg_a(alias.resolve() == reg_a.resolve())。
      • 实测结果:BASE_ORIGIN_MAIN alias -> 'TITLE_FROM_B', reg_a -> 'TITLE_FROM_A';HEAD_1f31c755 同作用域直连 reg_a 的 load_goal_from_registry 与 load_scoped_registry 均返回 'TITLE_FROM_B',退出作用域后才恢复 'TITLE_FROM_A'。
  • 当前 HEAD 其他已验证通过的检查与回归(修复上述 [P2] 后将在新 HEAD 复核):
    • 6059501353 Python 3.12 符号链接环对照已固定(PRIOR_6f057522: ProjectRegistryRestoreError/'v1' -> HEAD_1f31c755: ok=True/'v2');
    • test_capability_hooks_equivalence.py 9/9(2.26s)、18 目标组合 pytest -n 6 -rs 2,632 passed(313.76s)、补充作用域/钩子/登记套件 101 + 41 + 44 = 186 passed(及 53 passed, 2 PowerShell skips)、ruff 19/19、裸 mypy 17/17、严格 mypy 8/8、TS 63/63 与 Goal canary premerge 18/18 均通过(另:宿主真实 HOME 下 quota-scheduler-registry-route-smoke.py 因感知宿主能力 external_evidence_poll 会多出第 3 个能力参数,随 premerge 隔离 HOME 通过)。

语义与 CI 对齐

1 条审阅线程未解决(PRRT_kwDOStEbEs67-jHf,unresolved_count=1);遵循 wait_for_ci: false 未查询远端 CI,保持 PR OPEN。

我的整体评价 / Verdict

  • 长程与体验评估: long_horizon=not_yet_proven(往返软链接竞争窗口会导致独立规范登记读回跨登记串扰),user_experience=preserved(此前 3 项 [P2] 与 3.12 环路 [P2] 均已证明有效,待本次来源绑定修复落地);visual_review=not_applicable(原因:仅涉及控制面 request_scope 读回来源绑定与回归测试,无前端界面修改;unverified_scope:上述同作用域 A -> B -> A 往返软链接规范缓存污染 [P2] 缺陷待新 HEAD 修复复审;遵循 wait_for_ci=false 未查询远端 GitHub Actions CI)。
  • 结论: 请修复 request_scope.py:123-149 首次读回的真实来源绑定或别名孤立缓存(并保留 _safe_absolute / _safe_resolve 环路防护),补充 A -> B -> A 往返软链接回归测试,解决 PRRT_kwDOStEbEs67-jHf 后推送新 HEAD 复审。

English verdict: REQUEST_CHANGES at 1f31c75. While 1f31c755bf cleanly resolves the prior [P2] Python 3.12 symlink-loop issue from 6059501353 (PRIOR_6f057522 rolled back with ProjectRegistryRestoreError vs 1f31c755bf2a2033450c14d17297e369c333c802 committing 'v2'; 9/9 equivalence, 2,632 combined pytest, 186 extra scope/hook tests, TS 63/63, ruff/mypy, and 18/18 canary premerge passed), I independently reproduced the new [P2] regression flagged by 6060566697 / PRRT_kwDOStEbEs67-jHf (loopx/control_plane/hook_runtime/request_scope.py:145). Comparing pre-read resolved_now and post-read resolved_after lets an atomic alias: A -> B -> A symlink round-trip during unmodified registry_codec.load_registry() poison self._decoded_registries[(A, name)] and self._goals_by_path[(A, name)] with B's payload (BASE_ORIGIN_MAIN direct read on reg_a: 'TITLE_FROM_A' vs 1f31c755bf2a2033450c14d17297e369c333c802 in-scope load_goal_from_registry(reg_a) & load_scoped_registry(reg_a): 'TITLE_FROM_B', reverting to 'TITLE_FROM_A' only after leaving the scope). Please bind decoded/goal caches to the provenance captured at actual byte read or isolate unproved/symlink routes solely under (route, name), add a round-trip regression test, resolve PRRT_kwDOStEbEs67-jHf, and push a new head for re-verification.

@loopx-agent

Copy link
Copy Markdown
Collaborator Author

Fixed in 0f8820a (thread PRRT_kwDOStEbEs67-jHf / comment 4697210471): CapabilityHookRequestScope in loopx/control_plane/hook_runtime/request_scope.py now keys _decoded_registries and _goals_by_path strictly by (route, expanded.name) and uses _alias_to_targets strictly for invalidate(), so an A -> B -> A symlink round-trip during load_registry(alias) or load_goal(alias, ...) isolates alias state under (alias_route, name) and never poisons independent direct reads of canonical reg_a while preserving load_registry 11 -> 1, read_bytes 12 -> 2, format isolation, atomic-write invalidation, and _safe_absolute/_safe_resolve symlink-loop protection. Covered by test_request_scope_aba_symlink_roundtrip_does_not_poison_canonical_target in tests/control_plane/test_capability_hooks_equivalence.py.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · Gemini · Google · self_reported

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

本次复审在独立干净 detached worktree 中对 PR #9433 新提交(codex/slim-capability-hooks-zero-any-20261125 -> main,精确提交 0f8820a202efe2115e782586f5f712d9fceaa788,基线 b34f0e6157968251dedbd88552ccad34c4fdeef9)完成了前版 1f31c755bf vs 0f8820a202efe2115e782586f5f712d9fceaa788 的 A -> B -> A 符号链接往返竞争规范路径投毒反例对照、6f05752233 vs 0f8820a202efe2115e782586f5f712d9fceaa788 的 Python 3.12 符号链接环路 RuntimeError 反例对照、10 项等价性与 18 组 2,633 项组合测试、9 组补充请求作用域/钩子/登记测试、TS 控制面校验、严格静态类型与 Goal 预合并门禁。全部四项 [P2] 缺陷——PRRT_kwDOStEbEs67-jHf(6060566697 / A -> B -> A ABA 往返投毒)、6059501353(Python 3.12 符号链接环 RuntimeError 阻断独立事务)、PRRT_kwDOStEbEs674DeA(6057030769 / 重指向软链接竞争与格式校验)与 PRRT_kwDOStEbEs67z2Xl / PRRT_kwDOStEbEs67z2Xt(6054631468 / 跨别名格式绕过与全别名失效)——均已彻底修复并覆盖严格回归测试;capability_hooks.py(277 LOC)与全部 6 个 hook_runtime/* 子模块(113 / 254 / 253 / 285 / 628 / 238 LOC)均 < 630 LOC、0 AST Any、0 # type: ignore、0 裸 O_NOFOLLOW(module_metric_baseline.json 未修改,5/5 DCO 提交,4/4 审阅线程已解决,unresolved_count=0,0 泄漏,git merge-tree 无冲突),批准精确提交 0f8820a202efe2115e782586f5f712d9fceaa788。

动机 / Motivation

在 quota should-run、heartbeat_prequota 与多阶段能力钩子派发链中通过符号链接别名、规范路径或事务写回路径读取并失效项目登记文件的控制面调用方需要请求级快照仅作透明的性能加速层:既要避免 load_registry 重复读盘(11 -> 1),也要保证不同调用路由各自以自身规范化路径隔离读取结果——绝不能因软链接在读写之间发生 A -> B -> A 往返跳转而污染另一份独立登记目标的读出,也不能因某条无关缓存别名沦为符号链接环而导致健康登记文件的提交或恢复失败。

  • **问题与修前/修后对比:**复核并关闭前序全部四项 [P2] 缺陷(PRRT_kwDOStEbEs67-jHf / 6060566697、6059501353、PRRT_kwDOStEbEs674DeA / 6057030769、PRRT_kwDOStEbEs67z2Xl & PRRT_kwDOStEbEs67z2Xt / 6054631468):1) A->B->A 符号链接往返竞争导致规范目标目录被另一份登记内容投毒(6060566697 / PRRT_kwDOStEbEs67-jHf):同一 capability_hook_request_scope 中先按别名 alias/registry.json(初始指向 reg_a)读取;在首次读取解析期 alias 改指向 reg_b 并读出 TITLE_FROM_B,随后又在收尾前切回 reg_a 时,前版 1f31c755bf 因同时按 resolved_after 额外写入规范路径 reg_a 的快照槽位,后续在同一请求内直接读取 reg_a 错返回了 'TITLE_FROM_B';当前提交 0f8820a202 在 loopx/control_plane/hook_runtime/request_scope.py 彻底去除共享规范目标槽位写入(cache_key = (route, expanded.name) 严格仅以调用方规范化路径键存储,同时用 _alias_to_targets 记录观测到的解析目标以便写后跨别名完整驱逐),并移除跨别名额外注册分支(文件从 270 LOC 精简至 238 LOC);同头独立反例实测 PRIOR_1f31c755 返回 {'alias_goal': 'TITLE_FROM_B', 'reg_a_goal_in_scope': 'TITLE_FROM_B', 'reg_a_reg_in_scope': 'TITLE_FROM_B', 'alias_final_is_A': True},而 HEAD_0f8820a2 返回 {'alias_goal': 'TITLE_FROM_B', 'reg_a_goal_in_scope': 'TITLE_FROM_A', 'reg_a_reg_in_scope': 'TITLE_FROM_A', 'alias_final_is_A': True};2) Python 3.12 符号链接环 RuntimeError 阻断独立事务(6059501353):保留 _safe_absolute(L30-34)与 _safe_resolve(L37-41)在 invalidate()(L147-182)中的 (OSError, RuntimeError) 防护,对照实测前版 6f05752233 抛出 ProjectRegistryRestoreError 回滚至 'v1',而 0f8820a202efe2115e782586f5f712d9fceaa788 在 3.12 环路异常与真实 POSIX 循环链接下均返回 {'ok': True, 'title': 'v2', 'disk': 'v2', 'goal': 'v2'};3) 严格全局/项目登记边界校验与单请求 I/O 收益:CF_STRICT_GLOBAL_SYMLINK 实测 {'proj': ['g1'], 'glob_err': 'global registry root must be a JSON object'},且单回合 load_registry 保持 11 -> 1、read_bytes <= 2。
  • **可观测效果:**在干净 detached worktree 实测精确提交 0f8820a202efe2115e782586f5f712d9fceaa788:tests/control_plane/test_capability_hooks_equivalence.py 10 passed in 3.07s(0 skipped)(新增 test_request_scope_aba_symlink_roundtrip_does_not_poison_canonical_target L704-740 并保留 test_request_scope_invalidate_ignores_unresolvable_symlink_loop_alias L743-787);双反例同头对照(1f31c755bf ABA 竞争、6f05752233 3.12 循环链接 RuntimeError)均在前版复现缺陷、现版完全隔离与通过;pytest -n 6 -rs 合并运行 18 个核心/架构/棘轮/注册表套件 2,633 passed in 327.79s(0 failed, 0 skipped);9 组补充请求作用域/钩子/注册表回归 186 passed in 35.86s(0 skipped),tests/test_delegation_turn_context.py 32 passed, 2 skipped in 76.03s(macOS 缺 PowerShell 7 跳过 2 项);ruff 19/19、裸 mypy 17/17、严格 mypy 8/8、TS 63/63(2184.77ms)及 Goal canary premerge 18/18(direct=6/6、catalog=10/10、risk=8/8、failures=0、manual_hold_count=0) 全部通过。
  • **非目标与边界:**不改变 TypeScript 事务协议与对外 CLI/JSON 合同,不修改 module_metric_baseline.json,不跨请求保留缓存,保持 PR OPEN 供维护者授权合并。
  • **规范对齐:**对应 docs/architecture/rfcs/loopx-overall-roadmap-v0.md(基线 b34f0e6157968251dedbd88552ccad34c4fdeef9)下的控制面零 Any 模块化拆分与单请求作用域一致性验收项 CAPABILITY-HOOKS-MODULARITY-800 与 CAPABILITY-HOOKS-REQUEST-SCOPE。

改动思路 / Approach

  1. 严格按 (route, expanded.name) 分键存储快照与解码,彻底杜绝 ABA 竞争下跨规范目标投毒(loopx/control_plane/hook_runtime/request_scope.py:79-145):
    • CapabilityHookRequestScope.load_registry(L97-122)仅计算一次 route = _safe_absolute(expanded) or expanded 并严格以 cache_key = (route, expanded.name) 存取 registry_snapshots 与 _decoded_registries,同时记录请求期间观测到的 resolved_before/resolved_after 与新增键集合 new_keys = set(self.registry_snapshots) - before_keys - {route} 至 _alias_to_targets,不再将经由符号链接 alias 读得的载荷写入 reg_a 等规范目标键。
    • 相比 1f31c755bf 通过额外写入规范目标键来“同步”别名的复杂做法,本次改为单键隔离 + 失效期反向匹配 _alias_to_targets,既从根本上消除 A -> B -> A 往返写污染,又净删减 32 行代码(request_scope.py 由 270 LOC 缩减至 238 LOC)。
  2. 保留安全路径解析与双路径失败防护(loopx/control_plane/hook_runtime/request_scope.py:30-41,147-182):
    • _safe_absolute(L30-34)与 _safe_resolve(L37-41)统一捕获 (OSError, RuntimeError),invalidate(path)(L147-182)先纳入 _alias_to_targets.get(route) 与命中 targets 的全部别名,再以安全解析扫描 registry_snapshots,确保不可解析或循环软链接只静默跳过解析而不阻塞相邻健康文件提交,并同步清理 registry_snapshots、_alias_to_targets、_decoded_registries 与 _goals_by_path。
  3. 新增 ABA 往返与循环软链接双回归测试(tests/control_plane/test_capability_hooks_equivalence.py:704-787):
    • test_request_scope_aba_symlink_roundtrip_does_not_poison_canonical_target(L704-740)复现首次 Path.resolve 将 alias 切至 reg_b、二次 Path.resolve 切回 reg_a 的完整 ABA 竞争,断言读取 reg_a 与 load_scoped_registry(reg_a) 始终返回 'TITLE_FROM_A';test_request_scope_invalidate_ignores_unresolvable_symlink_loop_alias(L743-787)覆盖 POSIX 与模拟 Python 3.12 循环链接 RuntimeError 下事务提交与回读。
  4. **架构归属与当前 PR 边界:**本 PR 将 capability_hooks.py 收口为 277 LOC / 0 Any 薄门面与 6 个 < 630 LOC / 0 Any hook_runtime/* 子模块(113 / 254 / 253 / 285 / 628 / 238 LOC),在 0f8820a202 进一步收敛为单一的 (route, expanded.name) 快照分键 加 _alias_to_targets 写后全别名失效机制,在不额外引入并行缓存键或修改 registry_codec 耐久边界的前提下彻底消除跨目标投毒与循环链阻断。精确提交 0f8820a202 已完整修复 PRRT_kwDOStEbEs67-jHf(6060566697)与前序全部 [P2] 缺陷(4/4 审阅线程均 resolved、unresolved_count=0,5/5 DCO 提交),module_metric_baseline.json 未修改。

具体改动 / Changes

全部 19 个文件(+2,946/-1,112,5/5 DCO 提交,相对 1f31c755bf 精调 2 个文件 +89/-122,git merge-tree 无冲突;module_metric_baseline.json 未修改);依据 docs/architecture/rfcs/loopx-overall-roadmap-v0.md 逐项核对:CAPABILITY-HOOKS-MODULARITY-800 为 implemented,CAPABILITY-HOOKS-REQUEST-SCOPE 为 implemented:

  1. loopx/control_plane/hook_runtime/request_scope.py(238 LOC、0 AST Any): 严格以 (route, expanded.name) 分键存储 registry_snapshots/_decoded_registries/_goals_by_path,以 _alias_to_targets 维持写后跨别名失效并保留 _safe_absolute/_safe_resolve 循环链异常保护。
  2. tests/control_plane/test_capability_hooks_equivalence.py(787 LOC、0 AST Any): 新增 test_request_scope_aba_symlink_roundtrip_does_not_poison_canonical_target(L704-740),并保留 test_request_scope_invalidate_ignores_unresolvable_symlink_loop_alias(L743-787)与前序重指向软链接及 11 -> 1 I/O 缩减验证。
  3. 其余 17 个拆分与调用方文件: capability_hooks.py(277 LOC)、__init__.py(113 LOC)、contracts.py(254 LOC)、turn_context.py(253 LOC)、dispatch.py(285 LOC)、post_writeback.py(628 LOC)、turn_start.py(60 LOC)与 cadence_runtime.py(132 LOC)保持 < 630 LOC、0 AST Any 与 0 # type: ignore。

关键代码讲解

  • CapabilityHookRequestScope.load_registry:始终将快照与解码按调用方规范化键 (route, expanded.name) 存储,仅向 _alias_to_targets[route] 追记观测到的解析目标与新入库子键,使 alias 上的 A -> B -> A 软链接瞬态切换绝不会写入并污染 reg_a 的直读槽位。
  • _safe_absolute & _safe_resolve:集中捕获 (OSError, RuntimeError) 避免 CPython 3.12 下 Path.resolve() 在 ELOOP 循环软链接上抛出的 RuntimeError 泄漏到事务调用栈。
  • CapabilityHookRequestScope.invalidate:整合 route、resolved、_alias_to_targets 双向命中集及安全扫描到的 registry_snapshots 键,成批驱逐快照、别名表、解码缓存与 Goal 索引。

对主干的风险 / Risks

  • 精确提交 0f8820a202efe2115e782586f5f712d9fceaa788 全量独立实测结果(于干净 detached worktree 实测,遵循 wait_for_ci: false 未等远端 GitHub Actions CI):
    1. 双反例对照与等价性验证: uv run --extra test python -m pytest -v -rs tests/control_plane/test_capability_hooks_equivalence.py 10 passed in 3.07s(0 skipped);独立复现探针实测:(a)ABA 竞争下 1f31c755bf 读取 reg_a 错返 'TITLE_FROM_B',而 0f8820a202efe2115e782586f5f712d9fceaa788 严格隔离返还 'TITLE_FROM_A';(b)6f05752233 遇 3.12 循环链报 ProjectRegistryRestoreError 回滚 'v1',而 0f8820a202efe2115e782586f5f712d9fceaa788 在 3.12 RuntimeError 与 POSIX 循环链下均提交 'v2';(c)严格全局/项目软链接格式边界 CF_STRICT_GLOBAL_SYMLINK 通过。
    2. 广谱核心、架构、棘轮与注册表回归: uv run --extra test python -m pytest -n 6 -rs(18 个目标:含 tests/architecture/、test_maintainability_ratchet.py、test_capability_hooks_equivalence.py、test_project_registry_codec.py、test_project_registry_m0_contract.py 及全部 13 个核心钩子/路由/配额/日程/Lark/托管会话套件)2,633 passed in 327.79s(0 failed, 0 skipped)。
    3. 补充作用域与钩子专项: 9 组补充作用域/钩子/CLI/普查套件 186 passed in 35.86s(0 skipped);tests/test_delegation_turn_context.py 32 passed, 2 skipped in 76.03s(macOS 缺 PowerShell 7 跳过 2 项)。
    4. 静态类型、TS 与 Goal 预合并: ruff check(19 文件)0 问题;mypy --no-incremental 17/17 干净;mypy --strict --follow-imports=silent 8/8 干净;turn_start.py(1 条)+ cadence_runtime.py(6 条)无新增错误;npm run typecheck:control-plane clean;TS 3 套件 63 passed, 0 failed, 0 skipped(2184.77ms);check_rfc_bilingual.py clean;diff/正文/提交 0 泄漏;Goal loopx check ok=True, errors=0;Goal canary premerge ok=True, status="passed", merge_gate_passed=true(direct=6/6、catalog=10/10、risk=8/8、executed=18/18、failures=0、manual_hold_count=0)。

语义与 CI 对齐

无新增控制面语义词表(semantic-vocabulary-drift-smoke 与架构所有权套件全绿);4/4 条审阅线程均已 resolved(unresolved_count=0);遵循 wait_for_ci: false 未查询远端 CI,保持 PR OPEN。

我的整体评价 / Verdict

  • 长程与体验评估: long_horizon=improved(单请求快照缓存保留 11 -> 1 I/O 降幅,同时完全解决跨别名格式绕过、写后失效、重指向软链接、Python 3.12 循环链与 ABA 往返投毒),user_experience=preserved(全部 47 项导出、接缝、静态类型与外部事务行为严格等价);visual_review=not_applicable(原因:仅涉及控制面钩子模块拆分与 request_scope 严格按规范化路由分键及安全失效策略与回归测试,无前端界面修改;unverified_scope:遵循 wait_for_ci=false 未查询远端 GitHub Actions CI;本地主机未预装 CPython 3.12 二进制(cpython-3.11/3.13/3.14 可用),已在真实 CPython 3.14.8 + POSIX 符号链接环路及 Python 3.12 Path.resolve RuntimeError 精确复现探针下完整验证;所有相关 18 项组合套件(2,633 项)、等价性 10 项、TS 63 项、mypy、CQR 与 Goal canary premerge 18/18 均已在精确提交 0f8820a 本地干净工作树完整跑通)。
  • 结论: 全部四项 [P2] 缺陷均已彻底修复并通过同头对照与全量回归,批准精确提交 0f8820a202efe2115e782586f5f712d9fceaa788;保持 PR OPEN 供维护者授权合并。

English verdict: APPROVE at 0f8820a. Independently verified resolution of all four [P2] findings — including PRRT_kwDOStEbEs67-jHf (6060566697 / A -> B -> A ABA symlink round-trip poisoning canonical targets), 6059501353 (Python 3.12 symlink-loop RuntimeError), PRRT_kwDOStEbEs674DeA (6057030769), and PRRT_kwDOStEbEs67z2Xl / PRRT_kwDOStEbEs67z2Xt (6054631468) — with 4/4 threads resolved, unresolved_count=0, 5/5 DCO commits, clean git merge-tree, 0 leaks, and module_metric_baseline.json untouched. loopx/control_plane/hook_runtime/request_scope.py simplifies from 270 to 238 LOC (0 AST Any) by strictly keying snapshots/decodes by normalized (route, expanded.name) while tracking _alias_to_targets and _safe_absolute/_safe_resolve (L30-41) for full alias eviction without aborting unrelated registry transactions. Counterfactual probes confirm 1f31c755bf returned poisoned 'TITLE_FROM_B' for reg_a during an A -> B -> A race whereas 0f8820a202efe2115e782586f5f712d9fceaa788 preserves 'TITLE_FROM_A', and 6f05752233 failed with ProjectRegistryRestoreError under a 3.12 symlink loop whereas 0f8820a202efe2115e782586f5f712d9fceaa788 commits 'v2'. Clean-worktree checks pass in full: test_capability_hooks_equivalence.py 10 passed in 3.07s (0 skipped), 18-target combined pytest -n 6 -rs 2,633 passed in 327.79s (0 failed, 0 skipped), 9 supplementary scope/hook/registry suites 186 passed in 35.86s (0 skipped), test_delegation_turn_context.py 32 passed, 2 skipped in 76.03s (PowerShell 7 absent on macOS), ruff 19/19, bare mypy 17/17, strict mypy 8/8, typecheck:control-plane clean, TS 63/63 (2184.77ms), check_rfc_bilingual clean, Goal loopx check (0 errors), Goal CQR (pass), and Goal canary premerge (passed, direct=6/6, executed=18/18, failures=0, manual_hold_count=0).

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

[P2] 事务成功删除了登记文件,同一 hook 请求仍能读回已删除的 Goal。合成普通文件的基线和精确头对照确认了差异。

动机 / Motivation

运行 quota should-run、heartbeat pre-quota 或能力钩子编排的调用者会在同一轮多次读取项目登记。 本次交付集中于源码 hook 调用和项目登记读回。 启用能力时,配对的正式请求从 13 次登记文件读取降至 2 次。 常规请求的钩子观察一致,事务删除后的同轮读回出现差异。 还需让已提交删除在当前请求中立即可见。 仓库的 registry readback parity 验收将已提交状态和原调用方读回作为兼容依据。 重构真实路径门

改动思路 / Approach

减少真实钩子入口重复解析与文件读,同时保持已提交变更的可观察读回、扩展开关和 TypeScript 事务语义。 CLI 打开请求作用域,运行可用的注册钩子,Python Registry codec 提供文件事实,TypeScript 决定 hook 验证、投影及 post-writeback 的提交。 同一请求内的钩子共享 registry 快照和 Goal 索引,原子更新由现有写入位置驱逐缓存。只缓存 quota 自己的直接读无法消除多个钩子各自的读盘。由已有事务 owner 统一处理成功创建、更新和删除后的快照失效,可以保留当前派发结构与 I/O 收益。

具体改动 / Changes

精确提交 0f8820a202efe2115e782586f5f712d9fceaa788,基线 b34f0e6157968251dedbd88552ccad34c4fdeef9。兼容 facade 从 1,059 行缩到 277 行,拆出合同、派发、上下文、快照与 post-writeback 逻辑。quota、heartbeat pre-quota、Goal 路由和 Todo 读回接入请求快照。Explore、periodic-report、capability memory 复用 dispatch 合并逻辑。写回继续使用 TypeScript preflight/finalize 和既有兼容写锁。五个提交都有 DCO 签署。

关键代码讲解

  • dispatch_quota_turn_start_hooks。负责 quota 的预览与正式 hook 组合,打开同一请求作用域。 源码
  • CapabilityHookRequestScope.load_goal。为一次派发复用按路由建立的解析结果与 Goal 索引并隔离返回副本。 源码
  • _atomic_write_bytes。替换登记文件后立即驱逐本轮缓存,让后续读看见更新。 源码
  • ProjectRegistryTransaction.remove。执行删除和文件缺失读回;该分支还需驱逐本轮缓存。 源码
  • dispatch_post_writeback_hooks。沿用 TS preflight、provider 与 finalize 事务及当前 legacy 写锁兼容逻辑。 源码

对主干的风险 / Risks

  • [P2] 事务删除后失效当前 hook 请求的 registry 快照。 在同一已进入的 hook request scope 内,以普通文件创建、更新并读回一个项目登记,随后成功调用 ProjectRegistryTransaction.remove(),再查同一 Goal。 登记文件已不存在,基线和退出 scope 后都返回 None,候选在原 scope 却返回已删除的 Goal 和旧标题。 remove() 直接调用 unlink()。更新走 _atomic_write_bytes,成功替换文件后会驱逐本轮缓存。这是可组合 API 的确定性差异。仓库内现有项目卸载调用在 hook scope 外,本次观察限定于通过新 scope 组合的读取。在删除成功的 mutation owner 复用既有 invalidate_hook_registry_snapshot,覆盖当前快照、解码和索引。将新建后的删除补偿作为同类路径复核。 独立对照在删除后补调用现有失效函数,读回恢复为 None。使用普通本地临时登记,在同一 scope 断言创建后可见、更新后为新数据、事务删除后立即不可见,再核对 scope 外一致。 删除 卸载调用

语义与 CI 对齐

  • PASS。File 和 SQLite 各三种配对请求,比较 hook ID、状态、计数、错误、上下文字段和写入摘要,六组一致。实际 local quota turn-start 路径启用能力时,统计到的配置加载 10→1、文件读 13→2。 三组请求分别覆盖 dry-run、默认能力和显式注册能力。前两组的本地变更标志在两侧均为 false。启用能力时两后端均为 true。配对比较的是结构化结果摘要。
  • PASS。Python 3.14.8 本地源码,基线 116 项通过,当前头 122 项通过、4 项未选。标准 premerge 6 项直接检查与 18 项所选检查通过。 定向检查包含 post-writeback 重放及普通锁竞争、quota 预览、heartbeat 通知、定时报告和 Lark 开关。
  • FAIL。同请求创建和原子更新后能立即读回,删除则继续返回更新后的旧 Goal,且文件已缺失。退出 scope 后,新查询与基线一致。
  • UNVERIFIED。测试使用普通合成项目、真实文件事务与 File/SQLite。本轮未独立验证符号链接竞争、PostgreSQL、安装版、远端 CI 或端到端延迟。

我的整体评价 / Verdict

拆分保留了已有 TypeScript 权威与主要 hook 调用面,也确实减少文件读取。另一模型的同头 review 已覆盖此前报告的路径隔离问题。这次请求修改的依据是独立配对确认的普通事务删除回归。请补齐删除失效并重跑同请求生命周期验证。

English verdict: REQUEST_CHANGES at 0f8820a. A committed registry deletion leaves the cached Goal visible within the same hook request. Invalidate the existing snapshot on successful removal and test create, update, and remove in one scope. File and SQLite quota comparisons and the standard local premerge gate passed.

@loopx-agent

Copy link
Copy Markdown
Collaborator Author

Addressed review 6061054004 in 34aa7a942a:

  • Extracted _invalidate_registry_snapshot() in loopx/control_plane/projects/registry_codec.py and wired it into _atomic_write_bytes(), ProjectRegistryTransaction.remove() (both after self._path.unlink() and on the not self._path.exists() early-return branch), and ProjectRegistryTransaction.restore()'s else: newly-created delete compensation branch after self._path.unlink(missing_ok=True).
  • Added tests/control_plane/test_capability_hook_request_scope.py (129 LOC, 0 Any, 4 tests) verifying create -> update -> remove() invalidates both plain files and symlink aliases inside and outside capability_hook_request_scope(), missing-path remove() clears stale snapshots before returning False, and restore() delete compensation (_existed=False) immediately returns None inside and outside the scope.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · Gemini · Google · self_reported

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

本次复审在独立干净 detached worktree 中对 PR #9433 新提交(codex/slim-capability-hooks-zero-any-20261125 -> main,精确提交 34aa7a942a264a8b52fcda202d2864b3d523eeb9,基线 b34f0e6157968251dedbd88552ccad34c4fdeef9)完成了前版 0f8820a202efe2115e782586f5f712d9fceaa788 vs 34aa7a942a264a8b52fcda202d2864b3d523eeb9 的事务删除(ProjectRegistryTransaction.remove 常规/软链接/缺失路径)与新建回滚(ProjectRegistryTransaction.restore)同请求快照失效反例对照、14 项 request_scope + equivalence 测试、19 组 2,637 项组合测试、9 组 186 项补充测试、TS 控制面校验、严格静态类型与 Goal 预合并门禁。最新外审 6061054004 指出的 [P2] 缺陷(事务成功删除登记文件或新建回滚清除后,同一 capability_hook_request_scope() 仍返回已删除 Goal)以及前序四项 [P2](PRRT_kwDOStEbEs67-jHf / 6060566697、6059501353、PRRT_kwDOStEbEs674DeA / 6057030769、PRRT_kwDOStEbEs67z2Xl & PRRT_kwDOStEbEs67z2Xt / 6054631468)均已彻底修复并补齐回归;capability_hooks.py(277 LOC)与全部 6 个 hook_runtime/* 子模块(113 / 254 / 253 / 285 / 628 / 238 LOC)及两份测试文件(129 / 787 LOC)均 < 790 LOC、0 AST Any、0 # type: ignore、0 裸 O_NOFOLLOW(module_metric_baseline.json 未修改,6/6 DCO 提交,4/4 审阅线程已解决,unresolved_count=0,0 泄漏,git merge-tree 与 origin/main 无冲突),批准精确提交 34aa7a942a264a8b52fcda202d2864b3d523eeb9。

动机 / Motivation

在 quota should-run、heartbeat_prequota、project_uninstall 与多阶段能力钩子派发链中于同一 capability_hook_request_scope() 内执行创建、更新、删除(remove())或新建回滚(restore())并随即回读的项目登记调用方需要单请求快照缓存与持久化事务保持强一致:既要在多钩子读取时复用快照消除重复 I/O,也绝不能在 ProjectRegistryTransaction.remove() 删除文件或 ProjectRegistryTransaction.restore() 回滚清除新建文件之后,同一请求内仍从过时快照读回已经不存在的 Goal 导致错误决策。

  • **问题与修前/修后对比:**复核并关闭前轮外审 6061054004([P2])及前序全部 [P2] 缺陷:1) 事务删除 remove() 与新建回滚 restore() 未失效同请求快照导致删除后仍读回已删 Goal(6061054004):在同一 capability_hook_request_scope() 内先创建、更新并读回项目登记(经由原文件或符号链接别名),再通过 ProjectRegistryTransaction.remove() 删除文件或对新建登记(_existed=False)调用 ProjectRegistryTransaction.restore() 回滚清除后,前版 0f8820a202 仅在 _atomic_write_bytes() 调用了失效,而 remove() 与 restore() 的 else: 分支直接调用 unlink() 未触发失效,导致同作用域后续 load_goal_from_registry / load_scoped_registry 仍返回已删除的 'v1'/'bn';当前精确提交 34aa7a942a264a8b52fcda202d2864b3d523eeb9 在 loopx/control_plane/projects/registry_codec.py 抽取统一辅助 _invalidate_registry_snapshot(path)(L308-311),并在 _atomic_write_bytes(L330)、ProjectRegistryTransaction.remove() 的 not self._path.exists() 提前返回路径(L464-467)与 self._path.unlink() 后(L468-469)、以及 ProjectRegistryTransaction.restore() 新建删除补偿分支 self._path.unlink(missing_ok=True) 后(L489-490)全面调用失效;同头独立反例实测 CF_0f8820a2 返回 {'rm_real': 'v1', 'rm_alias': 'v1', 'after_restore': 'bn'},而 CF_34aa7a94 返回 {'rm_real': None, 'rm_alias': None, 'after_restore': None};2) 同族写入边界审计:核对 registry_codec.py、control_plane/projects/registry.py(项目登记均经由 registry_codec 事务,仅 ACTIVE_GOAL_STATE.md 直接原子写)、project_uninstall.py:460-471(本地卸载通过 project_registry_transaction(...).remove())及 hook_runtime/(无登记写操作),确认无遗漏的同域项目登记删改路径(global_registry.py 的 write_json 仅写 registry.global.json,不经由 load_scoped_registry/load_goal_from_registry 请求作用域读取);3) 前序四项 [P2] 修复完整保留:ABA 往返竞争隔离(6060566697 / PRRT_kwDOStEbEs67-jHf)、Python 3.12 符号链接环路安全 invalidate()(6059501353)、重指向软链接隔离与格式边界(6057030769 / PRRT_kwDOStEbEs674DeA)以及跨别名格式校验与全别名清理(6054631468 / PRRT_kwDOStEbEs67z2Xl & PRRT_kwDOStEbEs67z2Xt)均在本头回归套中持续通过。
  • **可观测效果:**在干净 detached worktree 实测精确提交 34aa7a942a264a8b52fcda202d2864b3d523eeb9:tests/control_plane/test_capability_hook_request_scope.py + tests/control_plane/test_capability_hooks_equivalence.py 14 passed in 5.12s(0 skipped)(含新增 4 项 remove() 常规/软链接、缺失文件 remove()->False 清理脏缓存与 _existed=False restore() 回归,及全部 10 项 ABA/3.12 环路/IO 降幅等价测试);同头独立反例证实 0f8820a202 保留已删 'v1'/'bn' 脏缓存,而 34aa7a942a264a8b52fcda202d2864b3d523eeb9 在普通路径、软链接别名与新建回滚下均立即读回 None/{};pytest -n 6 -rs 合并运行 19 个核心/架构/棘轮/注册表套件 2,637 passed in 578.52s(0 failed, 0 skipped);9 组补充请求作用域/钩子/注册表/普查回归 186 passed in 114.51s(0 skipped),tests/test_delegation_turn_context.py 32 passed, 2 skipped in 148.10s(macOS 缺 PowerShell 7 跳过 2 项);ruff 20/20、裸 mypy 17/17、严格 mypy 9/9、registry_codec.py mypy 1/1、typecheck:control-plane clean、TS 3 套件 63/63(4186.74ms)、Goal loopx check 0 errors 与 Goal canary premerge 18/18(direct=6/6、catalog=10/10、risk=8/8、failures=0、manual_hold_count=0) 全部通过。
  • **非目标与边界:**不改变 TypeScript 事务协议与对外 CLI/JSON 合同,不修改 module_metric_baseline.json,不跨请求保留缓存,保持 PR OPEN 供维护者授权合并。
  • **规范对齐:**对应 docs/architecture/rfcs/loopx-overall-roadmap-v0.md(基线 b34f0e6157968251dedbd88552ccad34c4fdeef9)下的控制面零 Any 模块化拆分与单请求作用域一致性验收项 CAPABILITY-HOOKS-MODULARITY-800 与 CAPABILITY-HOOKS-REQUEST-SCOPE。

改动思路 / Approach

  1. 统一事务写/删/回滚失效出口,补齐 remove() 与 restore() 缓存驱逐(loopx/control_plane/projects/registry_codec.py:308-332,461-495):
    • 抽取模块级辅助 _invalidate_registry_snapshot(path)(L308-311)统一延迟转发至 invalidate_hook_registry_snapshot(path),避免在多个事务分支重复导入或漏接。
    • _atomic_write_bytes(L330)写入/替换并覆盖 restore() 的 if self._existed: 恢复路径;ProjectRegistryTransaction.remove() 在 not self._path.exists() 提前返回 False 前(L465)与 self._path.unlink() 后(L469)双路触发失效;ProjectRegistryTransaction.restore() 在新建补偿 else: 的 self._path.unlink(missing_ok=True) 后(L490)同步触发失效。
  2. 新增删除与新建回滚生命周期回归(tests/control_plane/test_capability_hook_request_scope.py:1-129):
    • 覆盖同请求 create -> update -> remove() 在普通路径与符号链接别名下立即返还 None/{}(且作用域退出后一致),缺失文件 remove() -> False 清除预存脏快照,以及新建文件 _existed=False 提交后调用 tx.restore() 同步清除原路径及软链接别名缓存。
  3. 保留 (route, expanded.name) 分键隔离与 3.12 循环链安全防护(loopx/control_plane/hook_runtime/request_scope.py:30-41,97-182):
    • 前序解决的 ABA 往返隔离(238 LOC)与 _safe_absolute/_safe_resolve 符号链接环保护保持完整且未受本次改动退化。
  4. **架构归属与当前 PR 边界:**本 PR 将 capability_hooks.py 收口为 277 LOC / 0 Any 薄门面与 6 个 < 630 LOC / 0 Any hook_runtime/* 子模块(113 / 254 / 253 / 285 / 628 / 238 LOC),同时让 registry_codec.py 事务写/删/回滚唯一共享 _invalidate_registry_snapshot 完成 CapabilityHookRequestScope 缓存失效协同,不改变磁盘事务或 TS effect_runtime 所有权。精确提交 34aa7a942a264a8b52fcda202d2864b3d523eeb9 已完整修复外审 6061054004 与前序全部 [P2] 缺陷(4/4 审阅线程均 resolved、unresolved_count=0,6/6 DCO 提交,git merge-tree 无冲突),module_metric_baseline.json 未修改。

具体改动 / Changes

全部 20 个文件(+3,082/-1,112,6/6 DCO 提交,相对 0f8820a202 精调 2 个文件 +139/-3,git merge-tree 无冲突;module_metric_baseline.json 未修改);依据 docs/architecture/rfcs/loopx-overall-roadmap-v0.md 逐项核对:CAPABILITY-HOOKS-MODULARITY-800 为 implemented,CAPABILITY-HOOKS-REQUEST-SCOPE 为 implemented:

  1. loopx/control_plane/projects/registry_codec.py(698 LOC、0 # type: ignore): 新增 _invalidate_registry_snapshot(path)(L308-311),复用于 _atomic_write_bytes(L330)、ProjectRegistryTransaction.remove 双分支(L465, L469)与 ProjectRegistryTransaction.restore 新建回滚分支(L490)。
  2. tests/control_plane/test_capability_hook_request_scope.py(129 LOC、0 AST Any): 新增 4 项事务删除/缺失清理/新建回滚请求作用域失效回归测试。
  3. 其余 18 个拆分、测试与调用方文件: capability_hooks.py(277 LOC)、__init__.py(113 LOC)、contracts.py(254 LOC)、turn_context.py(253 LOC)、dispatch.py(285 LOC)、post_writeback.py(628 LOC)、request_scope.py(238 LOC)、cadence_runtime.py(132 LOC)与 test_capability_hooks_equivalence.py(787 LOC)均 0 AST Any 与 0 # type: ignore。

关键代码讲解

  • _invalidate_registry_snapshot:单一私有转发入口封装对 invalidate_hook_registry_snapshot 的调用,避免写、删、回滚三处重复局部导入或产生同步分叉。
  • ProjectRegistryTransaction.remove:无论是目标已缺失提前返回 False 还是成功 unlink() 并通过存在性回读,均立即清空作用域内的规范路径及所有已跟踪别名快照。
  • ProjectRegistryTransaction.restore:已有文件通过 _atomic_write_bytes 自动失效;新建文件回滚(else: unlink(missing_ok=True))同样立即失效快照与 Goal 索引。

对主干的风险 / Risks

  • 精确提交 34aa7a942a264a8b52fcda202d2864b3d523eeb9 全量独立实测结果(于干净 detached worktree 实测,遵循 wait_for_ci: false 未等远端 GitHub Actions CI):
    1. remove/restore 失效反例对照与作用域等价验证: pytest -v -rs tests/control_plane/test_capability_hook_request_scope.py tests/control_plane/test_capability_hooks_equivalence.py 14 passed in 5.12s(0 skipped);独立对照实测 0f8820a202 在同请求 remove() 后普通路径与别名均返回 'v1'、新建 restore() 后仍返回 'bn',而 34aa7a942a264a8b52fcda202d2864b3d523eeb9 全部立即返回 None;前序 ABA 往返与 3.12 符号链接环路用例均同 suite 覆盖并通过。
    2. 广谱核心、架构、棘轮与注册表回归: pytest -n 6 -rs 合并运行 19 个目标(含 tests/architecture/、test_maintainability_ratchet.py、test_capability_hook_request_scope.py、test_capability_hooks_equivalence.py、test_project_registry_codec.py、test_project_registry_m0_contract.py 及全部 13 个核心钩子/路由/配额/日程/Lark/托管会话套件)2,637 passed in 578.52s(0 failed, 0 skipped)。
    3. 补充作用域、钩子与上下游专项: 9 组补充请求作用域/注册表 CLI/钩子/IO 普查套件 186 passed in 114.51s(0 skipped);tests/test_delegation_turn_context.py 32 passed, 2 skipped in 148.10s(macOS 缺 PowerShell 7 跳过 2 项)。
    4. 静态类型、TS 与 Goal 预合并: ruff check(20/20 文件)0 问题;裸 mypy --no-incremental 17/17 干净;严格 mypy --strict --follow-imports=silent 9/9 干净;mypy --follow-imports=silent registry_codec.py 1/1 干净;npm run typecheck:control-plane clean;TS 3 套件 63 passed, 0 failed, 0 skipped(4186.74ms);check_rfc_bilingual.py --base origin/main --head HEAD clean;diff/提交 0 泄漏;Goal loopx check ok=True, errors=0;Goal canary premerge --from-git-diff --git-diff-base b34f0e6157 ok=True, status="passed", merge_gate_passed=true(direct=6/6、catalog=10/10、risk=8/8、executed=18/18、failures=0、manual_hold_count=0)。

语义与 CI 对齐

无新增控制面语义词表(semantic-vocabulary-drift-smoke 与架构所有权套件全绿);4/4 条审阅线程均已 resolved(unresolved_count=0);遵循 wait_for_ci: false 未查询远端 CI,保持 PR OPEN。

我的整体评价 / Verdict

  • 长程与体验评估: long_horizon=improved(在保持单请求 load_registry 11 -> 1 I/O 收益的同时,完整闭环了写入、替换、事务删除 remove()、缺失清理与新建补偿回滚 restore() 的读回一致性及软链接/循环链安全边界),user_experience=preserved(全部 47 项导出、接缝、静态类型与外部事务行为严格等价);visual_review=not_applicable(原因:仅涉及控制面钩子模块拆分、registry_codec 事务删除/回滚失效协同及回归测试,无前端界面修改;unverified_scope:遵循 wait_for_ci=false 未查询远端 GitHub Actions CI;本地主机未预装 CPython 3.12 与 PowerShell 7(tests/test_delegation_turn_context.py 2 项 Windows/pwsh 用例跳过;CPython 3.14.8 上含 POSIX 与模拟 Python 3.12 RuntimeError 循环链接的 test_capability_hooks_equivalence.py 10/10 与 test_capability_hook_request_scope.py 4/4 共 14/14 全绿);其余 19 项组合套件(2,637 项)、补充 186 项、TS 63 项、mypy、CQR 与 Goal canary premerge 18/18 均已在精确提交 34aa7a9 本地干净工作树完整跑通)。
  • 结论: 外审 6061054004 与前序全部 [P2] 缺陷均已彻底修复并通过同头对照与全量回归,批准精确提交 34aa7a942a264a8b52fcda202d2864b3d523eeb9;保持 PR OPEN 供维护者授权合并。

English verdict: APPROVE at 34aa7a9. Independently verified resolution of external [P2] review 6061054004 alongside all four earlier [P2] findings (PRRT_kwDOStEbEs67-jHf / 6060566697, 6059501353, PRRT_kwDOStEbEs674DeA / 6057030769, and PRRT_kwDOStEbEs67z2Xl / PRRT_kwDOStEbEs67z2Xt / 6054631468), with 4/4 threads resolved, unresolved_count=0, 6/6 DCO commits, clean git merge-tree vs origin/main (50aa5b4fd1) and base b34f0e6157, 0 leaks, and module_metric_baseline.json untouched. loopx/control_plane/projects/registry_codec.py (698 LOC, 0 # type: ignore) extracts _invalidate_registry_snapshot(path) (L308-311) and calls it from _atomic_write_bytes (L330), both branches of ProjectRegistryTransaction.remove() (L465, L469), and ProjectRegistryTransaction.restore()'s newly-created unlink branch (L490); counterfactual execution proves 0f8820a202efe2115e782586f5f712d9fceaa788 returned stale 'v1' after remove() (on both real and symlinked paths) and stale 'bn' after restore(), whereas 34aa7a942a264a8b52fcda202d2864b3d523eeb9 immediately returns None. Clean-worktree checks pass in full: test_capability_hook_request_scope.py + test_capability_hooks_equivalence.py 14 passed in 5.12s (0 skipped), 19-target combined pytest -n 6 -rs 2,637 passed in 578.52s (0 failed, 0 skipped), 9 supplementary scope/hook/registry suites 186 passed in 114.51s (0 skipped), test_delegation_turn_context.py 32 passed, 2 skipped in 148.10s (PowerShell 7 absent on macOS), ruff 20/20, bare mypy 17/17, strict mypy 9/9, registry_codec.py mypy 1/1, typecheck:control-plane clean, TS 63/63 (4186.74ms), check_rfc_bilingual clean, Goal loopx check (0 errors), Goal CQR (pass), and Goal canary premerge (passed, direct=6/6, executed=18/18, failures=0, manual_hold_count=0).

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

动机 / Motivation

同一 Hook 请求内读取 Goal 和来源登记,以及通过现有登记事务执行并读回更新的调用方。同一请求的别名读取从已经缓存的登记来源 B 取值,随后通过正常登记事务更新 B。核对别名与源的写后读回。复跑确认之前独立 A 的错源已修复,冷缓存写后也返回 A。本头的删除和新文件回滚清除登记快照,新增生命周期回归已通过。无关链接环仍允许写回。

Hook activation and request-scoped registry invalidation。精确对照中,B 的原子提交成功,磁盘和直接读回都已更新。别名引用已缓存的 B 时,当前头同请求仍读到 B 的旧值。冷缓存对照与目标基线都返回 A。新请求恢复正确。 隔离验证使用同一 Python 3.12、实际 POSIX symlink 和 File 登记事务。同步探针只固定改指时序。常规 File 与 SQLite hook 由等价套件覆盖,暖缓存反例未扩到真实已安装候选或其他平台。 验收依据

改动思路 / Approach

项目 registry codec 决定读取字节的来源并拥有原子保存。hook request scope 用实际来源关联失效范围。load_goal_from_registry → registry_codec.load_registry → ProjectRegistryTransaction.commit → request-scope invalidation → 同请求 Goal 读回。让 codec 在选择原始快照时把实际来源交给请求缓存,同时覆盖冷读取和命中现有原始快照。继续按调用路由隔离解码,并对冷热场景验证真实写后别名读回与无关写入。

具体改动 / Changes

精确 head 34aa7a942a264a8b52fcda202d2864b3d523eeb9,目标分支快照与实际分叉基线均为 b34f0e6157968251dedbd88552ccad34c4fdeef9。20 个文件、+3082/-1112。当前增量显式接入 remove 与 restore 的快照失效,底层来源跟踪沿用上一提交。

关键代码讲解

  • load_goal_from_registry。复用活跃请求中的 Goal 查找。 源码
  • registry_codec.load_registry。通过实际上选中的来源取得字节,已有键时同样会被选中。 源码
  • CapabilityHookRequestScope.load_registry target inference。借请求前后路径和新增键推断来源。B 已缓存时不会出现在新增键中。 源码
  • CapabilityHookRequestScope.invalidate。提交 B 时按登记的来源关联挑选要失效的别名。 源码
  • ProjectRegistryTransaction.commit。完整验证磁盘写入并返回成功。 源码

对主干的风险 / Risks

[P2] 暖原始缓存命中时遗漏别名的实际登记来源

精确对照中,B 的原子提交成功,磁盘和直接读回都已更新。别名引用已缓存的 B 时,当前头同请求仍读到 B 的旧值。冷缓存对照与目标基线都返回 A。新请求恢复正确。

正式登记提交已经成功时,只有预热路径继续保留提交前的 Goal,导致同请求的读回取决于之前是否访问过 B。该反例的旧别名值持续到退出请求。 相关源码

语义与 CI 对齐

170 项定向 hook、登记与 CLI 测试通过,含新增删除/回滚与既有 File、SQLite hook。9 个源文件严格 mypy 通过。标准预检 18 项通过。预检设置隔离的 HOME 和两个 Git 引用。直接单独运行预算检查时,两个精确源码均报同样的 11951 字符超过 11400,保留这条环境差异。 暖缓存对照用 Python 3.12、真实临时 Git 外登记文件与隔离同步探针。

我的整体评价 / Verdict

REQUEST_CHANGES。 让 codec 在选择原始快照时把实际来源交给请求缓存,同时覆盖冷读取和命中现有原始快照。继续按调用路由隔离解码,并对冷热场景验证真实写后别名读回与无关写入。 复验冷热快照、提交后别名回读及原有独立路径。

English verdict: REQUEST_CHANGES at 34aa7a9. The remove and rollback paths now invalidate snapshots. A warm source cache still leaves a dependent alias stale after the source commits.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

动机 / Motivation

从全局登记读原 Goal Todo,再在同一 Hook 请求中读回原生来源和 Goal 的调用方。通过全局 Todo 列表读源时,登记 A 在取字节期间短暂指向已缓存的 B,随后恢复 A。B 通过现有 registry 事务提交新值,当前请求再次读取 A。当前头的直接 Goal 冷、暖别名写后读回均恢复正确,既有新增删除、恢复与无关来源提交用例通过。只让 Todo 路由走已有 scope loader 的本机隔离对照,在同一个失败输入下从 B-before 恢复为 A-original。

Hook request-scoped registry invalidation。本头的 Todo 列表成功使用真实 File authority,但源路由把原始字节写进共享 dict,未将 A 与实际读取的 B 关联。提交 B 成功后同一请求仍经 A 读到 B-before,直接读取 B 已为 B-after。基线与新请求均返回 A-original。 决定性反例在隔离 POSIX 文件和真实 File Todo authority 上执行。同步探针控制文件切换时序。常规 Hook 用例覆盖 File 和 SQLite。安装、真实项目和远端 CI 未复验。 验收依据

改动思路 / Approach

源路径选定由 resolve_goal_source_runtime_route 和 registry codec 拥有。请求 scope 以观察到的来源维护失效边,写入与反证由已有 ProjectRegistryTransaction 决定。list_goal_todos → resolve_goal_source_runtime_route → load_registry → ProjectRegistryTransaction.commit → load_goal_from_registry。活跃 Hook scope 中让 Todo 的 source route 使用同一请求缓存入口来捕获实际源。外部调用保留自己的临时字典。用同请求的 Todo list → 来源提交 → Goal readback 核对实际失效。

具体改动 / Changes

精确 head 5855025dc4e15c8276295c2d5e8152e6c3c8138b,目标分支快照与实际分叉基线均为 b34f0e6157968251dedbd88552ccad34c4fdeef9。20 个文件,增加 3246 行、删除 1112 行。相对上一头 2 文件增加 168 行、删除 4 行,加入访问观察字典和两项暖缓存测试。原全局 Todo 路由仍传入共享原始 dict。

关键代码讲解

  • list_goal_todos。从活跃 scope 取得共享原始 dict。 源码
  • source_snapshots。将共享 dict 显式传给源路由。 源码
  • resolve_goal_source_runtime_route。收到显式 source_snapshots 时跳过 scoped loader。 源码
  • CapabilityHookRequestScope.load_registry。只可记录本次 loader 触及的键,已缓存的 A 字节不会重新查询 B。 源码
  • _invalidate_registry_snapshot。沿已有事务通知当前 scope 清除来源和已记录别名。 源码

对主干的风险 / Risks

[P2] Todo 源路由绕开实际 registry 来源跟踪

本头的 Todo 列表成功使用真实 File authority,但源路由把原始字节写进共享 dict,未将 A 与实际读取的 B 关联。提交 B 成功后同一请求仍经 A 读到 B-before,直接读取 B 已为 B-after。基线与新请求均返回 A-original。

成功写入后的来源读回取决于先前走过的入口,当前请求内后续 Hook 可能继续使用另一登记的旧 Goal 数据。独立直接 Goal 读回测试和已有路由测试均可通过。 相关源码

语义与 CI 对齐

22 项定向 Hook、请求 scope 与源路由测试通过。用同一 File 真实入口、基线、上一头、当前头和候选最小调整对照读回。标准 premerge 未读到完成回执。

我的整体评价 / Verdict

REQUEST_CHANGES。 活跃 Hook scope 中让 Todo 的 source route 使用同一请求缓存入口来捕获实际源。外部调用保留自己的临时字典。用同请求的 Todo list → 来源提交 → Goal readback 核对实际失效。 复验同请求内的全局 Todo 列表、来源提交与后续 Goal 读回。

English verdict: REQUEST_CHANGES at 5855025. Direct warm-alias invalidation now passes. The Todo source route can still seed an untracked snapshot, leaving a stale Goal after the actual source commits.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

动机 / Motivation

在同一次 Hook 请求中读取 Goal 与 Todo 来源,或继续检查先前读失败的调用方。隔离的全局 registry 路径短暂指向已缓存的严格 project registry。让正常 decoder 拒绝错误格式,恢复路径,再用正常 registry 事务提交 project 源并重新读取全局 Goal。直接 Goal 冷、暖别名的正常解码在来源写入后均恢复。上轮的 Todo 路由问题已修复。相同路径在 File 和 SQLite authority 下都从上一候选的 B-before 恢复到 A-original。

失败快照的来源失效。首次读取在各版都报全局登记必须是 JSON 对象,来源事务都成功。基线第二次读出 A-original,已审核上一头与当前头仍报同样的格式错误,只在新请求读回 A-original。 决定性反例用真实隔离 POSIX 文件、registry codec 和事务,探针仅控制切换时点。File 和 SQLite 的 Todo 来源复验使用真实本机 authority。安装、生产环境、远端 CI 未复验。 验收依据

改动思路 / Approach

registry codec 负责选择字节和验证格式,request scope 记录来源与失效,ProjectRegistryTransaction 在实际提交后通知失效。Todo route 复用同一个 scoped loader。load_goal_from_registry 或 Todo 源路由 → registry_codec.load_registry → request scope 快照 → ProjectRegistryTransaction.commit → 同请求读回。让 raw snapshot 的持久化和真实来源依赖在失败路径也保持一致。可以在 decoder 抛出时放弃本次新存入的 alias 快照,或保留依赖并让对应源提交使其失效。保留全局 object-only 校验。

具体改动 / Changes

精确 head 45f353fdde97314303640db4af6fe9d1aabf7925,目标分支快照与实际分叉基线均为 b34f0e6157968251dedbd88552ccad34c4fdeef9。20 个文件增加 3375 行、删除 1112 行。相对上一头 2 个文件增加 131 行、删除 2 行。新增 Todo 来源进入 scoped loader 的路径与回归。

关键代码讲解

  • load_goal_from_registry。在活跃请求中通过 scope 取得隔离 Goal 读本 源码
  • _ObservedSnapshotDict.__setitem__。把字节写进共享缓存,早于格式校验 源码
  • CapabilityHookRequestScope.load_registry。调用 loader,成功后才登记来源依赖和失效关系 源码
  • ProjectRegistryTransaction.commit。按真实项目格式提交并使登记来源失效 源码
  • list_goal_todos。活跃请求让源解析复用 scoped loader,修复上轮绕开跟踪 源码

对主干的风险 / Risks

[P2] 解码失败的别名快照绕过提交失效

首次读取在各版都报全局登记必须是 JSON 对象,来源事务都成功。基线第二次读出 A-original,已审核上一头与当前头仍报同样的格式错误,只在新请求读回 A-original。

本来的失败限制在一次读操作。候选会在整个请求中继续使用失败字节,即使提交已成功,调用路径已恢复且当前磁盘内容有效。写回本身和新请求读取均正常。 相关源码

独立验证

已分别用 Python 3.12 和 3.14 复验失败读回,并在 File 与 SQLite 对照原 Todo 问题。108 项定向测试和 9 文件 strict mypy 通过。标准 premerge 通过。

我的整体评价 / Verdict

REQUEST_CHANGES。 让 raw snapshot 的持久化和真实来源依赖在失败路径也保持一致。可以在 decoder 抛出时放弃本次新存入的 alias 快照,或保留依赖并让对应源提交使其失效。保留全局 object-only 校验。 保留全局格式拒绝,复验来源提交后同请求的恢复。

English verdict: REQUEST_CHANGES at 45f353f. The Todo source-route fix passes on File and SQLite. A failed registry decode still leaves an untracked raw alias snapshot, so a successful source commit does not restore a same-request read.

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · Gemini · Google · self_reported

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

本次复审在独立干净 detached worktree(/tmp/rev-9433-37164996)中对 PR #9433 最新提交(codex/slim-capability-hooks-zero-any-20261125 -> main,精确提交 371649968108d359264060251ae81064ad3a262a,实际分叉与目标基线 b34f0e6157968251dedbd88552ccad34c4fdeef9)完成了 45f353fdde..371649968108d359264060251ae81064ad3a262a 增量核查与全量基线回归、前序 [P2] 缺陷 PRRT_kwDOStEbEs68GYXH 的冷/暖配对反例复验、file 与 sqlite 双后端 list_goal_todos ABA 别名失效实测、Python 3.12.15 symlink-loop 与 3.14.8 运行验证、Zero-Any / 零裸 os.O_NOFOLLOW 扫描、ruff / strict mypy、全量 TS 与 Python 回归以及 Goal loopx check / canary premerge / change-quality 验证。PR #9433 全部 7/7 条讨论串均已闭环解决且当前头提交无阻断缺陷。

动机 / Motivation

当 quota should-run、heartbeat_prequota、turn_start、periodic_report、load_goal_from_registry 及 list_goal_todos 在同一请求周期内多次读取全局或源项目 registry 时,此前 loopx/control_plane/capability_hooks.py 膨胀至 1,059 行并混杂61 处 Any 与重复磁盘 JSON 解析,缺乏统一的请求级快照共享与写/解码失败隔离机制。在上一轮提交 45f353fdde 上,虽然已修复 list_goal_todos 作用域内的 ABA 别名失效,但 _ObservedSnapshotDict.__setitem__ 仍直接原地写入共享 scope.registry_snapshots;当隔离的全局路径 registry.global.json 临时符号链接到严格项目登记文件 project-reg.json并触发 decode_registry_snapshot 抛出 ProjectRegistryError: global registry root must be a JSON object时,失败读取会提前在 _record_targets 注册别名前把原始字节残留在 scope.registry_snapshots 中,致使恢复符号链接至合法 real-global.json(A-original)并经由 project_registry_transaction 提交后,同请求第二次 load_goal_from_registry 仍持续报错直到新请求;在当前提交 371649968108d359264060251ae81064ad3a262a 中,移除 _ObservedSnapshotDict._backing、__delitem__ 与 clear 覆写使加载读取在临时视图中暂存并在校验成功后才提交至 scope.registry_snapshots,无论冷/暖源库均在同请求内立即恢复 A-original / B-after。当前提交在不新增任何顶层 loopx/*.py 文件(维持 112 个)且不改变默认 CLI/hook 输出与全局 JSON 对象校验规则的前提下,将 capability_hooks.py 拆分为 277 行兼容门面与 hook_runtime 下 6 个零 Any、均不超过 628 行的子模块,同时兼顾多别名 ABA 失效与解码失败零污染;未扩展至独立 PostgreSQL 实时数据库服务端的外部联调测试(仅执行本地单测与受控环境测试),亦未重塑既有未拆分的周边调用方文件与 list_readback.py / registry_codec.py 中历史残留的 Any 注解。

改动思路 / Approach

with capability_hook_request_scope():                    (request_scope.py:279)
  └─ CapabilityHookRequestScope.load_registry            (request_scope.py:147)
       ├─ observed = _ObservedSnapshotDict(self.registry_snapshots)  (无 _backing 直接拷贝暂存)
       ├─ _invoke_registry_loader(loader, path, source_snapshots=observed)
       │    ├─ [decode 失败 -> ProjectRegistryError] 抛出异常,observed 丢弃,self.registry_snapshots 保持洁净
       │    └─ [decode 成功] 提交 observed -> self.registry_snapshots;记录 _alias_to_targets 并缓存解码结果
       └─ _invalidate_registry_snapshot -> scope.invalidate (registry_codec.py:308 -> request_scope.py:201)

说明(基于精确提交 371649968108d359264060251ae81064ad3a262a 源码推导,非运行时覆盖率追踪):request_scope.py、list_readback.py。

按职责把 contracts、request_scope、turn_context、dispatch、post_writeback 与兼容门面 capability_hooks.py 分层,并用 ContextVar 请求作用域结合仅暂存成功快照的 _ObservedSnapshotDict 在解码与路径别名校验全部通过后才原子提交到 scope.registry_snapshots,避免解码异常把未追踪原始字节遗留进共享快照表(当前 PR 边界),将零 Any 拆分与请求作用域快照暂存/失效生命周期收敛在 capability_hooks.py、hook_runtime/、11 处作用域接入点与对应单测中(当前 PR 边界),保持作用域外自动回退为无共享单次读;调用方外围与 registry_codec.py(22 处)、list_readback.py(2 处)原有 Any 留作独立后续重构,不在此扩大范围。

具体改动 / Changes

精确提交 371649968108d359264060251ae81064ad3a262a(相对基线 b34f0e6157968251dedbd88552ccad34c4fdeef9 共改动 20 个文件,+3,441 / -1,112 行,9/9 DCO 提交;相对上一轮 45f353fdde 仅增量修改 loopx/control_plane/hook_runtime/request_scope.py(292 LOC,净 -11 行)与 tests/control_plane/test_capability_hook_request_scope.py(434 LOC,+77 行)):将原 1,059 行的 capability_hooks.py 拆分为 277 行兼容门面与 hook_runtime/ 下 6 个严格零 Any 模块(__init__.py=113、contracts.py=254、dispatch.py=285、post_writeback.py=628、request_scope.py=292、turn_context.py=253 LOC)及 test_capability_hooks_equivalence.py(787 LOC),AST 扫描上述 7+2 核心文件均为 0 Any 与 0 type: ignore,0 处裸 os.O_NOFOLLOW,loopx/*.py 维持 112 个且 module_metric_baseline.json 未改动。依据规范 docs/reference/protocols/host-integration-surface-v0.md(固定基线 b34f0e6157968251dedbd88552ccad34c4fdeef9):

Criterion ID Requirement Disposition (371649968108d359264060251ae81064ad3a262a) Evidence
HOOK-SURFACE-COMPAT 保持薄 hook 生命周期契约、capability_hooks 兼容再导出与 CLI 默认输出一致 Implemented 277 LOC 门面全量再导出;69/69 TS hook/writeback、2,409 passed, 6 skipped pytest PASS
HOOK-REQUEST-SCOPE 请求内共享不可变快照,兼顾多别名 ABA 失效与解码失败零污染、作用域外严格隔离 Implemented request_scope.py:16-176 & list_readback.py:65-78;冷/暖失败解码与 file/sqlite ABA 探针均恢复 A-original/B-after
CP-STATIC-ZERO-ANY 拆分模块 <700 LOC、Zero-Any 且保持 loopx/*.py == 112 与可维护性棘轮 Implemented 核心 7+2 文件 0 Any/type: ignore(最高 628 LOC);ruff 20/20、strict mypy 9/9、maintainability-ratchet PASS

关键代码讲解

  • _ObservedSnapshotDict 与 CapabilityHookRequestScope.load_registry(源码):移除 _backing、__delitem__ 与 clear,改由 super().__init__(initial) 在局部副本中暂存读写并记录 observed_keys;仅在 _invoke_registry_loader 成功解码返回后执行 self.registry_snapshots.update(observed) 与 _record_targets,根除 PRRT_kwDOStEbEs68GYXH 失败解码污染共享快照缺陷。
  • CapabilityHookRequestScope.invalidate 与 _safe_resolve(源码):在 OSError/RuntimeError 下安全返回 None 规避 symlink loop 崩溃(Python 3.12.15 与 3.14.8 均实测通过),并基于 _alias_to_targets 与快照路径级联驱逐所有别名与依赖目标。
  • list_goal_todos(源码):通过 current_hook_registry_snapshots() 在作用域内传入 source_snapshots=None 让 resolve_goal_source_runtime_route 复用共享观测字典(作用域外仍隔离 {}),在 file 与 sqlite 两种 backend 上实测均通过 ABA 切换恢复。
  • capability_hooks.py 与 hook_runtime/*(源码):保留全部兼容性再导出与调用入口,所有注册表写入事务(registry_codec.py:308)均触发 invalidate_hook_registry_snapshot。

对主干的风险 / Risks

经与基线/无作用域分支及上一缺陷提交 45f353fdde 配对核验,PR #9433 当前头提交已不存在已知阻塞合入缺陷:在冷/暖 STRICT_ENVELOPE_V1 project-reg.json + 符号链接 registry.global.json 触发 ProjectRegistryError: global registry root must be a JSON object 后,作用域不再残留 registry.global.json 脏字节,恢复符号链接并提交源项目事务后同请求 load_goal_from_registry 与 load_scoped_registry 立即恢复 A-original / B-after(与无作用域分支一致);同时 file 与 sqlite 双后端 list_goal_todos 实测均通过 ABA 源切换并恢复 A-original / B-after。外围调用方及 list_readback.py(2 处 Any)、registry_codec.py(22 处 Any)为未在本 PR 扩面修改的既有意图外边界。

语义与 CI 对齐

本 PR 未修改任何公共状态枚举、RFC 或默认控制面策略;check_rfc_bilingual、semantic-vocabulary-drift-smoke.py(34/34、62/62、conflicting_values_semantic=0/0)、control-plane-maintainability-ratchet-smoke.py(unreviewed_count=0、stale_exception_count=0)、Goal loopx check(0 错误/0 警告、公开边界 clean)、Goal canary premerge(direct=4/4 + py_compile、catalog=10/10、risk_profile=8/8、failures=0、manual_hold_count=0)与 Goal change-quality(cqr_8669a411b990589cb6ac valid)均已在 371649968108d359264060251ae81064ad3a262a 全部通过。

我的整体评价 / Verdict

APPROVE(Author-owned COMMENTED 等效批准结论)。 在长程维度上(long_horizon: preserved),请求作用域兼顾重复读消减、多别名 ABA 失效与解码失败洁净隔离,6 个 <=628 LOC 零 Any 子模块显著提升长期可演进性;在用户体验维度上(user_experience: preserved),所有 CLI/hook 接口与全局/项目格式拒绝边界保持零回归;visual_review 为 not_applicable(本次仅重构后端 Python 控制面模块、请求作用域快照暂存及测试文件,未改动前端 UI、HTML/CSS 或渲染输出,visual_review 不适用。 unverified_scope: 未启动外部实时 PostgreSQL 数据库服务器运行 test:postgresql-* 联调集成套件(test:control-plane 全量 6,911 项中 93 项跨服务端/环境门控用例跳过,0 项失败);Python 套件中 tests/canary/test_git_path_display.py 因 macOS APFS 拒绝非 UTF-8 文件名与 root 名称跳过 6 项。)。本地独立全套验证于 371649968108d359264060251ae81064ad3a262a 全部通过:ruff(20/20)、strict mypy(9/9)、mypy --follow-imports=silent(list_readback.py/registry_codec.py)、TS tsc 控制面校验、69/69 定向 TS hook/writeback 套件、6,818/6,911 全量 test:control-plane(0 失败,93 跳过)、Python 3.12.15 symlink-loop 验证、18/18 作用域/等价专测、2,409 passed, 6 skipped 跨 17 套件 pytest、canary premerge 及 change-quality verify,7/7 条讨论串均已解决,建议合入。

English verdict: APPROVE at 3716499. Clean <=628-LOC Zero-Any modular split of capability_hooks, list_goal_todos scoped ABA routing passes on both file and sqlite, and _ObservedSnapshotDict local staging prevents failed registry decodes from poisoning scope.registry_snapshots (PRRT_kwDOStEbEs68GYXH resolved).

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

在同一 hook 请求内复用 registry 快照,同时保留全局与 project registry 的格式边界、真实来源写后失效,以及失败后的同请求恢复。 受影响的是 quota、heartbeat 和 Todo 列表中调用这些 hook 投影的操作者与维护者。

分叉基线拒绝错误格式,恢复全局路径后同一请求能读取 A-original。上次评审的提交在第一次解码异常后仍保留原始 alias 快照,下一次读取继续报错。

本轮核对同请求的格式拒绝和源提交后读回。用相同隔离输入重放。三版都拒绝第一次错误格式并成功提交实际 project 来源。只有上次候选 45f353f 在路径恢复后仍报格式错误。 当前 3716499 和精确分叉基线都在同一请求恢复出 A-original。实际 Todo 列表路线的 File 与 SQLite 对照,在来源 B 提交后也都读回 A-original,B 独立读回 B-after。

使用真实本地 registry decoder、事务和 File/SQLite authority fixture。文件路径变化通过测试同步控制。未覆盖外部部署、PostgreSQL 和远程 CI。 基线运行时合同 本次变更范围

改动思路 / Approach

保持 registry codec 作为格式 owner、实际事务作为写后失效 owner。拆分后的 scope 仅保存同一次请求的观测,hook facade 保留调用和扩展路径。

复用 scope 内的临时字典承接原始快照,成功解码后合入,失败时自然丢弃。这一步修复无需持久缓存、重试分支或修改 codec 调用签名。

load_goal_from_registry / list_goal_todos / ProjectRegistryTransaction.commit。

具体改动 / Changes

精确提交 371649968108d359264060251ae81064ad3a262a,目标分叉点 b34f0e6157968251dedbd88552ccad34c4fdeef9。整批 20 个文件,包含 facade、请求缓存、dispatch 与验证。与已独立审阅的 45f353f 比较,18 个 base/head 文件对象对相同。另两处实现与测试在本轮逐行核对。新目标基线额外改动的五个文件不在此 diff。

  • CapabilityHookRequestScope.load_registry。解码成功后才把临时快照合入请求作用域,并记录真实触达的来源。 源码
  • _ObservedSnapshotDict。暂存原始快照写入,记录命中与依赖。 源码
  • _invalidate_registry_snapshot。有状态事务完成后使来源和相关读回失效。 源码
  • list_goal_todos。在活跃作用域内让来源路由进入同一 owner。 源码
  • merge_turn_start_dispatch。让现有调用者复用派发结果组合。 源码

对主干的风险 / Risks

当前头定向 pytest 222 passed in 64.56s (0:01:04)。Python 3.12.15 两项临界测试通过,9 个文件 strict mypy 通过,本地标准 premerge 通过。

使用真实本地 registry decoder、事务和 File/SQLite authority fixture。文件路径变化通过测试同步控制。未覆盖外部部署、PostgreSQL 和远程 CI。

我的整体评价 / Verdict

APPROVE。 旧头的失败解码反例已关闭。继续保留全局格式拒绝、同一请求写后失效和 File/SQLite 来源路由。 结构化派发与现有 registry 授权边界已随本次完整 diff 一起复查。

English verdict: APPROVE at 3716499. The previous decode failure no longer leaves a raw alias snapshot, and exact-base File/SQLite source readback and recovery passed.

@mergify

mergify Bot commented Nov 26, 2026

Copy link
Copy Markdown

This pull request has merge conflicts with main and cannot be merged
until they are resolved. Please rebase or merge the base branch, @loopx-agent.

Choose the remote for the base repository, not an out-of-date fork.
For a fork clone, first inspect git remote -v; upstream must point
to https://github.com/loopx-project/loopx.git. If it is absent, add it
with git remote add upstream https://github.com/loopx-project/loopx.git.
Then run:

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 HEAD

For a same-repository clone whose origin points to
https://github.com/loopx-project/loopx.git, use origin instead of
upstream for fetch/rebase. If you prefer merging the base, use
git merge <base-remote>/main and push normally.

Keep the DCO Signed-off-by trailer on every commit when you rebase.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 26, 2026
…uest-scoped snapshots

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
…alidation

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
…ation

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
…oop errors

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
…ymlink races

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
…nd rollback

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
…idation tracking

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
…odos

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
@loopx-agent
loopx-agent force-pushed the codex/slim-capability-hooks-zero-any-20261125 branch from 3716499 to 3ccf408 Compare November 26, 2026 15:31

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · deepseek-flash · DeepSeek · runtime_reported · high

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

在同一 hook 请求内复用 registry 快照,同时保留全局与 project registry 的格式边界、真实来源写后失效,以及失败后的同请求恢复。 受影响的是 quota、heartbeat 和 Todo 列表中调用这些 hook 投影的操作者与维护者。

分叉基线拒绝错误格式,恢复全局路径后同一请求能读取 A-original。上次评审的提交在第一次解码异常后仍保留原始 alias 快照,下一次读取继续报错。

本轮核对同请求的格式拒绝和源提交后读回。用相同隔离输入重放。三版都拒绝第一次错误格式并成功提交实际 project 来源。只有上次候选 45f353f 在路径恢复后仍报格式错误。 当前 3ccf408 和精确分叉基线都在同一请求恢复出 A-original。实际 Todo 列表路线的 File 与 SQLite 对照,在来源 B 提交后也都读回 A-original,B 独立读回 B-after。

使用真实本地 registry decoder、事务和 File/SQLite authority fixture。文件路径变化通过测试同步控制。未覆盖外部部署、PostgreSQL 和远程 CI。 基线运行时合同 本次变更范围

改动思路 / Approach

保持 registry codec 作为格式 owner、实际事务作为写后失效 owner。拆分后的 scope 仅保存同一次请求的观测,hook facade 保留调用和扩展路径。

复用 scope 内的临时字典承接原始快照,成功解码后合入,失败时自然丢弃。这一步修复无需持久缓存、重试分支或修改 codec 调用签名。

load_goal_from_registry / list_goal_todos / ProjectRegistryTransaction.commit。

具体改动 / Changes

精确提交 3ccf408f62a36654a78bed7a6c4e147b02f1b493,目标分叉点 b34f0e6157968251dedbd88552ccad34c4fdeef9。整批 20 个文件,包含 facade、请求缓存、dispatch 与验证。与已独立审阅的 45f353f 比较,18 个 base/head 文件对象对相同。另两处实现与测试在本轮逐行核对。新目标基线额外改动的五个文件不在此 diff。

  • CapabilityHookRequestScope.load_registry。解码成功后才把临时快照合入请求作用域,并记录真实触达的来源。 源码
  • _ObservedSnapshotDict。暂存原始快照写入,记录命中与依赖。 源码
  • _invalidate_registry_snapshot。有状态事务完成后使来源和相关读回失效。 源码
  • list_goal_todos。在活跃作用域内让来源路由进入同一 owner。 源码
  • merge_turn_start_dispatch。让现有调用者复用派发结果组合。 源码

对主干的风险 / Risks

当前头定向 pytest 222 passed in 64.56s (0:01:04)。Python 3.12.15 两项临界测试通过,9 个文件 strict mypy 通过,本地标准 premerge 通过。

使用真实本地 registry decoder、事务和 File/SQLite authority fixture。文件路径变化通过测试同步控制。未覆盖外部部署、PostgreSQL 和远程 CI。

当前 exact head 复核 / Rebased-head validation

PR #9433 已无冲突 rebase 到 origin/main bcb47536cfdb3ae57c9eaf99209caa30109edcff,当前精确头为 3ccf408f62a36654a78bed7a6c4e147b02f1b493。本轮在新的 base 上重新执行定向测试、静态检查和 diff 级 premerge,并验证依赖 PR 合入后的真实调用路径。

最终 exact head 复核:107 项 capability-hook、request-scope、turn-start、post-writeback 与 heartbeat-prequota 测试通过;9 个核心文件的严格 mypy、Ruff 和 diff 检查通过;标准 premerge 的 18 项选定检查全部通过。冲突解决同时保留了最新 effect_runtime_request_scope 与 load_scoped_registry,没有回退 #9392 的 RPC 收敛。

我的整体评价 / Verdict

APPROVE。 旧头的失败解码反例已关闭。继续保留全局格式拒绝、同一请求写后失效和 File/SQLite 来源路由。 结构化派发与现有 registry 授权边界已随本次完整 diff 一起复查。

English verdict: APPROVE at 3ccf408. The previous decode failure no longer leaves a raw alias snapshot, and exact-base File/SQLite source readback and recovery passed.

@mergify mergify Bot removed the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 26, 2026
@loopx-agent
loopx-agent merged commit 87edfc7 into main Nov 26, 2026
10 of 32 checks passed
@loopx-agent
loopx-agent deleted the codex/slim-capability-hooks-zero-any-20261125 branch November 26, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant