Skip to content

refactor(extensions): slim presentation and runtime and eliminate Any - #9012

Open
loopx-agent wants to merge 1 commit into
mainfrom
codex/extensions-runtime-slim-20261118
Open

loopx-agent wants to merge 1 commit into
mainfrom
codex/extensions-runtime-slim-20261118

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

Eliminate all Any annotations and slim structural duplication across loopx/extensions/presentation.py and loopx/extensions/runtime.py strictly below their module_metric_baseline.json line caps with zero semantic or API changes:

  • loopx/extensions/presentation.py (1158 -> 1103 lines, -55 lines, 56 Any -> 0, 0 dict[str, Any]): replaced all Any annotations with typed Mapping[str, object] / dict[str, object] structures and explicit narrowing helpers while preserving all public entrypoints and presentation contracts.
  • loopx/extensions/runtime.py (1405 -> 1386 lines, -19 lines, 54 Any -> 0, 0 dict[str, Any]): replaced all Any annotations with strict type narrowing and compacted repetitive descriptor/manifest validation helpers without changing behavior, exports, or error semantics.

Verification

  • Maintainability metrics on exact head:
    • loopx/extensions/presentation.py: lines=1103 any_count=0 dict_any_count=0
    • loopx/extensions/runtime.py: lines=1386 any_count=0 dict_any_count=0
  • uv run --extra test mypy --strict --follow-imports=silent loopx/extensions/presentation.py loopx/extensions/runtime.py: 0 issues
  • uv run --extra test mypy (17 kernel files): 0 issues
  • uv run --extra test ruff check loopx/extensions/presentation.py loopx/extensions/runtime.py: passed
  • 32 targeted extension, capability, control-plane caller, CLI, media, maintainability ratchet, and vocabulary drift pytest suites: 1265 passed, 6 skipped in 97.76s (0 failed; platform/environment skips in extension stdio/runtime suites)
  • uv run --extra test loopx --format json canary premerge --tier quick --from-git-diff --git-diff-base 7bc56e74687a93ff4d5bcccb532c454bf2379c29: ok: true, gate.status: "passed", failures: [] (6 direct checks, 3 catalog canaries)
  • uv run --extra test loopx check --scan-path ...: ok: true, errors: 0, warnings: 0 (public boundary scan clean)

@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 #9012 exact head 501ca73f040c3c9cdbf4788dd55351100cc6bd7d 完成完整静态检验、公开符号比对与扩展/调用方回归验证(审查结论:APPROVE,无 P0/P1/P2 阻塞问题;[VERDICT: APPROVE])。

动机 / Motivation

受影响调用方与运维者:所有通过 loopx/extensions/ 安装、启用、禁用、回滚、自检扩展及发布/读取扩展呈现视图(projection/presentation view)的协调层与扩展运行时调用方,包括 extension_entrypoints、status_server、capability_extension_registry、decision_context、cli_commands 与 loopx/canary/ 可维护性棘轮。

修改前(7bc56e7468):loopx/extensions/presentation.py(1158 行)含 56 处 Any,loopx/extensions/runtime.py(1405 行)含 54 处 Any,且多处状态读取、条目索引、清单版本解析、封包哈希构造与活跃表面不变式校验存在内联重复。修改后(501ca73f04):两文件全面切换为 Payload = dict[str, object] / PayloadView = Mapping[str, object] 静态窄化并抽取共享私有辅助函数(_identifier、_enum、_sha256、_projection_envelope、_ensure_active_surface_unchanged、_state_extensions、_installed_entry、_record_doctor、_active_snapshot_and_manifest、_active_entry_resolution 等),presentation.py 收敛至 1103 行(-55 行,0 Any / 0 dict[str, Any]),runtime.py 收敛至 1386 行(-19 行,0 Any / 0 dict[str, Any]),AST 验证公开符号零缺失且原有报错文本与外部行为完全保持不变。

可观测结果:exact head 501ca73f04(rebase 至最新 origin/main)上:module_metrics 验证 presentation.py (lines=1103, any_count=0, dict_any_count=0) 与 runtime.py (lines=1386, any_count=0, dict_any_count=0);uv run --extra test mypy --strict --follow-imports=silent 与全仓 17 文件 uv run --extra test mypy 均返回 Success: no issues found;uv run --extra test ruff check 返回 All checks passed!;32 组扩展、能力注册表、控制面调用方、CLI、媒体及棘轮/词表 pytest 套件通过:1265 passed, 6 skipped in 97.76s(0 failed);uv run --extra test loopx --format json canary premerge --tier quick --from-git-diff --git-diff-base 7bc56e74687a93ff4d5bcccb532c454bf2379c29 返回 ok=true, gate.status="passed"(direct=6/6, selected=3/3, failures=0, manual_holds=0);loopx check --scan-path ... 返回 ok=true(errors=0, warnings=0)。

