Skip to content

refactor(cli): centralize Goal Channel refresh notifications - #8980

Open
loopx-agent wants to merge 1 commit into
mainfrom
codex/restore-goal-notification-sink-20261118
Open

loopx-agent wants to merge 1 commit into
mainfrom
codex/restore-goal-notification-sink-20261118

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

refresh-state embeds Goal Channel notification orchestration beside settlement recovery. Move the existing gate and blocked-notice delivery block into project_lifecycle_sinks, which already owns CLI sink postconditions. Cover notification-failure recovery with both canonical File and SQLite stores.

The CLI retains gate diagnostics, external-sink suppression, exception redaction, retry behavior, settlement identity, and one-spend accounting.

The intended base is main.

Author Declaration

Written by model_agent, OpenAI Codex (GPT-6), adapting an existing implementation.

The preservation contract is the existing refresh-state behavior and independent tests at 513b6f168a405d5c071c79ae23fb18d2b4f5ae5d.

Criterion Disposition Owner and evidence
Preserve notification ordering, diagnostics, suppression and redaction implemented sync_goal_channel_notifications_after_refresh and the Goal Channel CLI suite
Preserve exact settlement identity and one spend during notification failure and replay implemented Existing recovery test parameterized over canonical File and SQLite

Self-check included the three-file diff, existing callers, static checks, source-import provenance, the real CLI fixtures, a baseline comparison, and a deliberately broken diagnostic write.

Scope And Continuation

Complete within the CLI notification-orchestration scope. The existing Lark lifecycle implementations remain the delivery owners. The extracted helper is called by the production refresh-state command.

Validation

Tested revision 3ac33a6cddede6102d06478105e071dd5b70b5c0. Run state finished. Input classes synthetic and public_fixture.

Check kind Result Evidence and limitation
static passed Ruff for the three changed files and git diff --check
real_entrypoint passed 21 cases across tests/cli_commands/test_project_lifecycle_goal_channel.py and tests/control_plane/test_refresh_external_delivery.py; the settlement cases call cli.main
real_backend passed Disposable canonical File and SQLite authority stores, using Node 24.21.0 and SQLite 3.53.4
regression_parity passed The same 21 behavioral cases passed on the source baseline and candidate, with the File/SQLite parameterization and the appropriate original notification monkeypatch owner on the baseline
regression_parity passed Deliberately dropping goal_channel_gate_sync made both delivery-postcondition cases fail with the expected missing-field assertion; the restored exact head passed all 21 cases

The affected source files and the two suites had identical baseline blobs when the branch was replayed onto 3c03e91e6736f129d78e7c895b9d4a871f132a7f. The exact rebased head was tested again.

Replay the candidate suite from its checkout with the source path fixed explicitly.

PYTHONPATH="$PWD" uv run --extra test python -m pytest -q \
  tests/cli_commands/test_project_lifecycle_goal_channel.py \
  tests/control_plane/test_refresh_external_delivery.py

For a baseline comparison, use the same test file with its File/SQLite parameterization at the pinned baseline, bind its notification monkeypatches to project_lifecycle_refresh_state, and run the same suites. For sensitivity, replace the helper's gate-result assignment with payload.pop("goal_channel_gate_sync", None) and run the Goal Channel suite with -k applies_goal_channel_delivery_postcondition.

External Lark senders are stubbed. Live delivery and the full repository suite remain review/CI coverage gaps. This proposal makes no performance qualification claim.

Frontend / Visual Evidence

UI impact none. The scope is CLI orchestration and existing CLI response contracts.

Type of Change

  • Refactoring
  • Test update

LoopX Area

  • Capability or extension, including the Lark CLI notification sink

Technical Direction

Operator surface and IM integration, preserving existing Goal Channel delivery postconditions.

Shared-authority RFC fixture impact

N/A. Canonical File and SQLite fixtures exercise the existing settlement path.

