Skip to content

refactor(lark): slim manager_reply_parts to zero Any with typed state - #9475

Merged
huangruiteng merged 1 commit into
mainfrom
codex/slim-lark-manager-reply-parts-zero-any-20261126
Nov 26, 2026
Merged

huangruiteng merged 1 commit into
mainfrom
codex/slim-lark-manager-reply-parts-zero-any-20261126

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

  • Modularize loopx/extensions/lark/manager_reply_parts.py (614 -> 457 LOC <= 550, 42 -> 0 AST Any, 0 # type: ignore, 0 # noqa) by extracting durable part-delivery constants, typed receipts/results, locator lookup, and stall-notice planning into loopx/extensions/lark/manager_reply_parts_state.py (331 < 750 LOC, 0 AST Any, 0 # type: ignore, 0 # noqa).
  • Preserve all exported constants, functions, and test monkeypatch surfaces (reply_lark_event_inbox, verify_lark_inbox_reply) in loopx/extensions/lark/manager_reply_parts.py, import LARK_MESSAGE_ID_PATTERN from its canonical owner (identity_shapes.py), and keep top-level loopx/*.py unchanged (112 modules).
  • Deduplicate part/notice reconciliation into shared _reconcile_recorded_attempt, extract _deliver_single_part and _strict_int / coerce_int_default_zero / strip_before_send_option, and add typed TypedDict option/receipt boundaries (VerifyInboxOptions, PartSendInboxOptions, SendInboxOptions, CompletedPartDeliveryReceipt, ManagerPartDeliveryPendingResult).
  • Add tests/extensions/test_lark_manager_reply_parts_contract.py (271 LOC, 0 AST Any) covering LOC/zero-Any/zero-suppression/complexity/re-export contracts, boolean vs integer guards, before_send stripping only on stall-notice reconciliation, readback/pending schemas, and string-typed stall-count coercion.

Verification

  • Static & type checks: git diff --check origin/main...HEAD, scripts/check_rfc_bilingual.py, ruff check, mypy --strict --no-incremental --follow-imports=silent (3/3 touched files -> 0 errors), repo [tool.mypy] (17/17, 0 errors), 4-caller mypy (goal_topic_runtime.py, post_delivery.py, test_lark_manager_reply_parts.py, test_lark_goal_topic_runtime.py -> +0 regressions), npm run typecheck:control-plane + tests/control_plane_ts/content_digest_single_owner.test.ts (17/17).
  • Smokes & counterfactual parity: clean-HOME examples/lark-extension-activation-smoke.py, examples/semantic-vocabulary-drift-smoke.py, examples/control_plane/control-plane-maintainability-ratchet-smoke.py, and paired 57c4c43b52 counterfactual parity across key/receipt/reason/locator/stall/readback/transport delivery sequences (330,933-byte JSON exact match).
  • Suites & pre-merge gate: pytest -n 6 -rs across tests/extensions/, tests/architecture/, tests/canary/, and tests/test_cli_entrypoint.py (4,404 passed, 7 skipped: 1 Windows junction + 6 APFS filename skips); canary premerge --from-git-diff --git-diff-base origin/main passed (gate.status="passed", merge_gate_passed=true, 0 failures, 0 manual holds).

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

将 Lark 分片回复的持久记录与类型移到同一模块,保留未确认写入的读回、重启恢复和零重复发送。 基线由同一门面管理发送、定位符和分片完成字段。分片和停滞通知的 readback 逻辑重复。 收到长答复分片的原 Lark 会话,以及从本地分片记录恢复发送的管家。

把已接受的片段错当作未发会将同一答复再次发送。把不确定记录当完成则可能丢掉余下分片。 实际分片交付函数使用独立磁盘记录和受控 transport。第一片已发送但未证实时写下 locator,两次重开从同一 locator 读回,验证成功后只发送第二片,下一次重放复用完成回执。与目标基线完整 trace 相同。 目标基线 18 项、精确头 22 项分片与契约测试通过。独立磁盘重开对照覆盖发送未知、确认失败、恢复第二片、完成重放及无 locator。git diff --check 与当前目标静态 merge-tree 通过。 外层 Topic 实际调用路径中断回执写入、恢复单片及停滞提示三项,基线和精确头各 3 项通过。 provider transport 与凭据使用 fixture。已验证真实分片方法和持久记录,运营账户、线上回复、安装态和远程 CI 未核验。 较宽 Topic 套件为 120 通过、3 失败。隔离同命令复跑基线和精确头,63 和 128 条队列均在等最后一个普通输入超时,64 条均通过,首次运行的 64 条超时未稳定复现。 基线契约

改动思路 / Approach

该改动沿用 manager reply length fallback → deliver_manager_reply_parts → existing Lark send/readback ports → private File receipt。合并分片和通知的 readback 含义,在相关 adapter 内重用持久 schema。已有发送与验证回调仍是唯一外部传输口。 回执通过定位符验证原片段,只有确认后移动至下一片。未确认和未知意图保留原序列及恢复边界。 保持公开发送入口和已保存回执,只提取重复定位符核验与类型层;无需迁移现有记录。

具体改动 / Changes

精确提交 ac669ef,分叉基线 7f7297a。相对分叉点 57c4c43 的 PR 差分为 3 个文件 +806/-359。当前目标 7f7297a 的独立 Steward 变更在静态 merge-tree 中保留。

关键代码讲解

  • deliver_manager_reply_parts。从现有磁盘序列指针开始,按分片保存原尝试和结果。 源码

  • _deliver_single_part。先核验 locator,按原发送意图处理未确认分片。 源码

  • _reconcile_recorded_attempt。同一 readback 逻辑处理先前分片和停滞通知。 源码

  • plan_stalled_part_notice。继续使用已有次数、进度和一次通知门槛。 源码

  • reply-part-readback-before-retry(implemented)。部分或不确定发送沿原回复和 provider readback 恢复,保留外部效果防重和原受众。

对主干的风险 / Risks

首片无确认时维持 pending,无第二次发送。已记录 intent 但没有 locator 时也保持待处理。readback 路径不运行 before_send,正常发送和状态更新使用原 owner。 分片和通知共用 helper 后可能误清理或确认别的发送。独立测试确认当前原片段恢复不重发。 按原 locator 做只读核验,未获证明时保持待处理。验证成功后仅处理下一未知未发片。

我的整体评价 / Verdict

APPROVE。 认可当前精确头。独立配对读回显示未确认写入安全恢复,已发分片没有再次发送。 故障后从同一分片和 locator 恢复,避免让用户重复阅读或继续等待一份被误报完成的回复。

English verdict: APPROVE at ac669ef. Exact base/head file-restart tests preserve the same locator, verify before progress, send only the remaining part, and replay the completion receipt without another send.

@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 (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

复核字段: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.

将 Lark 分片回复的持久记录与类型移到同一模块,保留未确认写入的读回、重启恢复和零重复发送。 基线由同一门面管理发送、定位符和分片完成字段。分片和停滞通知的 readback 逻辑重复。 收到长答复分片的原 Lark 会话,以及从本地分片记录恢复发送的管家。

把已接受的片段错当作未发会将同一答复再次发送。把不确定记录当完成则可能丢掉余下分片。 实际分片交付函数使用独立磁盘记录和受控 transport。第一片已发送但未证实时写下 locator,两次重开从同一 locator 读回,验证成功后只发送第二片,下一次重放复用完成回执。与目标基线完整 trace 相同。 目标基线 18 项、精确头 22 项分片与契约测试通过。独立磁盘重开对照覆盖发送未知、确认失败、恢复第二片、完成重放及无 locator。git diff --check 与当前目标静态 merge-tree 通过。 外层 Topic 实际调用路径中断回执写入、恢复单片及停滞提示三项,基线和精确头各 3 项通过。 provider transport 与凭据使用 fixture。已验证真实分片方法和持久记录,运营账户、线上回复、安装态和远程 CI 未核验。 较宽 Topic 套件为 120 通过、3 失败。隔离同命令复跑基线和精确头,63 和 128 条队列均在等最后一个普通输入超时,64 条均通过,首次运行的 64 条超时未稳定复现。 基线契约

改动思路 / Approach

复核字段:criterion=reply-part-locator-readback architecture_reason=职责沿现有调用、provider 和持久化边界拆分,公共入口保持。 current_pr_boundary=仅 loopx/extensions/lark/manager_reply_parts.py, loopx/extensions/lark/manager_reply_parts_state.py, tests/extensions/test_lark_manager_reply_parts_contract.py。

该改动沿用 manager reply length fallback → deliver_manager_reply_parts → existing Lark send/readback ports → private File receipt。合并分片和通知的 readback 含义,在相关 adapter 内重用持久 schema。已有发送与验证回调仍是唯一外部传输口。 回执通过定位符验证原片段,只有确认后移动至下一片。未确认和未知意图保留原序列及恢复边界。 保持公开发送入口和已保存回执,只提取重复定位符核验与类型层;无需迁移现有记录。

具体改动 / Changes

精确提交 ac669ef,分叉基线 7f7297a。相对分叉点 57c4c43 的 PR 差分为 3 个文件 +806/-359。当前目标 7f7297a 的独立 Steward 变更在静态 merge-tree 中保留。

关键代码讲解

  • deliver_manager_reply_parts。从现有磁盘序列指针开始,按分片保存原尝试和结果。 源码

  • _deliver_single_part。先核验 locator,按原发送意图处理未确认分片。 源码

  • _reconcile_recorded_attempt。同一 readback 逻辑处理先前分片和停滞通知。 源码

  • plan_stalled_part_notice。继续使用已有次数、进度和一次通知门槛。 源码

  • reply-part-readback-before-retry(implemented)。部分或不确定发送沿原回复和 provider readback 恢复,保留外部效果防重和原受众。

对主干的风险 / Risks

首片无确认时维持 pending,无第二次发送。已记录 intent 但没有 locator 时也保持待处理。readback 路径不运行 before_send,正常发送和状态更新使用原 owner。 分片和通知共用 helper 后可能误清理或确认别的发送。独立测试确认当前原片段恢复不重发。 按原 locator 做只读核验,未获证明时保持待处理。验证成功后仅处理下一未知未发片。

我的整体评价 / Verdict

APPROVE。 认可当前精确头。独立配对读回显示未确认写入安全恢复,已发分片没有再次发送。 故障后从同一分片和 locator 恢复,避免让用户重复阅读或继续等待一份被误报完成的回复。

本轮独立复核:31 passed; Ruff passed; strict mypy passed;premerge passed 10/10 with 0 manual holds。

English verdict: APPROVE at ac669ef. Exact base/head file-restart tests preserve the same locator, verify before progress, send only the remaining part, and replay the completion receipt without another send.

@huangruiteng
huangruiteng merged commit ba07edb into main Nov 26, 2026
36 of 47 checks passed
@huangruiteng
huangruiteng deleted the codex/slim-lark-manager-reply-parts-zero-any-20261126 branch November 26, 2026 12:09
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