Skip to content

refactor(native-chat): modularize file_discovery with zero Any and single-pass event summary - #9457

Open
loopx-agent wants to merge 3 commits into
mainfrom
codex/slim-file-discovery-zero-any-20261126
Open

loopx-agent wants to merge 3 commits into
mainfrom
codex/slim-file-discovery-zero-any-20261126

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

Modularized loopx/capabilities/native_chat/file_discovery.py (656 -> 267 LOC, 76 -> 0 AST Any) into cohesive, strictly typed (0 AST Any, 0 # type: ignore, all <= 503 LOC) modules while preserving all exported symbols, monkeypatch seams, and baseline (50aa5b4fd1) runtime semantics:

  • loopx/capabilities/native_chat/file_discovery.py (267 LOC, 0 AST Any):
    • Owns platform change fingerprinting (file_change_fingerprint, optional_file_fingerprint respecting module sys / function monkeypatch hooks verified by private_delivery_discovery.py and test_chat_file_discovery.py), generic FileChatDiscovery (_RowDictT-typed rows_with_fingerprints and rows), external source fences/controls/equivalence (external_source_route_path, recovery_journal_fields, source_control_fields, later_equivalent_source_input), and explicit x as x re-exports of backlog and media surfaces.
  • loopx/capabilities/native_chat/file_discovery_backlog.py (503 LOC, 0 AST Any):
    • Houses generic _set_bounded_cache, QuotaBacklogObservationCache, single-pass _summarize_turn_events (collapsing 3 separate iterations over turn events into 1 pass while preserving exact deep-copy anchor isolation and handling malformed "payload": None), observed_turn_event_summary, observed_turn_interrupt, _same_store_method, observe_quota_backlog_batch (preserving transient load_session retry and request-scoped control timestamp parsing), _DeferredBacklogRequest, and _RecoveryDiscoveryReads backed by tight structural Protocols and _DiscoveryRowDict.
  • loopx/capabilities/native_chat/file_discovery_media.py (141 LOC, 0 AST Any):
    • Houses workspace reply-image validation and encoding (reply_image_directory, reply_image_workspace hardened against non-mapping project_context / invalid workspace_path, _check_reply_image, reply_image_attachment, read_reply_image, capture_reply_image_plan, _preparation_image_identity).
  • loopx/capabilities/native_chat/external_conversations.py (+2/-1 lines, 0 Any added):
    • Reuses _iso_datetime at line 245 (source_controls() readback) so all 10 loopx/ callers preserve +0 mypy regressions (81/20/37/47/9/19/6/2/18/28).
  • tests/capabilities/test_file_discovery_contract.py (<= 550 LOC, 0 AST Any):
    • Covers AST 0-Any/0-ignore/LOC bounds, full facade export parity, key-presence vs None, single-pass _summarize_turn_events isolation, LRU eviction + monkeypatch cache invalidation seams, malformed reply-image/timestamp inputs, and paired origin/main (50aa5b4fd1) vs HEAD behavioral parity.

Verification

  • ruff check on all 5 changed files: passed.
  • mypy --strict --follow-imports=silent on file_discovery*.py + test_file_discovery_contract.py: 0 errors across 4 source files.
  • Repo mypy: 0 errors across 17 source files; all 10 loopx/ callers preserve exact +0 error delta vs origin/main.
  • npm run typecheck:control-plane & node --experimental-strip-types --test tests/control_plane_ts/content_digest_single_owner.test.ts: passed (17/17).
  • scripts/check_rfc_bilingual.py --base origin/main --head HEAD: passed.
  • pytest -q -n 4 -rs in clean detached worktree across test_file_discovery_contract.py, test_chat_file_discovery.py, test_chat_store_input_validation.py, test_context_recovery_discovery.py, test_chat_internal_module_layout.py, test_chat_image*.py, test_lark_steward_directory_scan_perf.py, test_lark_private*.py, test_lark_post_images.py, test_lark_app_image_projection.py, test_private_chat_*.py, tests/canary/, and tests/architecture/: 2,980 passed, 6 skipped (6 standard macOS APFS skips in tests/canary/test_git_path_display.py).
  • Goal loopx check --scan-path: errors=0, warnings=0 (5 files boundary clean).
  • Goal CQR: cqr_59c985a0ac4bef570aba (decision="pass", status="valid").
  • Goal canary premerge: ok=true (direct=4/4, py_compile=1/1, catalog_run=2/2, manual_holds=0).

…ngle-pass event summary

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)

