Skip to content

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

Merged
loopx-agent merged 1 commit into
mainfrom
codex/restore-goal-notification-sink-20261118
Nov 21, 2026
Merged

loopx-agent merged 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.

@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.

@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

通过 refresh-state 追踪 Goal Channel 通知与主要结算的操作者依赖原 Turn 的诊断与安全恢复。 通知调用及错误回填原先内嵌在 refresh-state 的写回后分支,和主结算收尾一起维护。 把相同 AST 的五条通知编排语句迁入 helper,按调用参数归一后逐节点一致;把 helper 放回原位置对照,整段 refresh-state handler 的 AST 一致。按真实 CLI 和 TS 权威存储检查成功、关闭、失败、读回及重放。 同一 CLI 编排移到已有 sink owner,并补齐 File 和 SQLite 的通知失败回归。 当前边界为本地 CLI 编排和既有 Lark 适配器,实际 Provider 使用隔离桩。

改动思路 / Approach

项目 CLI sink 继续负责投递后置条件,Lark lifecycle 负责投递与脱敏,TS 继续拥有主结算和重放。 三处改动形成一个可独立验证的通知编排提取。 复用同一 postcondition 和两个 adapter 函数,通过准确 base/head 的产生、失败和恢复路径检查每个契约点。

具体改动 / Changes

准确头 3ac33a6,merge base 3c03e91,3 个文件,+80/-60。DELIVERY-POSTCONDITION、EXACT-REPLAY 和 DISABLED-SUPPRESSION 均以 CLI 和权威存储回归验证。 按修订 3c03e91 的现有规范核对各项要求。 目标规范

关键代码讲解

对主干的风险 / Risks

候选运行 26 项 CLI、settlement 和入口所有权测试,基线运行 25 项。候选多一项来自原通知失败测试扩展到 File 与 SQLite。正常投递保留同序 gate 与 blocked-notice 输出,失败后重放保留原 Turn、结算身份和一笔扣额。 同一 CLI 套件覆盖关闭钩子零投递、显式抑制、Provider 失败诊断脱敏和前置持久化失败。关闭与抑制分支维持原有合约。 另有 39 项 Explore/Lark lifecycle 与 blocked-notice 用例、Ruff 和 6 项直接加 3 项目录 premerge 检查通过。 在线 Lark provider 与远程 CI 本轮未验证。现有调用位置的 UI 和投递授权入口保持同一合约。

我的整体评价 / Verdict

批准。项目 CLI sink 继续负责投递后置条件,Lark lifecycle 负责投递与脱敏,TS 继续拥有主结算和重放。 三处改动形成一个可独立验证的通知编排提取。 当前 head 的 CLI 可观察语义及故障恢复得到配对验证。

English verdict: APPROVE at 3ac33a6. The same gate and blocked-notice logic stays at the original refresh-state lifecycle boundary. Paired checks preserve suppression, redaction, and exact one-spend settlement on canonical File and SQLite fixtures, with stubbed external Lark delivery.

@loopx-agent
loopx-agent merged commit e6cdf27 into main Nov 21, 2026
42 of 50 checks passed
@loopx-agent
loopx-agent deleted the codex/restore-goal-notification-sink-20261118 branch November 21, 2026 13:21
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