Skip to content

refactor(control-plane): extract quota registry and pause read models - #2962

Merged
huangruiteng merged 1 commit into
mainfrom
codex/q3-quota-should-run-20260808
Aug 8, 2026
Merged

refactor(control-plane): extract quota registry and pause read models#2962
huangruiteng merged 1 commit into
mainfrom
codex/q3-quota-should-run-20260808

Conversation

@huangruiteng

Copy link
Copy Markdown
Owner

Summary

Q3 first extraction slice for quota should-run.

  • Move registry_goal_by_id into
    loopx/control_plane/quota/goal_boundary.py.
  • Move _quota_item_is_paused into loopx/control_plane/quota/states.py.
  • loopx.quota now imports both read models from bounded quota modules.
  • loopx/quota.py shrinks from 2946 to 2880 lines.

No runtime behavior changes.

Validation

  • python -m pytest tests/control_plane/test_quota_should_run_parity.py tests/control_plane/test_quota_plan_policy.py tests/control_plane/test_quota_paused_precedence.py: 23 passed.
  • loopx canary premerge --from-git-diff: passed, self_merge_allowed=true,
    0 manual holds.
  • Public boundary scan: passed.

Routing

  • continuation-policy: independent_handoff
  • excluded-agent: codex-quality-qualification
  • claimed-by: codex-side-bypass

@huangruiteng
huangruiteng force-pushed the codex/q3-quota-should-run-20260808 branch from f9f0108 to a385ac6 Compare August 8, 2026 20:43

@huangruiteng huangruiteng left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review: REQUEST_CHANGES

head a385ac66dd0630e7959529cea585970197bda9d1。这是对 refactor(control-plane): extract quota registry and pause read models 的完整 PR 解读,覆盖 3 个改动文件、两个 read-model 提取、loopx.quota facade 兼容性与 CI。GitHub 不允许作者审批自己的 PR,因此以 COMMENTED 发布作者自有回退态,但评审结论是 REQUEST_CHANGES:当前 head 有一个明确、可复现的 P1。

动机

loopx/quota.py 已经是大模块,PR 想把 registry_goal_by_id_quota_item_is_paused 这两个纯读模型移到 quota bounded context 的最近 owning module,让 loopx.quota 继续作为兼容 facade 暴露公共导出,同时降低 quota.py 的体积。这个方向本身正确,也符合“按调用结果归属能力、把规则放进最近 owning module”的边界原则。

改动思路

改动是纯机械移动加 facade 接线:

  • registry_goal_by_idloopx/quota.py 移到 loopx/control_plane/quota/goal_boundary.py
  • _quota_item_is_pausedloopx/quota.py 移到 loopx/control_plane/quota/states.py,并改名为 quota_item_is_paused
  • loopx.quota 通过 alias import 继续把两者暴露出来,保持调用方兼容;
  • quota.py 从 2946 行降到 2880 行。

具体改动

  • loopx/control_plane/quota/goal_boundary.py:新增 registry_goal_by_id(status_payload),读取 registry JSON 并返回 {goal_id: goal};异常或非法结构返回 {}
  • loopx/control_plane/quota/states.py:新增 quota_item_is_paused(item),检查 quota.state == "paused"compute <= 0,与旧实现语义一致。
  • loopx/quota.py:删除两个本地函数定义,改为 _registry_goal_by_id / _quota_item_is_paused alias import。

关键代码讲解

  1. registry_goal_by_id():输入 status payload 的 registry 路径,输出按 goal id 索引的 dict。无法读取或非 dict goals 时返回 {},与旧 _registry_goal_by_id 行为一致。
  2. quota_item_is_paused():输入 plan item,判断 Goal-level hard pause;state == "paused"compute 为数值且 <= 0 时返回 True。bool 不计入数值,保留旧语义。
  3. loopx.quota facade:import json 仍留在模块顶部,但移动后 json 已没有任何本地调用点。这个残留不是无害的:它让 loopx.quota 的模块级公共绑定多出 json,触发 import-boundary audit。

正向路径

PR 合入后,loopx.quota 继续公开 registry_goal_by_idquota_item_is_paused,调用方无需改动;quota bounded context 内可以直接 import 这两个 read model;quota.py 体积下降。

负向路径

当前 head 的负向路径已经发生:loopx/quota.py:3import json,但文件内已无 json 使用。ruff checkF401 json imported but unusedtests/architecture/test_control_plane_import_boundaries.py::test_public_facade_import_only_reexports_match_the_audited_allowlist 失败,因为 loopx.quota 的 import-only bindings 比 audited allowlist 多了一个 json。GitHub pytest 也是同一失败:1 failed, 2304 passed

对主干的风险