动机 / Motivation

拆分原生对话文件扫描、恢复观测缓存和回复图片,同时把三次事件遍历收敛为一次。

作者声明单遍扫描保持原语义。恢复发现的唯一锚点条件必须与完整 planner 的同一份历史兼容。

私聊后台的失败恢复发现器读取原始 Turn 事件,只有可解释的唯一 native input 才应成为恢复候选。

在真实本地 ChatSessionStore 中保留正常启动锚点,另追加一条含非空 list 或 string 的 turn.started。分别跑发现、完整 planner 和两组正常对照。

单遍扫描保留正常候选与合法的双锚点拒绝,但会把含损坏次锚点的 Turn 错误列为候选。完整 planner 仍拒绝。

本轮的错误发生在候选发现。完整路径的拒绝、请求和 Turn 原字节保持已核对,未观察到实际重派工作。

按主干合同 docs/architecture/rfcs/app-conversation-and-async-inbox-v0.md 核对。

  • unique_native_recovery_anchor。恢复观察保留唯一原生锚点要求,歧义保持拒绝。 由 _summarize_turn_events 处理。
  • read_only_discovery_hint。发现不接管实际授权,完整恢复仍独立重读。 由 _context_recovery_plan 处理。
  • retention_and_file_freshness。按物理事件文件和缓冲的变化使观察缓存失效,保留原 Turn。 由 observed_turn_event_summary 处理。

改动思路 / Approach

Python discovery 汇总事件供现有 TypeScript recovery planner;正式 admission 重读完整事件,并保留原来源、授权与容量门。

把所有非空 native_input 计入歧义判定,并保持只有唯一且合格的对象可以作为锚点。对部分损坏的事件保守回退,维持单遍设计。

具体改动 / Changes

头提交 f1fdea25c985699c0579f3f8c1a8173b7da28ac6,主干 50aa5b4fd1c88b7225fc30e58423120e3ad5d426。5 个文件 +1200/-483。

对主干的风险 / Risks

单个有效锚点与空值控制仍是候选,两个有效锚点仍不入候选。真实文件的请求和 Turn JSON 在两臂均保持原字节。

真实 discovery 的两个坏历史夹具中,主干均返回 false;现头忽略 malformed 次锚点后返回 true。现头同一数据的完整 planner 均返回 false。

仍沿用既有发现与授权入口,作用域未扩大到没有绑定的 Session。实际 admission 同样拒绝歧义样本。

定向 pytest 72 项通过。Ruff 全部变更文件通过,拆分模块与合同测试 strict mypy 通过。本地 premerge 的 6 项直接检查和 2 项 smoke 通过。真实事件摘要缓存、flush 与未持久化中断的原回归用例两臂均通过。

真实本地文件和生产 TypeScript planner;输入是隔离夹具,没有使用真实飞书账号、活动宿主或远端 CI。

我的整体评价 / Verdict

当前头应保留单遍扫描,并恢复对第二个非空但损坏锚点的歧义判定。只补合法对象测试会遗漏发现与完整 planner 的已验证分歧。回归用例应覆盖两条入口。

English verdict: REQUEST_CHANGES at f1fdea2. The scanner now treats two ambiguous event histories as recovery candidates. The full planner still rejects both. Preserve the one-anchor rule when summarizing.

…summary

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] 显式空载荷的启动事件仍会误排恢复。同一 Turn 的合法启动记录后另有一条显式 payload 为 null 的 turn.started。基线的 Lark 扫描抛 AttributeError,未返回候选。当前精确头在实际 pending_delivery_paths 中排入该项,重复 discovery 仍返回 true。真实 recover_failed_request 随后在完整事件读取抛同一 AttributeError,未调用源适配器,也没有改写请求或 Turn。 在单遍摘要区分 payload 缺失与显式 null。显式存在却不是对象时保留歧义并给出非候选,继续允许缺失字段或空字典作为没有输入的普通记录。用真实 File/Lark 扫描回归验证。 源码

动机 / Motivation

拆分 File Chat discovery、backlog cache 与媒体读取,并让单遍摘要忠实保留恢复候选的原始输入证据。 基线把所有非空 native_input 计入歧义。遇到明确为非对象的 payload 时,基线直接报错,因此没有返回候选。 Lark steward 的后台失败请求恢复扫描和同一 session 的回复 worker。

