Repository navigation
refactor(global_registry): eliminate Any annotations and slim module - #8968
loopx-agent wants to merge 1 commit into
Conversation
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google (self_reported)
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
已针对 PR #8968 exact head 833917747ea374f7dcc9c086b54146c6b0e1a5b2 完成完整审查与本地验证(审查结论:APPROVE,无 P0/P1/P2 问题)。
动机 / Motivation
受影响调用方与运维者:所有调用 loopx/global_registry.py 执行共享全局注册表读写锁、同步、Route 碰撞保护与 Goal 退役的调用方(如 loopx/cli_commands/registry_admin_lifecycle.py、loopx/project_uninstall.py、loopx/history.py、loopx/control_plane/goals/configure_goal_service.py、loopx/extensions/lark/goal_topic_edit.py),以及 loopx/canary/ 可维护性棘轮门禁维护者。
修改前(6844005820):loopx/global_registry.py 存在 1,020 行代码与 65 处 Any / dict[str, Any] 宽松类型标注,且尚未登记进 loopx/canary/module_metric_baseline.json 零 Any 棘轮门禁;_merge_global_registry_payload 仅有一个内部调用方、global_write_denied_payload 调用与 projects 列表校验存在重复样板、retire_global_registry_goals 重复构建两份结果字典。修改后(833917747e):全模块净减 81 行至 939 行,any_count 降至 0、dict_any_count 降至 0,并以 any_count=0, dict_any_count=0, lines=954 纳入 loopx/canary/module_metric_baseline.json。
可观测结果:module_metrics 返回 {'lines': 939, 'any_count': 0, 'dict_any_count': 0};mypy --strict --follow-imports=silent loopx/global_registry.py 与全仓 mypy(17 个文件)均为 0 错误;ruff check 通过;4 个 project smokes 全部通过;15 个核心测试套件 527 passed, 3 skipped(含 test_global_registry_write_serialization.py、test_global_goal_retirement_writer_fence.py、test_maintainability_ratchet.py、test_semantic_vocabulary_drift.py、test_thread_agent_binding.py、test_agy_host_surface.py 等)且并行竞争用例顺序复跑全通过(58 + 1 passed);canary premerge --tier quick 与 loopx check 全通过;锁语义、原子写入、返回 dict 结构与报错文本保持逐字符等价。
非目标边界:本 PR 不改变全局注册表持久化格式、跨进程锁顺序、碰撞/拒写判定语义或外部报错文本,也不修改任何下游调用方文件(project_uninstall.py、registry_admin_lifecycle.py 等留待各自零 Any 收敛),亦不授予自动合入权限。
改动思路 / Approach
全部瘦身与强类型收口严格限定在 loopx/global_registry.py 与 loopx/canary/module_metric_baseline.json 既定边界内,直接复用标准库结构化协议(object、Mapping[str, object]、Sequence[object]、Sequence[str]、TypedDict)与现有原子写入/锁原语,未引入新运行时开关、平行模块或兼容适配器。
当前 PR 边界:范围收敛于 loopx/global_registry.py 的零 Any 强类型化与内部重复样板收敛(净减 81 行)以及 loopx/canary/module_metric_baseline.json 基线锁定;多文件广域并行扫测中存在的 4 项基线既有/工作树构建缺失外部失败(未构建 web/chat dist、quota.capture_decision 既有重构漂移、外部 Doubao 网络传输、旧状态 fixture 拒绝)均在 PR 外隔离且不阻塞本 PR。
- 强类型边界与结构化返回(
loopx/global_registry.py):定义GlobalRegistryMutation(TypedDict)精确刻画mutate_global_registry/_mutate_global_registry_locked的 5 键返回值;将全部Any/dict[str, Any]收敛为object/Mapping[str, object]/dict[str, object]/Sequence[...],并保证retire_global_registry_goals与sync_project_registry_to_global返回dict[str, object]、Markdown 渲染器接受Mapping[str, object],与registry_admin_lifecycle.py的PrintPayload契约完全兼容。 - 小型窄化与去重辅助函数(L68-112, L655-674):引入
_list_items、_str_items、_dict_items、_equal_except_key、_resolve_source_text、_registry_projects、_goals_by_id、_load_sync_route与_unpack_sync_receipt,统一替代多处松散字典拆包、列表校验、源路径规范化和同步路由解析样板。 - 内部冗余折叠(L418-464, L552-635, L677-840):将单调用方
_merge_global_registry_payload折叠入_sync_global_registry_reduction并保留原 docstring;在retire_global_registry_goals中抽取局部result_payload统一构建错误与成功回执;在_sync_project_registry_to_global_once中以reduce_current与write_denied闭合重复参数传递,同时完整保留原有 docstring、注释、模块级 monkeypatch 入口(_load_global_registry、write_json、now_local、exclusive_cross_runtime_file_lock、probe_registry_write_path、load_registry)与双锁/原子 temp+replace 顺序。 - 棘轮基线锁定(
loopx/canary/module_metric_baseline.json:85-89):按字母序在private_conversations.py与heartbeat_prompt.py之间登记"loopx/global_registry.py": {"any_count": 0, "dict_any_count": 0, "lines": 954}。
具体改动 / Changes
本次 diff 仅触及 2 个文件(331 insertions(+), 407 deletions(-),净减 76 行):
loopx/global_registry.py(1020 -> 939行,-81行,65 Any -> 0):清除全部Any/dict[str, Any],新增GlobalRegistryMutation与 typed 窄化/去重辅助函数,折叠冗余包装与重复字典构建,保持全部导出符号、锁顺序、原子写入与错误文案不变。loopx/canary/module_metric_baseline.json(+5行):登记loopx/global_registry.py零Any与954行上限棘轮基线。
对主干的风险 / Risks
- 锁与原子写入不变式:
_mutate_global_registry_locked仍先写入 PID 临时文件再.replace(path),retire_global_registry_goals仍按shadow_maintenance_lock_target->global_path顺序持锁并先探针后写,sync_project_registry_to_global仍在获取全局锁后重新读取source_registry(test_global_registry_write_serialization.py与test_global_goal_retirement_writer_fence.py全部实测通过)。 - 调用方与公共边界:
mypy --strict --follow-imports=silent与全仓mypy(17 个文件)均为 0 错误;loopx check --scan-path ...报告 0 错误、0 警告、无本地绝对路径或私密内容泄露。 - 本地完整验证结果(exact head
833917747ea374f7dcc9c086b54146c6b0e1a5b2):module_metrics(Path("loopx/global_registry.py")):{'lines': 939, 'any_count': 0, 'dict_any_count': 0}uv run --extra test mypy --strict --follow-imports=silent loopx/global_registry.py&uv run --extra test mypy: 0 issues(1 source file / 17 source files)uv run --extra test ruff check loopx/global_registry.py tests/canary/test_maintainability_ratchet.py: All checks passed- Project smokes(
global-registry-sync-smoke.py、global-registry-writability-smoke.py、registry-boundary-contract-smoke.py、configure-goal-global-sync-smoke.py,独立临时HOME): 4/4 passed - Core pytest(15 个核心测试套件含并发锁序列化、writer fence、host poll receipts、thread binding、agy host surface、maintainability ratchet、semantic vocabulary drift、project registry codec/CLI 等): 527 passed, 3 skipped in 120.94s;并行竞争用例顺序复跑(
test_codex_operation_launch.py与test_connect_adds_a_missing_bot_and_retry_does_not_add_it_twice): 58 passed + 1 passed(全量 68 文件-n auto跑出2478 passed, 57 skipped,其余失败均属工作树未构建 chat dist 或主干既有外部问题) uv run --extra test loopx canary premerge --tier quick --from-git-diff --git-diff-base origin/main: passed (ok=true,selected=3,failures=0)loopx check --scan-path ...: ok=True (errors=0, warnings=0, checks=5)- 远端 CI 诊断行(Packet 采样时):
2 success, 9 pending(非阻塞诊断记录)。
我的整体评价 / Verdict
- Long-horizon 影响:
improved— 消除跨项目全局注册表协调中65处Any盲区与81行冗余样板并纳入棘轮基线,防止后续迭代回退。 - User-experience 影响:
not_applicable— 纯 Python 内部强类型收敛、结构简化与静态棘轮基线注册,不改变 CLI/UI 输出行为;visual_review为not_applicable。 - 可观测语义 / 复用 / 词表:
observable_semantics为equivalent,repository_reuse为reused,authority_semantics与semantic_alignment均为aligned(candidate_decision="reuse_existing")。
本 PR 范围克制、行为等价验证完备、静态检查与锁并发回归均通过,无阻断问题;作为作者自有 PR 且涉及核心控制面依赖模块 loopx/global_registry.py,正式合入仍需维护者显式授权。
English verdict: APPROVE exact head 8339177 (author-owned COMMENTED approval review); eliminates all 65 Any occurrences and trims 81 net lines (1020 -> 939) in loopx/global_registry.py with a zero-Any baseline ratchet (ceiling lines=954), verified by strict/repo mypy (0 issues), ruff, 4 project smokes, 527 passed core pytest cases (plus 58 + 1 sequential reruns), quick premerge canary, and loopx boundary check.
Summary
Behavior-preserving type hardening, boilerplate consolidation, and maintainability-ratchet baseline registration for
loopx/global_registry.py.Why
loopx/global_registry.pypreviously stood at1,020lines with65Any/dict[str, Any]annotations and no zero-Anyceiling registered inloopx/canary/module_metric_baseline.json.Anyannotations masked structured payload/receipt boundaries (mutate_global_registry, sync/retire receipts, markdown renderers) and duplicated sync route loading,projectslist validation, and retirement result construction.Changes
loopx/global_registry.py(1,020 -> 939lines,-81net lines;65 Any -> 0):Any/dict[str, Any]annotations withobject,dict[str, object],Mapping[str, object],Sequence[object],Sequence[str], andGlobalRegistryMutation(TypedDict)._list_items,_str_items,_dict_items,_equal_except_key,_resolve_source_text,_registry_projects,_goals_by_id,_load_sync_route,_unpack_sync_receipt)._merge_global_registry_payloadwrapper into_sync_global_registry_reduction, consolidated duplicated retirement payload assembly and syncwrite_denied/reduce_currenthandling, and preserved every existing docstring, explanatory comment, public/tested symbol name, atomic file lock/write semantics, return dict shape, and error message.loopx/canary/module_metric_baseline.json(+5lines):"loopx/global_registry.py": {"any_count": 0, "dict_any_count": 0, "lines": 954}alphabetically between"loopx/extensions/lark/private_conversations.py"and"loopx/heartbeat_prompt.py".Verification (
833917747ea374f7dcc9c086b54146c6b0e1a5b2)module_metrics(Path("loopx/global_registry.py")):{'lines': 939, 'any_count': 0, 'dict_any_count': 0}uv run --extra test mypy --strict --follow-imports=silent loopx/global_registry.py:Success: no issues found in 1 source fileuv run --extra test mypy:Success: no issues found in 17 source filesuv run --extra test ruff check loopx/global_registry.py tests/canary/test_maintainability_ratchet.py:All checks passed!examples/project/global-registry-sync-smoke.py,examples/project/global-registry-writability-smoke.py,examples/project/registry-boundary-contract-smoke.py,examples/project/configure-goal-global-sync-smoke.pyunder isolatedHOME): 4/4 passedglobal_registry/ ratchet / semantic-drift / host-surface / binding pytest suites: 527 passed, 3 skipped in120.94stests/control_plane/test_codex_operation_launch.pyandtest_connect_adds_a_missing_bot_and_retry_does_not_add_it_twice): 58 passed + 1 passed (in the full 68-file-n autosweep,2478 passed, 57 skipped, with pre-existing/worktree-env failures isolated outsideglobal_registry.py: 56test_chat_cold_source_import.pymissing unbuilt chat bundle errors, 1quota.capture_decisionattr mismatch, 2DoubaoActorTransportError, and 1 legacystatus=pausedfixture error intest_sqlite_archive_and_registry_health.py)uv run --extra test loopx canary premerge --tier quick --from-git-diff --git-diff-base origin/main: passed (ok=true,selected=3,failures=0)loopx check --scan-path loopx/global_registry.py --scan-path loopx/canary/module_metric_baseline.json: ok=True (errors=0, warnings=0, checks=5)