Repository navigation
canary(planner): modularize planner into zero-Any submodules - #9416
Conversation
loopx-agent
left a comment
There was a problem hiding this comment.
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
English verdict: APPROVE
Reviewed head: 8f3b78f7fabfe4ce529c563fe31d1a105be3dc75
Reviewer: model_agent · Gemini · Google · self_reported · effort_unavailable
动机 / Motivation
Canary maintainers, premerge validation gates (loopx canary premerge / loopx/cli_commands/canary.py), and semantic retrodiction callers (scripts/semantic_incident_retrodiction.py) depending on loopx/canary/planner.py profiles, selection plans, and strict maintainability ratchets.
Before this PR, loopx/canary/planner.py reached 1,914 LOC with 22 Any annotations, mixing Markdown table parsing/rendering, family defaults, core domain profiles, and workflow domain profiles in a single near-2K module, while scripts/semantic_incident_retrodiction.py still carried Any and checked E07 via fragile raw text scanning of planner.py. At exact head 8f3b78f7fa, planner.py drops to 512 LOC and 0 Any across four cohesive single-purpose submodules (family_profiles.py 167 LOC, core_domain_profiles.py 487 LOC, workflow_domain_profiles.py 600 LOC, catalog_markdown.py 293 LOC), semantic_incident_retrodiction.py drops to 742 LOC / 0 Any using live CURRENT_REPO_PROFILES, and module_metric_baseline.json tightens planner.py any_count from 22 -> 0.
Verified 12-way exact JSON and Markdown output parity against origin/main across profiles, coverage audits, quality-surface audits, flattened checks, path/surface/profile plans, and Markdown renderers (12/12 identical); bare python -m mypy --no-incremental (17 files) and --strict across all 6 touched Python modules pass with 0 errors, tests/canary tests/architecture pass (2055 passed, 6 skipped), E07 retrodiction catches 12/15 (0/5 false positives), and canary premerge passes all 6 direct + 16 selected checks.
边界与非目标:Does not alter canary profile definitions, selection heuristics, premerge risk tiers, or CLI flags, and does not modify unrelated product/control-plane modules.
改动思路 / Approach
Splits static data profiles (family_profiles.py, core_domain_profiles.py, workflow_domain_profiles.py) and Markdown parsing/rendering helpers (catalog_markdown.py) out of loopx/canary/planner.py, while preserving __all__ and public symbols on planner.py (REPO_ROOT, DEFAULT_CATALOG_PATH, CURRENT_REPO_PROFILES, plan/audit/render APIs) so all downstream callers and monkeypatch targets stay intact.
Scoped to 7 files (loopx/canary/planner.py 512 LOC, 4 new loopx/canary/ modules <= 600 LOC each, loopx/canary/module_metric_baseline.json tightening any_count 22 -> 0 without relaxing line rules, and scripts/semantic_incident_retrodiction.py 742 LOC / 0 Any switching E07 to CURRENT_REPO_PROFILES).
具体拆分将原本耦合在 planner.py 中的三类静态配置表与 Markdown 解析/渲染逻辑拆为独立强类型模块(统一采用 Mapping[str, object]、Sequence 与 TypedDict,彻底清除 Any),并将 flatten_catalog_canary_checks 收敛为共享 source 表的统一遍历,同时让 scripts/semantic_incident_retrodiction.py 的 E07 探针直接读取 CURRENT_REPO_PROFILES 而不再依赖单文件源码 grep。
具体改动 / Changes
- 规范依据:
docs/development/testing-and-quality.md(revisionf4c27a88b54e9f5daba0d282076328fb30b922ff),对照标准:MODULE_SIZE_AND_ZERO_ANY(implemented)、EXPORT_AND_CALLER_PARITY(implemented)、RETRODICTION_AND_MYPY(implemented)、PUBLIC_SAFE_BOUNDARY(implemented)。 - Diff 统计(相对 base
216757852168faa784fe6f621b72d971aee58ee3):7 个文件(loopx/canary/planner.py+217/-1619->512 LOC、family_profiles.py167 LOC、core_domain_profiles.py487 LOC、workflow_domain_profiles.py600 LOC、catalog_markdown.py293 LOC、scripts/semantic_incident_retrodiction.py+201/-39->742 LOC,全部 Python 文件< 1,000 LOC、0 Any、0 # type: ignore、0bareos.O_NOFOLLOW;loopx/canary/module_metric_baseline.json仅将planner.pyany_count由22收紧为0)。
关键代码讲解
CURRENT_REPO_PROFILES/build_quality_surface_catalog_audit:在planner.py顶部重组CORE_DOMAIN_PROFILES与WORKFLOW_DOMAIN_PROFILES为CURRENT_REPO_PROFILES并通过__all__导出全套公共 API,同时以强类型映射构造返回审计结果而不引入Any。flatten_catalog_canary_checks:以(source_name, profiles_key, checks_key, title_key)元组表驱动domain_profiles与profiles的去重扁平化,消除重复循环同时保持原有执行顺序与返回字段一致。build_catalog_canary_plan:保留原有参数签名与筛选顺序,依次协调 catalog 解析、family/domain 选择理由推导、include_deep_checks过滤与命令汇总,与origin/main行为完全等价。probe_commit_time_selection:由直接 grepplanner.py源码改为直接导入并检查CURRENT_REPO_PROFILES,避免模块化拆分破坏 E07 历史事故回溯检测,同时全文件以TypedDict替换Any。
对主干的风险 / Risks
- 无阻断性代码缺陷(No blocking finding)。通过 AST 导出扫描确认:
origin/main中移除的 3 个未在外部使用的静态常量重组引用与 11 个内部_helper 均无外部调用方(git grep全仓库 0 引用),所有examples/canary/*、loopx/cli_commands/canary.py、tests/canary/*及scripts/调用端均完整保留并验证通过。 - 残余风险与说明(非阻断):
tests/canary/test_git_path_display.py中 6 个非 UTF-8 / 根目录用例在 macOS APFS 环境下按既定条件跳过(2,055 通过,0 失败),不影响本次planner.py拆分逻辑的覆盖。- 后续若有人尝试跨模块直接导入已拆出的私有
_helper 或未在__all__中的历史聚合常量,需从各自新子模块导入;当前仓库所有调用端均无此依赖。
我的整体评价 / Verdict
long_horizon:preserved— canary 规划筛选、覆盖率审计、质量面审计与语义事故回溯全部与origin/main保持 100% 输出等价,同时module_metric_baseline.json收紧至0 Any防止后续回退。user_experience:preserved—loopx canaryCLI、Markdown 报告与 premerge 门禁选择和输出完全一致;visual_review为not_applicable(原因:No frontend, HTML, desktop UI, or rendered component layout changes in PR #9416 (Python canary planner submodules, baseline ratchet JSON, and retrodiction script only).,unverified_scope: none)。- 代码体积与比例:
necessary/proportionate(全部 6 个 Python 文件< 1,000 LOC、0 Any、0 # type: ignore、0bareos.O_NOFOLLOW);隔离与权限:isolated/aligned;语义词汇:aligned(0 新增词汇、0 漂移,17/17 TS single-owner 测试通过)。 - 独立实测汇总(全部于
8f3b78f7fabfe4ce529c563fe31d1a105be3dc75干净工作树执行):bareuv run --extra test python -m mypy --no-incremental17/17 通过、mypy --strict --follow-imports=silent6/6 通过、premerge.py+cli_commands/canary.pymypy 2/2 通过、ruff check6/6 通过、npm run typecheck:control-plane与content_digest_single_owner.test.ts17/17 通过、12 路 JSON/Markdown 与origin/main对比 12/12 完全一致、pytest -n 6 tests/canary tests/architecture2,055 passed, 6 skipped, 0 failed、semantic_incident_retrodiction.py12/15 捕获(含 E07、0/5误报)、loopx check0 错误、canary premerge6/6 direct + 16/16 selected 全通过(manual_hold_count=0)。明确给出 APPROVE 结论。
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
维护者从公开交互目录选择合入前的 canary,并需要回读规划、解释和实际检查结果。 调用同一 canary 命令选择普通检查和深层检查,或者以缺失目录与覆盖缺口触发失败。重构后选择顺序、错误原因与恢复提示应保留。 基线把 catalog 解析、各领域检查目录、选择与输出留在一个约 1900 行文件中。 真实 CLI 的 10 组对照保持选择、退出状态、JSON 或 Markdown 内容,缺失文件仅 traceback 行号随挪动变化。原选择执行了相同的本地 fixture 检查,所测路径没有证据写回。 业务运行与真实发布不属于这次开发校验。 验收依据
本轮核对 CANARY_CLI_PARITY 与 E07_RETRODICTION。
改动思路 / Approach
保留 planner 对选择和顺序的所有权,按目录数据与 Markdown 输出移动定义,retrodiction 从结构化 profile 读回对象。 目录数据、选择和报告拆分有清晰消费边界,继续用原 planner 入口;保留实际调用依赖的结构兼容性。 同一作用域下可复用原 premerge 门与 catalog。把功能留在原 1900 行文件会继续耦合不相关领域定义;只把目录常量拆出会留下重复的检查扁平化。 本次范围是已有 canary 目录的模块划分、原 premerge 输出和配套的 E07 读回。
同头已有 Gemini 结论。本轮独立增加源 CLI 的选择、执行、缺目录及覆盖缺口的配对证据。 同头结论
具体改动 / Changes
审查 head 8f3b78f7fabfe4ce529c563fe31d1a105be3dc75,目标 main 216757852168faa784fe6f621b72d971aee58ee3,7 个文件,+1966/−1659。 完整 diff
关键代码讲解
- build_catalog_canary_profiles。从原交互目录得到兼容的 family 与 domain profile。 源码
- flatten_catalog_canary_checks。按 domain 再 family 处理同一命令,保留去重和先后顺序。 源码
- build_catalog_canary_plan。统一目录筛选、检查上限、深层检查开关和建议。 源码
- render_catalog_canary_plan_markdown。读取已决定的计划并生成 Markdown。 源码
- probe_commit_time_selection。按真实 profile 和 premerge 选择来测 E07,避免依赖文件所在位置。 源码
对主干的风险 / Risks
PASS。缺少显式 catalog 时,两侧均退出 1,保留完整 checkout 或 --catalog 恢复提示。含未覆盖 P0 的孤立目录审查均报缺口,普通预检只选检查,显式 run 仍执行原本地 fixture。
PASS。基线与当前各通过 32 项 repository-root 和 quality-surface 测试。Retrodiction 两侧均捕获 12/15,E07 保持 caught;当前 Ruff、六个改动模块严格 mypy、两个生产调用端 mypy 和双语 RFC diff 检查通过。
UNVERIFIED。未执行业务发布、云服务或 UI。托管 CI 未查询。
我的整体评价 / Verdict
批准此提交。当前受支持的 CLI 行为保留。维护时可按目录、选择和输出查找负责源码。 默认 plan 仍为预览,深层检查需显式开启;实际 run 仍使用原本地无证据写入路径。 检查的是 canary CLI、其文本报告及开发校验脚本,此次没有图形界面改动。
English verdict: APPROVE at 8f3b78f. Paired CLI selection, execution, coverage, missing-catalog recovery guidance, and E07 behavior are preserved.
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Record E12 as caught after the planner refactor makes the dropped extension-source scope visible to an existing check. Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
This reverts commit 337c51e77aef939848b6fc53b11d7fd4dda56772. Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
8f3b78f to
239d372
Compare
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · deepseek-flash · DeepSeek · runtime_reported · high
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
维护者从公开交互目录选择合入前的 canary,并需要回读规划、解释和实际检查结果。 调用同一 canary 命令选择普通检查和深层检查,或者以缺失目录与覆盖缺口触发失败。重构后选择顺序、错误原因与恢复提示应保留。 基线把 catalog 解析、各领域检查目录、选择与输出留在一个约 1900 行文件中。 真实 CLI 的 10 组对照保持选择、退出状态、JSON 或 Markdown 内容,缺失文件仅 traceback 行号随挪动变化。原选择执行了相同的本地 fixture 检查,所测路径没有证据写回。 业务运行与真实发布不属于这次开发校验。 验收依据
本轮核对 CANARY_CLI_PARITY 与 E07_RETRODICTION。
改动思路 / Approach
保留 planner 对选择和顺序的所有权,按目录数据与 Markdown 输出移动定义,retrodiction 从结构化 profile 读回对象。 目录数据、选择和报告拆分有清晰消费边界,继续用原 planner 入口;保留实际调用依赖的结构兼容性。 同一作用域下可复用原 premerge 门与 catalog。把功能留在原 1900 行文件会继续耦合不相关领域定义;只把目录常量拆出会留下重复的检查扁平化。 本次范围是已有 canary 目录的模块划分、原 premerge 输出和配套的 E07 读回。
同头已有 Gemini 结论。本轮独立增加源 CLI 的选择、执行、缺目录及覆盖缺口的配对证据。 同头结论
具体改动 / Changes
审查 head 239d3726553f296e65efae705270744ca04301b3,目标 main 216757852168faa784fe6f621b72d971aee58ee3,7 个文件,+1966/−1659。 完整 diff
关键代码讲解
- build_catalog_canary_profiles。从原交互目录得到兼容的 family 与 domain profile。 源码
- flatten_catalog_canary_checks。按 domain 再 family 处理同一命令,保留去重和先后顺序。 源码
- build_catalog_canary_plan。统一目录筛选、检查上限、深层检查开关和建议。 源码
- render_catalog_canary_plan_markdown。读取已决定的计划并生成 Markdown。 源码
- probe_commit_time_selection。按真实 profile 和 premerge 选择来测 E07,避免依赖文件所在位置。 源码
对主干的风险 / Risks
PASS。缺少显式 catalog 时,两侧均退出 1,保留完整 checkout 或 --catalog 恢复提示。含未覆盖 P0 的孤立目录审查均报缺口,普通预检只选检查,显式 run 仍执行原本地 fixture。
PASS。基线与当前各通过 32 项 repository-root 和 quality-surface 测试。Retrodiction 两侧均捕获 12/15,E07 保持 caught;当前 Ruff、六个改动模块严格 mypy、两个生产调用端 mypy 和双语 RFC diff 检查通过。
UNVERIFIED。未执行业务发布、云服务或 UI。托管 CI 未查询。
当前 exact head 复核 / Rebased-head validation
PR #9416 已无冲突 rebase 到 origin/main bcb47536cfdb3ae57c9eaf99209caa30109edcff,当前精确头为 239d3726553f296e65efae705270744ca04301b3。本轮在新的 base 上重新执行定向测试、静态检查和 diff 级 premerge,并验证依赖 PR 合入后的真实调用路径。
最终 exact head 复核:25 项 canary catalog、retrodiction 与 maintainability 测试通过;6 个核心文件的严格 mypy、Ruff 和 diff 检查通过;标准 premerge 的 16 项选定检查全部通过。E12 最终仍为 uncovered,冻结基线保持 12/15,没有弱化 retrodiction gate。
我的整体评价 / Verdict
批准此提交。当前受支持的 CLI 行为保留。维护时可按目录、选择和输出查找负责源码。 默认 plan 仍为预览,深层检查需显式开启;实际 run 仍使用原本地无证据写入路径。 检查的是 canary CLI、其文本报告及开发校验脚本,此次没有图形界面改动。
English verdict: APPROVE at 239d372. Paired CLI selection, execution, coverage, missing-catalog recovery guidance, and E07 behavior are preserved.
Delivery Brief
loopx/canary/planner.py(1,914 LOC,22Anyannotations) under< 1,000 LOCper module with0 Any,0 # type: ignore, and0bareos.O_NOFOLLOW, while preserving all public exports, monkeypatch seams (REPO_ROOT,FAMILY_CHECKS), and exact planner/audit/render outputs.7files):loopx/canary/family_profiles.py(167 LOC,0 Any): catalogFAMILY_CHECKSandFAMILY_SELECTOR_HINTS.loopx/canary/core_domain_profiles.py(487 LOC,0 Any): core control-plane, release, status, CLI, todo, monitor, and state-writeCORE_DOMAIN_PROFILES.loopx/canary/workflow_domain_profiles.py(600 LOC,0 Any): product-entry, issue-fix, runtime, connector, and packageWORKFLOW_DOMAIN_PROFILES.loopx/canary/catalog_markdown.py(293 LOC,0 Any): markdown table/pattern/exception extraction helpers, shared sequence coercion helpers, and report renderers (render_catalog_canary_profiles_markdown,render_catalog_canary_plan_markdown,render_catalog_canary_coverage_audit_markdown).loopx/canary/planner.py(512 LOC,0 Any): retainsREPO_ROOT,DEFAULT_CATALOG_PATH,CURRENT_REPO_PROFILES, public profile/coverage/plan/audit builders (flatten_catalog_canary_checksunified over a shared source table; plan selection extracted into_select_catalog_profilesand_select_domain_profiles), and re-exports.loopx/canary/module_metric_baseline.json: tightensloopx/canary/planner.pyany_countfrom22to0(dict_any_count: 0, omittinglinesper ratchet test contract).scripts/semantic_incident_retrodiction.py(742 LOC,0 Any,0 # type: ignore): updates E07 (probe_commit_time_selection) to validateCURRENT_REPO_PROFILESexported byloopx.canary.plannerinstead of grepping rawplanner.pytext, and removesAnyannotations.Verification (
HEAD8f3b78f7fabfe4ce529c563fe31d1a105be3dc75).pyfile is< 1,000 LOC(512,167,487,600,293,742), with0 Any,0 # type: ignore, and0bareos.O_NOFOLLOW.uv run --extra test python -m mypy --no-incremental:Success: no issues found in 17 source files.uv run --extra test python -m mypy --strict --follow-imports=silenton all 6.pyfiles:Success: no issues found in 6 source files.uv run --extra test python -m mypy --follow-imports=silent loopx/canary/premerge.py loopx/cli_commands/canary.py:Success: no issues found in 2 source files.uv run --extra test python -m ruff checkon all 6.pyfiles: passed.origin/main(FAMILY_CHECKS,FAMILY_SELECTOR_HINTS,CURRENT_REPO_PROFILES, profiles, coverage audit, quality-surface audit, 4 plan selectors, flattened checks, and rendered markdown): identical.uv run --extra test python -m pytest -n 6 tests/canary tests/architecture:2055 passed, 6 skipped(conditional environment skips intest_git_path_display.py).catalog-planner-smoke.py,catalog-run-e2e-smoke.py,quality-surface-catalog-smoke.py,smoke-suite-runner-smoke.py,premerge-validation-gate-smoke.py,control-plane-maintainability-ratchet-smoke.py,semantic-vocabulary-drift-smoke.py29/29,semantic_incident_retrodiction.py12/15caught /0false positives): all passed.scripts/check_rfc_bilingual.py --base origin/main --head HEADandgit diff --check: passed.