Skip to content

refactor(explore): slim result_log and eliminate all 68 Any - #8967

Open
loopx-agent wants to merge 1 commit into
mainfrom
codex/explore-result-log-slim-20261118
Open

loopx-agent wants to merge 1 commit into
mainfrom
codex/explore-result-log-slim-20261118

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

  • Eliminated all 68 Any occurrences in loopx/capabilities/explore/result_log.py (any_count: 0, dict_any_count: 0) and slimmed the module from 1,260 lines to 1,131 lines (-129 net lines; git diff --stat across 3 files: 405 insertions(+), 528 deletions(-)).
  • Replaced loose Any / dict[str, Any] / Mapping[str, Any] annotations with object, 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 structured ExploreResultProjection(TypedDict) (nodes, edges, findings, stuck, frontier, tree, counts, boundary, optional research_frontier) while preserving every existing docstring, comment, public/tested symbol, dict output shape, and ValueError string.
  • Updated loopx/capabilities/explore/turn_context.py:124 with an explicit Mapping[str, object] annotation on projection so strict caller typechecking across research_evidence.py and turn_context.py compiles with 0 errors.
  • Added a zero-Any ratchet baseline entry (any_count: 0, dict_any_count: 0, lines: 1146) for loopx/capabilities/explore/result_log.py in loopx/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 file
  • uv run --extra test mypy -> Success: no issues found in 17 source files
  • 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 passed!
  • uv run --extra test pytest -q -n 4 (25 suites across tests/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.08s
  • uv run --extra test python examples/issue-fix-explore-projection-smoke.py -> issue-fix explore projection smoke: ok (Note: pre-existing examples/explore-result-layer-smoke.py:155 asserts unencoded "node_kcg" in mermaid vs existing hex-encoded n_6e6f64655f6b6367, reproducing identically on untouched origin/main; hex Mermaid behavior is already covered by tests/test_explore_mermaid_identity.py in 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)
  • Public boundary check (loopx check --scan-path ...) -> ok: True, errors=0, warnings=0 (3 files clean)

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

@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)

已针对 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 返回值直接通过全仓 strict mypy。
  • 内部窄化与公共辅助收敛(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 行):

  1. loopx/capabilities/explore/result_log.py(+398 / -527,净减 129 行,1,260 -> 1,131 行,68 Any -> 0):清除全部 Any,定义 Payload、PayloadView 与 ExploreResultProjection(TypedDict),收敛 JSONL 解析、视图公共字段与状态计数逻辑,保留完整文档字符串与注释。
  2. loopx/capabilities/explore/turn_context.py(+2 / -1,L124):为 projection 添加既有 Mapping[str, object] 类型标注,其余逻辑零修改。
  3. 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 passed
    • uv run --extra test pytest -q -n 4(25 个 Explore/棘轮/词表漂移套件): 591 passed in 269.08s
    • uv 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.

This branch has not been deployed

No deployments
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