Skip to content

refactor(chat): colocate leaf chat helpers under loopx.chat and ratchet module budget (#5072) - #9179

Merged
loopx-agent merged 1 commit into
mainfrom
codex/m1-chat-leaf-move-20261121
Nov 22, 2026
Merged

loopx-agent merged 1 commit into
mainfrom
codex/m1-chat-leaf-move-20261121

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

  • Outcome basis / optional anchor: docs/architecture/rfcs/monorepo-distribution-split-v0.md (Milestone M1, Invariant I3, and Section 9 top-level module budget ratchet; related to RFC: split LoopX distributions inside the monorepo (loopx-core / loopx-workspace / capability packages) and pin top-level module growth #5072).
  • Goal/source and gap: Three internal-only Chat leaf modules (loopx/chat_operator_provider_api.py, loopx/chat_attachments.py, loopx/chat_dsh.py) still sat at the package top level (121 top-level modules on main), instead of co-locating under loopx/chat/.
  • Observable before → after, with the validation row that proves it:
    • Before: loopx/ held 121 top-level *.py modules (tests/architecture/top_level_module_budget.json pinned 121 on 06fd6feeab08dc8c9d75ccf6050a16126fbc606d).
    • After: Moved all three modules under loopx/chat/ (operator_provider_api.py, attachments.py, dsh.py) via git mv with zero top-level compatibility shims, updated all internal callers/tests/smokes/RFC references, kept no-shim assertions in tests/test_chat_internal_module_layout.py, and lowered max_top_level_modules to 118 (baseline_commit 06fd6feeab08dc8c9d75ccf6050a16126fbc606d). Proven on exact HEAD 8c1d8fe1ff2659eef6461a5bb4a52e274c020561 by tests/architecture/test_top_level_module_budget.py, tests/test_chat_internal_module_layout.py, targeted architecture/Chat/Lark pytest (1608 passed), canary premerge (11/11 selected checks passed), and Goal-bound CQR cqr_462398dfbcbf242ef31e.
  • Issue/task and intended base: Related to RFC: split LoopX distributions inside the monorepo (loopx-core / loopx-workspace / capability packages) and pin top-level module growth #5072; base branch main (rebased onto 06fd6feeab08dc8c9d75ccf6050a16126fbc606d).

Author Declaration

  • Written by: model_agent (Antigravity, Google Deepmind)

Implemented against

  • Specification and revision: docs/architecture/rfcs/monorepo-distribution-split-v0.md (M1, I3, Section 9) at 06fd6feeab08dc8c9d75ccf6050a16126fbc606d
  • Criteria:
Criterion (spec clause) Disposition Symbol / path Test or command
M1 internal Chat leaf relocation under loopx/chat/ implemented loopx/chat/operator_provider_api.py, loopx/chat/attachments.py, loopx/chat/dsh.py pytest -q --no-cov tests/test_chat_internal_module_layout.py
I3 pure internal moves delete old top-level modules with all callers updated implemented loopx/presentation/*, loopx/chat/*, loopx/chat_*.py, loopx/extensions/lark/*, loopx/capabilities/native_chat/*, tests/*, examples/* rg -n "loopx\\.chat_(operator_provider_api|attachments|dsh)|chat_(operator_provider_api|attachments|dsh)\\.py" loopx tests examples docs + tests/test_chat_internal_module_layout.py
Symmetrical EN/ZH RFC reference update implemented docs/architecture/rfcs/harness-selection-dsh-pi-v0.md, docs/architecture/rfcs/harness-selection-dsh-pi-v0.zh-CN.md python scripts/check_rfc_bilingual.py --base origin/main --head HEAD
Top-level module budget ratchet lowered in same PR implemented tests/architecture/top_level_module_budget.json (121 → 118) pytest -q --no-cov tests/architecture/test_top_level_module_budget.py
  • Self-check before submission: Verified ls -1 loopx/*.py | wc -l == 118, confirmed zero stale old-module imports across loopx, tests, examples, and docs via rg, checked bilingual RFC diff, ran targeted architecture/Chat/Lark pytest (1608 passed), ran ruff, configured strict mypy (17 files), loopx check (0 errors on 32 files), Goal-bound CQR (cqr_462398dfbcbf242ef31e), and loopx canary premerge --from-git-diff --git-diff-base origin/main.

Scope And Continuation

Validation

  • Tested revision: 8c1d8fe1ff2659eef6461a5bb4a52e274c020561 (rebased onto 06fd6feeab08dc8c9d75ccf6050a16126fbc606d; all checks below ran directly on exact HEAD 8c1d8fe1ff2659eef6461a5bb4a52e274c020561)
  • Run state: finished
  • Input classes: synthetic, public_fixture
Check kind Result Public-safe evidence / limitation
unit passed pytest -q --no-cov -n auto tests/architecture/test_top_level_module_budget.py tests/architecture/test_control_plane_import_boundaries.py tests/architecture/test_package_kernel_import_ratchet.py tests/test_chat_internal_module_layout.py tests/test_chat_image_attachments.py tests/test_chat_image_http.py tests/test_chat_dsh_adapter.py tests/test_chat_endpoint_readiness.py tests/test_chat_executor_profile.py tests/test_atomic_write_modes.py tests/test_chat_reasoning_selection.py tests/control_plane/test_goal_activation.py tests/test_audit_cli_and_runtime_fixes.py tests/test_manager_context_roundtrip.py tests/test_lark_private_conversations.py tests/test_lark_private_images.py tests/test_chat_file_discovery.py tests/test_chat_machine_configuration_api.py tests/test_chat_agent.py tests/test_chat_server_cors.py tests/test_chat_startup_isolation.py → 1608 passed in 175.35s
real_entrypoint passed python examples/loopx-managed-turn-operator-flow-smoke.py (ok: true, 5/5 checks passed); examples/loopx-steward-managed-chat-smoke.py exited 0 (printed skip: deepseek-harness-sdk is not installed because optional SDK is absent in this environment)
static passed ruff check on 29 touched Python files (All checks passed!); python -m mypy (Success: no issues found in 17 source files); scripts/check_rfc_bilingual.py --base origin/main --head HEAD (RFC bilingual diff check passed.); loopx check --scan-path ... (ok: true, errors: 0, 32 files)
regression_parity passed loopx canary premerge --from-git-diff --git-diff-base origin/main --goal-id personal-loopx-maintenance → ok: true, direct_checks: 6/6, selected_checks: 11/11 (catalog_run: 2/2, risk_profile_run: 8/8, boundary_run: 1/1), failure_count: 0, CQR cqr_462398dfbcbf242ef31e (valid)
  • Coverage and gaps: Full-repo pytest suite was not run in full; examples/loopx-steward-managed-chat-smoke.py skipped live SDK execution (deepseek-harness-sdk not installed), while tests/test_chat_dsh_adapter.py and examples/loopx-managed-turn-operator-flow-smoke.py exercised loopx.chat.dsh.DshChatAdapter directly.

Frontend / Visual Evidence

  • UI impact: none
  • Before: N/A
  • After: N/A
  • First viewport and preview: N/A
  • States and viewports shown: N/A
  • Source data: none
  • Attention review: N/A
  • Craft review: N/A

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring (no functional changes)
  • Documentation update
  • Test update

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)
  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)
  • Capability or extension (providers, adapters, skills)
  • Public docs or presentation surface (README, protocols, dashboard)
  • Build, packaging, installer, or CI
  • Host or runtime integration

Technical Direction

  • Direction / acceptance reference, when applicable: docs/architecture/rfcs/monorepo-distribution-split-v0.md (M1, I3, Section 9)

Shared-authority RFC fixture impact

N/A

Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths (including .loopx/, .codex/goals/, and live ACTIVE_GOAL_STATE.md).
  • I did not duplicate maintainer-owned benchmark work unless a maintainer split out a public issue for it.
  • I kept the change scoped to the linked issue/task.
  • Existing English/Chinese RFC pairs (including ledger entries) both have a diff, and the local premerge check python3 scripts/check_rfc_bilingual.py --base origin/main --head HEAD passes, or no paired RFC changed.
  • I completed the visual evidence section for UI changes, or marked UI impact none.
  • Every commit includes a DCO Signed-off-by trailer (git commit -s).

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

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

Reviewer: model_agent · Antigravity · Google Deepmind · self_reported

动机 / Motivation

在 loopx/ 顶层目录中,面向个人工作区与受管 chat 通道的内部叶子模块(loopx/chat_operator_provider_api.py、loopx/chat_attachments.py、loopx/chat_dsh.py)此前仍平铺在包根目录下,使 loopx/*.py 顶层模块总数停留在 124 个。对于需要按目录划定 CODEOWNERS 与推进 loopx-core / loopx-workspace 拆分(#5072)的贡献者和维护者而言,这种平铺结构让私有/内部 chat 辅助模块与 quota.py、todos.py 等核心内核入口混在一起,阻碍模块归属清晰化并使顶层模块预算停滞。

迁移前后的核心变化如下:迁移前 loopx/ 顶层包含 124 个 .py 模块且 3 个内部 chat 叶子模块平铺在包根目录,而迁移后 3 个模块归位到 loopx/chat/ 且零永久顶层 shim,顶层模块数降至 121 个。可验证的结果是:loopx/*.py 数量从 124 降为 121,test_top_level_module_budget.py 与 test_chat_internal_module_layout.py 通过且所有调用方保持原有行为不变。本 PR 不修改任何公开 API 语义、协议 schema、运行期权限边界或默认行为。作为 #5072 M1 的一个独立可回滚批次,其余尚未迁移的顶层 chat_* 与 *_goal_mode 模块仍待后续 M1/M2 PR 推进。

改动思路 / Approach

变更维度 迁移前(64353773dc) 迁移后(149a7ed12b) 约束 / 收益
模块落点 loopx/chat_{operator_provider_api,attachments,dsh}.py loopx/chat/{operator_provider_api,attachments,dsh}.py 复用 loopx/chat.py 的 __path__ 命名空间包,无 __init__.py
相对导入深度 同级 .control_plane / .chat / .chat_agent 子包内 ..control_plane / ..chat / ..chat_agent 保持原有导入图与延迟加载时机不变
兼容桥接 顶层文件直接存在 无永久顶层 shim(I3 内部迁移直接删除旧入口) importlib.util.find_spec 确认旧模块不再解析
预算棘轮 max_top_level_modules: 124 max_top_level_modules: 121(baseline 更新至 64353773dc) 由 test_top_level_module_budget.py 强制锁定只降不升

整体架构复用既有模式:入口与调用边界维持在 loopx/presentation/configuration_api.py、loopx/presentation/codex_attached_api.py、loopx/chat_server.py、loopx/chat_runtime.py、loopx/chat_ingress.py、loopx/chat_agent.py、loopx/extensions/lark/ 与 loopx/capabilities/native_chat/,没有任何第二份配置或重复状态。在架构归属与职责边界上,本次迁移纯属既有 loopx.chat 命名空间下的目录归位且零新增运行期机制,完整保留了原有 provider IO 与策略边界的归属不变。当前 PR 的边界严格限定为迁入这 3 个内部 chat 叶子模块、同步全部调用方与测试和 smoke 及成对 RFC 引用、补充无 shim 断言并把顶层预算从 124 收紧至 121,其余顶层模块留待后续切片。

正向走读:ChatConfigurationRequestMixin 通过 from ..chat import operator_provider_api 挂载 /api/chat/operator-credential;ChatRuntimeController 与 builtin_chat_endpoints 从 loopx/chat/dsh.py 读取 DshChatAdapter 与 STEWARD_SEGMENT_ENV;HTTP、Lark、Codex/Antigravity adapter 从 loopx/chat/attachments.py 导入附件大小与格式校验函数。反向与架构守卫:tests/test_chat_internal_module_layout.py 显式验证三个新模块 __module__ 均位于 loopx.chat.* 下,且旧顶层模块 importlib.util.find_spec("loopx.chat_*") 返回 None。

具体改动 / Changes

依据规范 docs/architecture/rfcs/monorepo-distribution-split-v0.md(基线修订 64353773dc8b1ca82ff531cc7653dec6c3d41c0b),各条验收准则在本 exact head(149a7ed12ba92bf7737004263abba17e8ff029bc)的核对映射如下:

Criterion ID 规范条款 Disposition 验证路径 / 命令
M1-LEAF-MOVE M1 将内部 loopx/chat_* 迁入 loopx/chat/ 并更新内部相对导入与调用方 implemented loopx/chat/{operator_provider_api,attachments,dsh}.py;pytest -q tests/test_chat_internal_module_layout.py
I3-NO-SHIM 纯内部迁移同步更新所有活跃调用方并删除旧顶层入口,不保留永久兼容 shim implemented 全仓 rg -n 零残留引用;tests/test_chat_internal_module_layout.py 校验 find_spec 为 None
SEC9-BUDGET 同 PR 下调 tests/architecture/top_level_module_budget.json 的 max_top_level_modules implemented tests/architecture/top_level_module_budget.json(124 → 121);pytest -q tests/architecture/test_top_level_module_budget.py
RFC-BILINGUAL-SYNC 同步更新受影响的中英文成对 RFC 文档路径并保持双语一致性 implemented docs/architecture/rfcs/harness-selection-dsh-pi-v0.{md,zh-CN.md};scripts/check_rfc_bilingual.py --base origin/main --head HEAD

全量 diff 共 32 个文件(+48 / -39 行):3 个 git mv 重命名及内部相对导入深度调整(from .foo → from ..foo)、21 个内部代码/测试/smoke 调用路径更新、1 组对称中英文 RFC 路径更新(loopx/chat_dsh.py → loopx/chat/dsh.py)、1 个布局测试新增 3 项校验与无 shim 断言,以及 tests/architecture/top_level_module_budget.json 预算下调。

关键代码讲解

  1. loopx/chat/operator_provider_api.py(OperatorProviderRequestMixin):原顶层模块通过 from .control_plane.operator_provider import ... 读取凭据投影与写入方法;迁入 loopx/chat/ 后改为 from ..control_plane.operator_provider import ...,而 loopx/presentation/configuration_api.py 改为 from ..chat import operator_provider_api as operator_api。实际路由 /api/chat/operator-credential、只写不回显的密钥约束与异常错误码(400 invalid_operator_credential、500 operator_credential_write_failed)均原样保留。
  2. loopx/chat/dsh.py(DshChatAdapter、STEWARD_SEGMENT_ENV):迁入子包后将 4 处顶层相对导入(.chat、.chat_agent、.control_plane.turn_driver.host_binding、.dsh_goal_mode.turn_host_adapter)全部调整为 .. 父级包导入,确保在 loopx/chat.py 通过 __path__ 暴露的子包结构中正确绑定 parse_agent_response、CodexChatAgentError、dsh_output_token_budget 与 run_dsh_turn;单 executor 槽位锁与 DSH_PERMISSION_MODE="read-only" 沙箱固定逻辑保持一致。
  3. loopx/chat/attachments.py(normalize_chat_attachments、require_text_document_route):纯标准库实现,无内部相对导入;迁入 loopx/chat/ 后由 loopx/chat_server.py、loopx/chat_ingress.py、loopx/chat_runtime.py、loopx/chat_agent.py、loopx/chat/result_files_api.py(同级改为 from .attachments import ...)、loopx/presentation/codex_attached_api.py、loopx/extensions/lark/ 与 loopx/capabilities/native_chat/ 统一导入,继续执行图片 4 张 / 单张 5MB / 总计 12MB 与本地受管 Codex 文本文档路由限制。
  4. loopx/chat/endpoint_catalog.py(managed_host_capability):将 from ..chat_dsh import STEWARD_SEGMENT_ENV 调整为同级导入 from .dsh import STEWARD_SEGMENT_ENV,使内置端点目录返回的 sandbox_mode 与实际执行片段环境变量保持单一事实源。

对主干的风险 / Risks

  • 未发现阻断性回归风险(No blocking findings):全仓通过 rg -n "chat_operator_provider_api|chat_attachments|chat_dsh" 扫描 loopx/、tests/、examples/、apps/、packages/、scripts/、docs/,除 tests/test_chat_internal_module_layout.py 中有意检查 importlib.util.find_spec 返回 None 的负向断言外,零残留旧模块引用;ls -1 loopx/*.py | wc -l 实测精确等于 121。
  • 调用方与负向边界验证:
    • 架构与核心单元测试:uv run --extra test python -m pytest -q tests/architecture/test_top_level_module_budget.py tests/architecture/test_control_plane_import_boundaries.py tests/architecture/test_package_kernel_import_ratchet.py tests/test_chat_image_attachments.py tests/test_chat_image_http.py tests/test_chat_dsh_adapter.py tests/test_chat_endpoint_readiness.py tests/test_chat_executor_profile.py tests/test_atomic_write_modes.py tests/test_chat_reasoning_selection.py tests/control_plane/test_goal_activation.py tests/test_chat_internal_module_layout.py tests/test_audit_cli_and_runtime_fixes.py tests/test_manager_context_roundtrip.py → PASS(340 passed in 127.91s),覆盖预算棘轮、无 shim 负向断言、附件超限拒绝、DSH 并发执行器拒绝与超时错误路径。
    • 下游调用方测试:uv run --extra test python -m pytest -q tests/test_lark_private_images.py tests/test_lark_app_image_projection.py tests/test_lark_post_images.py tests/test_chat_file_discovery.py tests/test_chat_machine_configuration_api.py tests/test_chat_transport_composition.py tests/test_chat_agent.py tests/test_chat_server_cors.py tests/test_chat_startup_isolation.py tests/test_lark_private_conversations.py → PASS(1288 passed in 823.36s)。
    • 静态与双语校验:ruff check(All checks passed!)、mypy(Success: no issues found in 17 source files)、scripts/check_rfc_bilingual.py --base origin/main --head HEAD(RFC bilingual diff check passed.)、loopx check(errors=0)与 Goal 绑定 loopx canary premerge --from-git-diff --git-diff-base origin/main --goal-id personal-loopx-maintenance --format json(ok: true, selected=11 failures=0, change_quality receipt cqr_c5dce6287469e9a502b9 valid)全部 PASS。
    • Smoke 与残余风险(Residual risk):examples/loopx-managed-turn-operator-flow-smoke.py 在 64353773dc 基线与 149a7ed12b 当前 head 均输出完全一致的 5 项检查 PASS;examples/loopx-steward-managed-chat-smoke.py 在当前环境因未安装可选包 deepseek-harness-sdk 打印 skip: deepseek-harness-sdk is not installed 并退出 0(UNVERIFIED 真实 SDK 链路;DshChatAdapter 行为本身已由 test_chat_dsh_adapter.py 与 loopx-managed-turn-operator-flow-smoke.py 覆盖)。此外未运行全仓全部 pytest,未咨询远端 CI(wait_for_ci: false)。

我的整体评价 / Verdict

本次 PR 为 justified_increment:在不引入任何兼容债务与行为漂移的前提下,将 3 个内部 chat 叶子模块干净迁入 loopx/chat/ 并将顶层模块预算从 124 棘轮收紧至 121。

  • Long-horizon (improved):降低平铺模块规模并巩固 loopx/chat/ 目录边界与单向预算棘轮,利于后续 #5072 M1/M2 分包交付与维护边界清晰化。
  • User experience (preserved) / Visual review (not_applicable):纯内部 Python 模块搬迁与 RFC 路径同步,未修改任何渲染界面或前端展示逻辑;已核对 loopx/presentation/configuration_api.py 与 loopx/presentation/codex_attached_api.py 仅更新 import 路径(unverified_scope: none)。
  • 语义词表与兼容评估:未新增或修改任何状态枚举、协议字面量或配置语义词表(semantic_alignment: not_applicable);observable_semantics 在不可变基线 64353773dc 与当前 head 149a7ed12b 的同命令对比下保持完全等价(equivalent)。
  • Exact-head freshness:复核远端 head 仍为 149a7ed12ba92bf7737004263abba17e8ff029bc,已通过本地 premerge 与 change-quality 验证。

English verdict: APPROVE at exact head 149a7ed (published as COMMENTED review because PR #9179 is author-owned; 3 M1 internal leaf modules moved to loopx/chat/, all callers/tests/bilingual RFC refs updated with zero permanent shims, top_level_module_budget ratcheted 124 -> 121, 340 + 1288 pytest cases + ruff + mypy + canary premerge PASS; optional deepseek-harness-sdk live step in loopx-steward-managed-chat-smoke.py skipped in local env).

@mergify

mergify Bot commented Nov 21, 2026

Copy link
Copy Markdown

This pull request has merge conflicts with main and cannot be merged
until they are resolved. Please rebase or merge the base branch, @loopx-agent.

Choose the remote for the base repository, not an out-of-date fork.
For a fork clone, first inspect git remote -v; upstream must point
to https://github.com/loopx-project/loopx.git. If it is absent, add it
with git remote add upstream https://github.com/loopx-project/loopx.git.
Then run:

git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEAD

For a same-repository clone whose origin points to
https://github.com/loopx-project/loopx.git, use origin instead of
upstream for fetch/rebase. If you prefer merging the base, use
git merge <base-remote>/main and push normally.

Keep the DCO Signed-off-by trailer on every commit when you rebase.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 21, 2026
@loopx-agent
loopx-agent force-pushed the codex/m1-chat-leaf-move-20261121 branch from 149a7ed to 01bd56d Compare November 21, 2026 14:07
@mergify mergify Bot removed the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 21, 2026

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

动机 / Motivation

LoopX Chat 运行时(ChatRuntimeController、chat_server、chat_agent、chat_ingress)、Lark 私有图片与会话交付扩展、前端配置 API(presentation/configuration_api、codex_attached_api)以及 loopx-core 与 loopx-workspace 分包维护者。

迁移前(含 149a7ed12b 基线旧提交):loopx/chat_attachments.py、loopx/chat_dsh.py 与 loopx/chat_operator_provider_api.py 仍位于 loopx/ 顶层,且原 PR 分支因主干已先合并 #9056/#8905/#9190 而发生冲突与预算错位;变基到 db76a91f0c 后(精确 head 01bd56d3be):三个内部模块直接迁入 loopx/chat/{attachments,dsh,operator_provider_api}.py,dsh.py 同步对齐主干 #8905 的 _turn_prompt 导入,全仓 32 个文件(含双语 RFC)同步更新并删除旧顶层入口,预算从 122 精确棘轮收紧至 119。

loopx/*.py 顶层模块数实测为 119 且与 top_level_module_budget.json(119)吻合;importlib.util.find_spec 对 loopx.chat_attachments、loopx.chat_dsh 与 loopx.chat_operator_provider_api 均返回 None;附件校验拒收、DSH 沙箱只读环境变量与并发互斥拒绝、Operator 凭据读写及 1630 项定向单元测试均与迁移前等价。

本 PR 不改动附件校验阈值、DSH 单段只读执行契约、Operator 凭据脱敏逻辑或并发 PR #9196 的搬迁文件,也不要求本地环境安装可选 deepseek-harness-sdk。

剩余顶层 chat_*.py 与 *_goal_mode 模块迁移仍在 #5072 后续批次推进;可选依赖 deepseek-harness-sdk 未在本地安装故实跑链路跳过;另主干已推进至 PR #9193(202d7bdb05),本分支处于 BEHIND(无文件冲突)。

改动思路 / Approach

本轮是对 PR #9179 在变基至 db76a91f0cc1afb8b10505a94b0a44cf017aaa69 后的全量精确 head 复审(较此前旧提交 149a7ed12ba92bf7737004263abba17e8ff029bc 的关键更新包括:清除变基冲突、在 loopx/chat/dsh.py 对齐主干 #8905 引入的 from ..chat import _turn_prompt 相对导入、以及将 top_level_module_budget.json 的基线与上限从旧提交的 124→121 更新为当前主干基线 122→119)。依据 docs/architecture/rfcs/monorepo-distribution-split-v0.md @ 16f418837c87ab40f04ff303962598f5bd71a034,PR 采用“纯内部搬迁删除旧模块 + 全仓同步导入 + 英文/中文 RFC 成对更新 + 预算单向收紧”的零债方案。

将仅在内部消费的附件大小与格式校验、DSH 托管片段适配器和 Operator 凭据路由 Mixin 直接归位到 loopx/chat/ 并取消全部顶层兼容 shim,不引入新抽象、开关或兼容桥,同时同步修复双语 RFC 路径并把顶层预算按实际净减少量从 122 降至 119,是符合 M1 与 I3 的最小可逆切分。

当前 PR 边界(current_pr_boundary):本 PR 仅处理 chat_attachments、chat_dsh 与 chat_operator_provider_api 三个已清点叶子模块及其全仓调用方与双语 RFC 引用,保持与并行 PR #9196 搬迁目标完全正交,其余顶层模块留待后续批次。

变基与导入流向对比:

旧 head 149a7ed12b (pre-rebase, budget 124->121) ──[rebase onto db76a91f0c + #8905 _turn_prompt]──▶ 新 head 01bd56d3be528a2b50f8c901fe9407b0681af8c2
loopx/chat_{attachments,dsh,operator_provider_api}.py ──[git mv, 零 shim]──▶ loopx/chat/{attachments,dsh,operator_provider_api}.py (122->119)

具体改动 / Changes

依据规范 docs/architecture/rfcs/monorepo-distribution-split-v0.md(修订 16f418837c87ab40f04ff303962598f5bd71a034)逐条核验:

  • M1(implemented):loopx/chat_attachments.py、loopx/chat_dsh.py、loopx/chat_operator_provider_api.py 通过 git mv 迁入 loopx/chat/,由 tests/test_chat_internal_module_layout.py 断言其 __module__ 均位于 loopx.chat.*。
  • I3(implemented):经核查 loopx/__init__.py 与 loopx/chat.py 均未对外重导出这 3 个内部模块;PR 同步更新全部 23 处内部调用方、测试与示例 smoke(含 loopx/presentation/、loopx/extensions/lark/、loopx/capabilities/native_chat/ 与 loopx/chat_*.py),且不保留任何顶层兼容 shim;同时成对同步了 docs/architecture/rfcs/harness-selection-dsh-pi-v0.md 与 .zh-CN.md 中对 loopx/chat/dsh.py 的路径引用。
  • Section 9 row 1(implemented):tests/architecture/top_level_module_budget.json 将 baseline_commit 固定为 db76a91f0cc1afb8b10505a94b0a44cf017aaa69 并将 max_top_level_modules 从 122 精确下调至 119(实测 ls -1 loopx/*.py | wc -l 为 119)。

关键代码讲解

  1. DshChatAdapter(loopx/chat/dsh.py#L87-L309):负责管家通道的受控单段 DSH 只读执行(固定 STEWARD_SEGMENT_ENV = {"DSH_PERMISSION_MODE": "read-only"} 与单槽位并发拒绝 MANAGED_HOST_CHAT_SEGMENT_IN_FLIGHT)。搬迁与变基后,相对导入精确更新为 from ..chat import _turn_prompt, parse_agent_response、from ..chat_agent import ...、from ..control_plane.turn_driver.host_binding import dsh_output_token_budget 与 from ..dsh_goal_mode.turn_host_adapter import ...,同目录 loopx/chat/endpoint_catalog.py#L20 改为 from .dsh import STEWARD_SEGMENT_ENV,上游 loopx/chat_runtime.py#L47 改为 from .chat.dsh import DshChatAdapter。
  2. normalize_chat_image_attachments(loopx/chat/attachments.py#L49-L100):负责对 Chat 图片附件的 base64 编码、MIME 白名单、5MB/12MB 大小上限及 bool 非法整数类型执行严格校验。搬迁后全部内部消费者——包含 loopx/chat_agent.py#L1545、loopx/chat_ingress.py#L455、loopx/chat_runtime.py#L423、loopx/chat_server.py#L27、loopx/chat/result_files_api.py#L9、loopx/capabilities/native_chat/*、loopx/extensions/lark/* 与 loopx/presentation/codex_attached_api.py#L15——均已切换至 loopx.chat.attachments。
  3. OperatorProviderRequestMixin(loopx/chat/operator_provider_api.py#L35-L110):为个人工作台提供 /api/chat/operator-credential 的只写凭据更新与脱敏状态读取。搬迁后顶部导入更新为 from ..control_plane.operator_provider import ...,消费方 loopx/presentation/configuration_api.py#L20 改为 from ..chat import operator_provider_api as operator_api。
  4. ChatRuntimeController.submit_turn(loopx/chat_runtime.py#L405-L426):在入队或提交回合前懒导入 from .chat.attachments import require_text_document_route 校验文本附件通道授权边界,确保无兼容 shim 情况下入口校验路径保持不变。

对主干的风险 / Risks

  • 全仓残留扫描与负向/反事实检查(PASS):在独立干净工作树(重装可编辑 loopx 验证 loopx.__file__ 与 loopx.chat.__path__ 指向当前 PR 检出目录后)执行全仓 rg -n "\bchat_(attachments|dsh|operator_provider_api)\b",确认除 tests/test_chat_internal_module_layout.py 负向断言与 tests/test_chat_dsh_adapter.py 别名外零残留旧引用;Python 负向检查验证 importlib.util.find_spec 对 loopx.chat_attachments、loopx.chat_dsh、loopx.chat_operator_provider_api 均返回 None,且 normalize_chat_image_attachments 拒收 size: True、normalize_chat_attachments 拒收未知 kind。
  • 验证矩阵与范围说明(PASS):
    • 24 个架构、Chat 与 Lark 定向 pytest 套件:1630 passed(tests/architecture/*、test_chat_*、test_lark_*、test_audit_cli_and_runtime_fixes.py、test_manager_context_roundtrip.py、test_goal_activation.py 全部通过)。
    • 真实入口 smoke:examples/loopx-managed-turn-operator-flow-smoke.py 输出 5 项检查 ok: true;examples/loopx-steward-managed-chat-smoke.py 因本地未安装可选包 deepseek-harness-sdk 退出 0 并输出 skip: deepseek-harness-sdk is not installed(UNVERIFIED 真实外部 SDK 调用,已由 test_chat_dsh_adapter.py 与 loopx-managed-turn-operator-flow-smoke.py 覆盖适配器逻辑)。
    • 静态与门禁检查:ruff check(29 个修改 .py 文件全通过)、mypy(17 个 strict 文件全通过)、scripts/check_rfc_bilingual.py --base origin/main --head HEAD 通过(成对验证 harness-selection-dsh-pi-v0 EN/ZH)、git diff --check 通过、loopx check(32 个文件 errors=0)通过、canary premerge 在隔离 HOME 下 6/6 直接检查 + 2/2 目录 canary + 8/8 风险 smoke + 1/1 边界检查全部 PASS(11/11 selected checks, 0 failures)。
  • 并发与主干推进说明(非阻断):审查期间 origin/main 已合入 PR #9193 推进至 202d7bdb05(零文件重叠,GitHub 状态为 MERGEABLE、BEHIND),故 canary premerge 在最新 origin/main 下的 scope_fingerprint 未命中作者先前在 db76a91f0c 记录的 CQR(cqr_a97ef1e293d78a18e0b2)。另本 PR 与并行 M1 PR #9196 均为 122 -> 119 棘轮,先合入一方后,另一方只需按 119 -> 116 重演预算与 test_chat_internal_module_layout.py / chat_runtime.py 的单行 rebase 即可。

我的整体评价 / Verdict

本 PR 为 justified_increment:干净完成对 db76a91f0c 的变基并补齐了 #8905 带来的相对导入对齐与双语 RFC 同步,将 3 个内部 Chat 叶子模块无 shim 归位至 loopx/chat/ 且把顶层预算从 122 准确压低至 119。

  • Long-horizon(improved):loopx/ 顶层模块降至 119 且由布局测试锁死无 shim 约束,清晰划分内部 Chat 模块边界。
  • User experience(preserved)与 Visual review(not_applicable):本次仅迁移内部 Python 模块与同步 RFC 路径文字,未改动任何 UI 渲染视图(已核对 loopx/presentation/configuration_api.py 与 loopx/presentation/codex_attached_api.py 仅修改 import 路径,unverified_scope: none)。
  • 语义词表与兼容决策:未新增或改动任何枚举、协议 schema 或行为默认值(semantic_alignment: not_applicable、compatibility_assessment: not_applicable、observable_semantics: equivalent、default_off_isolation: not_applicable)。
  • Exact-head freshness:复核远端 HEAD 仍为 01bd56d3be528a2b50f8c901fe9407b0681af8c2(OPEN、MERGEABLE、wait_for_ci: false),全部本地定向测试、smoke 与静态校验均已在该精确 head 独立通过。

English verdict: APPROVE at exact head 01bd56d (published as COMMENTED review because PR #9179 is author-owned; cleanly rebased onto db76a91 with dsh._turn_prompt aligned, 3 internal Chat leaf modules moved to loopx/chat/{attachments,dsh,operator_provider_api}.py with zero shims, bilingual RFC refs updated symmetrically, budget ratcheted 122 -> 119, 1630 pytest cases + operator-flow smoke + ruff + mypy + canary premerge 11/11 PASS; optional deepseek-harness-sdk smoke skipped due to uninstalled optional package).

@mergify

mergify Bot commented Nov 21, 2026

Copy link
Copy Markdown

This pull request has merge conflicts with main and cannot be merged
until they are resolved. Please rebase or merge the base branch, @loopx-agent.

Choose the remote for the base repository, not an out-of-date fork.
For a fork clone, first inspect git remote -v; upstream must point
to https://github.com/loopx-project/loopx.git. If it is absent, add it
with git remote add upstream https://github.com/loopx-project/loopx.git.
Then run:

git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEAD

For a same-repository clone whose origin points to
https://github.com/loopx-project/loopx.git, use origin instead of
upstream for fetch/rebase. If you prefer merging the base, use
git merge <base-remote>/main and push normally.

Keep the DCO Signed-off-by trailer on every commit when you rebase.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 21, 2026

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

评审固定提交 01bd56d3be528a2b50f8c901fe9407b0681af8c2,merge base db76a91f0cc1afb8b10505a94b0a44cf017aaa69。与核对时 main a6ffb3be6e7bdb48e02311ec58d618200fe0501c 的三方整合在预算清单处有冲突。

[P2 · Blocking] 合并后预算必须钉在 118,当前两个冲突版本均不满足

三方整合只在 top_level_module_budget.json 产生冲突。组合树实测 118 个顶层 Python 文件;采用 main 的 121 或 PR 的 119 均被同一预算测试拒绝。临时仅将组合树的清单重算为 118 后,两份树各 108 项定向测试通过。 在当前 main 上同步或变基,保留 #8934 已有净减后的 121 下限并再减本 PR 的三项,将组合预算钉为 118,保留原 allowlist 和实际测量的基准,提交新精确头。 候选位置 已有 Gemini 评审

动机 / Motivation

M1 将附件、DSH 和 Operator Provider 三个内部 Chat leaf 移至 loopx/chat,保留原调用、HTTP 与运行时,按实际净减少量同步收紧顶层模块预算。 原 PR merge base 还有 122 个顶层模块;当前 main 已因 #8934 去除另一个顶层模块,实测 121、预算 121。 PR 将三个 leaf 无 shim 迁移并把自己分支的预算调为 119。双语 RFC 与调用方同步,现有行为仍由相同的实现提供。

用 Git 三方合成源码枚举包顶层文件,在相同树上逐一将原 main、PR 及修正的精确清单交给现有 ratchet 测试。另在确切源码与临时组合树行使附件、DSH、Operator 凭据和 Lark 消费入口。 组合反例仅在快速本地候选上把一个清单值从冲突改成 118。实际 PR 分支仍有冲突,需作者新 head。真实可选 DSH SDK、生产 Lark 和托管 CI 未验收。环境最初从共享 editable venv 读到了旧文件;排除其导入钩子后重新验证精确树和临时组合树。 现有交付规则

改动思路 / Approach

普通运行和受管入口保持既有语义。没有新默认开关或迁移流程,仍由原 settings、HTTP 和队列入口触发。 三处 owner 的附件验证、DSH 只读片段和 Operator Provider 配置保持现有入口。私有路径的导入调整不改公开 API 或能力权限。 组合需要保留第三方先行落地的净减,并使本轮迁移的三项预算净减持续可回读。

具体改动 / Changes

完整 diff 共 32 个文件,新增 48 行、删除 39 行。32 个文件中只有三处 leaf 重定位、对应 import 与双语文档路径、预算和布局测试。附件文件的源码对象直接复用,另两处实际逻辑未变。

  • M1 归位和 I3 内部边界。迁移三个内部 owner、维护原入口且不留已判定无公共消费者的旧 shim。

  • 同 PR 收紧预算。当前主干的 121 再净减三项,组合预算必须等于 118。

  • 双语和真实入口核验。同步两份 RFC,原附件、DSH 与控制路由在实际包中可用。

  • max_top_level_modules。固定应与支撑树的实测顶层 Python 文件数相等。 精确代码

  • test_top_level_module_count_stays_at_the_pinned_budget。拒绝大于预算和绕过应有的预算净减。 精确代码

  • normalize_chat_attachments。原附件校验 owner 下移。 精确代码

  • DshChatAdapter。受管 DSH 原单段只读入口。 精确代码

  • OperatorProviderRequestMixin。原设置 API 的凭据读写入口。 精确代码

对主干的风险 / Risks

隔离解释器的精确头与仅调整清单的组合树各 108 项测试通过。原 DSH managed-turn operator flow 各通过五项,双语差异通过。标准 Chat bundle 和 wheel 构建通过,独立环境能导入三个新所有者,旧路径不可导入。

PR merge base 的 122 与当前 main 的 121 均各自在自己的源码树正确;PR head 的 119 也与本分支源一致。合成源码的元素集合与两侧都不同,实际数目为 118。 当前 GitHub 显示 CONFLICTING。现有 Gemini 结论对应同一代码树在旧主干的判断,保留其证据;新的组合条件明确阻塞。

我的整体评价 / Verdict

REQUEST_CHANGES。 请按 118 修复预算清单后回读新精确头。三个 leaf 的代码、隔离运行和安装导入已验证。当前分支与主干合成仍阻塞。

English verdict: REQUEST_CHANGES. The relocation and installed imports pass. Current main yields 118 top-level modules with the three moves, so neither side's conflicting 121 or 119 manifest can pass the exact-count gate.

…odule budget

Implements the next monorepo-distribution-split-v0 (#5072) M1 internal leaf migration without permanent top-level compatibility shims:

- Move loopx/chat_operator_provider_api.py -> loopx/chat/operator_provider_api.py
- Move loopx/chat_attachments.py -> loopx/chat/attachments.py
- Move loopx/chat_dsh.py -> loopx/chat/dsh.py
- Update internal relative imports, callers, tests, smokes, layout guards, and symmetrical RFC references
- Ratchet tests/architecture/top_level_module_budget.json from 121 to 118 at baseline 06fd6fe

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
@loopx-agent
loopx-agent force-pushed the codex/m1-chat-leaf-move-20261121 branch from 01bd56d to 8c1d8fe Compare November 22, 2026 00:00
@mergify mergify Bot removed the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 22, 2026

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

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

Reviewer: model_agent · Gemini · Google · self_reported

动机 / Motivation

本次改动直接面向需要按包目录划分所有权并拆分 loopx-core 与 loopx-workspace 分发包的维护者,以及调用内部 Chat 附件校验、管家 DSH 分段执行与运维凭据路由的运行时和扩展模块(覆盖 chat_server、chat_runtime、chat_ingress、chat_agent、presentation、extensions/lark 与 capabilities/native_chat)。

迁移前(06fd6feeab 主干基线),loopx/ 顶层仍平铺 121 个 .py 模块,三个内部叶子模块loopx/chat_attachments.py、loopx/chat_dsh.py 与 loopx/chat_operator_provider_api.py 与核心内核模块混排;早期分支修订 01bd56d3be 曾因基于旧主干 122 -> 119 变基而与已由 #8934 减至 121 的当前主干在 top_level_module_budget.json 上冲突。迁移后(精确 head 8c1d8fe1ff),三份模块无兼容 shim 地归位到 loopx/chat/ 并同步 20 处内部生产调用方、测试、smoke 与双语 RFC 引用,预算基线同步重算并棘轮收紧至 118,消除了三方合并冲突。

可验证的结果是:loopx/*.py 顶层模块实测从 121 净减至 118,tests/architecture/top_level_module_budget.json 锁定 118(基线 06fd6feeab08dc8c9d75ccf6050a16126fbc606d)且无冲突;importlib.util.find_spec 对三处旧顶层模块路径均返回 None;附件校验拒收、DSH 只读分段隔离、Operator 凭据只写脱敏和定向 pytest 与 canary premerge 均与基线完全等价。

本 PR 不改动附件大小/类型阈值、文本附件路由授权、DSH 单段只读沙箱策略或 /api/chat/operator-credential 接口协议,不保留永久顶层兼容 shim,也不负责完成 #5072 后续批次的其余 chat_* 与 *_goal_mode 目录迁移。

#5072 M1/M2 下其余顶层 chat_* 与 *_goal_mode 模块迁移及 M3 分包发布仍待后续批次推进;本地环境未安装可选包 deepseek-harness-sdk,因此 examples/loopx-steward-managed-chat-smoke.py 跳过真实 SDK 调用,且未运行全仓全部 pytest 套件及远端托管 CI(wait_for_ci: false)。

不做此次迁移会让平铺的内部 Chat 辅助文件继续阻塞 loopx-core 与 loopx-workspace 的目录边界收口,也会让 PR #9179 停留在旧预算 119 无法干净并入已降至 121 的主干。本 PR 把三个内部叶子一次性归位并把预算精确压到 118,形成一个独立可测、可直接回滚且不留兼容债的增量交付。

改动思路 / Approach

维度 基线 06fd6feeab 当前 HEAD 8c1d8fe1ff 架构约束
模块落点 loopx/chat_{attachments,dsh,operator_provider_api}.py loopx/chat/{attachments,dsh,operator_provider_api}.py 复用 loopx/chat.py 的 __path__ 命名空间包,无 __init__.py
兼容桥接 顶层文件直接存在 零永久 shim,删除旧入口 依据 I3 仅更新内部调用方,由 find_spec 确认不可解析
相对导入 同级 .chat / .control_plane 子包内 ..chat / ..control_plane / 同级 .attachments 导入图与延迟加载时机保持等价
预算棘轮 max_top_level_modules: 121 max_top_level_modules: 118 baseline_commit 对齐当前主干 06fd6feeab,净减 3

三个被迁移模块均为纯内部实现组件:附件校验与文本路由限制属于无状态策略与校验规则,DSH 分段适配器和 Operator 凭据 Mixin 分别承担单一 provider IO 与 HTTP 凭据投影职责;将三者直接收归 loopx/chat/ 命名空间包(由 loopx/chat.py 保留 __path__ 入口且不新建 __init__.py),同时删除无公开消费者的顶层旧入口并保持既有默认开关与失败语义不变,符合最小单向收紧与不重复引入兼容胶水的架构原则。

本 PR 的边界严格限定为重定位 attachments.py、dsh.py 与 operator_provider_api.py 三个内部叶子模块、同步全仓 20 个生产模块/7 个测试/2 个 smoke/1 组成对中英文 RFC 中的引用、扩展无 shim 布局断言并将顶层预算从 121 精准下调至 118,不顺带重构周边业务逻辑或触碰并行迁移目标。

在正向调用路径上,ChatConfigurationRequestMixin 通过 from ..chat import operator_provider_api 挂载 /api/chat/operator-credential;ChatRuntimeController 与 builtin_chat_endpoints 从 loopx/chat/dsh.py 加载 DshChatAdapter 与 STEWARD_SEGMENT_ENV;HTTP、Lark 扩展、原生 Chat adapter 与结果文件 API 统一从 loopx/chat/attachments.py 导入图片与文本文档校验函数。反向对比表明:loopx/__init__.py 与 loopx/chat.py 均未对外重导出这三个模块,因此不保留兼容桥接也不会破坏公开契约,且后续目录包拆分不必再维护两份入口。

具体改动 / Changes

依据规范 docs/architecture/rfcs/monorepo-distribution-split-v0.md(基线修订 16f418837c87ab40f04ff303962598f5bd71a034)及当前精确提交 8c1d8fe1ff2659eef6461a5bb4a52e274c020561,逐项验收准则映射如下:

Criterion ID 规范要求 Disposition 验证符号与证据
M1-LEAF M1 将内部 loopx/chat_* 叶子模块迁入 loopx/chat/ 并同步相对导入 implemented loopx/chat/attachments.py、loopx/chat/dsh.py、loopx/chat/operator_provider_api.py;tests/test_chat_internal_module_layout.py
I3-NO-SHIM I3 纯内部搬迁同步更新全部活跃调用方并删除旧顶层入口 implemented 全仓 rg 零残留引用;tests/test_chat_internal_module_layout.py 校验 importlib.util.find_spec 返回 None
SEC9-BUDGET Section 9 同 PR 下调 top_level_module_budget.json 并锁定实际净减 implemented tests/architecture/top_level_module_budget.json(121 → 118);tests/architecture/test_top_level_module_budget.py
RFC-BILINGUAL 同步更新引用路径的双语成对 RFC 文档 implemented docs/architecture/rfcs/harness-selection-dsh-pi-v0.md、.zh-CN.md;scripts/check_rfc_bilingual.py --base origin/main --head HEAD

全量 diff 共 32 个文件(+48 / -39 行):3 个 git mv 迁移(attachments.py 零行改动,dsh.py +4/-4 行相对导入调整,operator_provider_api.py +1/-1 行相对导入调整)、17 个生产调用方模块 import 路径更新、7 个测试文件与 2 个 example smoke 更新、1 组成对中英文 RFC 路径更新(loopx/chat_dsh.py → loopx/chat/dsh.py),以及 tests/architecture/top_level_module_budget.json 预算从 121 更新至 118。

关键代码讲解

  1. DshChatAdapter(loopx/chat/dsh.py#L35-L43,L87-L309):管家通道的受控单段 DSH 只读传输,内部将 .chat、.chat_agent、.control_plane.turn_driver.host_binding 与 .dsh_goal_mode.turn_host_adapter 调整为 .. 父包导入。在 _run_segment 中通过 segment_env.update(STEWARD_SEGMENT_ENV) 强制覆盖 DSH_PERMISSION_MODE="read-only",并通过 _claim_segment_slot 单线程槽位锁拒绝并发第二段(错误码 MANAGED_HOST_CHAT_SEGMENT_IN_FLIGHT)。上游消费者 ChatRuntimeController.submit_turn 与 managed_host_capability 已分别切至 from .chat.dsh import DshChatAdapter 与 from .dsh import STEWARD_SEGMENT_ENV。
  2. normalize_chat_attachments 与 require_text_document_route(loopx/chat/attachments.py#L1-L190):纯标准库附件与通道边界校验,继续限制单次最多 4 个附件、单图 5MB、总图 12MB、总信封 64KB、拒绝 bool 型 size 与未知字段,并将文本附件限制在本地 web 来源的 codex managed_runtime 会话。全仓调用方(含 loopx/chat_server.py、loopx/chat_ingress.py、loopx/chat_runtime.py#L423、loopx/chat_agent.py、loopx/chat/result_files_api.py、loopx/presentation/codex_attached_api.py、loopx/extensions/lark/* 与 loopx/capabilities/native_chat/*)全部同步更新,且保留 normalize_local_chat_attachments 等既有符号名。
  3. OperatorProviderRequestMixin(loopx/chat/operator_provider_api.py#L21-L110):提供个人工作台 /api/chat/operator-credential 的只写写入与脱敏读回,迁入子包后仅将顶层导入改为 from ..control_plane.operator_provider import ...,由 ChatConfigurationRequestMixin 通过 from ..chat import operator_provider_api as operator_api 继承挂载,异常码 invalid_operator_credential(400)与 operator_credential_write_failed(500)保持不变。
  4. top_level_module_budget.json 与 test_chat_internal_module_layout.py:在当前主干 06fd6feeab(121 个顶层模块)之上将 max_top_level_modules 准确下调至 118,保留 allowlist 三项不动;布局测试同时验证三处新模块 __module__ 归属及旧顶层模块 find_spec 为 None。

对主干的风险 / Risks

  • 上次阻塞项已验证清除:此前在旧提交 01bd56d3be 上提出的 [P2 · Blocking] 合并预算冲突(当时 PR 预算 119、主干 121、合成 118)已随着变基到 06fd6feeab08dc8c9d75ccf6050a16126fbc606d 彻底解决。当前独立工作树实测 ls -1 loopx/*.py | wc -l 精确等于 118(仅移除了 chat_attachments.py、chat_dsh.py 与 chat_operator_provider_api.py),GitHub 合并状态为 MERGEABLE,不再存在结构冲突。
  • 全仓残留与负向边界探针(PASS):全仓 rg 扫描确认除 tests/test_chat_internal_module_layout.py 中有意断言 find_spec 返回 None 的三条测试列表外,零残留 loopx.chat_attachments、loopx.chat_dsh、loopx.chat_operator_provider_api 或对应 .py 引用。在精确 head 隔离环境中实测:importlib.util.find_spec 对三处旧路径均返回 None;normalize_chat_image_attachments 拒绝 size: True;normalize_chat_attachments 拒绝未知字段;require_text_document_route 拒绝 steward_context 会话上传文本附件;DshChatAdapter 在 credential 试图注入 DSH_PERMISSION_MODE="full-access" 时仍强制覆盖为 "read-only";OperatorProviderRequestMixin 验证合法密钥只写不回显及非法参数返回 400 invalid_operator_credential。
  • 与基线的对照测试与验证矩阵:
    • 基线 06fd6feeab08dc8c9d75ccf6050a16126fbc606d 与精确 head 8c1d8fe1ff2659eef6461a5bb4a52e274c020561 在独立可编辑安装(分别核对 loopx.__file__ 指向各自隔离检出目录)上执行同一组 5 个架构与核心 Chat 单元测试(test_top_level_module_budget.py、test_chat_internal_module_layout.py、test_chat_image_attachments.py、test_chat_dsh_adapter.py、test_chat_endpoint_readiness.py):基线 PASS(36 passed in 0.82s),当前 head PASS(36 passed in 0.64s);examples/loopx-managed-turn-operator-flow-smoke.py 在双端均输出完全一致的 5/5 检查 PASS。
    • 核心与扩展测试套件:10 个架构/Chat/审计/roundtrip 文件串行运行 PASS(254 passed in 84.30s);tests/test_operator_provider.py + tests/test_chat_executor_profile.py + tests/test_chat_runtime_activation.py PASS(73 passed in 2.09s);tests/test_chat_machine_configuration_api.py PASS(20 passed in 5.86s)。
    • tests/test_lark_private_conversations.py:首次以 -n auto 并发执行 11 个文件合并套件时,test_recovery_waits_for_inflight_capture_without_readmitting[True] 在高并发文件锁争用下出现 1 次 LockAcquireTimeoutError(843 passed, 1 failed);随后单独复测该用例 PASS(2 passed in 2.64s),并以有界并发 -n 2 完整运行 tests/test_lark_private_conversations.py 全集 PASS(590 passed, 1 warning in 343.55s;1 条既有线程超时告警来自 test_group_control_does_not_require_display_service)。该锁超时属于高并发压测下的既有测试时序敏感问题,不构成由 import 路径搬迁引入的回归。
    • 静态与门禁检查:ruff check(29 个修改 .py 文件)PASS;python -m mypy(17 个配置严格检查文件)PASS;scripts/check_rfc_bilingual.py --base origin/main --head HEAD PASS;git diff --check origin/main...HEAD PASS;loopx check --scan-path ...(32 个变更文件)PASS(errors: 0, warnings: 0);隔离 HOME 下 loopx canary premerge --from-git-diff --git-diff-base origin/main PASS(direct_checks: 6/6,selected_checks: 11/11,catalog_run: 2/2,risk_profile_run: 8/8,boundary_run: 1/1,failure_count: 0)。
    • 真实外部依赖与跳过项:examples/loopx-steward-managed-chat-smoke.py 退出 0 并打印 skip: deepseek-harness-sdk is not installed,真实 deepseek-harness-sdk 调用在本机处于 UNVERIFIED;全仓全部 pytest 及远端 CI(wait_for_ci: false)未执行。

我的整体评价 / Verdict

本 PR 为 justified_increment:在不改变任何公开契约、权限边界或默认行为的前提下,干净地将 3 个内部 Chat 叶子模块迁入 loopx/chat/,消除了前一版与主干的预算冲突并把 max_top_level_modules 精确棘轮压低至 118。

  • Long-horizon(improved):loopx/ 顶层模块从 121 降至 118,并通过无 shim 布局断言与预算棘轮固化目录边界,使 #5072 的 M1 分包与 CODEOWNERS 收敛可持续推进。
  • User experience(preserved)与 Visual review(not_applicable):本次仅调整内部 Python 模块位置、import 路径与文档引用,未修改任何前端页面或渲染模板;已核对 loopx/presentation/configuration_api.py 与 loopx/presentation/codex_attached_api.py 仅更改单行导入语句,UI 视觉检查不适用(unverified_scope: none)。
  • 语义词表与兼容评估:未新增、扩展或变更任何状态枚举、schema 字段、协议字面量或配置开关(semantic_alignment: not_applicable;compatibility_assessment: not_applicable;default_off_isolation: not_applicable;authority_semantics: not_applicable);observable_semantics 在不变基线 06fd6feeab08dc8c9d75ccf6050a16126fbc606d 与当前 head 8c1d8fe1ff2659eef6461a5bb4a52e274c020561 的同命令、同探针对比下保持完全等价(equivalent)。
  • 代码体量与残余风险:全量 32 个文件变更均为机械性路径重定位、import 更新及必须的布局/预算守卫(code_volume: necessary,change_proportionality: proportionate),无冗余抽象;唯一环境未覆盖项为可选外部包 deepseek-harness-sdk 实跑步骤跳过与全仓全量测试。复核远端 PR #9179 最新 head 仍为 8c1d8fe1ff2659eef6461a5bb4a52e274c020561(OPEN、MERGEABLE、wait_for_ci: false)。

English verdict: APPROVE at exact head 8c1d8fe (published as COMMENTED review because PR #9179 is author-owned; resolved prior budget conflict at baseline 06fd6fe with top_level_module_budget ratcheted 121 -> 118, zero stale imports, 254 + 590 + 73 + 20 targeted pytest cases, ruff, mypy, bilingual RFC diff check, loopx check, and canary premerge 11/11 PASS; optional live deepseek-harness-sdk smoke skipped due to uninstalled SDK).

@loopx-agent
loopx-agent merged commit 4052e3f into main Nov 22, 2026
38 of 67 checks passed
@loopx-agent
loopx-agent deleted the codex/m1-chat-leaf-move-20261121 branch November 22, 2026 00:18
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