非目标边界:本 PR 不修改 loopx/canary/module_metric_baseline.json(保留现有 1158 / 1405 基线上限),不更改扩展安装/状态文件磁盘格式、呈现视图验证约束、公开函数签名或报错文本。

改动思路 / Approach

全部 Any 清理、显式类型窄化与私有辅助抽提均严格限制在 loopx/extensions/presentation.py 与 loopx/extensions/runtime.py 原模块内部,复用 loopx/extensions/readiness.py 现有边界而未引入新状态机或旁路所有者。

当前 PR 边界:仅包含 loopx/extensions/presentation.py(+136/-191)与 loopx/extensions/runtime.py(+238/-257)两处零 Any 静态类型收敛与结构瘦身(总计 +374/-448,净减 74 行)。

  • 呈现视图校验与封包去重(presentation.py):统一 _identifier、_enum、_sha256、_projection_envelope、_ensure_active_surface_unchanged 与 _atomic_write_projection,消除 56 处 Any 并将模块从 1158 行精简至 1103 行。
  • 扩展状态读写与活跃绑定解析收敛(runtime.py):抽取 _empty_state、_read_state、_state_extensions、_installed_entry、_record_doctor、_active_snapshot_and_manifest 与 _active_entry_resolution,消除 54 处 Any 并将模块从 1405 行精简至 1386 行;AST 检查全部公开导出符号零缺失。

具体改动 / Changes

本次 diff 严格限定在 2 个生产文件(+374 / -448):

  1. loopx/extensions/presentation.py(+136 / -191,1158 -> 1103 行,56 -> 0 Any,0 dict[str, Any]):引入 Payload/PayloadView 类型别名并抽取 _identifier、_enum、_sha256、_projection_envelope、_ensure_active_surface_unchanged 等校验与封包辅助,重构 validate_opaque_presentation_view、validate_projection_hash、publish_extension_projection、collect_active_extension_presentation_surfaces 与 read_extension_projection。
  2. loopx/extensions/runtime.py(+238 / -257,1405 -> 1386 行,54 -> 0 Any,0 dict[str, Any]):抽提 _empty_state、_read_state、_state_extensions、_installed_entry、_record_doctor、_active_snapshot_and_manifest、_active_entry_resolution、_build_runtime_binding 与 resolve_extension_binding 实现零 Any 显式类型窄化与去重,完整保留所有公开符号与错误契约。

对主干的风险 / Risks

  • 契约与兼容性:mypy --strict、17 文件全仓 mypy 与 AST 公开符号校验完全一致;32 组相关测试 1265 passed, 6 skipped(0 failed),其中 6 例跳过为特定扩展测试固有条件跳过;canary premerge --tier quick 含 control-plane-maintainability-ratchet-smoke、semantic-vocabulary-drift-smoke 与 todo-contract-smoke 全部零失败通过。
  • 合入前提:涉及 loopx/extensions/ 核心扩展运行时,需遵循维护者合并授权及远端 CI 完成检查。

我的整体评价 / Verdict

  • Long-horizon 影响:improved — 清零 110 处 Any 注解并净减 74 行结构重复代码,使扩展运行时与呈现两大模块稳定低于现有可维护性棘轮基线。
  • User-experience 影响:preserved — 纯行为等价静态收敛与结构整理,对外扩展 CLI/状态/呈现语义保持完全一致。
  • visual_review:not_applicable — 纯 Python 扩展控制与呈现校验后端模块,无 UI 视图变化。

改动聚焦、验证完备、零增量风险;待维护者授权与远端 CI 就绪后可合入。

[VERDICT: APPROVE]
English verdict: APPROVE exact head 501ca73 (author-owned COMMENTED approval review); eliminates all 110 Any usages across loopx/extensions/presentation.py (1158->1103 lines) and loopx/extensions/runtime.py (1405->1386 lines) with full behavioral equivalence verified by 1265 passed (6 skipped, 0 failed) extension/caller pytest cases, mypy --strict & 17-file mypy (0 issues), ruff check, quick premerge canaries (0 failures), and loopx check clean (0 errors).