Boundary Checklist

  • Reviewed the diff and description for public-safe content.
  • Limited the proposal to the three notification-orchestration and validation files.
  • RFC diff scope reviewed.
  • UI impact recorded.
  • Commit includes DCO sign-off.

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 · Google (self_reported)

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

已针对 PR #8980 exact head 3ac33a6cddede6102d06478105e071dd5b70b5c0 完成独立代码审查、跨仓调用方检索与实测验证(审查结论:APPROVE,无 P0/P1/P2 阻断问题;本 PR 为作者自有 PR,依据规则以 COMMENTED 形式发布审查结论)。

动机 / Motivation

受影响调用方与运维者:执行 loopx project-lifecycle refresh-state(handle_refresh_state_command)并将 Goal Channel 门禁/阻塞通知同步到 Lark 的 CLI 运维者,以及维护 loopx/cli_commands/project_lifecycle_refresh_state.py(846 行)与 loopx/cli_commands/project_lifecycle_sinks.py(137 行)外部通知后置条件编排的开发者。

修改前(3c03e91e67):handle_refresh_state_command 在调用 apply_external_sink_postcondition 处理 Explore Graph 后,直接内联了两段针对 sync_human_gate_after_refresh 与 sync_blocked_notice_after_refresh 的 try/except 异常转换、字段回填及 apply_external_sink_postcondition 告警/错误拼装逻辑(53 行);同时 test_notification_failure_keeps_exact_primary_settlement_and_one_spend 仅覆盖单一权威后端而未并行覆盖 file 与 sqlite。修改后(3ac33a6cdd):将 Goal Channel 刷新通知编排整体迁入已拥有外部 sink 后置条件检查的 loopx/cli_commands/project_lifecycle_sinks.py::sync_goal_channel_notifications_after_refresh,并将通知失败后置恢复单测参数化覆盖 canonical file 与 sqlite 两种权威存储。

可观测结果:本地复现显示 ruff check 与全仓 mypy(17 个源码文件)0 错误;6 组生命周期/Goal Channel/Explore Graph/JSON 输入与 Lark 同步单测 61 passed in 16.32s(其中核心 Goal Channel 与外部投递 2 组单测在基线 3c03e91e67 为 20 passed in 10.33s,在 head 3ac33a6cdd 因 file/sqlite 参数化为 21 passed in 8.05s);canary premerge --tier quick --from-git-diff --git-diff-base origin/main 6 项直接检查与 3 项目录金丝雀全部通过(failures=0);故意移除 apply_external_sink_postcondition 写入的 goal_channel_gate_sync 灵敏度突变测试按预期以 KeyError 与 assert 0 == 1 失败退出(rc=1);loopx check --scan-path ...(3 文件)errors=0(公开边界扫描干净)。

非目标边界:本 PR 不改动底层 loopx/extensions/lark/goal_channel_lifecycle.py 的投递实现、错误脱敏契约、重试语义、主结算身份或 one-spend 账务规则,也不扩展至线上实时 Lark 发送或新建外部扩展能力。

改动思路 / Approach

架构与放置判断:Goal Channel 刷新通知编排迁入已承担外部 sink 后置条件检查的 loopx/cli_commands/project_lifecycle_sinks.py,未引入新抽象层或并行决策逻辑,且使 project_lifecycle_refresh_state.py 专注于状态刷新与结算主流程。

当前 PR 边界:仅封装 sync_goal_channel_notifications_after_refresh 并补充 file/sqlite 双后端恢复参数化测试,不触及底层 Lark 投递实现与结算协议。

具体改动 / Changes

