Skip to content

refactor(chat): modularize goal_configuration_api and eliminate Any annotations - #9477

Merged
huangruiteng merged 1 commit into
mainfrom
codex/slim-chat-goal-configuration-api-zero-any-20261126
Nov 26, 2026
Merged

huangruiteng merged 1 commit into
mainfrom
codex/slim-chat-goal-configuration-api-zero-any-20261126

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Delivery Brief

  • Source / Goal: Eliminated all AST Any annotations (49 -> 0), # type: ignore, and # noqa comments in loopx/chat/goal_configuration_api.py (789 -> 371 LOC) while modularizing capability option translation and transaction plan/receipt formatting.
  • Owning Boundary: Keeps class GoalConfigurationRequestMixin defined directly inside loopx.chat.goal_configuration_api (GoalConfigurationRequestMixin.__module__ == "loopx.chat.goal_configuration_api") and adds no top-level loopx.chat_goal_configuration_api compatibility shim (tests/test_chat_internal_module_layout.py verified), while preserving _goal_capability_options, GoalConfigurationReader, GoalConfigurationWriter, and all endpoint/path constants.
  • Implementation:
    • loopx/chat/goal_configuration_options.py (344 LOC, 0 AST Any): hoisted module-level _CLEAR_CAPABILITY_OPTIONS, _ALLOWED_CAPABILITY_FIELDS (frozenset sets), and _CAPABILITY_OPTION_TRANSLATORS dispatch tables instead of per-call dict/set allocation; split typed option translators for all 14 editable Goal capabilities and resolved mypy normalize_configuration re-import conflict.
    • loopx/chat/goal_configuration_plans.py (229 LOC, 0 AST Any): typed request validation (parse_goal_configuration_update), capability_entry, goal_configuration_update_plan, build_partial_write_receipt_payload, build_applied_goal_configuration_payload, bounded changed_fields_list, and codex_home_override (accepting Path as well as str, matching ChatRuntimeController.codex_home).
    • loopx/chat/goal_configuration_api.py (371 <= 550 LOC, 0 AST Any, 0 # type: ignore, 0 # noqa, max_span=78): typed GoalConfigurationRequestMixin declaring _read_json/_send_json/_send_error Liskov-compatible stubs, re-exporting _goal_capability_options, skipping the duplicate _read_public_goal_configuration call on verified-mismatch 207 partial-write paths (prefetched_readback), and eliminating all 4 baseline mypy errors (4 -> 0).
    • tests/control_plane/test_chat_goal_configuration_api_contract.py (297 LOC, 0 AST Any): checks AST/LOC/Zero-Any/Zero-ignore/Zero-noqa/layout pins, capability clear/validation error boundaries, codex_home_override/runtime_root_override_arg, inspect query validation and 500 error sanitization, single-read prefetched_readback 207 emission, and non-written readback mismatch refusal.
  • Boundary & Hygiene Scan: Clean (0 # type: ignore, 0 # noqa, 0 local/private paths, module_metric_baseline.json untouched, loopx/*.py == 112).

Validation Summary

  • On rebased exact HEAD (88d6073078 over origin/main 7f7297a790, clean git merge-tree e2600d15838c0912c445b6cb7d324fc22af43b48):
    • ruff check (4/4): passed.
    • mypy --strict --no-incremental --follow-imports=silent (4/4): Success: no issues found in 4 source files (goal_configuration_api.py: 4 -> 0 errors).
    • Repo [tool.mypy] (17/17): Success: no issues found in 17 source files.
    • Caller mypy --no-incremental --follow-imports=silent: loopx/presentation/configuration_api.py 0 -> 0 errors, loopx/chat_server.py 28 -> 28.
    • pytest -q -n 4 -rs (test_chat_goal_configuration_api_contract.py, test_chat_internal_module_layout.py, test_chat_goal_configuration_api.py, test_native_steward_reports.py, test_reward_memory_agent_bindings.py, test_capability_improvement.py, test_goal_capability_inspection.py, tests/architecture/): 2,173 passed (0 failures, 0 skipped).
    • Pre-merge gates: Goal loopx check (5 checks, errors=0), Goal CQR (cqr_11a4ab1b6a76747f87d7, decision="pass", status="valid"), Goal canary premerge --from-git-diff --git-diff-base origin/main (ok=true, merge_gate_passed=true, direct_check_count=6, executed_check_count=2, manual_hold_count=0).
  • Earlier on identical source tree over 57c4c43b52:
    • npm run typecheck:control-plane clean; npm run test:control-plane (6,818 pass, 93 skip, 0 fail); node --no-warnings --experimental-sqlite --experimental-strip-types --test tests/control_plane_ts/content_digest_single_owner.test.ts tests/control_plane_ts/action_review_plan.test.ts (38/38 pass).
    • Paired 57c4c43b52 vs candidate counterfactual parity (45 cases across all 14 capability translators, clear paths, error types, request parsing, inspect/preview/apply/stale/partial-write/500 sanitization): 45/45 keys matched identically (PARITY_DIFFS: {}).
    • 5/5 clean-HOME smokes passed (control-plane-maintainability-ratchet-smoke.py unreviewed=0, semantic-vocabulary-drift-smoke.py, explore-configure-goal-smoke.py, capability-extension-registry-smoke.py, capability-gate-smoke.py).
    • Full pytest -q -n 6 -rs (test_chat_goal_configuration_api_contract.py, test_chat_internal_module_layout.py, test_chat_goal_configuration_api.py, test_native_steward_reports.py, tests/capabilities/, tests/architecture/, tests/canary/): 6,388 passed, 60 skipped (9 Linux-isolation, 45 explicit live-only, 6 APFS filename skips, 0 failures).

…nnotations

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 · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

拆分 Goal 配置 HTTP 门面、能力参数翻译与事务回执,保留用户从预览到带 revision 应用、再读回真实配置的完整路径。 原门面混合 14 项能力配置、plan 和回执,已承担命令参数验证、过期计划拒绝以及部分写成功的恢复。 在 Personal Workspace 查看、预览、应用和恢复 Goal 配置的人。

缺失 revision 门禁会让过期编辑覆盖当前配置。若写成功后发普通异常,用户失去已写事实并可能反复提交。 基线与精确头的真实 loopback HTTP 同样读到默认 off、返回 201 预览且保持原 registry 字节、成功 200 应用并验证源与共享镜像、拒绝重放旧 plan 且不改两份文件。 精确目标基线 18 项、头部 22 项配置与架构测试通过。真实 HTTP 读写对照一致。14 个能力共 74 组转换、clear 和拒绝对照相同。5 组受控读回覆盖 200、207、未写拒绝和后续收敛。git diff --check 和静态 merge-tree 通过。 HTTP 使用隔离 source/shared registry,受控读回序列由夹具提供。未运行安装态 UI 或远程 CI。 基线契约

改动思路 / Approach

该改动沿用 ChatRequestHandler → GoalConfigurationRequestMixin → configure_goal_with_global_sync → source/shared registry → public configuration readback。保持现有 configure-goal 决策、registry 写入、revision 计算和 UI schema。小模块分担选项翻译和组装输出,未新增持久或公共入口。 过期计划依当前 revision 拒绝。部分写回执仍保留写入事实,已读到明确 mismatch 时用这一次观察生成 207;浏览器已有刷新原源的恢复入口。缺失回执仍尝试原读回。 仅提取现有 translator、parser 和响应组合,沿用原计划与写入 owner。原门面的读回优化独立对照,未来可单独优化 dispatch 表而无需改变事务边界。

具体改动 / Changes

精确提交 88d6073,分叉基线 7f7297a。4 个路径 +1041/-567。HTTP 门面缩至 371 行,选项与回执新增两个内部模块,新增契约测试 317 行。总生产 diff 有净增,主要将大门面职责拆为可逐个比较的调用面。

关键代码讲解

  • _goal_configuration_update。翻译已校验 body,生成预览,绑定计划 revision,调用原配置服务。 源码

  • _send_applied_goal_configuration。区分已确认、已写但未验证、未证明写入三路,207 保留已写事实和读回状态。 源码

  • goal_capability_options。按现有可编辑能力先核验字段,再交给该能力原有 translator。 源码

  • goal_configuration_update_plan。继续使用现有 transaction owner 绑定目标和 revision。 源码

  • goal-config-revision-locked-preview-apply-readback(implemented)。当前 Goal 的配置仍由现有原子写入和 revision 约束接管,预览零写入,过期计划拒绝,状态显示来源于实际读回。

对主干的风险 / Risks

错误 composition scope 类型两侧都返回 400,旧计划返回 409。无 write 事实时 mismatch 仍拒绝。已写入但首次读回确认为 mismatch 时,当前头返回保留 source_written 的 207,UI 可重新读源;读回异常保持原重试。 第一次确认 mismatch 后立刻收敛时,当前头的 207 仍暂报未确认。两侧均保留写入事实和重新读源入口。 保留旧计划拒绝和独立读回。已确认 mismatch 用观察到的配置报告 207,并保留用户主动重新读源。

我的整体评价 / Verdict

APPROVE。 认可当前精确头。真实配置路径和 74 组参数行为对照保持。明确 mismatch 只用一次读回是已披露的保守变化,207 仍保留已写事实与原恢复入口。 版本化计划、结构化部分写回执和复用原 writer 一起降低并发编辑覆盖和不必要的重试。

English verdict: APPROVE at 88d6073. Exact base/head HTTP tests preserve revision-locked preview, apply, mirrored readback, and stale rejection. The documented single-snapshot 207 remains recoverable through the existing reload path.

@huangruiteng huangruiteng left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · GPT-5 · OpenAI · self_reported

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

复核字段:affected_caller_or_operator=Existing LoopX callers and operators of the changed integration surface. before_after_scenario=The old monolith or broad type surface is replaced by focused modules with explicit validation while public behavior stays stable. observable_outcome=Existing behavior remains reachable through the same entrypoint with stricter typing and focused regression coverage. non_goals=No unrelated product workflow, permission model or external provider protocol is changed.

规范依据:docs/architecture/rfcs/goal-scoped-capability-portfolio-v0.md(精确头分叉基线 7f7297a790771dab08e2444700f4d76699169950)。

拆分 Goal 配置 HTTP 门面、能力参数翻译与事务回执,保留用户从预览到带 revision 应用、再读回真实配置的完整路径。 原门面混合 14 项能力配置、plan 和回执,已承担命令参数验证、过期计划拒绝以及部分写成功的恢复。 在 Personal Workspace 查看、预览、应用和恢复 Goal 配置的人。

缺失 revision 门禁会让过期编辑覆盖当前配置。若写成功后发普通异常,用户失去已写事实并可能反复提交。 基线与精确头的真实 loopback HTTP 同样读到默认 off、返回 201 预览且保持原 registry 字节、成功 200 应用并验证源与共享镜像、拒绝重放旧 plan 且不改两份文件。 精确目标基线 18 项、头部 22 项配置与架构测试通过。真实 HTTP 读写对照一致。14 个能力共 74 组转换、clear 和拒绝对照相同。5 组受控读回覆盖 200、207、未写拒绝和后续收敛。git diff --check 和静态 merge-tree 通过。 HTTP 使用隔离 source/shared registry,受控读回序列由夹具提供。未运行安装态 UI 或远程 CI。 基线契约

改动思路 / Approach

复核字段:criterion=goal-configuration-revision-readback architecture_reason=职责沿现有调用、provider 和持久化边界拆分,公共入口保持。 current_pr_boundary=仅 loopx/chat/goal_configuration_api.py, loopx/chat/goal_configuration_options.py, loopx/chat/goal_configuration_plans.py, tests/control_plane/test_chat_goal_configuration_api_contract.py。

该改动沿用 ChatRequestHandler → GoalConfigurationRequestMixin → configure_goal_with_global_sync → source/shared registry → public configuration readback。保持现有 configure-goal 决策、registry 写入、revision 计算和 UI schema。小模块分担选项翻译和组装输出,未新增持久或公共入口。 过期计划依当前 revision 拒绝。部分写回执仍保留写入事实,已读到明确 mismatch 时用这一次观察生成 207;浏览器已有刷新原源的恢复入口。缺失回执仍尝试原读回。 仅提取现有 translator、parser 和响应组合,沿用原计划与写入 owner。原门面的读回优化独立对照,未来可单独优化 dispatch 表而无需改变事务边界。

具体改动 / Changes

精确提交 88d6073,分叉基线 7f7297a。4 个路径 +1041/-567。HTTP 门面缩至 371 行,选项与回执新增两个内部模块,新增契约测试 317 行。总生产 diff 有净增,主要将大门面职责拆为可逐个比较的调用面。

关键代码讲解

  • _goal_configuration_update。翻译已校验 body,生成预览,绑定计划 revision,调用原配置服务。 源码

  • _send_applied_goal_configuration。区分已确认、已写但未验证、未证明写入三路,207 保留已写事实和读回状态。 源码

  • goal_capability_options。按现有可编辑能力先核验字段,再交给该能力原有 translator。 源码

  • goal_configuration_update_plan。继续使用现有 transaction owner 绑定目标和 revision。 源码

  • goal-config-revision-locked-preview-apply-readback(implemented)。当前 Goal 的配置仍由现有原子写入和 revision 约束接管,预览零写入,过期计划拒绝,状态显示来源于实际读回。

对主干的风险 / Risks

错误 composition scope 类型两侧都返回 400,旧计划返回 409。无 write 事实时 mismatch 仍拒绝。已写入但首次读回确认为 mismatch 时,当前头返回保留 source_written 的 207,UI 可重新读源;读回异常保持原重试。 第一次确认 mismatch 后立刻收敛时,当前头的 207 仍暂报未确认。两侧均保留写入事实和重新读源入口。 保留旧计划拒绝和独立读回。已确认 mismatch 用观察到的配置报告 207,并保留用户主动重新读源。

我的整体评价 / Verdict

APPROVE。 认可当前精确头。真实配置路径和 74 组参数行为对照保持。明确 mismatch 只用一次读回是已披露的保守变化,207 仍保留已写事实与原恢复入口。 版本化计划、结构化部分写回执和复用原 writer 一起降低并发编辑覆盖和不必要的重试。

本轮独立复核:19 passed; Ruff passed; strict mypy passed;premerge passed 2/2 with 0 manual holds。

English verdict: APPROVE at 88d6073. Exact base/head HTTP tests preserve revision-locked preview, apply, mirrored readback, and stale rejection. The documented single-snapshot 207 remains recoverable through the existing reload path.

@huangruiteng
huangruiteng merged commit 5454506 into main Nov 26, 2026
35 of 47 checks passed
@huangruiteng
huangruiteng deleted the codex/slim-chat-goal-configuration-api-zero-any-20261126 branch November 26, 2026 12:36
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.

2 participants