Repository navigation
refactor(lark): slim private_conversations below 2000 lines with net LOC reduction - #8929
Conversation
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent; gpt-6.1-sol; OpenAI; reasoning effort max; runtime_reported.
Request changes conclusion (author-owned PR; GitHub blocks formal self-review)
动机 / Motivation
维护私聊和 App 镜像的开发者,需要缩小大模块,同时保留原会话、发送回执和授权撤销语义。原来的进度编辑、历史呈现和 App 镜像集中在 2654 行模块;本头拆为两个现有 adapter 内的职责模块,并合并重复发送保存与身份比较。四组实际 App→原私聊路径的 base/head 观察一致,原回执、防重及撤销拒绝保持;当前头的必需 diff hygiene 检查仍失败。本轮不执行真实飞书账户、生产安装、模型调用或合并,也不把行数下降当成长程收益证明。
改动思路 / Approach
进度与 App 镜像留在原 Lark adapter 内,Core 继续拥有 Session、Turn 和授权;拆分有实际 caller,回执没有迁移。当前 PR 只整理现有 adapter 的实现并保持传输行为;需先修复当前头的必需 diff hygiene 失败。
原 private_progress 已负责进度文本,追加同一职责的编辑、轮换与恢复方法合理;新 private_web_projection 收拢 App 镜像、历史提示和原 outbox。原服务仍构造同一个 LarkPrivateConversations,ChatHTTPServer 的历史 reader 及现有导入名保留。phase 保存、发送者校验、provider JSON 读取与图片核验也在原 adapter 内合并,没有另造配置或控制面规则。这是有真实调用链的内部整理,价值来自职责收拢及重复规则减少;总行数仅减少 18 行不能单独证明效果。
具体改动 / Changes
评审 head:8e2bf44aee679dddd8f923b399bcfc7045954d0c。PR base:68fe1788518e7edbf912638dcc421e17b0c9bc31。完整四路径 diff 为 +875/-893:三个 Python provider 模块及既有 maintainability baseline 的例外退役。主文件降至 1906 行,进度文件 345 行,新镜像文件 549 行。
关键代码讲解
- admit 保留原来源和 Core 准入,把重复 capture 构造、消息类型和发送者判断集中到局部 helper;仍在原锁和来源核验下提交。
- _deliver 用 save_phase 收拢落盘,保留 provider 写入前的 intent、原 attempt、未知结果拒绝重发及读取验证。
- _edit_progress 继续对原草稿执行编辑,预先记录尝试次数,保持 12 次预算及确定性拒绝后的轮换边界。
- _reconcile_web_projection 重读原 transcript、binding、source 和 grant,再发送原 App 消息;文件发现只是提示,不产生执行或发送授权。
规格使用上述 base 的 docs/development/README.md#engineering-scope-and-refactoring,并读取同 revision 的 docs/development/testing-and-quality.md:
- Bounded Future-Facing Refactoring:同域、可回退的拆分已实现。原 Core 权限 owner 不变,保留实际 HTTP/history 消费者与兼容导入。
- Refactor Real-Path Gate:实际 App HTTP、Core 持久状态、原生协议子进程及 provider outbox 已做相同输入对照;成功、未知上传、上传后撤销、读回失败恢复和 restart 均核对原回执。让来源发现遗漏有效 App 输入的 mutation 会使同一真实入口验收失败。
状态、帮助、未支持媒体标签、历史时间及四个既有进度函数共八个函数 AST 相同。没有新增命令、状态 schema、安装指令或默认权限。没有渲染页面变更。
对主干的风险 / Risks
[P2] 恢复当前头必需的 diff hygiene 检查
位置:private_progress.py:345。实际运行仓库标准 premerge 时,committed diff 检查报告“new blank line at EOF”,并令当前头的必需 gate 返回 ok=false。这个新增空行来自本次 diff,不能把当前验证描述为全部通过。最小修复是去掉文件尾多余空行,再在修复后的精确 head 重跑既有 diff check 和标准 premerge;无需为此新增测试或放宽检查。
| 验证 | 结果与边界 |
|---|---|
| 相同的 788 项源码套件,4 worker | base 788 PASS;head 首次 787 PASS / 1 FAIL |
| 失败用例的六轮定点复验 | 两个参数,双方各 12 PASS |
| 完整私聊 552 项,4 worker 再验 | 双方各 552 PASS,均保留清理期 BrokenPipe warning |
| 四组实际 App/Core/outbox 对照 | 双方各 4 PASS;正文、发送数、上传数、phase 状态与原身份关联一致 |
| 来源遗漏 mutation | 同一实际 reconcile 入口按预期失败,证明验收能发现镜像丢失 |
| 标准 premerge | FAIL:新增 EOF 空行;其余 5 项直接检查和 14 项选中检查通过 |
| Ruff / 配置内 mypy | PASS,类型检查 17 文件 |
首次 head 失败是处理中 capture 的恢复读者等待文件锁超时,位置在 capture_private_chat_request;同轮 base 未失败。其后双方定点及完整四 worker 再验均通过,断言、超时与锁预算未改。原失败原因仍未知,保留完整运行集合,不声称已定位或修复,也不将它归为已证实的本 PR 运行时回归。base 的首次套件和双方再次套件均出现过关闭协议子进程时的 BrokenPipe 清理 warning;额外 head 对照还有一次临时目录清理 warning,这些观察保留。
对照使用 d25e044,其整个 loopx 生产树及三个主要场景 fixture 共 1980 个路径与 PR base 68fe178 逐字相同。实际测试运行 Core、App HTTP 和文件回执,飞书网络及模型由合成 provider 提供;没有使用真实账户。
语义与 CI 对齐
现有绑定、来源、发送回执和 grant 仍是权威状态;重新导出、模块可用或缓存发现都不激活权限。实际“上传后撤销”对照零发送,“未知上传”重开后不再次上传或发送。没有新的 default-off 声明或工作义务。CI 按当前策略未查询、轮询或等待;上述失败是本地必需检查的实际结果。
我的整体评价 / Verdict
REQUEST_CHANGES。职责拆分及已执行的实际路径对照有充分支持,目前没有确认新的运行时语义缺陷;当前头仍需先恢复必需的 diff hygiene gate。修复应保持为文件尾清理,继续复用既有回执和验证,不扩展成新框架。仅移动 adapter 内部实现;状态与帮助函数 AST 相同,四组实际传输正文读回相同,没有渲染页面变更。真实飞书服务、安装后 App/桌面及原生平台采用未验证。此前单次并发超时的归因保持未知,完整失败与后续验证均保留;本评审不授予合并权限。
English verdict: REQUEST_CHANGES — head 8e2bf44 fails the required committed-diff hygiene check at private_progress.py:345; runtime parity evidence and the earlier unresolved lock-timeout observation are preserved.
|
This pull request has merge conflicts with Choose the remote for the base repository, not an out-of-date fork. git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEADFor a same-repository clone whose Keep the DCO |
8e2bf44 to
1f5d757
Compare
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent; Gemini; Google; self_reported.
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
维护飞书私聊、进度草稿及 App 镜像投影路径的开发者与长期维护者,在变更或排查私聊投递时受单文件过长及基线例外积压影响。
重构前,private_conversations.py 达 2,646 行(主干基线例外 2,654 行),将核心私聊收发与进度草稿编辑、App 镜像 outbox、历史媒体读取、状态文本及重复字段校验混在同一个热点文件中;若放任不管,每次私聊适配器调整都需绕过 2,000 行阈值且难以隔离回归。重构后,在不改变任何 Core 权限或会话所有权的前提下,把进度编辑方法拆回 private_progress.py(367 行)、把 App 镜像与不支持媒体历史拆入 private_web_projection.py(549 行),将 private_conversations.py 降至 1,914 行并移除其基线行数例外,总体变更净减 1 行(+895/-896)。
private_conversations.py 稳定低于 2,000 行硬阈值并退出 module_metric_baseline.json 例外;原导入方与测试 monkeypatch(PROGRESS_EDIT_BUDGET、PrivateUnsupportedMediaHistory、_status_text、private_conversations.time.time 与 _read_json)及主干图片修复语义均保持等价。
边界与非目标:本 PR 不迁移 Core 的 Session/Turn/Grant 所有权,不修改飞书协议或状态 schema,不消除既有未纳入 pyproject mypy 列表文件的历史 Any 类型注解,也不顺带修复主干既有的无关控制面复杂度债务或主干已存在的失败测试。
改动思路 / Approach
进度草稿编辑(_edit_progress、_close_progress、_retire_progress_parts、_continue_progress、_progress、_repair_recovery_presentation)直接归属同域既有模块 private_progress.py;App/Web 镜像 outbox、不支持媒体历史及命令状态文案归属新建同域适配器模块 private_web_projection.py;LarkPrivateConversations 仅通过双 Mixin 继承组合并在入口保留原重导出符号,未引入新的控制面、持久化或配置所有权。
当前 PR 边界:仅限 loopx/extensions/lark/** 内部传输适配器模块拆分与 loopx/canary/module_metric_baseline.json 例外退役;保留主干 Turn 级 answer_image_plan 与遗留 captured_images 恢复逻辑,单提交可完整回滚。
从结构与复用角度看,本次拆分没有新建第二套状态机或重复决策 owner:所有入口仍经由 LarkPrivateConversations(admit、reconcile_request、pending_body_paths、pending_delivery_paths、reconcile_app_feedback)进入,持久化回执(lark-private-deliveries/*.json、web-projections/*.json、external-requests/*.json)与授权校验仍直接读写原路径与 Core ChatExternalConversations / ChatConversationBindings。针对此前版本在 private_progress.py 末尾遗留空行导致 git diff --check 失败的 [P2] 问题,以及 rebase 上最新 origin/main(41ea75e898)后主干已将 _private_answer_images / _read_answer_images 外移至 private_delivery_discovery.py / return_files.py 并新增 answer_image_plan 与 captured_images 恢复路径的合入冲突,当前头 1f5d7577ee 已完整对齐主干实现并通过延迟局部导入 private_answer_images 消除了模块初始化循环依赖。
flowchart LR
Caller["ChatHTTPServer / 外部事件入口"] --> LPC["LarkPrivateConversations (1914 行)"]
LPC --> PPM["PrivateProgressMixin (private_progress.py, 367 行)"]
LPC --> PWPM["PrivateWebProjectionMixin (private_web_projection.py, 549 行)"]
LPC --> Core["Core: ChatExternalConversations / Bindings / Store"]
PPM -->|动态读取 time/_read_json| LPC
PPM -->|局部导入 private_answer_images| PDD["private_delivery_discovery.py"]
LPC -->|图片读取 read_answer_images| RF["return_files.py"]
图示说明(基于 exact head 1f5d7577ee 源码结构,仅作模块边界示意而非执行证据):原有对外入口与兼容重导出保留在 private_conversations.py,进度草稿与 App 镜像分别收敛到各自职责模块,Core 授权和图片读取职责不漂移。
具体改动 / Changes
评审精确基线:41ea75e89892ed88d0ae543e97e31aad0a181c47;评审精确 head:1f5d7577ee391ee3e750aabd3992e9b993520b15。四文件总改动为 +895 / -896(净 -1 行):
loopx/extensions/lark/private_conversations.py(+159 / -891,降至1,914行,any_count: 96,dict_any_count: 0):改为继承(PrivateProgressMixin, PrivateWebProjectionMixin),重导出PROGRESS_EDIT_BUDGET、PrivateUnsupportedMediaHistory、_status_text等兼容符号;以_msg_type、_valid_user_sender、_lark_payload、_binding_row、_STEWARD_PREFIX_COMMANDS与_deliver内局部save_phase收拢重复样板;并通过_ensure_answer_images统一完成 Turn 级answer_image_plan(local_scope)与遗留captured_images(captured_images_verified)校验落盘。loopx/extensions/lark/private_progress.py(+187 / -2,367行,any_count: 17,dict_any_count: 0):新增PROGRESS_EDIT_BUDGET与PrivateProgressMixin(6 个进度编辑/续接/恢复方法),保留origin/main(9ff078d199)对presentation_phase、presentation_stream与project_progress的健壮性修复;_edit_progress内改为延迟导入private_answer_images避免循环引用;通过_pc()动态访问private_conversations.time/_read_json保持测试 monkeypatch 兼容;同时清理原评审指出的文件尾多余空行。loopx/extensions/lark/private_web_projection.py(新增549行,any_count: 28,dict_any_count: 0):集中承载PrivateUnsupportedMediaHistory、PrivateWebProjectionMixin(App 镜像发现、发送与 reaction 反馈)、_same_fields、_projection_source_eligible、_command_text与_status_text。loopx/canary/module_metric_baseline.json(-3行):完整保留主干全部既有条目(含近期#8925、#8931、#8982等),仅退役private_conversations.py临时"lines": 2654超限豁免。
关键代码讲解
_deliver与_ensure_answer_images:前者用局部save_phase统一将image_keys、started、attempt、rejected_update、verified/blocker原子写入递送回执,保持 provider 写前强校验与未知回执拒绝重发;后者合并常规已完成回复与历史图片恢复两条路径的图片下载、SHA-256 校验和状态落盘,并在digests != expected_digests时提前返回None不污染已验证标记,同时完整支持主干的local_scope惰性计算与verification_key(source_urls_verifiedvscaptured_images_verified)。_deliver_completed_answer与_reconcile_historical_answer_images:完整保留主干03e0b9a992与d80c1d1f69的 Turn 级answer_image_plan(workspace_write+ 计划一致性核验)与遗留captured_images宿主私有目录核验逻辑,不放松任何图片来源或授权门禁。PrivateProgressMixin._edit_progress与_progress:_edit_progress在函数体内部延迟导入private_answer_images剥离私聊 Markdown 图片预览,破解private_conversations -> private_delivery_discovery -> private_progress环路;_progress继续通过_pc().time.time()调度频控与PROGRESS_EDIT_BUDGET=12滚动切分新草稿,保证既有用例 monkeypatch 原路径继续生效。PrivateWebProjectionMixin._reconcile_web_projection与PrivateUnsupportedMediaHistory.read:所有文件指纹与定位索引均只作为只读提示,真正读写或派发前始终重读绑定授权、原私聊来源及 Core 会话/Turn 记录,确保撤销绑定后零外发、零错误回显。
规范映射 / Specification Mapping
依据 docs/development/README.md#engineering-scope-and-refactoring(固定基线提交 41ea75e89892ed88d0ae543e97e31aad0a181c47)核对结果如下:
SPEC-SCOPE-MODULARITY(implemented):将超 2,000 行热点模块按稳定职责拆回既有private_progress.py与同域private_web_projection.py,主文件降至 1,914 行且净减少 1 行。SPEC-COMPAT-REUSE(implemented):通过父类组合及显式重导出保持LarkPrivateConversations、_status_text、PROGRESS_EDIT_BUDGET、PrivateUnsupportedMediaHistory与time/_read_jsonmonkeypatch 完整兼容,AST 公共签名与origin/main完全一致。SPEC-REALPATH-PARITY(implemented):在真实ChatSessionStore、ChatRuntimeController、ChatHTTPServer与合成Provider/ImageIO上完成基线与 head 对照(fixture_fingerprint与归一化观测指纹完全一致)及双路语义 mutation 敏感性验证。SPEC-HYGIENE-BASELINE(implemented):消除private_progress.py末尾多余空行,本地ruff、mypy、typecheck:control-plane、loopx check与loopx canary premerge(merge_gate_passed: true)全部通过并正确退役基线豁免。
对主干的风险 / Risks
经精确 head 全面检查,未发现阻塞合并的新缺陷(No blocking finding)。针对关键负向边界已验证:篡改 captured_images 字节摘要时 _reconcile_historical_answer_images 返回 0 且不产生 provider 写操作或写入 captured_images_verified;伪造/不匹配的 answer_image_plan 会保持 unverified 并拒绝发送图片;草稿编辑达到 PROGRESS_EDIT_BUDGET 后非终态编辑被拦截并经 _continue_progress 安全切换至新段;撤销绑定或缺失 session 时 PrivateUnsupportedMediaHistory 与 App 镜像均拒绝输出。
在基线与 head 对照敏感性验证中,未修改 head 对 App 镜像与进度剥离测试均通过(fixture_fp=ebf708f6a873ed09,obs_fp=ef226d5ef772bb28);当分别注入“令 _projection_source_eligible 漏掉合法 App 输入”与“跳过 _edit_progress 图片 Markdown 剥离”两条 mutation 时,同一真实入口的独立验收均按预期失败。
| 验证项目 | 状态 | 结果与归因说明 |
|---|---|---|
ruff check(3 个改动 Python 文件) |
PASS | 0 错误(All checks passed!) |
mypy --config-file pyproject.toml(17 个配置内文件) |
PASS | 0 错误(Success: no issues found in 17 source files) |
npm run typecheck:control-plane |
PASS | TypeScript control-plane 零报错通过 |
scripts/check_rfc_bilingual.py & git diff --check |
PASS | 0 空白/EOF 违例,双语 RFC 门禁通过 |
loopx check --scan-path(4 个改动文件) |
PASS | errors: 0,公开边界扫描干净 |
loopx canary premerge --from-git-diff --git-diff-base origin/main --tier quick |
PASS | merge_gate_passed: true(maintainability_ratchet 报告的 2 条 oversized_decision_function 为 origin/main 既有无关文件 heartbeat/builder.py 与 interaction_contract.py 的 advisory 继承失败) |
| AST 公共/MRO 签名对比 + 等价与 mutation 探针 | PASS | origin/main 与 HEAD 观测指纹完全一致(875d7b2a3666de64);两条 mutation 均令独立 oracle 失败 |
tests/architecture/test_semantic_vocabulary_drift.py |
PASS | 124 passed |
私聊与扩展 pytest 套件(test_lark_private_conversations.py 552 项等 23 个文件) |
PASS / FAIL(基线既有) | 1178 passed, 10 failed;全部 10 项失败(test_lark_native_reply_context.py 1 项 + test_lark_source_authority_reply.py 9 项)在未修改 origin/main 上 100% 同签名复现(33 passed, 10 failed),与本 PR 无关 |
架构/棘轮/管家/绑定套件(test_maintainability_ratchet.py 等) |
PASS / FAIL(基线既有) | 882 passed, 4 failed;1 项为上述主干既有的 heartbeat/builder.py & interaction_contract.py 控制面复杂度债务,1 项 [stopped_after_model] 在未修改 origin/main 同签名复现,另 2 项 15s 超时仅因 12 路并行负载抖动、单独复跑全部通过 |
| 其余飞书/管家套件(14 组测试文件) | PASS | 并行下 3 项超时类抖动经非拥塞复跑全数通过(test_lark_event_collector_git_budget.py 6 passed,test_lark_steward_reports.py 全过) |
| 远端 GitHub CI | UNVERIFIED | 按 Goal 配置 wait_for_ci: false(ci_policy: not_consulted),未查询或等待远端 CI |
我的整体评价 / Verdict
综合 problem_context 的两个效果维度:long_horizon 为 preserved(保留 Core 持久会话、Turn 恢复、进度分段滚动与幂等重试语义),user_experience 为 preserved(保留私聊命令文案、进度反馈、App 镜像与图片送达行为)。visual_review 为 not_applicable(本次仅调整 loopx/extensions/lark/ 内部 Python 传输适配器模块拆分及基线配置,未变更任何前端 Dashboard、HTML 或渲染页面;已核对 private_conversations.py、private_progress.py 与 private_web_projection.py 的 diff 确认无渲染输出变更。),未验证范围:none(纯后端适配器重构,无渲染 UI 变更)。
observable_semantics 结论为 equivalent(AST 签名及真实存储/HTTP/合成 provider 对照均无漂移),code_volume 为 necessary(净减 1 行并将热点模块收敛至 1,914 行),change_proportionality 为 proportionate(architecture_assessment 决定为 retain:仅限 loopx/extensions/lark/** 内部传输适配器模块拆分与 loopx/canary/module_metric_baseline.json 例外退役;保留主干 Turn 级 answer_image_plan 与遗留 captured_images 恢复逻辑,单提交可完整回滚。),default_off_isolation、authority_semantics 与 semantic_alignment 均为 not_applicable(无新增开关、权限语义或共享词汇变更)。
剩余风险与未覆盖边界:测试均使用合成 provider 与本地 HTTP/文件/SQLite 后端,未在真实飞书开放平台账户或打包桌面二进制中运行;同时 origin/main 自身存在 test_lark_source_authority_reply.py 等既有失败,合入时需遵循仓库独立的合并权限与就绪门禁。当前精确 head 1f5d7577ee391ee3e750aabd3992e9b993520b15 已满足评审验收标准。
English verdict: APPROVE — exact head 1f5d757 cleanly slims private_conversations.py to 1,914 lines (-1 net LOC across 4 files), preserves all post-branch origin/main image and progress fixes, resolves the prior EOF hygiene blocker, and matches baseline runtime/AST semantics under local verification (CI not consulted).
|
This pull request has merge conflicts with Choose the remote for the base repository, not an out-of-date fork. git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEADFor a same-repository clone whose Keep the DCO |
…LOC reduction Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
1f5d757 to
9b18df7
Compare
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent; Gemini; Google; self_reported.
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
维护飞书私聊传输、进度草稿编辑、消息撤回核验及 App 镜像投影路径的开发者与长期维护者。 重构前,private_conversations.py 在主干上达 2,651 行并依赖 module_metric_baseline.json 的 2,654 行临时豁免,把私聊核心收发、进度草稿编辑与 App 镜像/不支持媒体历史耦合在同一热点模块;重构后,进度编辑归入 private_progress.py(367 行)、App 镜像与媒体历史归入 private_web_projection.py(549 行),private_conversations.py 降至 1,914 行且整体净减 6 行(+901/-907)。 private_conversations.py 稳定低于 2,000 行硬阈值并移除基线豁免;保留全部原公开导入与测试 monkeypatch(PROGRESS_EDIT_BUDGET、PrivateUnsupportedMediaHistory、_status_text、time.time 与 _read_json),同时完整保留主干最近的 report_private_recall 撤回标识与 answer_image_plan 图片校验语义。 边界与非目标:本 PR 不迁移 Core 的 Session/Turn/Grant 所有权,不改变飞书协议或状态 schema,也不修改主干既有无关文件(如 interaction_contract.py 的 mypy 注解或 test_lark_native_reply_context.py / test_bound_owner_web_input.py 既有失败)。
改动思路 / Approach
本次沿用既有同域适配器分层,将进度草稿编辑、分段轮换与恢复期草稿修补归入既有模块 private_progress.py(PrivateProgressMixin),将 App/Web 镜像 outbox、不支持媒体历史只读投影及命令状态文案归入新建同域适配器 private_web_projection.py(PrivateUnsupportedMediaHistory、PrivateWebProjectionMixin),入口 LarkPrivateConversations 通过双 Mixin 组合并在原模块重导出兼容符号,同时用 _valid_user_sender、_msg_type、_lark_payload、_same_fields、_binding_row 与局部 save_phase / _ensure_answer_images 收拢重复样板。
当前架构决策与边界:仅限 loopx/extensions/lark/** 内部传输适配器模块拆分与 loopx/canary/module_metric_baseline.json 行数例外退役;保留主干 Turn 级 answer_image_plan、captured_images 恢复及 report_private_recall 撤回标识逻辑,单提交可完整回滚。 当前 PR 边界:Lark 传输适配器内部分层重构(private_conversations.py + private_progress.py + private_web_projection.py)与 module_metric_baseline.json 例外移除,不触及 Core 控制面或前端页面。 从结构与复用角度看,本次拆分没有新建第二套状态机或决策 owner:所有入口仍经由 LarkPrivateConversations 调度,持久回执路径与 Core ChatExternalConversations / ChatConversationBindings 授权校验保持原样,且 private_progress.py 与 private_web_projection.py 通过 _pc() 动态访问 private_conversations.time / _read_json,确保现有测试 monkeypatch 继续命中同一运行时对象。
flowchart LR
Caller["ChatHTTPServer / 入站事件与定时器"] --> LPC["LarkPrivateConversations (1914 行)"]
LPC --> PPM["PrivateProgressMixin (private_progress.py, 367 行)"]
LPC --> PWPM["PrivateWebProjectionMixin (private_web_projection.py, 549 行)"]
LPC --> Core["Core: ChatExternalConversations / Bindings / Store"]
PPM -->|动态读取 time/_read_json| LPC
PPM -->|局部导入 private_answer_images| PDD["private_delivery_discovery.py"]
PWPM -->|只读投影与出站镜像| Core
图示说明(基于 exact head 9b18df710e 源码结构的示意,仅作模块职责边界说明而非执行证据):原有外部调用面与兼容重导出保留在 private_conversations.py,进度草稿编辑与 App 镜像投影分别收敛到独立职责模块,Core 授权、Turn 恢复与图片读取职责不发生漂移。
具体改动 / Changes
依据目标基准 1c540c3e5ae059f974abdfcfe27b42f5cad9e992 的规范 docs/development/README.md#engineering-scope-and-refactoring 与精确 head 9b18df710e52dd07628e86271d3d8cbc99ea9945 的四文件 diff(+901 / -907,净 -6 行),各文件改动与规范映射如下:
loopx/extensions/lark/private_conversations.py(+163 / -904,由2,651行降至1,914行):改为继承(PrivateProgressMixin, PrivateWebProjectionMixin),重导出PROGRESS_EDIT_BUDGET、PrivateUnsupportedMediaHistory、_status_text与project_private_reply_history;新增_msg_type、_valid_user_sender、_lark_payload、_binding_row、save_phase与_ensure_answer_images收拢重复判断;在 rebase 过程中完整并入主干7dc4164553的report_private_recall撤回返回语义(render_content and not group时不阻断deleted标识,而在group与original路径传not_deleted=True)及62784ecc53注释清理,并进一步用_valid_user_sender简化_reply_context_message校验与sender_identity条件分支。loopx/extensions/lark/private_progress.py(+189 / -2,367行):收拢PROGRESS_EDIT_BUDGET = 12与PrivateProgressMixin(_progress_proof、_edit_progress、_close_progress、_retire_progress_parts、_continue_progress、_progress、_repair_recovery_presentation),并在_edit_progress内部延迟局部导入private_answer_images避免循环导入;既有 4 个纯进度函数 AST 与主干完全一致。loopx/extensions/lark/private_web_projection.py(新增549行):承载PrivateUnsupportedMediaHistory、PrivateWebProjectionMixin、_same_fields、_projection_source_eligible、_unsupported_media_label、_history_timestamp、_command_text与_status_text;4 个基础纯函数 AST 与主干完全一致。loopx/canary/module_metric_baseline.json(-3行):完整保留主干最新条目(含#8961更新后的content_ops/surface.py),仅退役private_conversations.py的"lines": 2654临时行数豁免。
规范条目映射(docs/development/README.md#engineering-scope-and-refactoring @ 1c540c3e5ae059f974abdfcfe27b42f5cad9e992):
SPEC-SCOPE-MODULARITY(implemented):将热点适配器按职责拆回private_progress.py与private_web_projection.py,private_conversations.py降至1,914行且四文件净减6行。SPEC-COMPAT-REUSE(implemented):LarkPrivateConversations、导出符号及 AST 公共/MRO 方法签名与主干完全对齐(无缺失方法、无参数签名漂移),动态_pc()访问保持原有 monkeypatch 有效。SPEC-REALPATH-PARITY(implemented):在真实ChatSessionStore、ChatRuntimeController与合成 provider 上验证私聊/群聊、撤回标识、App 镜像及_projection_source_eligiblemutation 敏感性。SPEC-HYGIENE-BASELINE(implemented):git diff --check零空白/EOF 违例,ruff、loopx check与loopx canary premerge全部通过并退役行数例外。
关键代码讲解
LarkPrivateConversations._source_message:在保留主干 P2P/群聊双读与停止配对逻辑的同时,用_valid_user_sender统一校验发送方、消息类型与删除态。关键分支区分了 P2P 原文渲染路径与群聊/原文校验路径:render_content and not group时保留deleted标识交由后续report_private_recall返回{"deleted": True}或None,而群聊canonical与original根消息显式传入not_deleted=True,确保既不回归主干7dc4164553撤回保护又消除冗余判空。LarkPrivateConversations._deliver与_ensure_answer_images:前者用局部save_phase收拢image_keys、started、attempt、rejected_update与verified/blocker原子落盘,维持 provider 写前 intent 与未知结果拒绝重发边界;后者统一合并正常完成回复与历史图片恢复的图片拉取、SHA-256 校验和验证键写回,保留local_scope惰性校验和篡改拒发语义。PrivateProgressMixin._edit_progress:继续执行 P2P Markdown 图片预览剥离、写前edit_attempts计数持久化与PROGRESS_EDIT_BUDGET = 12滚动切分;方法内延迟导入private_answer_images切断初始化期模块循环依赖,并通过_pc().time.time()保留既有频控测试兼容。PrivateWebProjectionMixin._reconcile_web_projection:文件指纹与 outbox 只作只读提示,发送前仍经authorized_source重读原私聊来源、当前绑定授权与 Core 会话输入,保证解绑或源变更后不外发 App 镜像。
对主干的风险 / Risks
经精确 head 9b18df710e52dd07628e86271d3d8cbc99ea9945 全面核查与本地验证,未发现阻塞合并的新缺陷(No blocking finding)。关键负向边界已在真实存储与控制器探针及套件中核实:report_private_recall=False 时已删除私聊消息返回 None,仅在 report_private_recall=True 时返回 {"deleted": True};对 App 镜像注入破坏 _projection_source_eligible 的 mutation 后,同一真实入口 _web_projection_paths() 立即丢失发现项([]),证明测试与探针能真实捕捉回归。
| 验证项目 | 状态 | 结果与范围说明 |
|---|---|---|
tests/test_lark_private_conversations.py -q -n 4 |
PASS | exact head 9b18df710e:574 passed, 0 failed(246.34s) |
| 13 个相关 Lark/棘轮/身份单测套件 | PASS | exact head 9b18df710e:364 passed, 0 failed(147.54s,含 test_maintainability_ratchet.py、test_lark_source_authority_reply.py、test_lark_private_steward_triage.py) |
tests/architecture/test_semantic_vocabulary_drift.py 等 2 项架构套件 |
PASS | 368 passed, 0 failed(含 TS AST 词汇漂移校验) |
tests/test_lark_steward_reports.py 与其余 26 项 Lark/Chat 套件 |
PASS / FAIL(基线既有与并发超时) | 初始 -n 4 共 1257 passed, 43 failed;其中 test_lark_steward_reports.py(29 passed)与 32 项 chat turn wait timed out 用例在非拥塞顺序复跑下 100% 通过;剩余 3 项(test_lark_native_reply_context.py 1 项与 test_bound_owner_web_input.py 2 项)在未修改 origin/main 上 100% 同断言复现(3 failed, 85 passed) |
loopx canary premerge --tier quick --from-git-diff --git-diff-base origin/main --goal-id personal-loopx-maintenance |
PASS | exact head 9b18df710e:ok: true, merge_gate_passed: true(包含 diff_check_*、check_rfc_bilingual.py、py_compile、3 项 catalog smokes 及有效质量回执 cqr_dd47910440fd526a4315) |
ruff check(3 个变更 Python 文件) & npm run typecheck:control-plane & loopx check |
PASS | ruff 0 错误;TS control-plane tsc --noEmit 0 错误;公开边界扫描 4 文件 0 泄露 |
mypy --config-file pyproject.toml --no-incremental |
FAIL(基线既有) | 17 个配置内文件仅报 origin/main 1c540c3e5a 既有的 interaction_contract.py:1004 错误(base 与 head stdout/stderr 字节完全一致,SHA-256 签名一致),变更的 Lark 文件未引入回归 |
| 真实 store 撤回与 App 镜像 mutation 探针 + AST 签名对比 | PASS | LarkPrivateConversations 方法集合零缺失、零签名漂移;两项独立纯函数群 AST 与主干一致;撤回标识与 mutation 探针按预期通过 |
| 远端 GitHub CI | UNVERIFIED | 按 Goal 配置 wait_for_ci: false(ci_policy: not_consulted),未查询或等待远端 CI |
我的整体评价 / Verdict
综合 problem_context 两个维度:long_horizon 为 preserved(保留 Core 持久会话、Turn 恢复、进度分段滚动、report_private_recall 撤回保护与幂等重试语义),user_experience 为 preserved(保留私聊命令与状态文案、图片送达与 App 镜像投影行为)。visual_review 为 not_applicable(本次仅调整 loopx/extensions/lark/ 内部 Python 传输适配器模块拆分及基线配置,未变更任何前端 Dashboard、HTML 或渲染页面;已核对 private_conversations.py、private_progress.py 与 private_web_projection.py 的完整 diff 确认无渲染输出变更。),未验证范围:none(纯后端适配器重构,无渲染 UI 变更)。
observable_semantics 为 equivalent(AST 签名、独立纯函数群与真实存储/控制器探针均无行为漂移),code_volume 为 necessary(将热点文件由 2,651 行收敛至 1,914 行并净减 6 行),change_proportionality 为 proportionate(architecture_assessment 决定为 retain:仅限 loopx/extensions/lark/** 内部传输适配器模块拆分与 loopx/canary/module_metric_baseline.json 行数例外退役;保留主干 Turn 级 answer_image_plan、captured_images 恢复及 report_private_recall 撤回标识逻辑,单提交可完整回滚。 当前 PR 边界:Lark 传输适配器内部分层重构(private_conversations.py + private_progress.py + private_web_projection.py)与 module_metric_baseline.json 例外移除,不触及 Core 控制面或前端页面。),default_off_isolation、authority_semantics 与 semantic_alignment 均为 not_applicable(无新增开关、权限语义或状态词汇变更,仅复用现有词汇)。
剩余风险与未覆盖边界:本地验证使用合成 provider 与本地存储/HTTP 测试替身,未连接真实飞书开放平台账户或打包桌面二进制;远端 CI 按策略未等待,且 origin/main 自身存在 interaction_contract.py:1004 mypy 报错及 3 项已复现的既有 pytest 失败。当前精确 head 9b18df710e52dd07628e86271d3d8cbc99ea9945 已在 rebase 至最新主干 1c540c3e5ae059f974abdfcfe27b42f5cad9e992 后完成全量验证与质量回执记录,满足评审标准(最终合并仍受仓库独立合并权限约束)。
English verdict: APPROVE — exact head 9b18df7 cleanly rebases PR #8929 onto origin/main 1c540c3, shrinks private_conversations.py to 1,914 lines (-6 net LOC across 4 files), preserves all post-branch recall/image/comment updates, passes local pytest/ruff/premerge checks with valid change-quality receipt cqr_dd47910440fd526a4315, and reproduces the remaining mypy and 3 pytest failures identically on unmodified origin/main (CI not consulted).
Summary
loopx/extensions/lark/private_conversations.py(2,654lines onorigin/main) well under the2,000-line maintainability ratchet ceiling while removing redundant transport/outbox boilerplate so the PR is strictly net-negative LOC without changing admission, recovery, or delivery invariants.4 files,1,906lines inprivate_conversations.py,+875 / -893 = -18net LOC across tracked + new files):loopx/extensions/lark/private_progress.py(345lines) withPROGRESS_EDIT_BUDGETandPrivateProgressMixin(_edit_progress,_close_progress,_retire_progress_parts,_continue_progress,_progress,_repair_recovery_presentation), routingtime/_read_jsondynamically throughprivate_conversationsso existing monkeypatches hold untouched.loopx/extensions/lark/private_web_projection.py(549lines) owningPrivateUnsupportedMediaHistory,PrivateWebProjectionMixin,_command_text,_status_text,_same_fields, and_projection_source_eligible.(PrivateProgressMixin, PrivateWebProjectionMixin)inLarkPrivateConversations, re-exportPROGRESS_EDIT_BUDGET,PrivateUnsupportedMediaHistory, and_status_textfor caller compatibility, and deduplicate repeated patterns insideprivate_conversations.py(save_phasein_deliver,_same_fields,_binding_row,_lark_payload,_valid_user_sender,_msg_type,_ensure_answer_images, and_STEWARD_PREFIX_COMMANDS)."lines": 2654ceiling forloopx/extensions/lark/private_conversations.pyinloopx/canary/module_metric_baseline.json.loopx/extensions/lark/**; preserves Core ownership of grants, sessions, turns, and recovery. Subject to maintainer merge authorization under repository policy; single-commit revert.Verification
uv run --extra test ruff check loopx/extensions/lark/private_conversations.py loopx/extensions/lark/private_progress.py loopx/extensions/lark/private_web_projection.py-> passed (All checks passed!)uv run --extra test mypy-> passed (Success: no issues found in 17 source files)uv run --extra test python examples/control_plane/control-plane-maintainability-ratchet-smoke.py-> passed (0regressions,0unreviewed exceptions)uv run --extra test python -m pytest tests/architecture/test_lark_identity_shape_owner.py tests/canary/test_maintainability_ratchet.py tests/test_conversation_status_presentation.py tests/test_lark_private_status.py tests/test_lark_private_progress.py tests/test_lark_private_recovery_progress.py tests/test_lark_private_feedback.py tests/test_lark_app_image_projection.py tests/test_lark_private_images.py -q-> 236 passed, 0 faileduv run --extra test python -m pytest tests/test_lark_private_conversations.py -q -n 4-> 552 passed, 0 faileduv run --extra test python scripts/check_rfc_bilingual.py --base origin/main --head HEAD-> passed