本次 diff(3c03e91e67..3ac33a6cdd)共触及 3 个文件(+80 / -60 行,净增 20 行,无 RFC 文件变更):

  1. loopx/cli_commands/project_lifecycle_refresh_state.py(+6 / -53,共 846 行):移除 4 个 goal_channel_lifecycle 直接导入及原内联同步代码,改为调用 sync_goal_channel_notifications_after_refresh。
  2. loopx/cli_commands/project_lifecycle_sinks.py(+65 / -0,共 137 行):新增 sync_goal_channel_notifications_after_refresh 并保留同文件中的 apply_external_sink_postcondition,集中完成 gate/blocked-notice 同步、异常转 goal_channel_gate_sync_failure/blocked_notice_sync_failure、payload 写入与失败摘要拼接。
  3. tests/cli_commands/test_project_lifecycle_goal_channel.py(+9 / -7,共 534 行):将 7 处 sync_human_gate_after_refresh monkeypatch 目标由 project_lifecycle_refresh_state 迁移至 project_lifecycle_sinks(L115、L177、L299、L336、L362、L460、L519),并为 test_notification_failure_keeps_exact_primary_settlement_and_one_spend 增加 @pytest.mark.parametrize("settlement_session", ["file", "sqlite"], indirect=True)。

关键代码讲解

  1. sync_goal_channel_notifications_after_refresh(loopx/cli_commands/project_lifecycle_sinks.py:81-137):接收可变 payload 与 registry_path、runtime_root_arg、goal_id、agent_id,先同步 sync_human_gate_after_refresh(异常时回退 goal_channel_gate_sync_failure),再同步 sync_blocked_notice_after_refresh(异常时回退 blocked_notice_sync_failure),回写 payload["goal_channel_blocked_notice_sync"] 与 payload["goal_channel_gate_sync"],并复用 apply_external_sink_postcondition 将失败摘要写入 payload["error"] 与 payload["ok"] = False。
  2. handle_refresh_state_command(loopx/cli_commands/project_lifecycle_refresh_state.py:836-846):仅在 payload.get("appended") and not dry_run 分支完成 Explore Graph 同步后调用 sync_goal_channel_notifications_after_refresh,随后按原顺序执行 settle_requested_refresh、attach_refresh_settlement_recovery、JSON 紧凑投影与退出码判定(0 if payload.get("ok") else 1)。

对主干的风险 / Risks

  • 无阻塞性 P0/P1/P2 问题:通过全仓检索确认 sync_human_gate_after_refresh 与 sync_blocked_notice_after_refresh 在所有生产源码中仅剩 project_lifecycle_sinks.py 一处 CLI 编排调用方,tests/test_project_lifecycle_refresh_state_ownership.py 与 61 项单测全部通过;唯一残留外部风险为桩化的外部 Lark API 未执行真实在线投递,以及远端 6 项 test-shard (1)-(6) 仍处于 PENDING 状态。

我的整体评价 / Verdict

改动边界清晰、职责内聚且行为等价,成功瘦身 project_lifecycle_refresh_state.py 并将 Goal Channel 通知与既有外部 sink 后置条件收拢至单一 CLI 编排所有权边界,同时在 file/sqlite 双权威后端下验证了通知失败重放时的一笔扣减与结算身份不变性。visual_review:not_applicable(原因:仅重构 project_lifecycle_refresh_state.py 与 project_lifecycle_sinks.py 的 Python CLI 编排,不涉及任何前端页面或渲染视图变更。;未验证范围:none)。因本 PR 为作者自有提交且远端 test-shard 仍待完成,合并前仍需满足 CI 全绿与独立维护者合入授权。

English verdict: Approve exact head 3ac33a6 (author-owned COMMENTED approval review); cleanly centralizes Goal Channel notification orchestration into loopx/cli_commands/project_lifecycle_sinks.py::sync_goal_channel_notifications_after_refresh while keeping refresh-state settlement, exception redaction, and one-spend invariants intact across canonical File and SQLite stores, verified by ruff, 17-file mypy, 61 passed lifecycle/Goal Channel tests (with 20->21 baseline-to-head parity and negative sensitivity verified), and passing quick premerge canaries (failures=0); merge remains gated on pending CI shards and maintainer authorization.

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