Repository navigation
refactor(control-plane): modularize todo_semantics with zero-Any types and hot-path optimizations - #9451
Conversation
…s and hot-path optimizations Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
精简 Todo 读取语义模块并减少重复统计,保留 agent scope、监控分区和推进项顺序。 基线同一模块处理单条、聚合和 TypeScript 读入,计数 fallback 复用会排序的行投影。 依赖 Todo 优先级和 scoped monitor 状态来判断长程继续条件的操作员和调用方。
用相同 Todo fixture 对照 File 和 SQLite。P0 watch、到期普通 monitor、未来 monitor 的计数与选择一致。另一个场景有 1 项缺排期和 2 项推进候选,两版都选择更高优先级的推进项。 同一生产 CLI 在两个后端各运行 3 种场景。对比退出状态、lane、选中 Todo、分区顺序、计数与 canonical Todo 读回,6 组观察完全一致,投影文件字节与 canonical 行未改变。 结论覆盖隔离 File、SQLite 和本地 CLI 回读。未测生产规模的延迟收益、前端安装版或远程 CI。 基线契约
过往评审经验提示要看变更后的实际任务选择。本次用两个真实 authority backend 的 CLI 投影与回读作判断。
改动思路 / Approach
本 PR 的边界是 quota should-run → File/SQLite canonical Todo readback → monitor/advancement 统计、顺序与选择。Todo authority store 提供记录,Python 读取层保留现有排序与统计,TypeScript frontier 决定分组和计数。 保留原持久状态和规则 owner,拆出单项、聚合和既有 TypeScript bridge,继续从原门面导出调用符号。 仅移动代码可减小单文件,但无助于计数 fallback 的排序开销。候选仅在输出数字时跳过排序,显示列表保持原顺序。
具体改动 / Changes
精确提交 fef253a,分叉基线 50aa5b4。完整 diff 为 4 个文件、+1,523 / −751,含原门面、单项、摘要和契约测试。
关键代码讲解
-
todo_presentation_sort_key。直接读取 display_order,保留旧索引及原生 Todo 的时间和身份排序。 源码
-
_summary_partitioned_due_monitor_items。已有 typed 分区优先,缺失时用 legacy due 列表区分 watch-only。 源码
-
todo_summary_has_only_future_scoped_monitor_work。复用 work counts 判断未来监控分支,并检查当前 scope 的推进项。 源码
-
_advancement_frontier_projection。序列化 claim、excluded 与 actionable,交由已有 TypeScript owner 分类后回填行。 源码
-
test_paired_origin_main_behavioral_parity_across_item_frontier_and_summary。覆盖分拆后的入口、计数和排序兼容。 源码
-
scoped-work-and-monitor-parity(implemented)。两种 authority backend 均保留当前 agent 的可执行项、监控分区和缺排期提示。
对主干的风险 / Risks
只剩本 agent 的未来 monitor 与到期 peer monitor 时,基线和候选均进入 monitor_quiet_skip,未选 Todo,未把 peer 项带进当前 scope。 候选 6 项契约测试通过。配对消费者套件基线 85 项、候选 85 项通过,含 monitor 时钟、选择和 advancement frontier。git diff --check 通过。 复核关闭 monitor writeback 的现有分区测试与类型提取后兼容入口。结论覆盖隔离 File、SQLite 和本地 CLI 回读。未测生产规模的延迟收益、前端安装版或远程 CI。
我的整体评价 / Verdict
APPROVE。 从同一 File、SQLite 数据得到相同的选择、顺序和计数。两版都保留未来监控的等待行为。长程继续与用户所见的当前动作维持同一意义,统计优化留在既有读取层。
English verdict: APPROVE at fef253a. Paired File and SQLite cases preserve scoped work selection, monitor partitions, and canonical readback.
Summary
loopx/control_plane/todos/todo_semantics.py(816 -> 236LOC,62 -> 0ASTAny,0# type: ignore) into an acyclic three-module Zero-Anystructure while preserving all exported constants, helpers, and facade symbols (loopx/*.py == 112,module_metric_baseline.jsonuntouched):loopx/control_plane/todos/todo_item_semantics.py(343LOC,0ASTAny): single-item predicates, blocker text redaction, priority prefix/label/rank parsing, presentation metadata & sort keys, monitor due/expiry/schedule checks, and claim/exclusion boundaries (TodoMapping/TodoObject,Mappingread-only compatibility).loopx/control_plane/todos/todo_summary_semantics.py(501LOC,0ASTAny): summary monitor aggregation, watch-only partition unification, due/schedule-gap counts, work count validation, future-scoped monitor detection, and first-executable lookup.loopx/control_plane/todos/todo_semantics.py(236LOC,0ASTAny): advancement frontier TS projection bridge (_advancement_frontier_projection,todo_advancement_frontier_items,agent_scoped_selectable_advancement_todo_ids,todo_scoped_runnable_advancement_count,todo_advancement_frontier_counts) plus explicit re-exports of item and summary symbols.mainedge-case semantics (key-presencevsNoneintodo_priority_label, empty[]vs missing-slot fallback,type(...) is not intbool rejection,monitor_due_countvsmonitor_schedule_gap_countprecedence, legacy v0 vs native record ordering) with safe hot-path wins:_PRIORITY_RANK_BY_VALUE._presentation_display_orderintodo_presentation_sort_keyavoiding per-comparison 5-key dict allocations andValueErrorround-trips.todo_item_task_textand pre-normalizedtodo_item_allows_normalized_agentacross summary loops.sort_items=False/_count_scoped_raw_monitor_items) and short-circuiting_summary_has_monitor_item+ reusingcounts["monitor_due"]/counts["monitor_schedule_gap"]insidetodo_summary_has_only_future_scoped_monitor_work.tests/control_plane/test_todo_semantics_contract.py(508LOC,0ASTAny,0# type: ignore) covering LOC/Zero-Any/export invariants, key-presence/presentation/malformed-input edges, hot-path non-allocation invariants, and pairedorigin/mainvsHEADcounterfactual parity.Verification
pytest -n 6 -rs(tests/control_plane/test_todo_*.py,test_advancement_frontier_classification.py,test_canonical_status_todos.py,test_capability_monitor_repair_tool_behavior.py,test_goal_acceptance_runtime.py,test_local_coordination_authority.py,test_quota_planning_transport.py,test_chat_cold_source_import.py,tests/canary/,tests/architecture/,tests/test_python_ci_workflow.py):3,815 passed, 6 skipped(6APFS skips intest_git_path_display.py,0failures).ruff check(4/4clean),mypy --strict --follow-imports=silent(4/4clean), repomypy(17/17clean), 50-callermypy --follow-imports=silent(28pre-existing errors matchingmain,0caller regressions).npm run typecheck:control-plane&node --test tests/control_plane_ts/content_digest_single_owner.test.ts(17/17passed),check_rfc_bilingual.pypassed,canary premerge(status=passed,8/8catalog smokes +8/8risk-profile smokes passed,manual_holds=0, receiptcqr_2f56f739f303209ca2eb).