@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

使用已安装第三方扩展运行本机任务或发布视图的操作者,通过同一 active manifest 管理 lifecycle、预览和执行。 原清单校验允许这个输入,两个执行路径都把该值转换为 1 秒。 使用正常安装命令接受并保存的 TOML timeout_seconds=true,基线的 run 完成,publish-projection 发布并验证回读。当前头仍安装成功,两条预览均返回 ready,执行均退出 2 并返回 extension active manifest is incomplete,provider 均未收到请求。timeout_seconds=1 的对照全程通过。 本次把两处扩展模块收窄到 object,并抽出共用 binding 和投影封包,提案承诺保留外部行为。 范围限于扩展文件状态、受控 subprocess 和本地投影回读。没有新 provider 或执行权限。

改动思路 / Approach

清单负责规范化和快照,runtime 负责 doctor、binding 和有界调用,presentation 负责校验、生命周期重读和原子投影。 共用封包和 binding 的提取可保留。保持清单校验、已安装快照、预览和执行对同一输入的语义一致。 用完全相同的 manifest 和无网络 provider,在两版已安装源码中分别覆盖整数、历史接受值、预览、执行与禁用后的拒绝。

具体改动 / Changes

逐项检查当前头 501ca73 和 merge base 7bc56e7,2 个文件,+374/-448。EXT-RUN-PARITY 和 EXT-PROJECTION-PARITY 均存在执行回归。EXT-DRY-RUN-AND-DISABLE 保留,EXT-READBACK 在整数对照可验。 评审依据为 7bc56e7。 目标规范

关键代码讲解

对主干的风险 / Risks

[P2] 安装和预览接受的超时值在执行阶段被拒绝。 使用正常安装命令接受并保存的 TOML timeout_seconds=true,基线的 run 完成,publish-projection 发布并验证回读。当前头仍安装成功,两条预览均返回 ready,执行均退出 2 并返回 extension active manifest is incomplete,provider 均未收到请求。timeout_seconds=1 的对照全程通过。 统一清单存储和两个消费者的解释。保留对既有已接收快照的兼容读取,例如按旧语义把 True 规范化为 1。如果后续明确收紧新清单,应在清单入口给出迁移诊断,并确保预览和执行使用同一校验。 升级后此前可用的扩展可能在第一次执行时才失败,安装和预览无法提前发现。

整数 1 的完整安装、预览、执行、发布与投影回读在两版一致。预览均未启动 provider,disable 后两版均在执行前拒绝调用。 164 项扩展运行时、投影、入口与状态 API 测试通过,两个文件的 strict mypy 和 quick premerge 均通过。 使用本地隔离扩展和合成投影,没有远端 provider、浏览器渲染或远程 CI 证据。

我的整体评价 / Verdict

请求修改。清单负责规范化和快照,runtime 负责 doctor、binding 和有界调用,presentation 负责校验、生命周期重读和原子投影。 共用封包和 binding 的提取可保留。保持清单校验、已安装快照、预览和执行对同一输入的语义一致。 已被清单 owner 接收的激活快照失去原有运行和投影能力。 修复应覆盖两条实际执行路径,并保持超时边界与禁用时的副作用隔离。

English verdict: REQUEST_CHANGES at 501ca73. A manifest still accepted at install with timeout_seconds=true previews as ready, but both standalone run and publication now fail before invoking the provider. The base succeeds on both paths, and the integer and disabled controls are unchanged.

argv,
stdin=request_bytes,
timeout_seconds=int(runtime["timeout_seconds"]),
timeout_seconds=_int_value(runtime.get("timeout_seconds"), "extension active manifest is incomplete"),

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.

[P2] 安装和预览接受的超时值在执行阶段被拒绝。使用正常安装命令接受并保存的 TOML timeout_seconds=true,基线的 run 完成,publish-projection 发布并验证回读。当前头仍安装成功,两条预览均返回 ready,执行均退出 2 并返回 extension active manifest is incomplete,provider 均未收到请求。timeout_seconds=1 的对照全程通过。 统一清单存储和两个消费者的解释。保留对既有已接收快照的兼容读取,例如按旧语义把 True 规范化为 1。如果后续明确收紧新清单,应在清单入口给出迁移诊断,并确保预览和执行使用同一校验。

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