Repository navigation
refactor(explore): slim result_log and eliminate all 68 Any - #8967
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 #8967 exact head e336254e9e271c6fec05f8a39ca5aa3ec82da31e 完成完整审查与本地验证(审查结论:APPROVE,无 P0/P1/P2 问题)。
动机 / Motivation
受影响调用方与运维者:所有消费 loopx/capabilities/explore/result_log.py 的 Explore 结果记录器、知识回放、研究前置条件与看板投影模块(包括 loopx/capabilities/explore/research_evidence.py、loopx/capabilities/explore/turn_context.py 与 loopx/extensions/lark/presentation/explore_results.py),以及 loopx/canary/ 可维护性棘轮维护者。
修改前(6844005820):loopx/capabilities/explore/result_log.py 共 1,260 行并存在 68 处 Any / dict[str, Any] / Mapping[str, Any] 宽松类型标注,JSONL 逐行读取、ID 选择与视图公共字段抽取存在重复样板,且未写入 module_metric_baseline.json 零 Any 上限棘轮门禁。修改后(e336254e9e):result_log.py 降至 1,131 行(净减 129 行),any_count 与 dict_any_count 均降至 0,并以 lines: 1146, any_count: 0, dict_any_count: 0 纳入棘轮门禁。
可观测结果:module_metrics 返回 {'lines': 1131, 'any_count': 0, 'dict_any_count': 0};mypy --strict --follow-imports=silent 与全仓 mypy(17 个文件,含 research_evidence.py 与 turn_context.py)均报 0 错误;ruff 全过;25 个 Explore/棘轮/词表单测套件 591 passed in 269.08s,issue-fix-explore-projection-smoke 通过,canary premerge --tier quick ok: true;所有公开函数名、字段返回值与 ValueError 报错文本逐字兼容。
非目标边界:本 PR 不更改 Explore 事件 Schema、Mermaid 十六进制编码规则或写入限制,不顺带修改主干 examples/explore-result-layer-smoke.py:155 上既有的 "node_kcg" in mermaid 过期断言(该断言在未改动的 origin/main 上同样复现,十六进制 Mermaid 契约已由 tests/test_explore_mermaid_identity.py 覆盖),亦不授予自动合入权限。
改动思路 / Approach
全部强类型收口与重复代码合并均在既有的 loopx/capabilities/explore/result_log.py 边界内完成,通过标准的 Payload = dict[str, object]、PayloadView = Mapping[str, object] 与 ExploreResultProjection(TypedDict) 表达返回值精确结构,仅在同级调用方 loopx/capabilities/explore/turn_context.py:124 补充一行 Mapping[str, object] 类型标注,避免为兼容未标注空字典 {} 初始化而引入 dict 子类黑魔法。
当前 PR 边界:范围锁定于 result_log.py 零 Any 与结构收敛、turn_context.py:124 单行兼容标注以及 module_metric_baseline.json 棘轮基线注册;既有 explore-result-layer-smoke.py:155 过期断言保留给独立修复 PR 处理。
- 结构化投影强类型化(
loopx/capabilities/explore/result_log.py:31-50,1043-1122):定义ExploreResultProjection(必选字段与可选research_frontier拆分),保证research_evidence.py:106对projection["nodes"]的精确可迭代推导。 - 调用方空字典初始化精确标注(
loopx/capabilities/explore/turn_context.py:124):将projection, plan, focus, todos = {}, {}, {}, {}拆为projection: Mapping[str, object] = {}与plan, focus, todos = {}, {}, {},使TypedDict返回值直接通过全仓 strictmypy。 - 内部窄化与公共辅助收敛(
loopx/capabilities/explore/result_log.py:187-242,685-778,1035-1041):统一抽取_as_int、_as_list、_text、_require_nonempty_title、_explicit_or_derived_id、_iter_jsonl_rows(复用于load_explore_result_events、load_explore_result_events_strict与_append_validated_explore_result_events)、_common_view_fields及_count_by_status。 - 棘轮基线锁死(
loopx/canary/module_metric_baseline.json:25-29):在字母序位置注册"loopx/capabilities/explore/result_log.py": {"any_count": 0, "dict_any_count": 0, "lines": 1146}。
具体改动 / Changes
本次 diff 仅触及 3 个文件(405 insertions(+), 528 deletions(-),整体净减 123 行):
loopx/capabilities/explore/result_log.py(+398 / -527,净减129行,1,260 -> 1,131行,68 Any -> 0):清除全部Any,定义Payload、PayloadView与ExploreResultProjection(TypedDict),收敛 JSONL 解析、视图公共字段与状态计数逻辑,保留完整文档字符串与注释。loopx/capabilities/explore/turn_context.py(+2 / -1,L124):为projection添加既有Mapping[str, object]类型标注,其余逻辑零修改。loopx/canary/module_metric_baseline.json(+5 / -0,L25-29):注册result_log.py零Any与1146行上限基线。
对主干的风险 / Risks
- 调用方兼容与运行时等价:严格检查
mypy覆盖全仓 17 个文件零错误,覆盖research_evidence.py、turn_context.py与yardstick_decision.py;25 个 Explore 相关单测套件共591个测试全部通过(含 24 套件基线467用例 +test_semantic_vocabulary_drift.py)。 - 公共与私密边界:
loopx check --scan-path ...与canary premerge --tier quick均报告 0 错误、3 个变更文件公共边界干净,且不改变任何持久化 Schema 或 CLI 默认开关。 - 本地完整验证结果(exact head
e336254e9e271c6fec05f8a39ca5aa3ec82da31e):module_metrics:{'lines': 1131, 'any_count': 0, 'dict_any_count': 0}uv run --extra test mypy --strict --follow-imports=silent loopx/capabilities/explore/result_log.py&uv run --extra test mypy: 0 issues(17 个源码文件)uv run --extra test ruff check loopx/capabilities/explore/result_log.py loopx/capabilities/explore/turn_context.py tests/canary/test_maintainability_ratchet.py: All checks passeduv run --extra test pytest -q -n 4(25 个 Explore/棘轮/词表漂移套件): 591 passed in 269.08suv run --extra test python examples/issue-fix-explore-projection-smoke.py: issue-fix explore projection smoke: ok(另确认examples/explore-result-layer-smoke.py:155为origin/main既有旧断言漂移)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)
我的整体评价 / Verdict
- Long-horizon 影响:
improved— 彻底消除了 Explore 核心事件日志中的68处Any与129行冗余代码并通过棘轮上限锁死,减少长程研究投影重构时的隐式字典字段漂移。 - User-experience 影响:
not_applicable— 纯内部 Python 强类型重构、1 行调用方标注与静态基线注册;visual_review为not_applicable。 - 可观测语义 / 复用 / 词表:
observable_semantics为equivalent,repository_reuse为reused,authority_semantics与semantic_alignment均为aligned(candidate_decision="reuse_existing")。
改动严格收敛、跨文件静态检查与 591 个测试充分通过、无 P0/P1/P2 阻断项。本 PR 为作者自有且触及产品运行时,正式合入仍需维护者授权及后续 CI 检查。
English verdict: APPROVE exact head e336254 (author-owned COMMENTED approval review); removes all 68 Any usages and 129 net lines in loopx/capabilities/explore/result_log.py with ExploreResultProjection TypedDict, a 1-line annotation in turn_context.py, and zero-Any baseline ratchet, verified by strict/repo mypy (0 issues across 17 files), ruff, 591 passing pytest tests, projection smoke, and quick premerge canary.
Summary
68Anyoccurrences inloopx/capabilities/explore/result_log.py(any_count: 0,dict_any_count: 0) and slimmed the module from1,260lines to1,131lines (-129net lines;git diff --statacross 3 files:405 insertions(+), 528 deletions(-)).Any/dict[str, Any]/Mapping[str, Any]annotations withobject,Payload = dict[str, object],PayloadView = Mapping[str, object], typed helpers (_as_int,_as_list,_text,_require_nonempty_title,_explicit_or_derived_id,_iter_jsonl_rows,_common_view_fields,_count_by_status), and structuredExploreResultProjection(TypedDict)(nodes,edges,findings,stuck,frontier,tree,counts,boundary, optionalresearch_frontier) while preserving every existing docstring, comment, public/tested symbol, dict output shape, andValueErrorstring.loopx/capabilities/explore/turn_context.py:124with an explicitMapping[str, object]annotation onprojectionso strict caller typechecking acrossresearch_evidence.pyandturn_context.pycompiles with0errors.Anyratchet baseline entry (any_count: 0,dict_any_count: 0,lines: 1146) forloopx/capabilities/explore/result_log.pyinloopx/canary/module_metric_baseline.json.Verification
uv run --extra test python -c 'from pathlib import Path; from loopx.canary.maintainability_ratchet import module_metrics; print(module_metrics(Path("loopx/capabilities/explore/result_log.py")))'->{'lines': 1131, 'any_count': 0, 'dict_any_count': 0}uv run --extra test mypy --strict --follow-imports=silent loopx/capabilities/explore/result_log.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/capabilities/explore/result_log.py loopx/capabilities/explore/turn_context.py tests/canary/test_maintainability_ratchet.py->All checks passed!uv run --extra test pytest -q -n 4(25 suites acrosstests/canary/test_maintainability_ratchet.py,tests/capabilities/test_explore_*.py,tests/capabilities/test_issue_fix_explore_private_evidence.py,tests/capabilities/test_research_composition_gate.py,tests/control_plane/test_explore_*.py,tests/presentation/test_explore_history.py,tests/test_chat_explore_results.py,tests/test_explore_mermaid_identity.py,tests/test_explore_source_history_reconcile.py,tests/architecture/test_semantic_vocabulary_drift.py) ->591 passed in 269.08suv run --extra test python examples/issue-fix-explore-projection-smoke.py->issue-fix explore projection smoke: ok(Note: pre-existingexamples/explore-result-layer-smoke.py:155asserts unencoded"node_kcg" in mermaidvs existing hex-encodedn_6e6f64655f6b6367, reproducing identically on untouchedorigin/main; hex Mermaid behavior is already covered bytests/test_explore_mermaid_identity.pyin the passing pytest run.)uv run --extra test loopx canary premerge --tier quick --from-git-diff --git-diff-base origin/main->status: passed,ok: true(selected=3, failures=0:control-plane-maintainability-ratchet-smoke.py,semantic-vocabulary-drift-smoke.py,explore-configure-goal-smoke.py)loopx check --scan-path ...) ->ok: True,errors=0, warnings=0(3 files clean)