Skip to content

refactor(lark): modularize goal_channel_gate_contracts with zero-Any typing and O(1) connection selection - #9481

Merged
huangruiteng merged 2 commits into
mainfrom
codex/slim-lark-goal-channel-contracts-zero-any-20261126
Nov 27, 2026
Merged

huangruiteng merged 2 commits into
mainfrom
codex/slim-lark-goal-channel-contracts-zero-any-20261126

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

  • Modularize human-gate, blocked-notice, auto-notify marker, and quota projection contracts out of loopx/extensions/lark/goal_channel_contracts.py (880 -> 511 LOC, 44 -> 0 AST Any, 0 # type: ignore, 0 # noqa, max function span 42) into acyclic loopx/extensions/lark/goal_channel_gate_contracts.py (365 LOC, 0 AST Any, 0 ignores, max function span 43).
  • Preserve loopx/extensions/lark/goal_channel_contracts.py::save_goal_binding provenance for loopx/semantics/goal_instance_binding_inventory_v1.json and preserve every public/private export with exact is identity matching goal_channel_gate_contracts, including lazy runtime imports inside _gate_notice_projection.
  • Deduplicate auto-notify flag & marker read/write helpers (_automation_flag, _marker_enabled, _write_marker), eliminate redundant registry copies in goal_from_registry when passed a dict, scan user_todo_summary once in quota_human_gate_state_generation (_summary_gate_items), and use direct O(1) connection/default lookups in binding_for_goal without materializing unused siblings.
  • Eliminate all caller mypy regressions (120 -> 105 errors across the 29-file caller check, 0 new regressions) via GateNoticeProjection TypedDict and narrow Mapping checks in goal_channel_notice.py, periodic_report_delivery.py, team_plan_confirmation.py, goal_topic_edit.py, manager_routing.py, goal_topic_connections.py, goal_topic_batch.py, and chat/lark_api.py.
  • Add tests/extensions/test_lark_goal_channel_contracts_contract.py (388 LOC, 0 AST Any) verifying LOC/Zero-Any/inventory/re-export invariants, routing enum & transaction lock, MappingProxyType vs dict non-copy registry parity, connection-set fallback selection & save_goal_binding peer preservation, public packet PII rejection, objective redaction, and >3-item gate identity projection.

Verification

  • ruff check across all 11 changed/added files: passed (0 issues)
  • mypy ([tool.mypy] 17/17 clean; --strict --no-incremental --follow-imports=silent on goal_channel_contracts.py, goal_channel_gate_contracts.py, test_lark_goal_channel_contracts_contract.py: 0 errors; 29-file caller --follow-imports=silent: 105 <= 120 baseline)
  • scripts/check_rfc_bilingual.py --base origin/main --head HEAD: passed
  • npm run typecheck:control-plane & tests/control_plane_ts/content_digest_single_owner.test.ts: 17/17 passed
  • Paired origin/main vs HEAD counterfactual parity across 24 binding/connection/gate/packet cases: PAIRED_COUNTERFACTUAL_PARITY=PASS items= 24
  • Clean-HOME smokes (control-plane-maintainability-ratchet-smoke.py [unreviewed=0, stale_exceptions=0, magnitude_regressions=0], semantic-vocabulary-drift-smoke.py, lark-goal-channel-human-gate-delivery-smoke.py, lark-goal-topic-connection-smoke.py): 4/4 passed
  • Broad pytest -n 6 -rs (tests/extensions/, tests/test_chat_lark_api_contract.py, tests/cli_commands/test_project_lifecycle_goal_channel.py, tests/test_lark_private*.py, tests/test_native_steward_private.py, tests/test_native_steward_reports.py, tests/control_plane/test_refresh_checkpoint_isolation.py, tests/control_plane/test_steward_goal_notice_integration.py, tests/architecture/, tests/canary/): 5,261 passed, 7 skipped, 0 failed (1 Windows junction + 6 APFS non-UTF-8/root-name skips)
  • Public/private boundary scan (loopx check, 0 errors) & pre-merge validation gate (loopx canary premerge --from-git-diff --git-diff-base origin/main): gate.status="passed", merge_gate_passed=true, failures=0, manual_hold_count=0, cqr_3e20f010977981acd49e (decision="pass", receipt_valid=true)

…typing and O(1) connection selection

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

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

[P2] 受众路由格式无效时拒绝团队计划卡片投递。现有绑定加载器允许非空非对象 routing 到达这里。新表达式将其判定为 false,使其通过 Goal 受众检查。隔离实测基线在提交前失败,当前头沿正式投递入口选择该绑定并写出 Goal 受众回执,传输使用替身。 在默认候选、备用候选和最终选中项共用同一受众判定。非空非对象 routing 应拒绝,不能按普通 Goal 受众回退。 源码

动机 / Motivation

拆分飞书 Goal Channel 的绑定、通知和 gate 投影,保留每个 Goal 或 manager 的原投递范围。 基线先确认既有绑定的 audience,再解析 provider target。非空、非对象的 routing 在受众选择阶段失败。 向 manager 和 Goal 两个受众投递审批卡片的飞书团队计划流程。

持久绑定读取只要求外层是对象。错误字段从拒绝变成卡片提交,可能将有操作权限的审批卡送到尚未确定类型的受众。 同样的合法 manager 与 Goal 绑定在两个版本中分别走各自受众,并产生两条对应的本地读回记录。 定向已有测试在基线 57 项、精确头 62 项通过。两侧运行真实本地绑定、目标、提案存储和投递入口,正例相同,畸形受众反例有差异。git diff --check 与 merge-tree 通过。 反例采用隔离构造的旧记录与合成飞书发送和读回。已覆盖真实选择和本地持久回执,未调用飞书线上服务,未核验安装版与远程 CI。 基线契约

改动思路 / Approach

该改动沿用 deliver_team_plan_review_cards → _resolved_binding → Goal Channel delivery route → 收据读回。门控提取维持原公开绑定入口。受众分类和 target 解析位于现有团队计划调用者,不能以类型收窄完成授权判定。 新 Mapping 判断在三个受众检查点把无效对象当成普通 Goal 受众;后续 route 验证只检查 Goal、provider、chat 和 sender,不重新检查受众。 保留当前 selector 优化,使用同一个 audience 检查拒绝无效 routing,再统一用于默认候选、其他候选和最终绑定。

具体改动 / Changes

精确提交 8a23fb9,本次对照目标 7f7297a。分叉点 7f7297a 起的完整 diff 涉及 11 个文件,+997/-600。

关键代码讲解

  • _resolved_binding。对最终绑定的 malformed routing 返回 false 并与 Goal audience 的 false 相配。 源码

  • deliver_team_plan_review_cards。解析两方绑定,再准备发布和分别写回执。 源码

  • binding_for_goal。先选一项再验证对应 target,保留合法绑定范围。 源码

  • goal_channel_gate_contracts。移动既有通知 marker、receipt 和 quota 投影。 源码

  • team-plan-card-audience-remains-explicitly-bound(not_met)。投递必须根据已验证的受众绑定进行。受众分类无法可靠读回时,先阻止投递、保留待处理提案。

对主干的风险 / Risks

持久 routing 为非空且非对象时,基线在任何投递前拒绝,精确头把该绑定当作 Goal 受众并创建卡片投递回执。实际测试只替换外部传输。 选择合法绑定前,畸形 routing 会落入非 manager 的默认匹配。 在统一的受众检查中拒绝非空、非 Mapping 的 routing,再进行 manager/Goal 匹配。

语义与 CI 对齐

持久 routing 为非空且非对象时,基线在任何投递前拒绝,精确头把该绑定当作 Goal 受众并创建卡片投递回执。实际测试只替换外部传输。 在统一的受众检查中拒绝非空、非 Mapping 的 routing,再进行 manager/Goal 匹配。

我的整体评价 / Verdict

REQUEST_CHANGES。 请先恢复对畸形受众配置的拒绝,在现有团队计划投递入口增加回归。 维持历史状态在正常路径与恢复路径中的一致性。

English verdict: REQUEST_CHANGES at 8a23fb9. The exact head treats a non-object saved routing value as the Goal audience and records a card delivery where the base refuses before sending. Reject malformed routing before classifying the audience.

Signed-off-by: huangruiteng <huangrt01@163.com>

@huangruiteng huangruiteng left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · GPT-5 · OpenAI · self_reported

Approval conclusion

动机 / Motivation

LoopX 的飞书 Goal Channel 同时服务 manager 受众和具体 Goal 受众。投递审批卡片前,系统必须从持久绑定中选择一个明确受众;如果保存的 routing 已经损坏,却仍按普通 Goal 受众继续,审批卡片可能进入错误会话并留下错误的投递回执。本 PR 将原有 745 行混合职责的契约文件拆成绑定持久化与 gate 投影两个 owner,同时修复当前 head 上发现的 malformed routing 回归:非空、非对象的 routing 现在会在投递准备前拒绝,而历史缺失或空的 Goal-only routing 仍保持兼容。

复核字段:affected_caller_or_operator=Existing LoopX callers and operators of the changed integration surface. before_after_scenario=The old monolith or broad type surface is replaced by focused modules with explicit validation while public behavior stays stable. observable_outcome=Existing behavior remains reachable through the same entrypoint with stricter typing and focused regression coverage. non_goals=No unrelated product workflow, permission model or external provider protocol is changed.

规范依据:docs/development/testing-and-quality.md(精确头分叉基线 7f7297a790771dab08e2444700f4d76699169950)。

改动思路 / Approach

绑定加载继续由 goal_channel_contracts.py 持有,通知 marker、receipt 和 quota gate 投影迁入 goal_channel_gate_contracts.py 并在旧模块保留兼容导出。连接选择先在一个连接集合中按 connection_id、agent_id、默认连接或最小连接 ID 选出单项,再解析唯一 provider target,避免把其他 Agent 的 target 错误应用到当前连接。

团队计划受众判断收口到 _binding_matches_audience。默认候选、备用候选和最终选中绑定共用该规则:Mapping 中 conversation_kind == "manager" 表示 manager 受众,合法的非 manager Mapping 表示 Goal 受众;缺失、None 或空的旧式值继续表示 Goal;任何非空非 Mapping 值都在发送前失败。这样保留了真实旧数据兼容性,也不会把损坏配置降格成可投递状态。

复核字段:criterion=goal-channel-gate-parity architecture_reason=职责沿现有调用、provider 和持久化边界拆分,公共入口保持。 current_pr_boundary=仅 loopx/chat/lark_api.py, loopx/extensions/lark/goal_channel_contracts.py, loopx/extensions/lark/goal_channel_gate_contracts.py, loopx/extensions/lark/goal_channel_notice.py, loopx/extensions/lark/goal_topic_batch.py, loopx/extensions/lark/goal_topic_connections.py, loopx/extensions/lark/goal_topic_edit.py, loopx/extensions/lark/manager_routing.py, loopx/extensions/lark/periodic_report_delivery.py, loopx/extensions/lark/team_plan_confirmation.py, tests/extensions/test_lark_goal_channel_contracts_contract.py, tests/extensions/test_lark_team_plan_confirmation.py。

具体改动 / Changes

精确 head b4a398994836888277a235cdd4907c94f2b516ac 相对当前 main 涉及 12 个文件,共 +1057/-607。两个契约模块保持零 AST Any 和零类型抑制;新 gate owner 承接 blocked-notice、human-gate marker、quota 请求投影和语义键,旧公开导出继续由绑定模块转发。

关键代码讲解

  • _binding_matches_audience 是团队计划受众的唯一分类点。它只把可读取的 Routing 或与旧数据等价的空值映射为受众,非空标量、列表等错误值抛出 team plan review audience routing is invalid。
  • _resolved_binding 在默认绑定、候选集合和最终绑定三处调用同一分类函数,之后才读取 target、解析 provider identity 并返回可投递绑定。
  • _select_connection_set_binding 在 connection Map 中按单个 ID 选择,再交给 _resolve_goal_binding 校验目标名称、provider、channel 和 identity,选择复杂度不再随所有候选的 target 解析增长。
  • goal_channel_gate_contracts.py 承接通知 marker、receipt 与 quota projection;goal_channel_contracts.py 保留兼容导出,调用方无需迁移符号。
  • 新增 malformed-routing 回归从持久 JSON 加载绑定,在真实 _resolved_binding 入口验证错误在 target 解析和传输前被拒绝;既有 manager/Goal 双受众投递与部分成功后恢复测试继续通过。

对主干的风险 / Risks

主要风险是拆分后导出不一致、连接选择顺序变化,或者 malformed routing 从拒绝变成默认 Goal 投递。当前 head 对旧导出做对象身份断言,保持 connection set、legacy single binding、默认 ID 失效时最小连接 ID 回退,以及 manager/Goal 双受众回执语义。新增反例确认非空非对象 routing 不再产生卡片投递;空的旧式 routing 仍覆盖原有 Goal-only 数据。

验证覆盖 402 项相关测试,包括契约/零 Any 边界、团队计划投递与恢复、Goal topic 连接、runtime 路由、通知和 periodic delivery;全部 12 个变更 Python 文件的 Ruff 通过,三个契约/受众模块的 strict mypy 通过,仓库 premerge 13/13 且无 manual hold。外部飞书网络、已安装发行版和远端 CI 未等待;本轮结论来自 exact-head 源码、真实本地持久化入口、合成 provider 传输和 repository-native 门禁。

我的整体评价 / Verdict

前序 [P2] 已在当前 head 真实修复,而不是仅缩小类型:损坏受众配置会在任何卡片投递或回执写入前被拒绝,合法 manager、合法 Goal 与空白旧式 Goal 受众仍保持原路径。拆分沿现有绑定、投递和 gate 边界完成,没有新增权限或持久状态 owner。

English verdict: APPROVE at b4a3989. The exact head preserves valid manager and Goal delivery while rejecting malformed non-object routing before selection or transport; 402 focused tests, Ruff, strict mypy for the new contracts, and 13/13 premerge checks passed.

@huangruiteng
huangruiteng merged commit 0694101 into main Nov 27, 2026
18 of 22 checks passed
@huangruiteng
huangruiteng deleted the codex/slim-lark-goal-channel-contracts-zero-any-20261126 branch November 27, 2026 07:43
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.

2 participants