Skip to content

fix(attention_queue): align AttentionWaitingOn with status contract and wire AttentionQueueProjection - #9464

Open
loopx-agent wants to merge 1 commit into
mainfrom
codex/fix-attention-queue-types-followup-20261126
Open

loopx-agent wants to merge 1 commit into
mainfrom
codex/fix-attention-queue-types-followup-20261126

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to PR #9452 (PRRT_kwDOStEbEs68KniQ) aligning the typed attention-queue contract with the production status vocabulary and wiring it into real callers (attention_queue.py, attention_projection.py, and status.py).

  • Single-Sourced waiting_on Contract:
    • Defined RegistryWaitingOnOverride in loopx/control_plane/status/goal_attention_projection.py (REGISTRY_WAITING_ON_OVERRIDES = set(get_args(RegistryWaitingOnOverride))) and MonitorSignalWaitingOn = Literal["monitor_signal"] in loopx/control_plane/status/monitor_display_projection.py (MONITOR_SIGNAL_WAITING_ON: MonitorSignalWaitingOn = "monitor_signal").
    • Reused both in loopx/control_plane/work_items/attention_queue_types.py (AttentionWaitingOn = Literal[RegistryWaitingOnOverride, MonitorSignalWaitingOn] and ATTENTION_WAITING_ON_VALUES), so AttentionWaitingOn accepts "monitor_signal" and every valid runtime waiting_on status value (user_or_controller, controller, codex, external_evidence, monitor_signal).
  • Removed Dead Conflicting Aliases & Bound Real Callers:
    • Removed unreferenced conflicting GlobalRegistryFindingSeverity and split AttentionQueueCounts helper (making "available" and "items": list[AttentionQueueItem] required fields on AttentionQueueProjection alongside count keys and NotRequired optional keys), while keeping all real callback Protocol types on AttentionQueueContext.
    • Defined AttentionQueueItem (TypedDict requiring waiting_on: AttentionWaitingOn plus real optional item fields) and wired (items: Sequence[AttentionQueueItem], ...) -> AttentionQueueProjection across loopx/control_plane/work_items/attention_queue.py (548 <= 550 LOC, adding _validated_queue_items for build_attention_queue), loopx/control_plane/status/attention_projection.py, and loopx/status.py (1339 lines unchanged ceiling; 0 AST Any, 0 # type: ignore).
  • Static & Runtime Tests (tests/control_plane/test_attention_queue_contract.py, 729 LOC):
    • Verified removed dead exports, vocabulary equivalence, AttentionQueueItem + AttentionQueueProjection parity across attention_queue, attention_projection, and status, plus a subprocess mypy --strict probe proving "monitor_signal" passes cleanly across real consumers while "waitng_on" typos fail statically (typeddict-item + typeddict-unknown-key) before reaching runtime KeyError.

Verification (be69f1d8fd978c6a405f2f3a9ce43347f18c14e8 over 57c4c43b52)

  • Style & Types: ruff check 7/7 clean; mypy --strict --follow-imports=silent 6/6 clean; repo [tool.mypy] 17/17 clean; 12-caller loopx/ mypy diff +0/-0 regressions (4358 -> 4358 across 444 transitive files).
  • CLI JSON Paired Parity (57c4c43b52 vs HEAD): Real python -m loopx.entrypoint --format json status on an isolated SQLite fixture with advancement_task (codex) + continuous_monitor (monitor_signal) goals produced identical attention_queue items/counts (watching_monitor=1, needs_codex=1) and byte-identical JSON across all non-timestamp fields.
  • TS, Boundary, & Smokes: npm run typecheck:control-plane clean; node --test tests/control_plane_ts/content_digest_single_owner.test.ts 17/17 passed; scripts/check_rfc_bilingual.py passed; clean git merge-tree (78245f3d68); clean-HOME smokes passed (control-plane-maintainability-ratchet-smoke [unreviewed=0, loopx/status.py=1339], semantic-vocabulary-drift-smoke [34/34, 62/62], attention-queue-readmodel-smoke, status-collection-readmodel-smoke, session-runtime-readonly-projection-smoke).
  • Pytest: pytest -n 4 -rs (test_attention_queue_contract.py, test_status_*.py, test_canonical_status_todos.py, test_goal_attention_integration.py, test_native_child_receipts.py, test_projection_envelope.py, test_global_risks.py, test_global_todo_readiness_characterization.py, test_session_dash_status_bucket.py, tests/canary/, tests/architecture/) -> 2,512 passed, 6 skipped (6 filesystem APFS skips in tests/canary/test_git_path_display.py, 0 failures).
  • Control Plane Gates: loopx check (0 errors, 6 checks), Change Quality Receipt cqr_658bb27e646145083259 (decision="pass", receipt_valid=true, status="valid"), canary premerge (ok=true, direct=6/6, catalog_run=10/10, risk_profile_run=8/8, manual_hold_count=0, failures=0).

…nd wire AttentionQueueProjection

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

@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

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

动机 / Motivation

把注意队列的 waiting_on 和返回类型对齐到生产 Status 的已使用值。 原声明遗漏 monitor_signal,真实 Status 仍会输出它。返回 dict 的精确字段未贯穿三个消费者。 读取全局 Status 和单 Goal 状态的操作人、监控 Agent 与下游展示。

类型落后于已有 monitor 值会妨碍添加正常消费者,也容易把观察任务误解成行动待办。 双版本真实 CLI 在隔离 File 和 SQLite 上均得到 3 行,执行等待 codex、监控 monitor_signal、owner 门槛 controller 各 1 行。监控同时保留 execution_waiting_on=codex,按 Goal 过滤后只留下监控项,各来源字节保持。 Head 217 项定向测试、attention-queue-readmodel-smoke 和 git diff --check 通过。原基线契约与集成 13 项通过。双版本真实 status CLI 各检查两个 provider 的全局及过滤投影。 结论覆盖精确工作树和隔离 CLI。运行时只校验 waiting_on,其他可选属性依其既有生产者。未核验当前安装、远程 CI 或浏览器。 基线契约

改动思路 / Approach

该改动沿用 loopx status → status attention projection → build_attention_queue。以现有状态 producer 定义 Literal,队列、adapters 和 Status 消费同一 TypedDict。 按结构化 waiting_on 做桶计数,监控显示和执行等待分别保留。构造队列时验证值,再用 typed projection 交给原消费者。 让已有 registry/monitor vocab 成为类型来源,保留一份桶计数实现,同时保留 monitor 的既有测试注入点。

具体改动 / Changes

精确提交 be69f1d,分叉基线 57c4c43。7 个文件,新增 248 行、删除 51 行,包括 producer/consumer 类型、行校验、桶计数契约与测试。

关键代码讲解

  • AttentionWaitingOn。复用 registry 和 monitor 既有词汇。 源码

  • _validated_queue_items。转换边界检查 waiting_on,对应原监控注入 seam。 源码

  • build_attention_queue_projection。保持现有分桶、计数与 Goal 过滤结果。 源码

  • build_attention_queue_projection。将 typed 投影交给生产 Status 消费者。 源码

  • preserve-existing-operator-wait-projection(implemented)。状态投影保留现有来源、可执行/观察区别和只读属性,并以已有状态词汇表达。

对主干的风险 / Risks

新增契约测试拒绝未知内部 waiting_on 值,严格 mypy 覆盖键名拼错。监控条目保持 watch,不进入需执行的 codex 桶;全局和 Goal 过滤结果在两版一致。 读模型若改变监控路由或过滤计数会误导操作者。双 provider 使用真实 CLI 验证。 复用真实 monitor 词汇和独立 execution_waiting_on 投影,按合法值 fail closed。

我的整体评价 / Verdict

APPROVE。 生产只读投影保持相同字段及分桶,类型已覆盖既有监控值,并守住未支持的内部等待值。 用户门槛、可执行下一步与自动监控等待继续按其原始状态展示和计数。

English verdict: APPROVE at be69f1d. Exact-base/head File and SQLite status preserve action, monitor and owner buckets and Goal-filtered readback. The typed queue includes the existing monitor value and rejects unsupported internal waits.

@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

本 PR 面向状态与注意力队列(attention_queue,即按等待方分桶的活跃目标队列)调用方(attention_projection、status 与控制面测试),修复 PR #9452 遗留的队列类型合同与运行时不一致问题。

  • 触发背景与前后对比(Before / After):改造前,AttentionWaitingOn 遗漏合法状态值 monitor_signal,且 build_attention_queue_projection 与 build_attention_queue 返回松散的 dict[str, object],导致拼写错误 waitng_on 可通过 mypy 检查并在运行时触发 KeyError,同时存在无调用方的冗余导出 GlobalRegistryFindingSeverity 与 AttentionQueueCounts。改造后,AttentionWaitingOn 复用状态契约全部 5 个值,AttentionQueueItem 强制约束 waiting_on,build_attention_queue 与状态门面统一返回 AttentionQueueProjection,静态检查可接受 monitor_signal 并在编译期拦截 waitng_on 拼写错误。
  • 可观测收益:已移除冗余导出并复用完整 5 值 waiting_on 词表,47 个 loopx 相关调用文件保持 +0/-0 mypy 错误增量,共享 SQLite 快照下的 status CLI JSON 输出与基线 57c4c43 完全一致,2071 项架构/金丝雀测试、756 项状态与注意力测试及 18/18 premerge 检查全部通过。
  • 非目标边界:非目标:不修改运行时调度决策、不改写既有 status CLI JSON 序列化结构、不改变 goal_attention_projection.py 既有 normalize_operator_question 签名,也不改造尚未迁移 TypedDict 标注的 examples/ 独立演示脚本。

改动思路 / Approach

本 PR 严格遵循单一真源原则修复 PR #9452 审查意见。[P2] 问题根源在于 attention_queue_types.py 手写了残缺词表且构造器只标注 dict[str, object]。将 RegistryWaitingOnOverride 与 MonitorSignalWaitingOn 保留在各自 status 投影模块中单点定义,并在 attention_queue_types.py 组合为 AttentionWaitingOn、接通 build_attention_queue 与 status 门面,无循环依赖且通过全部架构边界测试。当前 PR 边界仅对齐 AttentionWaitingOn、AttentionQueueItem、AttentionQueueProjection 类型定义与 3 处构造/门面签名,并增加严格静态检查和运行时校验测试,未改动调度策略或前端展示。

  • 入口与复用链路:在 goal_attention_projection.py 提取 RegistryWaitingOnOverride(4 项覆盖值),在 monitor_display_projection.py 提取 MonitorSignalWaitingOn("monitor_signal"),在 attention_queue_types.py 组合为 AttentionWaitingOn 与 ATTENTION_WAITING_ON_VALUES,同时删去无调用方的冲突导出 GlobalRegistryFindingSeverity 和 AttentionQueueCounts。
  • 端到端类型闭环与运行时防线:将 Sequence[AttentionQueueItem] 与 AttentionQueueProjection 返回类型统一接到 attention_queue.py、attention_projection.py 和 loopx/status.py,并在 build_attention_queue 出口新增 _validated_queue_items,在运行时也对非法 waiting_on 做到 fail closed。

具体改动 / Changes

本次共改动 7 个文件(+248/-51):goal_attention_projection.py(+4/-3)、monitor_display_projection.py(+3/-2)、attention_queue_types.py(+62/-21)、attention_queue.py(+26/-8,现 548 LOC)、attention_projection.py(+7/-4)、loopx/status.py(+4/-4,维持 1339 LOC 上限)及 test_attention_queue_contract.py(+142/-9)。

关键代码讲解

  • AttentionWaitingOn(loopx/control_plane/work_items/attention_queue_types.py#L12-L13):组合 RegistryWaitingOnOverride 与 MonitorSignalWaitingOn 构成全部 5 个合法 waiting_on 字面量,并经 get_args 派生 ATTENTION_WAITING_ON_VALUES,同时移除零调用方的 GlobalRegistryFindingSeverity 与 AttentionQueueCounts。
  • build_attention_queue_projection(loopx/control_plane/work_items/attention_queue.py#L100-L144):入参收紧为 Sequence[AttentionQueueItem]、返回值绑定为 AttentionQueueProjection(强制 available 与 items 字段,兼容任意 Sequence),并在 attention_projection.py 与 loopx/status.py 同步签名。
  • _validated_queue_items(loopx/control_plane/work_items/attention_queue.py#L453-L465):在 build_attention_queue 收口处逐项核验 waiting_on 为字符串且属于 ATTENTION_WAITING_ON_VALUES | {context.monitor_signal_waiting_on},拒绝如 "bogus_wait" 或 "other" 等未受支持值并抛出 ValueError。
  • build_attention_queue(loopx/status.py#L1035-L1065):使兼容门面与内部读模型共享同一个 AttentionQueueProjection 返回契约,并在不增减 StatusCollectionContext 调用错误的前提下保持 0 AST Any。

规范核对(Specification Mapping)

依据已验收协议文档 docs/status-data-contract.md(审阅基线提交 c10b100c049e8298622e5bc96e6756631dd3d8b5)逐条核对:

  • SDC-AQ-1:implemented — AttentionWaitingOn 与 ATTENTION_WAITING_ON_VALUES 完整涵盖 user_or_controller、controller、codex、external_evidence 和 monitor_signal 5 个活跃状态。
  • SDC-AQ-2:implemented — build_attention_queue_projection 与 build_attention_queue 在 work_items、status/attention_projection 与 loopx.status 全部绑定 AttentionQueueItem 与 AttentionQueueProjection,正例 monitor_signal 通过且反例 waitng_on 被 mypy --strict 捕获。
  • SDC-AQ-3:implemented — 已删除未使用的冲突类型 GlobalRegistryFindingSeverity 与 AttentionQueueCounts,并在真实 SQLite 状态 CLI 中与基线逐字段等价。

对主干的风险 / Risks

  • 反例与非阻塞跟踪点:
    1. 对照共享 SQLite 快照下的真实 status --format json 输出与 AttentionQueueItem.__annotations__,运行时条目还可能携带 3 个未写入 TypedDict 的可选键(goal_channel_projection、handoff_mode、long_task_cadence_hint);经核查 mypy --strict 下 item.get(...) 可正常编译(rc=0),全部 47 个 loopx/ 模块调用方均无新增错误(+0/-0),仅当外部类型化代码直接下标访问 item["goal_channel_projection"] 时才需在后续小补丁补全可选字段。
    2. [tool.mypy] 之外的 2 个示例 smoke 脚本(attention-queue-readmodel-smoke.py、session-runtime-readonly-projection-smoke.py)因局部变量仍保留 list[dict[str, Any]] / dict[str, object] 标注,直跑 mypy 会命中类型收敛后的入参/回传不兼容提示(7 -> 10 报错,而 session-runtime-readonly-projection-smoke.py#L331 原下标报错反而被本 PR 修复),但两套脚本运行时均 100% 通过。
  • 调用面、隔离与合并兼容性:本 PR 未引入 opt-in 开关(default_off_isolation: not_applicable),无新增权限或调度语义(authority_semantics: aligned),错误提示保持领域中立,与 main、#9463、#9465、#9467、#9468、#9469 均无冲突风险。
  • 验证矩阵(wait_for_ci: false,ci_policy: not_consulted):
    • ruff check(7/7 文件):PASS。
    • mypy --strict(契约测试正例 monitor_signal 通过、反例 waitng_on 报错拦截)与 47 个 loopx/ 调用方基线对比(97->97 silent,4359->4359 transitive,+0/-0 新增错误;唯一改动文件内错误为 goal_attention_projection.py:145->146 既有一致性行号顺延):PASS。
    • 共享 SQLite 快照 python -m loopx.entrypoint status --format json 基线 vs 本 PR 对比(覆盖 codex/monitor_signal/external_evidence/controller 全部桶计数与条目):PASS(完全一致),attention-queue-readmodel、session-runtime-readonly-projection、status-collection-readmodel 3 项 smoke 均 PASS。
    • pytest:tests/architecture/ + tests/canary/ + test_attention_queue_contract.py PASS(2071 passed, 6 skipped,6 项均为 test_git_path_display.py 在 APFS 上的预期跳过);21 项状态/注意力/CLI 套件 PASS(756 passed, 0 failed)。
    • TypeScript:typecheck:control-plane 与 content_digest_single_owner(17/17)+ goal_attention/steward_managed_mode(29/29):PASS。
    • canary premerge(standard 档位:4/4 direct checks、1/1 py_compile、10/10 catalog canaries、8/8 risk profile smokes,manual_hold_count=0)与合规检查(errors=0):PASS。
    • 远端 GitHub Actions CI:UNVERIFIED(按 wait_for_ci=false 策略未查询/等待远端 CI)。

我的整体评价 / Verdict

  • 长程与用户体验影响(outcome_impact):long_horizon: preserved,user_experience: preserved;视觉审阅 visual_review: not_applicable(原因:纯 Python 控制面类型定义与运行时校验收紧,不涉及 UI 渲染),unverified_scope: none。
  • 精简度与词表对齐:code_volume: necessary 且 compatibility_assessment: retain,change_proportionality: proportionate(architecture_assessment: retain),semantic_alignment: aligned / reuse_existing,observable_semantics 在有效负载上等价并在无效 waiting_on 上实现预期的静态与运行时 fail-closed 拦截。已基于精确提交 be69f1d8fd978c6a405f2f3a9ce43347f18c14e8 完成复核,PR #9452 [P2] 问题已完整闭环,无阻塞缺陷,建议通过。

English Verdict: APPROVE

This branch has not been deployed

No deployments
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