Skip to content

fix(canary,issue-fix): restore drain smoke selection and add unit coverage - #9075

Open
loopx-agent wants to merge 1 commit into
mainfrom
codex/issue-fix-drain-coverage-20261119
Open

loopx-agent wants to merge 1 commit into
mainfrom
codex/issue-fix-drain-coverage-20261119

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Follow-up to the #9073 post-merge audit P1 finding (review #5975681788).

Problem

  1. In loopx/canary/planner.py, PR #9073 placed examples/issue-fix-reviewer-notification-drain-postwrite-smoke.py at checks[4] and pushed examples/issue-fix-reviewer-notification-sink-smoke.py to checks[5] inside issue-fix-reviewer-routing. Because loopx/canary/premerge.py caps selection at max_checks_per_profile=4 (limit=3 in quick, limit=10 in standard) and tests/test_smoke_suite.py / build_catalog_canary_plan default to max_checks_per_profile=3, both notification drain/sink smokes were silently dropped under default selection, and product-entry-workflows matched broad issue_fix paths first.
  2. tests/ had zero unit tests directly covering drain_issue_fix_reviewer_notification_queue and _row_with_live_lifecycle_facts.

Changes

  • Canary Profile Partitioning (loopx/canary/planner.py, examples/canary/catalog-planner-smoke.py, tests/canary/test_issue_fix_drain_canary_selection.py):
    • Split the 6 checks cleanly into three focused <= 3-check profiles placed ahead of the broad product-entry-workflows profile:
      • issue-fix-reviewer-notification-drain (2 checks): issue-fix-reviewer-notification-drain-postwrite-smoke.py, issue-fix-reviewer-notification-sink-smoke.py
      • issue-fix-reviewer-routing (3 checks): issue-fix-capability-guide-smoke.py, issue-fix-reviewer-recommendation-smoke.py, issue-fix-reviewer-request-smoke.py
      • issue-fix-json-input-boundary (1 check): issue-fix-json-input-boundary-smoke.py
    • Preserves 100% catalog_canary ownership in loopx canary smoke-health while ensuring changing reviewer_notification_drain.py, reviewer_notification.py, or the drain/sink smokes selects issue-fix-reviewer-notification-drain-postwrite-smoke.py under both canary premerge (quick and standard, max_checks_per_profile=4) and tests/test_smoke_suite.py (max_checks_per_profile=3 / limit=3).
  • Focused Unit Coverage (tests/capabilities/test_issue_fix_reviewer_notification_drain.py):
    • Directly tests drain_issue_fix_reviewer_notification_queue and _row_with_live_lifecycle_facts without importing examples/:
      1. Restart-safe queued -> sent durable JSONL ledger writeback (including delivery-window hold and post-restart no-resend idempotency);
      2. sent_unverified suppression removing unverified items from the queue without fabricating verified receipts or duplicating reminder sends (contrasted with pre-write failure retention);
      3. semantic_history_matcher deduplicating already-delivered notifications through lark_reviewer_notification_sink (plus multi-sink scoping and fail-closed scope_ambiguous handling);
      4. _row_with_live_lifecycle_facts preserving maintainer_correction projection fields on OPEN PRs while refreshing terminal MERGED and CLOSED states cleanly (both _lifecycle_packet and compact-metadata fallback paths, plus end-to-end drain cancellation).

Verification (Head 288894864a66e8c653855302b6659e3f2fa618fb)

  • pytest -q tests/capabilities/test_issue_fix_reviewer_notification_drain.py tests/canary/test_quality_surface_catalog.py tests/canary/test_smoke_fleet_health.py tests/canary/test_issue_fix_drain_canary_selection.py: 21 passed
  • pytest -v tests/test_smoke_suite.py --loopx-smoke-suite catalog-plan --loopx-smoke-profile issue-fix-reviewer-routing: 4 passed
  • pytest -v tests/test_smoke_suite.py --loopx-smoke-suite catalog-plan --loopx-smoke-profile issue-fix-reviewer-notification-drain: 3 passed
  • pytest -v tests/test_smoke_suite.py --loopx-smoke-suite catalog-plan --loopx-smoke-profile issue-fix-json-input-boundary: 2 passed
  • python3 examples/canary/catalog-planner-smoke.py: ok
  • python3 examples/issue-fix-reviewer-notification-drain-postwrite-smoke.py: ok
  • python3 examples/issue-fix-reviewer-notification-sink-smoke.py: ok
  • loopx canary smoke-health: ok=true (358 inventory, 126 catalog_canary, 248 targeted owners, 0 identical groups, 0 nested execution)
  • ruff check, mypy --follow-imports=silent (4 touched files), git diff --check, scripts/check_rfc_bilingual.py --base origin/main --staged, loopx check --scan-path ...: all clean
  • loopx canary premerge --tier quick --from-git-diff --git-diff-base origin/main: passed (4/4 selected, 0 failures, 1 inherited advisory maintainability finding on unmodified interaction_contract.py)
  • loopx canary premerge --tier standard --from-git-diff --git-diff-base origin/main: passed (16/16 selected, 0 failures, 1 inherited advisory maintainability finding on unmodified interaction_contract.py)