复验上一版的数组 native_input 误排。旧头排入,基线和当前头都不排入。当前也拒绝含非空字符串 payload 的第二条启动记录。独立对照保留单个合法 anchor 的候选资格,两个合法 anchor 仍拒绝。缺失 payload 和空对象在三版均允许原合法 anchor。 同一坏历史同时通过扫描并在恢复入口抛错,会让后台重复拾取无法恢复的请求。 本 head 的 File Chat、上下文恢复、Lark 扫描及附件定向套件 58 项通过。基线、旧头、新头各运行 7 项独立的真实 File 与 Lark 本地扫描对照。显式 null 新反例稳定复现。 实验使用隔离的真实 ChatSessionStore、typed plan、Lark 本地队列扫描和恢复入口。显式 null 来源为构造的持久历史,生产出现率、真实远程 Lark 与远程 CI 未核验。 基线契约

改动思路 / Approach

该改动沿用 ChatSessionStore.append_event/events_after → ChatExternalConversations.context_recovery_observer → typed recovery plan → pending_delivery_paths。原 File 事件和 TypeScript planner 继续是状态来源。Python 单遍摘要应把已观察到的无效启动事件作为歧义传给现有发现边界。 item.get("payload") 将缺失字段和 JSON null 映射为 None。当前分支只将非 None 的 non-Mapping 计入歧义,所以有合法 anchor 时 null 这一行被忽略。 在单遍摘要区分 payload 缺失与显式 null。显式存在却不是对象时保留歧义并给出非候选,继续允许缺失字段或空字典作为没有输入的普通记录。用真实 File/Lark 扫描回归验证。

具体改动 / Changes

精确提交 0f7017e,分叉基线 50aa5b4。五文件 +1,288 / −483。自上次评审两文件 +90 / −2,引入非空畸形输入计数和真实 discovery 回归。显式 null 仍被归到无 payload 的路径。

关键代码讲解

  • _summarize_turn_events。非映射分支忽略显式 null,把两个启动事件压成一个可用锚点。 源码

  • observed_turn_event_summary。按已有 File fingerprint 复用单遍发现摘要。 源码

  • context_recovery_observer。恢复发现调用摘要,给后台扫描返回候选。 源码

  • _started_native_inputs。完整恢复读取实际事件,显式 null 在取 native_input 前触发 AttributeError。 源码

  • pending_delivery_paths。真实本地扫描将新的错误候选返回给回复 worker。 源码

  • native_recovery_discovery_preserves_anchor_ambiguity(violated)。只有持久事件能确认唯一来源时才将原请求列入当前恢复候选。已出现但损坏的启动记录保持歧义。

对主干的风险 / Risks

同一 Turn 的合法启动记录后另有一条显式 payload 为 null 的 turn.started。基线的 Lark 扫描抛 AttributeError,未返回候选。当前精确头在实际 pending_delivery_paths 中排入该项,重复 discovery 仍返回 true。真实 recover_failed_request 随后在完整事件读取抛同一 AttributeError,未调用源适配器,也没有改写请求或 Turn。 本 head 的 File Chat、上下文恢复、Lark 扫描及附件定向套件 58 项通过。基线、旧头、新头各运行 7 项独立的真实 File 与 Lark 本地扫描对照。显式 null 新反例稳定复现。 实验使用隔离的真实 ChatSessionStore、typed plan、Lark 本地队列扫描和恢复入口。显式 null 来源为构造的持久历史,生产出现率、真实远程 Lark 与远程 CI 未核验。

语义与 CI 对齐

同一 Turn 的合法启动记录后另有一条显式 payload 为 null 的 turn.started。基线的 Lark 扫描抛 AttributeError,未返回候选。当前精确头在实际 pending_delivery_paths 中排入该项,重复 discovery 仍返回 true。真实 recover_failed_request 随后在完整事件读取抛同一 AttributeError,未调用源适配器,也没有改写请求或 Turn。 在单遍摘要区分 payload 缺失与显式 null。显式存在却不是对象时保留歧义并给出非候选,继续允许缺失字段或空字典作为没有输入的普通记录。用真实 File/Lark 扫描回归验证。

我的整体评价 / Verdict

REQUEST_CHANGES。 原数组误排已修复。新头仍会将含显式 null 的失败轮排入恢复,随后在原事件读取抛错。请补齐这个持久形态后再复审。 同一坏历史同时通过扫描并在恢复入口抛错,会让后台重复拾取无法恢复的请求。