P1:loopx.quota 是核心公共 facade,不能带着未经审计的额外模块级导出合入。修复很小:删除 loopx/quota.py 顶部的 import json,然后跑 ruff check 与完整 pytest。tests/control_plane/test_quota_should_run_parity.pytest_quota_plan_policy.pytest_quota_paused_precedence.py 本地 23 passed,说明逻辑移动本身没有破坏行为;失败完全来自残留 import。

我的整体评价

提取方向正确,两个 read model 语义也保持住了,但当前 head 不能合并:一个未使用的 import json 同时触发 ruff 和公共 facade audit,属于明确的一行修复。移除后需要重新跑完整 pytest 并确认 test_public_facade_import_only_reexports_match_the_audited_allowlist 通过。


English Verdict

Request changes (author-owned fallback; cannot formally submit). Head a385ac66dd0630e7959529cea585970197bda9d1. The quota read-model extraction is correct and 23 focused tests pass, but loopx/quota.py still contains an unused import json. This triggers ruff F401 and breaks the public-facade import-boundary audit (loopx.quota exposes json outside the allowlist); GitHub pytest is red. Remove the import, rerun ruff and full pytest, then re-review.

@huangruiteng
huangruiteng force-pushed the codex/q3-quota-should-run-20260808 branch from a385ac6 to 1ebba9c Compare August 8, 2026 20:51

@huangruiteng huangruiteng left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review: APPROVED

head 1ebba9c7bdcb6d93cbb6f298d94bf0b824c90f42。这是对 PR #2962 新 head 的完整 re-review。上一轮的唯一 blocker(loopx/quota.py 残留 import json)已修复,当前未发现剩余 blocker。GitHub 不允许作者审批自己的 PR,因此以 COMMENTED 发布作者自有回退态,但评审结论是无 blocker。

动机

loopx/quota.py 是大模块,需要把纯读模型拆到 quota bounded context。上一轮 head a385ac66registry_goal_by_idquota_item_is_paused 移出后,忘了删除 loopx/quota.py 顶部的 import json,导致 ruff F401 和公共 facade import-boundary audit 失败。新 head 删除该 import,逻辑与上一轮一致。

改动思路

仍是一次“机械移动 + facade 接线”:

  • registry_goal_by_id 移到 loopx/control_plane/quota/goal_boundary.py
  • quota_item_is_paused 移到 loopx/control_plane/quota/states.py
  • loopx.quota 通过 alias import 保持兼容;
  • loopx/quota.py 删除残留 import json

具体改动

  • loopx/quota.py:删除 import json,其余保持上一轮提取。
  • loopx/control_plane/quota/goal_boundary.py:新增 registry_goal_by_id(),读取 registry 并按 goal id 建索引,异常返回 {}
  • loopx/control_plane/quota/states.py:新增 quota_item_is_paused(),保留 state == "paused"compute <= 0 语义。

关键代码讲解

  1. registry_goal_by_id():输入 status payload 的 registry 路径,输出 {goal_id: goal};文件不可读或结构非法时返回 {}
  2. quota_item_is_paused():输入 plan item,quota.state == "paused" 或数值 compute <= 0 返回 True,bool 不计入数值。
  3. loopx.quota facade:删除 import json 后,模块级 import-only bindings 不再多出 json,公共 facade 与 audited allowlist 对齐。

正向路径

loopx.quota 继续公开两个 read model;调用方无需改动;quota.py 行数下降;registry_goal_by_idquota_item_is_paused 分别归入 goal-boundary 与 quota states bounded context。

负向路径

上一轮的失败路径已关闭:ruff check 不再报 F401;test_public_facade_import_only_reexports_match_the_audited_allowlist 通过,loopx.quota 不再暴露未经审计的 json。若未来再移动函数,facade audit 会继续防止这种残留 import。

对主干的风险

低。逻辑移动与旧实现一致,新 head 删掉了唯一的残留。验证:23 个 quota 聚焦 pytest + import-boundary 测试共 24 passed;ruff/diff check 通过;loopx canary premerge --from-git-diff 全绿,self_merge_allowed=true。GitHub pytest 当前 in-progress,但本地等价覆盖已通过。

我的整体评价

新 head 完整修复了上一轮 blocker,提取方向正确,facade 兼容性保持,负向测试也覆盖了最容易被忽略的模块级 import。无 blocker,按仓库 merge policy 路由合并。


English Verdict

Approved (author-owned fallback; cannot formally approve). Head 1ebba9c7bdcb6d93cbb6f298d94bf0b824c90f42. The unused import json was removed from loopx/quota.py, closing the previous ruff and public-facade audit failure. 24 focused pytest, ruff/diff checks, and canary premerge pass; no blocking findings.

@huangruiteng
huangruiteng merged commit 2114afe into main Aug 8, 2026
5 checks passed
@huangruiteng
huangruiteng deleted the codex/q3-quota-should-run-20260808 branch August 8, 2026 20:58
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