Repository navigation
refactor(control_plane): type and slim attention_queue with zero Any - #9452
Conversation
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 · Gemini · Google · self_reported
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
本次在独立干净工作树中对 PR #9452(codex/slim-attention-queue-zero-any-20261126 -> main,精确提交 abb7c3010a280350e29ac4976b72ae8714afb4cb,基线 50aa5b4fd1c88b7225fc30e58423120e3ad5d426)完成了全量基线对比、Zero-Any 与 strict mypy 检查、6 模块调用方 mypy 对比、5 场景配对行为与畸形输入反例实验、2,508 项跨套件 pytest 回归、TS 控制面静态/单测以及 Goal check / canary premerge / change-quality 验证。PR #9452 无阻断缺陷,全部 4 个改动文件 0 AST Any、0 # type: ignore,批准合入精确提交 abb7c3010a280350e29ac4976b72ae8714afb4cb(APPROVE)。
动机 / Motivation
消费 attention_queue 投影的 loopx/status.py(1,339 行,全局 loopx status 与调度路由上游)、loopx/control_plane/status/attention_projection.py、loopx/control_plane/status/registry_health_projection.py、loopx/control_plane/status/collection.py,以及依赖强类型与可维护性阈值的控制面静态/预合并门禁。在基线 50aa5b4fd1c88b7225fc30e58423120e3ad5d426 上,loopx/control_plane/work_items/attention_queue.py(428 LOC)包含 71 个 AST Any 节点,build_attention_queue 对每个活跃 Goal 重复调用 context.latest_run(goal) 两次(_build_goal_attention_item 起始与 project_asset_latest_validation 各一次),build_attention_queue_projection 分 5 趟独立列表遍历统计等待桶数量,且 history.goals、global_registry.findings、finding.goal_ids 与 _reconcile_active_state_item 缺乏入口类型校验("bad" 字符串会被放行或误按字符遍历)。在当前提交 abb7c3010a280350e29ac4976b72ae8714afb4cb 中,类型与协议契约拆入 attention_queue_types.py(242 LOC),attention_queue.py 重构为内聚辅助函数并保持 530 LOC(<= 550)、0 AST Any、0 # type: ignore(同时保持全部公开导入、loopx/status.py 1,339 行不变且仅收窄 queue.get("items") 列表检查);单次遍历即可完成 5 个 waiting_on 计数、latest_run 对每个目标从 2x 降至 1x(多目标配对实验 8 -> 4 / 10 -> 5),对标量字符串显式抛 TypeError 而保持 legacy {} / [] / () 空容器兼容性。独立干净工作树在精确提交 abb7c3010a280350e29ac4976b72ae8714afb4cb 实测:530 / 242 / 596 LOC + loopx/status.py 1,339 LOC(+1/-1),全部 0 AST Any、0 # type: ignore,顶层 loopx/*.py == 112,module_metric_baseline.json 未变动;ruff check 4/4、mypy --strict 3/3、跨调用方 mypy 较基线消除 attention_queue.py 3 处错误且无新增回归(status.py、attention_projection.py、registry_health_projection.py 均为 0,collection.py:443-444 两处与基线一致)、[tool.mypy] 17/17、check_rfc_bilingual、typecheck:control-plane、content_digest_single_owner.test.ts(17/17)、semantic-vocabulary-drift-smoke(34/34、62/62)、maintainability-ratchet-smoke(unreviewed_count=0)、13 组 pytest -n 6 -rs 2,508 passed, 6 skipped in 190.30s、Goal loopx check 4/4(0 错)、Goal canary premerge(工作树 uv run:direct=6/6、catalog_run=10/10 含 cli-output-budget-regression-smoke 86.326s、risk_profile_run=8/8、failures=0、manual_hold_count=0)及 Goal change-quality 全数通过。未改动与 attention_queue 无关的 loopx/control_plane/status/collection.py:443-444 既有 len() 注解警告,亦未修改 attention_queue 序列化 JSON Schema 字段或 status.py 函数签名。
改动思路 / Approach
loopx/status.py (+1/-1: isinstance(raw_items, list) narrowing) & status/attention_projection.py & status/registry_health_projection.py
└─ attention_queue.py (530 LOC: build_attention_queue, _build_goal_attention_item, _enrich_registry_member_item, merge_global_registry_findings, build_attention_queue_projection)
├─ attention_queue_types.py (242 LOC: Literal/frozenset 词表, TypedDict, 10 个 Protocol, AttentionQueueContext)
└─ 复用 current_status_run (latest_run 2x->1x) & 单趟计数循环 & _sequence_or_empty / _optional_dict
说明(基于精确提交 abb7c3010a280350e29ac4976b72ae8714afb4cb 源码推导,非运行时覆盖率追踪):attention_queue.py、attention_queue_types.py、loopx/status.py。
将 AttentionWaitingOn、GlobalRegistryFindingSeverity、6 类 Protocol 与 AttentionQueueContext 独立为 attention_queue_types.py(242 LOC),attention_queue.py(530 LOC)下沉 _select_goal_attention_item、_active_state_goal_context、_reconcile_active_state_item、_unavailable_todo_source_item、_enrich_registry_member_item 与 _build_goal_attention_item 并经显式 as 再导出维持旧调用入口零破坏,职责清晰且无任何多余抽象。abb7c3010a280350e29ac4976b72ae8714afb4cb 严格锁定在 attention_queue 类型零 Any 化、单次循环计数与 latest_run 复用优化及对应边界契约测试内,同时 loopx/status.py 仅做 1 行 isinstance(..., list) 收窄。
具体改动 / Changes
共修改/新增 4 个文件(+1,216 / -276,1/1 DCO 提交,git merge-tree 无冲突,module_metric_baseline.json 未变动,loopx/*.py == 112);依据 docs/status-data-contract.md#L367-L392(固定基线 50aa5b4fd1c88b7225fc30e58423120e3ad5d426)逐项核对:
| Criterion ID | Requirement | Disposition (abb7c3010a280350e29ac4976b72ae8714afb4cb) |
Evidence |
|---|---|---|---|
ATTN-QUEUE-PARITY |
保持 attention_queue、merge_global_registry_findings、build_attention_queue_projection 全部计数、来源降级与可选字段契约 |
Implemented | 配对 5 场景与 5 组 monitor_signal_waiting_on 100% 一致;13 套件 2,508 passed, 6 skipped |
ATTN-HOTPATH-AND-GUARDS |
复用 current_status_run 消除重复 latest_run 调用、合并单趟计数并对畸形标量 fail-closed |
Implemented | 配对探针 latest_run 调用 8->4 / 10->5;bad_goals/bad_findings/empty_str 抛 TypeError 且保留 {}/[] 兼容 |
ATTN-STATIC-ZERO-ANY |
控制面模块 Zero-Any、0 # type: ignore、attention_queue.py <= 550 LOC 且调用方零新增 mypy 错误 |
Implemented | 530/242/596 LOC + status.py 1339、0 AST Any、ruff 4/4、strict mypy 3/3、调用方 mypy 3->0 |
关键代码讲解
build_attention_queue_projection:将原本 5 次遍历items的sum(...)合并为单次遍历,确保当monitor_signal_waiting_on与"codex"/"controller"/"external_evidence"重叠时仍保持与基线一致的独立计数。_build_goal_attention_item&latest_run复用:起始调用一次current_status_run = context.latest_run(goal)并直接复用至project_asset_latest_validation(current_status_run)(已核对status.py:latest_run->run_projection.latest_run为无副作用只读调用)。_sequence_or_empty&_reconcile_active_state_item:兼顾历史空容器{}/[]/()兼容,对str/bytes等标量及非dict运行时返回结果及时 fail-closed 报错。attention_queue_types.py与loopx/status.py:1112:提供完整的TypedDict/Protocol强类型上下文并用海象运算符将queue.get("items")精确收窄为list。
对主干的风险 / Risks
- 配对基线对比与兼容性验证(
50aa5b4fd1c88b7225fc30e58423120e3ad5d426vsabb7c3010a280350e29ac4976b72ae8714afb4cb):- 在多 Goal 混排、stopped-Goal 档案视图 opt-in、
RetiredTodoEventSourceError、LocalCoordinationAuthorityUnavailable(有无goal_id_filter)、global_registry.findings阴影挂载及全部 5 种monitor_signal_waiting_on组合下,abb7c3010a280350e29ac4976b72ae8714afb4cb与50aa5b4fd1c88b7225fc30e58423120e3ad5d426返回结构完全等价,同时活跃 Goal 的latest_run调用减半(8 -> 4/10 -> 5)。 - 对于空容器
{}/[]与{}配置,abb7c3010a280350e29ac4976b72ae8714afb4cb保持完全兼容;对非序列字符串标量("bad"或"")由旧版静默吞过改为明确TypeError(已有test_attention_queue_contract.py锁定该安全边界)。 - 跨 6 个相关文件对比
mypy --follow-imports=silent:attention_queue.py原有 3 处错误清零(3 -> 0),loopx/status.py、attention_projection.py、registry_health_projection.py保持0错,仅collection.py:443-444保留原有2处未修改行错误。
- 在多 Goal 混排、stopped-Goal 档案视图 opt-in、
- 其余全量验证:
test_attention_queue_contract.py5/5通过;13 套件pytest -n 6 -rs2,508 passed, 6 skipped in 190.30s;ruff 4/4、strict mypy 3/3、[tool.mypy] 17/17、check_rfc_bilingual、typecheck:control-plane、content_digest_single_owner.test.ts(17/17)、semantic-vocabulary-drift-smoke、maintainability-ratchet-smoke(0未评审 debt)、Goalloopx check(4/40错)、Goalcanary premerge(工作树uv run --extra test --timeout-seconds 240:direct=6/6、catalog_run=10/10、risk_profile_run=8/8、failures=0、manual_hold_count=0)全数通过。
语义与 CI 对齐
USER_OR_CONTROLLER_WAIT_STATES、ACTIONABLE_REGISTRY_SEVERITIES、AttentionWaitingOn 与 GlobalRegistryFindingSeverity 均为工作项局部投影词表(semantic-vocabulary-drift-smoke 通过,conflicting_values_semantic=0/0),未引入任何冲突状态或默认策略变更;遵循 wait_for_ci: false 未查询远端 CI,保持 PR OPEN。
我的整体评价 / Verdict
- 长程与体验评估:
long_horizon=preserved(Zero-Any边界拆分、单次循环计数与latest_run复用在不改变既有投影语义的前提下减少状态轮询与维护成本),user_experience=preserved(status.py与下游投影接口完全兼容,异常输入可诊断性更清晰);visual_review=not_applicable(原因:本次仅重构工作项attention_queue投影后端模块与单测(及loopx/status.py1 行isinstance收窄),未修改任何前端 UI、HTML/CSS、Lark 卡片或 CLI 展示文本;unverified_scope:2,508 项 pytest 中 6 项在tests/canary/test_git_path_display.py因 macOS APFS 拒绝非 UTF-8/root 文件名按设计跳过;注意若以缺少 pytest 依赖的外部精简解释器直接触发canary premerge内的cli-output-budget-regression-smoke.py会因ModuleNotFoundError: No module named 'pytest'失败,而在标准工作树uv run --extra test环境下10/10目录金丝雀全绿;遵循 wait_for_ci=false 未查询远端 GitHub Actions CI。)。 - 结论: 精确提交
abb7c3010a280350e29ac4976b72ae8714afb4cb质量扎实、验证全绿、无阻塞缺陷,具备合入条件(当前按规则保持OPEN)。
English verdict: APPROVE at abb7c30. Cleanly extracts attention_queue types and context into attention_queue_types.py (242 LOC) while keeping attention_queue.py at 530 LOC (<=550) and loopx/status.py at 1,339 LOC with 0 AST Any and 0 type-ignore comments across all 4 changed files, halving context.latest_run calls per goal (2x->1x), collapsing 5 bucket counts into 1 pass, and enforcing fail-closed sequence guards while preserving legacy {}/[] compatibility. Verified 4/4 ruff, 3/3 strict mypy, 0 caller mypy regressions (3->0 in attention_queue.py), 17/17 repo mypy, 17/17 TS content_digest_single_owner, 5/5 contract tests, 2,508 passed / 6 APFS-skipped pytest items, paired counterfactuals, Goal check (4/4), Goal canary premerge (18/18 smokes via worktree uv run), and Goal change-quality pass.
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Request changes conclusion (author-owned PR; GitHub blocks formal self-review)
Blocking finding / 阻断问题
[P2] 队列类型合同需接受现有 monitor lane 并约束实际调用。
严格 mypy 独立探针给出两项 assignment 错误:AttentionWaitingOn 拒绝合法的 monitor_signal,调用投影函数得到的 dict[str, object] 又不能赋给 AttentionQueueProjection。把 waiting_on 拼成 waitng_on 可通过静态检查,同一份输入在运行时触发 KeyError。
删除当前无消费方且与生产合同冲突的别名和导出,保留有真实调用方的 callback 类型。若要交付所声明的强类型队列,应从现有状态契约复用完整 waiting_on 词汇,给分桶入口绑定必需键并让返回类型接入实际构造器和调用者。加入一条真实消费者的静态正例 monitor_signal 与静态负例 waitng_on,并保持 CLI JSON 结果。
动机 / Motivation
给现有 Goal attention queue 的组装与消费端建立可用的类型合同,降低维护难度,保留状态投影、工作分派语义和故障定位。
相同的输入经过 File、SQLite 和 legacy/native Todo 记录四组真实 status CLI,队列分类、顺序、桶计数和 canonical Todo 读取一致。损坏 Markdown 保持原样。隔离移除 File/SQLite 数据源后分别得到各自相同的 unavailable 错误,未回落到显示副本。
原状态门面的 latest_run 调用由 2 降至 1。goal_attention 路由仍独立查询一次,在此次连接 Goal 输入上整条调用链由 3 降至 2 次。该指令数是定向探针的调用计数,未衡量整条命令延迟。
无新控制面权限、配额写入、自动化开关、页面或数据迁移。
维护者一边看需要控制器的工作,一边跟进 monitor watch,或通过已有 status 消费队列。 目标是减少重复统计与后续类型改动的维护成本,保留操作人看到的健康来源和候选来源。
以主干版本 50aa5b4fd1c88b7225fc30e58423120e3ad5d426 的 docs/status-data-contract.md 为当前合同。waiting-on-values 规定已有 monitor_signal。global-registry-findings 规定 actionable health 提升与信息项留在 registry。candidate-lanes 规定 monitor 候选和实际 advancement 候选各有来源,执行仍由现行 gate 决定。
经验提示提到 recovery RFC 的分期产品验收。这个改动属于内部状态投影,没有恢复产品里程碑。采用其中的真实入口和故障读回检查,以上一版公开契约判断合法 watch 输入,未继承旧案例的 verdict。
改动思路 / Approach
保留既有 status 门面和 TS reconciliation 责任。Python 只负责消费现有状态、组装所见数据和投影计数。
保留有真实调用方的 callback 类型和现有组装路径,清理无消费方的重复状态声明。
单次循环实现的几个桶可以重叠。controller 同时计入 owner/controller 汇总,monitor 再独立判断。原生 Todo/registry 仍由既有来源提供,停止状态默认过滤。回包容器校验收紧到当前 TS reconcile 结果。
具体改动 / Changes
精确检查 abb7c3010a280350e29ac4976b72ae8714afb4cb,全 PR 四个文件 +1216/−276。
build_attention_queue_projection。单次遍历累加五个重叠桶,产出原 JSON 队列。_build_goal_attention_item。从现有 owner 读 Goal、最新 run、Todo 和 quota,保留 enrichment 顺序。_reconcile_active_state_item。沿用 TS effect,并校验回包 item 和 warning 的容器形状。AttentionWaitingOn。新增状态别名遗漏公开的 watch lane 合法值。AttentionQueueProjection。声明了队列 shape,目前没有生产返回值用它约束调用。build_attention_queue。现有 status 门面继续构造原上下文和回执。test_build_attention_queue_projection_counts_and_optional_keys。覆盖运行时分桶和可选字段。
生产 callback Protocol 承接原有依赖注入,降低了函数签名中的模糊度。现有 queue result 类型仍未进入构造器或 status 兼容门面,新增的静态测试主要锁定 Any 数量、行数和重导出身份。定向行为测试覆盖桶计数、候选字段、活动状态缺失及 unknown 分支。应把新增类型的价值放到真实消费者的静态正负例上验证。
对主干的风险 / Risks
本轮在未变的提交上重跑 strict mypy,复现两条赋值错误。此前同一主干和同一提交的运行时配对、定向套件与 premerge 报告继续作为这两个精确版本的证据。
兼容入口保持 contract health、匹配的 scoped registry finding、活动 Goal 的队列顺序。默认略过 stopped Goal。三项混合桶的 watching_monitor 和 needs_controller 均为 1。缺少 waiting_on 的反例两版均触发 KeyError。
显式行为变化仅在所测非法容器上发生:旧版把非空字符串或非空映射迭代后返回空队列,现版以字段名报 TypeError。None 和空映射仍返回空队列。原 PR 已披露这类错误语义变化,两个生产来源均生成 list 形状,未发现此变化影响合法的旧记录。
候选定向 pytest 208 passed in 289.16s,同一基线快照另运行 38 项真实入口和失效测试,均通过。Ruff 与三文件 strict mypy 通过。标准本地 premerge 为 passed,执行 6 项直接检查与 18 项选中检查。diff advisory 命中四个 closed-set 声明,按现有状态词汇逐项核对。
状态读回采用隔离 File/SQLite 实例和合成 Goal,覆盖正常与数据源缺失。浏览器、已安装发行版、PostgreSQL 与远端 CI 未独立验证。本地审查范围没有 UI 改动。
我的整体评价 / Verdict
REQUEST_CHANGES。保留单次分桶和局部模块抽取,先把现有 monitor lane 与队列构造器的类型合同对齐。最小修复可去掉无消费者的重复声明;如果保留公开的 queue 类型,就让真实调用方验证合法 monitor 和拼错字段。
English verdict: REQUEST_CHANGES. The new typing surface rejects the existing monitor_signal lane, and the actual builder still accepts an item with a misspelled required key. Matched File and SQLite status probes preserved runtime queue behavior at abb7c30.
Summary
loopx/control_plane/work_items/attention_queue.pyand eliminate allAnyannotations (71 -> 0ASTAny,0 # type: ignore) into strong typed contracts underloopx/control_plane/work_items/attention_queue_types.py, keepingattention_queue.pyat530LOC (<= 550LOC) and every new/split module well under750LOC (242/596LOC), withloopx/canary/module_metric_baseline.jsonuntouched and top-levelloopx/*.py == 112.build_attention_queue_projectioninto 1 pass while preserving independentmonitor_signal_waiting_onbucket matching and strictwaiting_onKeyErrorbehavior.current_status_run = context.latest_run(goal)forproject_asset_latest_validation,compact_autonomous_replan_ack,latest_run_recommended_action_for_projection, and item selection — eliminating the duplicate secondcontext.latest_run(goal)call per active goal (2x -> 1x)._select_goal_attention_item,_enrich_registry_member_item,_build_goal_attention_item,_unavailable_todo_source_item,_reconcile_active_state_item,_sequence_or_empty,_optional_dict) preservingNone/empty-container legacy compatibility ({},[],None) while failing closed (TypeError) on malformed non-sequence scalars and invalid reconcile payloads.queue.get("items")withisinstance(..., list)on a single line inloopx/status.py(preserving exact1339-LOC baseline ceiling) so callermypystays clean (0regressions) with zeroAnyre-introduced.tests/control_plane/test_attention_queue_contract.py(596LOC,0ASTAny,0# type: ignore) covering static hygiene/export identity, projection bucket counts & key presence,merge_global_registry_findingsshadow attachment & filtering, singlelatest_runcall & stopped-goal opt-in &"unknown"/controllerselection fallback, and unavailable coordination / retired todo event source / malformed payload errors.Changed Files
loopx/control_plane/work_items/attention_queue_types.py(242LOC,0ASTAny,0# type: ignore)loopx/control_plane/work_items/attention_queue.py(530LOC,0ASTAny,0# type: ignore)loopx/status.py(1339LOC,+1/-1isinstancenarrowing onqueue.get("items"))tests/control_plane/test_attention_queue_contract.py(596LOC,0ASTAny,0# type: ignore)Verification (
abb7c3010aover50aa5b4fd1)ruff checkpassed (4/4);mypy --strict --follow-imports=silentpassed (3/3:attention_queue_types.py,attention_queue.py,test_attention_queue_contract.py); callermypy --no-incremental --follow-imports=silentpassed (5/5: includesattention_projection.py,registry_health_projection.py,loopx/status.py); repomypypassed (17/17);scripts/check_rfc_bilingual.py --base origin/main --head HEADpassed;git merge-tree --write-tree origin/main HEADclean;1/1DCOSigned-off-by;loopx/*.py == 112;module_metric_baseline.jsonuntouched.npm run typecheck:control-plane(tsc --noEmit) passed;node --test tests/control_plane_ts/content_digest_single_owner.test.ts(17/17passed).50aa5b4fd1vsabb7c3010aBehavioral Parity & Smokes: Deep output parityPARITY_MATCH=Trueacross all 7 multi-goal, stopped-goal, filter, shadow-finding, error-boundary, andstatus.build_attention_queueprobes (context.latest_runcalls2x -> 1xper active goal);7/7status & attention-queue smokes passed (attention-queue-readmodel-smoke,status-collection-readmodel-smoke,status-goal-filter-smoke,goal-attention-readmodel-smoke,serve-status-global-registry-smoke,derived-state-boundary-smoke,session-dash-panel-smoke) plussemantic-vocabulary-drift-smokeandcontrol-plane-maintainability-ratchet-smoke(unreviewed=0).pytest -n 6 -rsacrosstests/control_plane/test_attention_queue_contract.py,tests/test_projection_envelope.py,tests/test_status*.py,tests/control_plane/test_status*.py,tests/canary/, andtests/architecture/:2,276 passed, 6 skipped(6 standard APFS non-UTF-8 path skips intests/canary/test_git_path_display.py).loopx check(5/5checks,0errors/0warnings), Goalchange-quality(cqr_c06602f2badc9d4dfa4d,decision="pass",receipt_valid=true), andloopx canary premerge --from-git-diff --git-diff-base origin/main --timeout-seconds 240passed (ok=true,direct_checks=4/4,python_compile=1/1,catalog_canaries=10/10,risk_profile_smokes=8/8,failures=0,manual_hold_count=0).