…erage

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 · Gemini family · Google · self_reported

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

动机 / Motivation

当维护者或自动化门禁在改动 issue-fix 通知队列排空或接收端逻辑后运行 premerge 门禁与目录烟雾测试套件时,会直接触发该路径。

改动前,PR #9073 把通知队列回写烟雾测试排在 issue-fix-reviewer-routing 的第 5 位且产品入口大剖面先命中,导致 premerge 在每位上限 4 和烟雾套件上限 3 时把它静默丢弃,同时单元测试目录里没有任何针对排空函数与状态刷新助手的测试,回归只能靠手工全量跑或上线后才暴露;改动后,拆出的专用剖面把每组检查压到 3 项以内并排在大剖面之前,同时在单元测试目录直接验证 4 类核心排空与状态刷新合同。

实测改变通知队列排空实现文件时,premerge quick 与 standard 均稳定选中通知回写烟雾测试,烟雾测试套件三个子剖面全部全量通过且无截断,4 组排空单元测试和 21 项聚焦 pytest 全部通过。

本次仅调整 canary 剖面拆分与补充单元测试,不修改通知队列生产排空算法、持久化格式或无关剖面。

如果不修复这个缺口,后续任何针对通知重试抑制、语义历史去重或终端状态清理的回归都会继续绕过默认门禁并缺乏快速单测防线;把剖面控制在 3 项以内并补齐单元测试是一次完整、独立且可逆的闭环切片。

改动思路 / Approach

本次改动复用既有的 CURRENT_REPO_PROFILES、build_catalog_canary_plan、build_premerge_validation_gate 与 build_canary_smoke_suite_run 调度主链,以及 drain_issue_fix_reviewer_notification_queue 和 _row_with_live_lifecycle_facts 生产所有者,未新增任何抽象层、配置开关或运行期状态。

把通知排空、通知接收、reviewer 路由与 CLI JSON 边界校验拆分为互不干扰的窄剖面,保留原有 planner、premerge 与 smoke-suite 作为唯一调度和边界真源,不引入新的状态字段、配置开关或兼容分支;单元测试直接调用生产模块,不依赖 examples 包装层。当前 PR 边界严格限定在 canary 剖面定义、目录规划校验脚本与新增单元测试文件内,生产能力模块与领域状态写回路径零改动。

在剖面编排上,将原 issue-fix-reviewer-routing 里的 6 条烟雾检查按职责拆为三个各自不超过 3 项的聚焦剖面,并放在宽泛的 product-entry-workflows 之前:当只改动通知排空或通知接收模块时,精准命中 issue-fix-reviewer-notification-drain,从而不会因为宽剖面先占满 quick(上限 3)或 standard(上限 10)配额而漏掉通知回写回归。单元测试则直接构造临时目录中的合成 JSONL 账本和内存回调,独立验证核心状态转换而不耦合 examples/ 包装脚本。

具体改动 / Changes

对照规范 docs/development/good-smokes.md(固定基线 27eaeb127777378d1e95d98e478ccfa779d08873)以及 #9073 审阅 #5975681788 的修复准则:

规范条目 本 head 判断与核验证据
GS-UNIT-RULES implemented:纯规则与状态机分支放入 tests/capabilities/test_issue_fix_reviewer_notification_drain.py,直接覆盖 drain_issue_fix_reviewer_notification_queue 与 _row_with_live_lifecycle_facts,21 项聚焦 pytest 全通过。
GS-TARGETED-PROFILE implemented:loopx/canary/planner.py 拆分为三个 ≤3 项的聚焦剖面并在 tests/canary/test_issue_fix_drain_canary_selection.py 与 examples/canary/catalog-planner-smoke.py 验证在 max_checks_per_profile=3/4 和 limit=3 下稳定命中,且 smoke-health 保持零所有权流失。
GS-PUBLIC-SAFE implemented:所有新增测试使用 tmp_path 与合成标识(如 oc_fixture_chat、ou_fixture_reviewer),经 loopx check 扫描 4 个改动文件 0 告警、0 命中。

关键代码讲解

  1. CURRENT_REPO_PROFILES 剖面拆分:在 product-entry-workflows 之前定义了 issue-fix-reviewer-notification-drain(2 项)、issue-fix-reviewer-routing(3 项)和 issue-fix-json-input-boundary(1 项),确保每个剖面在 tests/test_smoke_suite.py(默认每剖面 3 项)和 premerge(每剖面 4 项、总上限 quick=3/standard=10)下都不会被截断,同时通过独立 trigger_hints 避免误命中无关的 workflow_plan.py 改动。
  2. test_drain_restart_safe_queued_to_sent_durable_writeback 与 test_drain_suppresses_sent_unverified_without_requeue_or_duplicate_resend:直接调用 drain_issue_fix_reviewer_notification_queue 与 read_issue_fix_pr_lifecycle_ledger_row,验证窗口外保持排队、窗口内 queued -> sent 落盘与重启后零重发;同时验证 sent_unverified 即使未生成已核验 receipt 也会把待发项清出队列避免重复打扰,并与写前失败保留队列形成正反对比。
  3. test_drain_semantic_history_matcher_deduplicates_delivered_notifications 与 test_row_with_live_lifecycle_facts_preserves_open_correction_and_refreshes_terminal:通过真实 lark_reviewer_notification_sink 与必失败 runner 证明语义历史命中时零外部调用、多 sink 精确隔离与范围歧义 fail-closed;并对 _row_with_live_lifecycle_facts 参数化测试 OPEN(保留 maintainer_correction 投影)与 MERGED/CLOSED(同时通过 _lifecycle_packet 与紧凑元数据回退路径刷新为 terminal/remove)。
  4. test_reviewer_notification_drain_change_selects_postwrite_smoke_under_premerge_and_smoke_suite:将基线 27eaeb1277 与当前 head 的反事实选测固化到 tests/canary/,同时校验 workflow_plan.py 不会误触发三个新剖面。