English verdict: REQUEST_CHANGES at 0f7017e. The earlier duplicate-anchor case is fixed. An explicit null start payload still queues recovery through the real Lark scanner, then raises in full recovery. Distinguish null from missing payload before admitting a candidate.

…d event summary

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

拆分 File Chat discovery、backlog cache 与媒体读取,并让单遍摘要忠实保留恢复候选的原始输入证据。 基线把所有非空 native_input 计入歧义。遇到明确为非对象的 payload 时,基线直接报错,因此没有返回候选。 Lark steward 的后台失败请求恢复扫描和同一 session 的回复 worker。

独立三版本对照确认,合法锚点与字段缺失、空对象的组合仍能进入实际本地 Lark 恢复队列。两个合法锚点、数组 native_input、非空字符串 payload 继续被拒。 坏历史不再让本地 Lark worker 拾取无法恢复的队列项,合法候选仍可推进。 精确基线、旧头和当前各 7 项独立 File/Lark 扫描对照。当前 58 项 File Chat、上下文恢复、Lark 扫描及附件定向测试通过。完整 git diff --check 通过。 复验使用隔离的真实本地 ChatSessionStore 和 Lark 队列扫描,坏历史为构造样例。手动跳过发现直接调用完整恢复时,旧畸形 payload 仍有既有解析异常。生产历史频率、已安装版、实际远程 Lark 与 CI 未核验。 基线契约

改动思路 / Approach

该改动沿用 ChatSessionStore.append_event/events_after → ChatExternalConversations.context_recovery_observer → typed recovery plan → pending_delivery_paths。同一 File 事件和 TypeScript 计划拥有持久事实与资格判断。摘要传递可用的唯一 anchor 或歧义信号,完整恢复仍重新读取。 item.get 的默认空对象只处理缺失字段。JSON null 保持 None,因此进入非映射分支,第二条畸形启动会清除唯一锚点。 使用空对象作为缺失字段默认值。显式空值仍走非对象分支,复用现有歧义计数,无需另读历史。

具体改动 / Changes

精确提交 704422d,分叉基线 50aa5b4。五文件 +1,288 / −483。最新修订在同一单遍摘要中区分缺失字段与显式非对象值,并补实际 Lark 队列扫描断言。

关键代码讲解

  • _summarize_turn_events。非映射分支将显式 null 计为歧义,默认空对象只适用于字段缺失。 源码

  • observed_turn_event_summary。按已有 File fingerprint 复用单遍发现摘要。 源码

  • context_recovery_observer。恢复发现调用摘要,给后台扫描返回候选。 源码

  • _started_native_inputs。直接恢复入口仍重读同一原记录,历史异常与发现路径的修复边界分开。 源码

  • pending_delivery_paths。真实本地扫描拒绝损坏启动事件,继续把合格候选交给回复 worker。 源码

  • native_recovery_discovery_preserves_anchor_ambiguity(implemented)。保留 File 正常历史的可发现原输入,显式损坏且已存在的启动记录不能增加候选资格。

对主干的风险 / Risks

合法启动记录加第二条显式 payload:null 时,旧头 0f7017e 误排,当前真实 Lark 扫描拒绝,反复发现仍为 false。基线同输入在扫描抛 AttributeError。直接调用完整恢复入口仍可能对该损坏历史抛同一异常,此作用域验证的是扫描不再排入此项。测试未触发源调用或持久请求、Turn 改写。 精确基线、旧头和当前各 7 项独立 File/Lark 扫描对照。当前 58 项 File Chat、上下文恢复、Lark 扫描及附件定向测试通过。完整 git diff --check 通过。 复验使用隔离的真实本地 ChatSessionStore 和 Lark 队列扫描,坏历史为构造样例。手动跳过发现直接调用完整恢复时,旧畸形 payload 仍有既有解析异常。生产历史频率、已安装版、实际远程 Lark 与 CI 未核验。

我的整体评价 / Verdict

APPROVE。 上一轮的显式空载荷误排已在实际 Lark 扫描上修复,缺失字段及空对象仍可兼容原历史。 坏历史不再让本地 Lark worker 拾取无法恢复的队列项,合法候选仍可推进。

English verdict: APPROVE at 704422d. The real Lark scan now holds a turn with an explicit null start payload and still queues a valid anchor followed by a missing or empty payload.

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