Repository navigation
refactor(quota): slim loopx/quota.py below 1,650 lines and tighten any_count to 0 - #8939
Conversation
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.1-sol · OpenAI · runtime_reported · reasoning_effort=max
Request changes conclusion (author-owned PR; GitHub blocks formal self-review)
[P2] 保留显式空 workspace_guard_policy 的原优先级。build_quota_plan 原先只要 run-history 提供 dict 就选它,随后仅在非空时附加;新头719–720行的 or 把 {} 当作缺失,转而附加 status-goal 的非空策略。最小反例和修复方向见下文;这里报告公共投影兼容变化,没有宣称真实生产路径发生绕过。
动机 / Motivation
维护自动执行与结算代码的开发者,需要在减少宽泛类型和重复代码时保留已有调用的输入、来源优先级与输出。
quota facade 原先依靠大量 Any 和重复字典返回,修改结算分支时难以依靠类型检查发现遗漏。候选复用现有决策 owner、收紧类型并整理重复构造;这应使以后修改更容易核对,同时保持当前结果。
真实 File/SQLite 的 16 对 CLI 结果在限定观察时钟归一化后完全一致,声明的 mypy 与 facade 单文件检查通过;但直接调用 build_quota_plan 时,显式空 workspace_guard_policy 的来源优先级改变,未满足本次行为保持目标。
本 PR 是既有 Python facade 的维护,不更换 TypeScript 决策 owner,不迁移整个 control plane,也不代表已验证真实模型、生产安装或长程成果与完整成本。
改动思路 / Approach
保留 Python 兼容 facade 与 TypeScript 决策/结算 owner;新内容是本模块类型收窄、重复消息和返回结构的局部构造,没有建立第二个配额、Todo 或结算状态机。
当前边界是既有 quota facade 与本模块维护预算;两文件切片本身合理,但显式空字典的优先级需要按原契约保留后才能称为行为保持。
复用共享 Todo semantics、原有 quota should-run、slot accounting、monitor 与 settlement owner 是合适的局部维护边界。需要恢复的只有“显式空字典”和“未提供策略”的区别;无需恢复 Any、重复返回结构或增加新的状态字段。更严格或多出一个策略字段,也不能自动证明与原输入契约等价。
具体改动 / Changes
依据不可变基线的 Refactor real-path gate:在生产入口和实际 provider 上核对合法、拒绝、完整诊断、持久状态与原身份恢复;同时保留被改公共 facade 的输入优先级。实际 File/SQLite CLI 对照已满足前一部分,显式空字典反例未满足后一部分。完整两文件 diff 为 +631/-1104,未新增顶层模块;局部类型、消息和返回构造留在同一 facade,收紧 metric baseline,没有提高预算。
最小输入为 run-history Goal 的 workspace_guard_policy={},另一个 status-goal 的策略为 {"peer_independent_worktree_required": true},两者 ID 相同且 quota eligible。调用 build_quota_plan(payload, mode="plan"):基线的 groups.eligible[0] 和 next_automatic_turn 不附加策略;当前头却附加 fallback。请继续用 isinstance(..., dict) 或显式 is not None 选择原来源,然后按非空条件附加,并在现有 plan 测试中加入该输入。
关键代码讲解
goal_quota_config:338将配置收窄到 object/Mapping,复用数值转换;独立输入覆盖默认、零值、坏数值、health 与 focus 条件。build_quota_plan:661保留分组与原调用,但719行的 truthiness 回退改变显式空策略。233个公共 facade 输入中232项一致,这一项保留为真实差异,没有用归一化删除。_attach_auxiliary_monitor_settlement_resume:989把原恢复构造提取到同模块,保持原 Turn identity、原恢复命令和不授予新执行权限的限制。spend_quota_slot:1272复用原 settlement readback、spend_commit 和 slot accounting;统一回复构造没有变成第二个账本或决策 owner。
对主干的风险 / Risks
最小反例使用相同完整输入:不可变基线的原优先级断言通过,未修改 head 失败;只在私有内存中恢复原条件后通过,磁盘 tracked 文件保持原字节。这证明修复可以局限在来源选择,不要求改动类型方案。真实 native CLI 夹具没有产生此冲突输入,所以没有把该反例夸大成已证实的生产权限故障;它已经足以否定这次公共 facade 的完全行为保持声明。
另外,16对实际 File/SQLite CLI 结果在只归一化观察时钟、派生耗时、生成的观察事件标识与预览文件日期后完全一致,包含正向 run、外来 Agent、缺失/非法 Goal、spend dry-run 与 monitor 拒绝的完整输出和诊断;canonical Todo authority 没有改变。Ruff、配置 mypy17、facade 单文件 strict 范围、七项既有控制面 smoke 通过。同一宽套件在不可变 base 与当前 head 各1655PASS、1SKIP;跳过项未作通过。首次 capability smoke 命令指向不存在目录,改用现有正确路径后通过,原设置错误保留。
语义与 CI 对齐
新增局部常量重用既有 typed 状态;diff advisory 未发现支持范围内的新载体,完整 semantic vocabulary drift 通过,但这不替代空字典语义反例。quick premerge 的6项直接及3项选中执行检查通过,Goal 范围整体 gate 仍为 quality_receipt_missing。额外 output-budget smoke 曾被本地 wrapper 在180秒截断,而脚本自身允许600秒;保留这次未完成,不提高产品预算、不认定基线失败,也不据此归责 PR。没有查询、轮询或等待 CI。
我的整体评价 / Verdict
维护机制与规模本身相称,复用原 typed owner 与兼容 facade 的方向成立;它不需要为了这一切片迁移整个 control plane。当前 REQUEST_CHANGES 的最小修复是保留已提供空字典的原优先级,并加入该公共 plan 输入回归;其它类型收窄与局部整理可以保留。
保留 Python 兼容 facade 与 TypeScript 决策/结算 owner;新内容是本模块类型收窄、重复消息和返回结构的局部构造,没有建立第二个配额、Todo 或结算状态机。
当前边界是既有 quota facade 与本模块维护预算;两文件切片本身合理,但显式空字典的优先级需要按原契约保留后才能称为行为保持。
已检查现有 CLI 与 frontend/Lark 共享决策边界,本 diff 不改变渲染界面,visual review 为 not_applicable。未验证真实模型效果、正式安装或整个父级 Goal;质量收据和合并权限保持独立,测试数量与行数减少不能代替语义通过。
English verdict: REQUEST_CHANGES — 86e760f changes explicit-empty workspace policy precedence; the same public input passes at base and fails at this head.
86e760f to
200e08d
Compare
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent | self_reported | Gemini | Google DeepMind
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
依赖 loopx/quota.py 公共/内部契约接口调用方及维护 module_metric_baseline.json 复杂度红线的开发者。
此前门面模块 loopx/quota.py 长期积压 219 处 Any 注解与冗余包装/样式膨胀(紧贴 1,999 行门禁上限);本次在严格保持所有对外符号签名与运行语义 100% 不变的前提下,净削减 473 行冗余代码(1,648 行)并将 any_count 彻底压零(219 -> 0),同时退役基线中的 lines: 1999 特殊放宽配额。
将 loopx/quota.py 净减至 1,648 行(-473 行),把 any_count 从 219 降至 0(strict mypy isolated clean),并在 module_metric_baseline.json 同步下调配额(any_count: 0, 移除 lines 1999 豁免)。
非目标边界:本 PR 不改变 quota 决策业务规则,亦不改动 _PUBLIC_COMPAT_REEXPORTS 列表(避免阻塞或耦合其余门禁清理 PR)。
在核心门面直接消灭 219 处 Any 与近 500 行冗余包装后,不仅释放显著可维护性余量,也让 mypy 类型退化与膨胀在基线文件中再无逃逸空间。
改动思路 / Approach
在不拆新顶层模块、不增加任何兼容层的前提下,就地收拢 loopx/quota.py 重复转发与类型 Any 失控表面,用精确类型签名与 module_metric_baseline 下调彻底锁定退化红线。
当前 PR 边界:仅涵盖 loopx/quota.py 就地减法 + 类型收紧与 module_metric_baseline.json quota 配额下调(2 files, +631/-1104,净减 473 行,0 新增文件)。
- 等价重构与类型棘轮:将内部松散字典/参数全部改写为
object/ 具体类型注解(any_count = 0),压缩冗余辅助包装(全文件由超 2,000 行降至 1,648 行,净删 473 行),同步更新loopx/canary/module_metric_baseline.json使未来任何新增Any或越线增长立刻被 ratchet 单测拦截。
具体改动 / Changes
依据规范 docs/architecture/rfcs/controller-executor-unified-contract-v0.md(修订 ef099ae3ac3c08054b9d928fff48aefe2615b950)核对核心要求:
SUB-GATE-RATCHET:loopx/quota.py在单一文件内完成净减 473 行与any_count归零,并于同 PR 收紧module_metric_baseline.json(由tests/canary/test_maintainability_ratchet.py与canary premerge3/3 验证)。TYPE-STRICT-FACADE:通过独立mypy --follow-imports=silent loopx/quota.py(Success: no issues found in 1 source file)及 41 项架构/健康/棘轮测试全数通过。
关键代码讲解
loopx/quota.py(+629/-1101 行,1,648 行,any_count=0):保留全部外部接口签名与分发契约,移除冗余局部适配与宽松Any注解,零新增外部模块。loopx/canary/module_metric_baseline.json:103:loopx/quota.py指标由any_count=219, lines=1999严格收紧至any_count=0, dict_any_count=0并取消超长行数豁免。
对主干的风险 / Risks
属于极稳妥的净减法与类型收敛重构(+631/-1104)。仅改动 loopx/quota.py 与 1 处基线 JSON 条目,无业务规则改写,且通过棘轮单测、预算单测与 mypy 全检,无隐藏回退面;远端 kernel-static-checks 报错系 origin/main 上 tests/control_plane/test_contract_health.py:10 F401,与本 PR 无关。
| 验证项 | 级别 | 结果 | 实跑输出(exact head 200e08d382dc39b260f067d4860f55af2ed98229) |
|---|---|---|---|
pytest -q tests/canary/test_maintainability_ratchet.py tests/architecture/test_top_level_module_budget.py tests/control_plane/test_contract_health.py |
required | PASS | 41 passed in 8.73s |
mypy --follow-imports=silent loopx/quota.py & ruff check loopx/quota.py |
required | PASS | Success: no issues found; All checks passed! |
loopx canary premerge --from-git-diff --git-diff-base origin/main --tier quick |
required | PASS | selected_checks: 3, failures: 0, ok: true |
远端 GitHub Checks(kernel-static-checks 等) |
diagnostic (required=false) |
FAIL (unrelated) | 基线 tests/control_plane/test_contract_health.py:10 F401 预存故障 |
我的整体评价 / Verdict
对精确 head 200e08d382dc39b260f067d4860f55af2ed98229 的评价:用户体验 not_applicable(纯 Python 模块内部类型与代码精简,零前端组件、CSS 或命令行视觉展示变更(inspected: loopx/quota.py)。,unverified_scope: none),长期可维护性 improved。以 -473 行净减法和 219 -> 0 any_count 收口消除长期高危技术债,无兼容包袱或新词汇(compatibility_assessment=not_applicable,semantic_alignment=not_applicable),精确 head 验证全部 PASS,同意合入。
English verdict: APPROVE
|
This pull request has merge conflicts with Choose the remote for the base repository, not an out-of-date fork. 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 HEADFor a same-repository clone whose Keep the DCO |
200e08d to
11fa112
Compare
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google · self_reported
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
Control-plane maintainers and quota CLI/scheduler callers depend on loopx/quota.py when enforcing single-file maintainability budgets, static type safety, and quota plan/gate readbacks.
Before this change, loopx/quota.py spanned 1,895 lines on origin/main with 145 Any usages (baseline ceiling 219 Any, 1,999 lines), while PR #8939's earlier branch conflicted with post-branch main commits (#8647, #8985, #8993) and masked an explicit empty workspace_guard_policy={} on goal with status_goal; after rebasing and fixing the precedence bug, loopx/quota.py is 1,427 lines with 0 Any usages and preserves every origin/main signature and CLI behavior.
Maintainability checks and mypy --strict pass on loopx/quota.py at 1,427 lines with any_count=0 and dict_any_count=0, module_metric_baseline.json tightens its ceiling to lines=1427 and any_count=0, and build_quota_plan keeps an explicit empty workspace_guard_policy={} on goal.
非目标与边界 / Non-goals: Does not add new top-level loopx/.py modules, alter loopx/control_plane/quota/ business logic or turn-envelope owners, modify unrelated maintainability-ratchet debt outside loopx/quota.py, or grant PR #8939 merge authority.
改动思路 / Approach
Keeping domain invariants, compatibility re-exports, and thin typed JSON coercion helpers inside the existing loopx/quota.py facade while tightening loopx/canary/module_metric_baseline.json removes Any debt and preserves all external caller contracts without splitting new top-level modules or duplicating quota owners.
当前 PR 边界 / Current PR boundary: Bounded exclusively to loopx/quota.py slimming/typing and build_quota_plan workspace_guard_policy precedence, the tightened loopx/quota.py ceiling in loopx/canary/module_metric_baseline.json, and one regression unit test in tests/control_plane/test_quota_plan_policy.py.
从调用链路来看,loopx.quota 继续作为兼容性与编排门面(compatibility facade),外部 CLI 与控制面调用方(loopx quota plan、quota should-run、quota spend-slot、quota scheduler-ack、quota monitor-poll)通过 _PUBLIC_COMPAT_REEXPORTS、build_quota_plan、build_quota_should_run、record_quota_scheduler_ack、record_quota_monitor_poll 与 spend_quota_slot 进入底层 loopx/control_plane/quota/* 所有者。本次重整保留全部 post-branch 主干修复:#8647 向 record_quota_scheduler_ack 透传 goal_ref 与 registry_path;#8985 移除已删除的 QUOTA_MONITOR_POLL_CLASSIFICATION 导入(保持 compatibility_facade:loopx.quota 的 package_reexport_count=101 不回退);#8993 在 record_quota_monitor_poll 与 _attach_auxiliary_monitor_settlement_resume 中保留 isinstance(..., Mapping) 防御。同时提取局部类型收窄辅助函数(_as_dict、_as_dict_or_none、_as_list、_dict_items、_string_list)及 _QuotaPlanSummary TypedDict,使所有静态类型约束由 object/Mapping[str, object]/Sequence 显式表达,而非回退 Any。
具体改动 / Changes
依据规范 docs/development/testing-and-quality.md(固定基线修订 2d64ef87175964dc20d4fa4ed00bb2e7b0eb7d4e)及可维护性棘轮约束进行逐项核对:
| Criterion ID | 规范要求 / Requirement | 处置 / Disposition | 实现与验证 / Evidence |
|---|---|---|---|
| C-1 | 重构兼容性门面须经真实生产 CLI/存储后端(File 与 SQLite)对比验证,且不得静默改变行为或签名 | implemented | loopx/quota.py 对齐主干全部 14 个公共函数签名,File/SQLite 双后端 quota plan、quota should-run、quota spend-slot 实跑及 5 项 control-plane smokes 均通过 |
| C-2 | 模块瘦身与 Any 清零不得通过新增顶层模块、拆散兼容性重导出或放松基线门槛完成 |
implemented | loopx/quota.py 降至 1,427 行(< 1,650)、any_count=0、dict_any_count=0,loopx/canary/module_metric_baseline.json 仅收紧 loopx/quota.py 至 1427 |
| C-3 | build_quota_plan 中 goal["workspace_guard_policy"] = {} 必须按 is None 判断,不得误回退至 status_goal |
implemented | loopx/quota.py:L732-L736 与 tests/control_plane/test_quota_plan_policy.py:L186 通过 pytest 验证 |
关键代码讲解
_as_dict_or_none(loopx/quota.py#L161):将宽松 JSON 读取收窄为dict[str, object] | None(仅当输入为Mapping时拷贝为普通dict,否则返回None),替代原先散落各处的isinstance(..., dict)重复判断与Any标注,为build_quota_plan等策略合并提供明确的三态边界(None缺失 vs{}显式空策略)。build_quota_plan(loopx/quota.py#L659):聚合状态负载与运行历史中的配额目标分组(blocked_health、operator_gate、focus_wait、eligible、waiting、throttled、paused),修复了此前评审指出的[P2]缺陷——当goal["workspace_guard_policy"]为显式空字典{}时先判is None再回退status_goal["workspace_guard_policy"],同时保留repo/project/root字段原有回退优先级与_QuotaPlanSummary结构。record_quota_scheduler_ack(loopx/quota.py#L927):完整保留主干 PR #8647 引入的goal_ref: Mapping[str, object] | None = None与registry_path: Path | None = None参数并透传至record_quota_scheduler_ack_for_decision,同时以dict[str, object]与精确函数契约满足mypy --strict --follow-imports=silent。record_quota_monitor_poll(loopx/quota.py#L1057):保留主干 PR #8993 引入的isinstance(..., Mapping)防护并通过_attach_auxiliary_monitor_settlement_resume(L991)复用辅助监听器结算恢复逻辑,清除已失效的QUOTA_MONITOR_POLL_CLASSIFICATION重导出依赖(#8985),使模块在不引入新的跨文件抽象的前提下降低重复代码量并保持零Any。
对主干的风险 / Risks
- 回归面可控:核心配额控制面业务规则仍留在
loopx/control_plane/quota/*,loopx/quota.pyAST 公共函数签名与默认参数与origin/main完全一致;已删除的 9 个未被仓库引用_todo_*包装器与 10 个未使用的projection_todo_*导入经全库检索确认无外部调用方,test_quota_policy_reexport.py与test_top_level_module_budget.py通过。 - 既有不相关失败核查(
pre_existing_unrelated):以下失败已在未修改的origin/main(41ea75e89892ed88d0ae543e97e31aad0a181c47)上同命令复现完全一致的报错特征,非本 PR 引入:tests/canary/test_maintainability_ratchet.py::test_current_repository_debt_is_reviewed_without_line_count_pins(由未改动文件heartbeat/builder.py与work_items/interaction_contract.py的oversized_decision_function触发;其余 29 个 ratchet 测试全过,且magnitude_regressions=0)。tests/control_plane/test_quota_acceptance_references.py(4 项)、test_quota_memory_context.py(8 项)、test_quota_selection.py门控用例(6 项)、test_quota_vision_audit_references.py(2 项)、test_quota_turn_envelope_validation_failure.py[True](1 项)以及test_cli_output_budget.py(10 项)。
- 远端 CI 未咨询(
ci_policy: not_consulted):遵循本地优先验证策略(wait_for_ci: false),本评审结论基于当前 exact head11fa11213531214d229d7302ce1a30f49fbd592d的完整本地检查与双后端实测,未授予自合并权限(PR 保持OPEN)。
我的整体评价 / Verdict
本 PR 以最小侵入范围干净完成了 loopx/quota.py 的重构瘦身与全量零 Any 类型收紧(1,895 -> 1,427 行,any_count: 145 -> 0),重基于最新 origin/main 并完整保留 #8647、#8985、#8993 全部语义,同时修复了前一轮 [P2] 显式空 workspace_guard_policy 优先级缺陷并补充测试与收紧 module_metric_baseline.json。mypy --strict、ruff、npm run typecheck:control-plane、loopx check、canary premerge --tier quick、TS 配额测试(315 passed)、配额与架构核心套件及 File/SQLite 真实路径对比验证均已通过。
Visual review explanation: Inspected loopx/quota.py, loopx/canary/module_metric_baseline.json, and tests/control_plane/test_quota_plan_policy.py; this refactoring only modifies Python facade typing/helpers, JSON ceiling configuration, and unit tests with no UI, HTML, or rendered visual surface changes. Unverified visual scope: none.
English verdict: APPROVE
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
11fa112 to
aecb54e
Compare
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google · self_reported
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
维护配额计划、结算与监控轮询的控制面开发者,以及通过 loopx.quota 调用 build_quota_plan、build_quota_should_run、spend_quota_slot 和 record_quota_monitor_poll 的 CLI 与扩展调用方。
变更前(86e760f1430c)当 run_history 中 goal 显式声明 workspace_guard_policy={} 而 status_goal 带有 peer_independent_worktree_required=true 时,build_quota_plan 会错误附加 fallback 策略;变更后(aecb54e7fd)改用 _as_dict_or_none 配合 is None 判断,与基线 898c9ef 一致不附加策略,同时全文件消除 145 处 Any 且精简 468 行。
在保持公共导出面与 File/SQLite 行为一致的前提下,loopx/quota.py 降至 1,427 行(any_count=0、dict_any_count=0),通过 mypy --strict、ruff、可维护性棘轮、canary premerge、change-quality 资格收据以及基线/head 11 项公共门面与 CLI 实路径对照,且原 P2 反例回归测试通过。
本 PR 不替换 TypeScript 决策与结算 owner,不改动 _PUBLIC_COMPAT_REEXPORTS 公共导入兼容契约,也不修改其它未触及模块的配额或工作流状态机。
对控制面而言,loopx/quota.py 此前是仓库中残留 Any 注解最多(145 处)且体量达 1,895 行的兼容门面文件;放任不做会让静态类型检查难以兜住分支遗漏,直接拆分顶层模块则会破坏历史导入路径,因此当前精确头 aecb54e7fdd2ec8049d6deb8fc44946b34accb40 是一个完整可独立审查且可回退的维护切片。
改动思路 / Approach
本次改造沿既有调用入口 loopx.cli_commands.quota 与 loopx.quota 推进,核心配额判断、槽位记账、结算和监控轮询继续由 loopx/control_plane/quota/* 及其 TypeScript effect owner 拥有,facade 仅承担输入规范化、向后兼容重导出与结果整备。正路径上,类型收窄统一以 Mapping[str, object]、dict[str, object]、Sequence[...] 与本地 _QuotaPlanSummary 替换全量 Any,并集中抽取 _as_dict、_as_dict_or_none、_as_list、_dict_items、_string_list、_compact_handoff_run、_spend_slot_reply 等模块内私有函数,删除无调用方的 _todo_* 透传包装;负路径上,goal_is_stopped 暂停、unreadable_event_count fail-closed 拦截与 spend_quota_slot 身份/来源拒绝顺序保持不变。
重构严格收敛于既有的 Python quota facade 与测试边界之内,复用现有 control_plane.quota 决策和结算 owner,未新增第二套状态机、CLI 入口或持久契约。
本 PR 仅处理 loopx/quota.py 的类型收窄、局部辅助提取、P2 优先级修复以及 module_metric_baseline.json 单项上限收紧,后续按需渐进迁移调用方至 canonical control_plane 模块即可。
具体改动 / Changes
本次改动严格覆盖 3 个文件(+662 / -1,101,净减少 439 行),且依据 docs/development/testing-and-quality.md(基线修订 62784ecc532585d4f277dd94fe9a169fb95b5050)核对两项验收标准:CRIT-1(真实入口与 File/SQLite 实路径兼容性及 P2 敏感性验证)为 implemented,CRIT-2(可维护性棘轮仅收紧当前模块上限)为 implemented。经检索 loopx/ 与 tests/ 下全部 loopx.quota 调用方(如 history.py、status.py、registry.py、configure_goal.py、cli_commands/quota.py 与 turn_run_once.py),既有导出与 _PUBLIC_COMPAT_REEXPORTS / _LAZY_PUBLIC_COMPAT_REEXPORTS 全部保留。
关键代码讲解
goal_quota_config:将配置入参和内部构造成分收窄为Mapping[str, object]与dict[str, object],保持compute_quota回退、正整数下限钳位和unreadable_event_reasons非空清洗语义不变。_quota_plan_goal_quota:复用_as_dict/_as_dict_or_none保持已停止目标强制重算、project_asset.quota覆盖、focus_wait、handoff_outcome_floor及不可读账本 fail-closed 优先级一致。build_quota_plan:通过_as_dict_or_none(goal.get("workspace_guard_policy"))与显式is None判断,在goal显式提供{}时不再落入status_goal回退,并以_QuotaPlanSummary标注summary输出,配合tests/control_plane/test_quota_plan_policy.py新增回归测试锁定。_attach_auxiliary_monitor_settlement_resume:将原内联辅助提取为私有函数,维持read_heartbeat_settlement失败即报错、grants_new_delivery=False与剥离后续选定项settlement_plan的保护。spend_quota_slot:借助_spend_slot_reply与_settlement_identity_failure统一各失败与重放字典拼装,并严格保留spend_request_rejection分支仅输出settlement_identity的既有字段形态。
对主干的风险 / Risks
当前 exact head aecb54e7fdd2ec8049d6deb8fc44946b34accb40 上未发现阻塞性缺陷(no blocking finding)。针对此前评审 5944046326 提出的 [P2](workspace_guard_policy={} 优先级回归),已在 86e760f1430c 上复现缺陷(old_p2_has_leaked_policy=true),而在 origin/main(898c9ef828)与当前 head 上均恢复 false 且单测通过。本地在两套真实存储后端上执行的跨版本实路径验证均给出精确一致的 SHA-256 指纹:11 项 Python门面用例在基线与 head 均为 sha256:9516caaf06d894d672765b6e9adb4ec28e79368fb525f22032aeea6aa4414dbf;File CLI 5 步实路径(connect -> quota plan -> quota should-run -> quota spend-slot dry-run -> missing-goal)均输出 sha256:871fa74a323befe94e921727cdd22611f864321c6befdd12082b9d54afeb783e,SQLite CLI 均输出 sha256:82e295537617176699f2b1f14ca4b725275c5e536e7394c7137987a67067d72c。
| 验证项 | 结果 | 备注 |
|---|---|---|
ruff check + mypy --strict loopx/quota.py + npm run typecheck:control-plane |
PASS | 目标文件零报错;默认 17 文件 mypy 仅在未触及的 interaction_contract.py:1004 报与 origin/main 相同的既有错误 |
test_quota_plan_policy.py (11) / test_maintainability_ratchet.py (14) / 4 项架构与契约套件 (182) |
PASS | 覆盖新 P2 优先级、棘轮零回归零过期例外与词汇/边界不变量 |
canary premerge --tier quick + change-quality verify + loopx check + check_rfc_bilingual.py |
PASS | 门禁全绿,cqr_6ec5d8b329cb9eff7f57 receipt_valid=true,3 文件公共边界零告警 |
全量 test_quota*.py (1333 passed, 1 skipped, 21 failed) |
UNVERIFIED / FAIL (diagnostic) | Windows 项按平台跳过;21 项失败全部为宿主机双 runtime-root 在 origin/main 即存在的基线失败 |
残余风险仅限宿主机双 runtime-root 引起的 21 项既有测试未在本次孤立清除,以及未在远程 CI、PostgreSQL 实例或真实前端渲染路径运行(均不在本次触及范围)。
我的整体评价 / Verdict
本次重构针对 loopx/quota.py 完成了精确且有实证支撑的减重与类型清零,同时彻底修复并锁死了此前的 [P2] workspace_guard_policy 空字典优先级问题。长程维度上 long_horizon 为 improved(消除了 145 处 Any 盲区并保留全部 fail-closed 与 settlement 不变量);用户体验维度上 user_experience 为 preserved,其中 visual_review 因本 PR 仅涉及 Python 配额门面及对应单测与基线配置而判定为 not_applicable(本 PR 仅修改 Python quota 门面模块 loopx/quota.py、tests/control_plane/test_quota_plan_policy.py 与 loopx/canary/module_metric_baseline.json,不涉及任何前端页面或渲染视图变更,未验证范围:none)。架构与规模上,code_volume 与 change_proportionality 均保持克制且与既存 control_plane.quota 所有权一致,default_off_isolation 与 semantic_alignment 均为 not_applicable(无新增开关与语义词汇,并复用既有语义漂移套件验证通过)。基于当前 exact head aecb54e7fdd2ec8049d6deb8fc44946b34accb40 的全部实路径与静态检查证据,给出通过结论。
English verdict: APPROVE — aecb54e slims loopx/quota.py to 1,427 lines with any_count=0, resolves the prior P2 empty workspace_guard_policy precedence regression, and matches origin/main across 11 facade probes, File/SQLite CLI parity, strict mypy/ruff, maintainability ratchet, CQR (cqr_6ec5d8b329cb9eff7f57), and canary premerge quick.
Summary
loopx/quota.pywas the repository's largest remainingany_countmaintainability debt module (1,895lines onorigin/main898c9ef828,any_count=145actual /219ceiling,dict_any_count=0,lines=1999ceiling inloopx/canary/module_metric_baseline.json).origin/main(898c9ef82862b4f2904eff6cc2983a0519f0753c, verified clean merge-tree against latestorigin/main1c540c3e5ae059f974abdfcfe27b42f5cad9e992), preserving post-branchorigin/mainadditions and fixes (goal_is_stopped,record_quota_scheduler_ack(..., goal_ref=..., registry_path=...)forwarding, removal of deletedQUOTA_MONITOR_POLL_CLASSIFICATION, andisinstance(..., Mapping)guards inrecord_quota_monitor_polland_attach_auxiliary_monitor_settlement_resume).[P2]review finding (5944046326) inbuild_quota_plan(loopx/quota.py): preserved explicit{}ongoal["workspace_guard_policy"]usingis Nonefallback checks (_as_dict_or_none) instead of truthyorfallback tostatus_goal, and added regression testtest_quota_plan_preserves_explicit_empty_workspace_guard_policy_precedenceintests/control_plane/test_quota_plan_policy.py._todo_*passthrough wrappers and unusedprojection_todo_*imports fromloopx.control_plane.todos.todo_semantics, keeping_todo_projection_sort_keydirectly and preserving_PUBLIC_COMPAT_REEXPORTS/_LAZY_PUBLIC_COMPAT_REEXPORTSandcompatibility_facade:loopx.quotaparity.loopx/quota.py(_as_dict,_as_dict_or_none,_as_list,_dict_items,_string_list,_unreadable_ledger_reason,_compact_handoff_run,_compact_handoff_readiness,_unreadable_event_reasons,_apply_unreadable_ledger_fail_closed,_quota_plan_goal_quota,_attach_auxiliary_monitor_settlement_resume,_spend_slot_reply,_settlement_identity_failure), module-level constants, and_QuotaPlanSummary(TypedDict).Anyannotations toMapping[str, object],dict[str, object],Sequence[...],object,TypeVar("_T"), andTypedDict(any_count: 145 -> 0,dict_any_count: 0,mypy --strictclean)."loopx/quota.py"inloopx/canary/module_metric_baseline.jsonto{"any_count": 0, "dict_any_count": 0, "lines": 1427}while preserving everyorigin/mainceiling entry.loopx/quota.py:1,895 -> 1,427lines (-468lines, strictly< 1,650),any_count: 145 -> 0(ceiling219 -> 0),dict_any_count: 0,linesceiling1999 -> 1427.origin/main...HEAD):3 files changed, 662 insertions(+), 1101 deletions(-)(-439net LOC).loopx/*.pymodules; zero changes outsideloopx/quota.py,loopx/canary/module_metric_baseline.json, andtests/control_plane/test_quota_plan_policy.py.Verification (at rebased HEAD
aecb54e7fdd2ec8049d6deb8fc44946b34accb40)module_metrics(Path("loopx/quota.py"))->{'lines': 1427, 'any_count': 0, 'dict_any_count': 0}(vsorigin/main{'lines': 1895, 'any_count': 145, 'dict_any_count': 0})git diff --check origin/main...HEAD-> cleanuv run --extra test ruff check loopx/quota.py tests/control_plane/test_quota_plan_policy.py->All checks passed!uv run --extra test mypy --strict --follow-imports=silent loopx/quota.py->Success: no issues found in 1 source file(note: repo-wideuv run --extra test mypyover the 17pyproject.tomlfiles has 1 identical pre-existing failure on untouchedloopx/control_plane/work_items/interaction_contract.py:1004onorigin/main)npm run -s typecheck:control-plane-> exit0uv run --extra test python scripts/check_rfc_bilingual.py --base origin/main --head HEAD->RFC bilingual diff check passed.uv run --extra test python examples/control_plane/control-plane-maintainability-ratchet-smoke.py->control-plane-maintainability-ratchet: ok(unreviewed: 0,stale_exceptions: 0,magnitude_regressions: 0)uv run --extra test loopx --format json check --scan-path loopx/quota.py --scan-path tests/control_plane/test_quota_plan_policy.py --scan-path loopx/canary/module_metric_baseline.json->ok: true,errors: 0,public_boundary_scan.ok: true(0findings across3files)uv run --extra test loopx --format json change-quality verify --goal-id personal-loopx-maintenance --repo-path . --base-ref origin/main->receipt_valid: true,receipt_id: "cqr_6ec5d8b329cb9eff7f57",status: "valid"uv run --extra test loopx --format json canary premerge --tier quick --from-git-diff --git-diff-base origin/main --goal-id personal-loopx-maintenance->ok: true,gate.status: "passed",merge_gate_passed: true,direct_failure_count: 0,3/3selected catalog checks passed (bounded-context-namespace-smoke.py,control-plane-risk-characterization-smoke.py,hot-path-interface-budget-smoke.py)tests/control_plane/test_quota_plan_policy.py->11 passed(includingtest_quota_plan_preserves_explicit_empty_workspace_guard_policy_precedence)tests/canary/test_maintainability_ratchet.py->14 passedtests/architecture/test_top_level_module_budget.py,tests/architecture/test_control_plane_import_boundaries.py,tests/architecture/test_semantic_vocabulary_drift.py,tests/control_plane/test_contract_health.py->182 passedtests/control_plane/test_quota_plan_policy.py tests/control_plane/test_quota*.py tests/cli_commands/test_quota*.py->1333 passed, 1 skipped(Windows PowerShell test skipped on macOS), plus21failures verified identical to the pre-existingorigin/mainhost dual-runtime-root baseline (test_quota_acceptance_references.py: 4,test_quota_memory_context.py: 8,test_quota_selection.py: 6,test_quota_vision_audit_references.py: 2,test_quota_turn_envelope_validation_failure.py[True]: 1);0new failures.