对主干的风险 / Risks

对基线与当前 head 进行反事实对比后未发现阻塞问题。主干变更集中在 loopx/canary/planner.py 的声明式剖面列表:由于将三个聚焦剖面移至 product-entry-workflows 之前,修改这些窄范围文件时 premerge --tier quick 会优先执行对应专项烟雾而非通用工作流烟雾;但负例验证显示修改 loopx/capabilities/issue_fix/workflow_plan.py 时选测集合与基线完全一致(仅 repo-architecture-budget 与 product-entry-workflows),且 loopx canary smoke-health 确认 358 个烟雾中仍有 126 个受 catalog_canary 覆盖、248 个具备定向归属、0 嵌套执行。

对于局部 tests/canary/ 中存在的 1 条失败(test_maintainability_ratchet.py::test_current_repository_debt_is_reviewed_without_line_count_pins),已通过在同一命令对比基线 27eaeb1277 与当前 head 证实为同一条未修改文件 loopx/control_plane/work_items/interaction_contract.py 上的既有 oversized_decision_function 超限(statements=96, decision_points=58),与本次 PR 改动路径完全无关;premerge 门禁已将其自动降级为 advisory_inherited_failure。

本 PR 未引入默认关闭的运行期开关(default_off_isolation 不适用),未新增公开协议/权限边界(authority_semantics 不适用),未修改任何共享词表(semantic_alignment 不适用),但直接测试内部辅助函数 _row_with_live_lifecycle_facts 意味着未来若重命名该私有符号需同步更新该单测。

我的整体评价 / Verdict

基于 exact head 288894864a66e8c653855302b6659e3f2fa618fb 的独立验证已全部在本地完成,不等待或依赖远程 CI。长程影响 long_horizon 为 improved,因为恢复了默认门禁对通知队列重启写回与防重发不变量的自动拦截,并补齐了快速单元测试;交互体验 user_experience 为 not_applicable(本次改动仅涉及 canary 剖面配置、planner 烟雾脚本与 pytest 单元测试,不触及渲染 UI 或用户交互入口,未核验范围 none)。可观测语义在通知排空相关改动下为 intentional_change_validated,在无关文件 workflow_plan.py 上保持完全等价。代码量 code_volume 为 necessary,整体改动比例 change_proportionality 为 proportionate(架构评估 retain)。

本地验证明细(全部基于 exact head 288894864a66e8c653855302b6659e3f2fa618fb):

  • pytest -q tests/capabilities/test_issue_fix_reviewer_notification_drain.py tests/canary/test_quality_surface_catalog.py tests/canary/test_smoke_fleet_health.py tests/canary/test_issue_fix_drain_canary_selection.py -> PASS(21 passed)
  • pytest -v tests/test_smoke_suite.py 三个剖面(issue-fix-reviewer-routing 4 passed、issue-fix-reviewer-notification-drain 3 passed、issue-fix-json-input-boundary 2 passed) -> PASS
  • 专项烟雾(catalog-planner-smoke.py、issue-fix-reviewer-notification-drain-postwrite-smoke.py、issue-fix-reviewer-notification-sink-smoke.py)与 loopx canary smoke-health -> PASS
  • 静态与边界检查(ruff check、mypy --follow-imports=silent 4 文件、git diff --check、scripts/check_rfc_bilingual.py、loopx check --scan-path) -> PASS
  • loopx canary premerge --tier quick(4/4 selected, 0 failures)与 --tier standard(16/16 selected, 0 failures,含 1 条对未改动文件的 inherited advisory) -> PASS
  • 诊断性全量 tests/canary/:144 passed, 6 skipped, 1 pre-existing unrelated failure(与基线相同的 interaction_contract.py ratchet)

剩余风险仅为测试直接依赖私有 helper _row_with_live_lifecycle_facts 名称这一低耦合点;无阻塞缺陷,建议准予合入。

English Verdict: APPROVE — Exact head 2888948 splits issue-fix reviewer notification drain/sink and JSON input checks into <=3-check profiles ahead of product-entry-workflows (restoring default premerge and smoke-suite coverage without over-matching unrelated files) and adds direct unit coverage for drain_issue_fix_reviewer_notification_queue and _row_with_live_lifecycle_facts, with all targeted pytest, smoke, lint/type, and premerge quick/standard checks passing locally.

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