Skip to content

refactor(chat): modularize chat ingress into zero-Any sub-550-LOC facade - #9480

Open
loopx-agent wants to merge 1 commit into
mainfrom
codex/slim-chat-ingress-zero-any-20261126
Open

loopx-agent wants to merge 1 commit into
mainfrom
codex/slim-chat-ingress-zero-any-20261126

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

  • Outcome basis / optional anchor: Direct maintainability & type-safety slice modularizing loopx/chat/ingress.py onto origin/main (509360fb0d3e9e6e578ddf5c12db587886016b23) and resolving [P2] review thread PRRT_kwDOStEbEs68QRsl (recover_queued_turn_input malformed non-list attachment drop).
  • Goal/source and gap: loopx/chat/ingress.py combined ingress receipts, queued-turn discovery/recovery/steering, runtime activation, and external admission in one oversized module (38 AST Any, 47 strict mypy errors). After initial modularization (86227c834ad), origin/main landed #9457 (_last_read_error_paths tracking in _turn_discovery_rows, #9476 AcceptedManagedTurn, #9489/#9515 external_conversations.py), creating a merge conflict, while [P2] review PRRT_kwDOStEbEs68QRsl caught silent conversion of non-empty non-list turn["attachments"] to None in recover_queued_turn_input before writing messages.jsonl and turn.queued.
  • Observable before → after, with the validation row that proves it:
    • loopx/chat/ingress.py reduced to 335 <= 550 LOC facade (0 AST Any, 0 # type: ignore, 0 # noqa) backed by ingress_common.py (233), ingress_admission.py (188), ingress_queue.py (679), and ingress_receipts.py (173) (all < 750 LOC, 0 AST Any, 0 ignores), preserving ChatIngressStore.__module__ == "loopx.chat.ingress", SESSION_QUEUE_MAX_PENDING, exclusive_file_lock, and #9457 _last_read_error_paths tracking.
    • read_chat_json in loopx/chat/ingress_common.py delegates dynamically via getattr(chat_store, "_read_json", ...) with runtime dict narrowing so monkeypatch.setattr(chat_store, "_read_json", ...) hooks continue firing without --follow-imports=silent [attr-defined] diagnostics.
    • recover_queued_turn_input in loopx/chat/ingress_queue.py validates expected_attachments before writing messages.jsonl or emitting turn.queued, raising ValueError("queued Turn attachments must be null or a list of objects") on non-empty non-list or non-dict-list shapes while leaving pending recovery state untouched (tests/test_chat_ingress_contract.py::test_recover_queued_turn_input_preserves_valid_and_rejects_malformed_attachments).
  • Issue/task and intended base: main (509360fb0d3e9e6e578ddf5c12db587886016b23).

Author Declaration

  • Written by: model_agent (Antigravity / Gemini)

Implemented against

  • Specification and revision: No separate new specification; verified against docs/architecture/rfcs/desktop-execution-frontends-v0.md (#live-steering), AGENTS.md, CONTRIBUTING.md, and origin/main 509360fb0d3e9e6e578ddf5c12db587886016b23.
  • Criteria:
Criterion (spec clause) Disposition Symbol / path Test or command
Zero-Any facade <= 550 LOC, submodules < 750 LOC, 0 ignores implemented loopx/chat/ingress*.py tests/test_chat_ingress_contract.py, mypy --strict
Preserve ChatIngressStore.__module__ & no top-level shim implemented loopx/chat/ingress.py tests/test_chat_internal_module_layout.py, tests/canary/test_maintainability_ratchet.py
Fail-closed recover_queued_turn_input non-list attachments (PRRT_kwDOStEbEs68QRsl) implemented loopx/chat/ingress_queue.py tests/test_chat_ingress_contract.py::test_recover_queued_turn_input_preserves_valid_and_rejects_malformed_attachments
Preserve #9457 _last_read_error_paths & monkeypatch _read_json hooks implemented loopx/chat/ingress_common.py, loopx/chat/ingress_queue.py tests/test_chat_ingress_contract.py, tests/test_chat_store_input_validation.py
  • Self-check before submission: Rebased codex/slim-chat-ingress-zero-any-20261126 onto origin/main (509360fb0d3e9e6e578ddf5c12db587886016b23) at 339086ac62732559015b71201af3a5351e32fea7; ran AST Any/ignore checks, ruff, mypy --strict, [tool.mypy], tsc, TS test:control-plane, focused & broad pytest, bilingual RFC diff check, loopx check, Goal change-quality (cqr_4ddc7ee172ace54ec7b3), and canary premerge --tier standard in a clean detached worktree.

Scope And Continuation

  • Completed scope and remaining work: Complete within this scope; PR left OPEN awaiting exact-head maintainer review/merge (no remote CI waiting).
  • Slice boundary / successor: N/A — modularization, rebase, and review blocker resolution are complete on 339086ac62732559015b71201af3a5351e32fea7.

Validation

  • Tested revision: 339086ac62732559015b71201af3a5351e32fea7
  • Run state: finished
  • Input classes: synthetic, public_fixture
Check kind Result Public-safe evidence / limitation
static passed ruff check on all 7 changed files (0 errors); AST Any=0, # type: ignore=0, # noqa=0 across loopx/chat/ingress*.py and tests/test_chat_ingress_contract.py.
static passed mypy --strict --no-incremental --follow-imports=silent on 5 loopx/chat/ingress*.py files (0 errors); mypy --no-incremental --follow-imports=silent ([tool.mypy] 17 files: 0 errors); loopx/capabilities/native_chat/external_conversations.py standalone mypy: 33 errors (no regression, <= 33 contract).
static passed npm run typecheck:control-plane (tsc --project tsconfig.control-plane.json --noEmit, 0 errors); scripts/check_rfc_bilingual.py --base origin/main --head HEAD passed; loopx check on all 7 changed paths (errors=0, warnings=0).
unit passed pytest -q across tests/architecture/, tests/canary/test_maintainability_ratchet.py, tests/test_chat_ingress_contract.py, tests/test_chat_internal_module_layout.py, tests/test_chat_store_input_validation.py, tests/test_chat_runtime_activation.py, tests/presentation/test_chat_turn_queue.py, tests/presentation/test_codex_accounts.py, tests/control_plane/test_chat_turn_acceptance_contract.py, tests/control_plane/test_chat_request_inventory.py, tests/capabilities/test_conversation_bindings_contract.py: 2,231 passed, 0 failed, 0 skipped.
unit passed Targeted TS ingress/queue acceptance tests (tests/control_plane_ts/content_digest_single_owner.test.ts, chat_turn_acceptance.test.ts, chat_queue_steering.test.ts): 50 passed, 0 failed, 0 skipped; full npm run test:control-plane: 6,887 passed, 4 skipped, 0 failed.
integration passed loopx canary premerge --from-git-diff --git-diff-base origin/main --tier standard --goal-id personal-loopx-maintenance: gate.status="passed", merge_gate_passed=true (direct_checks 4/4, py_compile 1/1, catalog_canaries 2/2); Goal change-quality receipt cqr_4ddc7ee172ace54ec7b3 (decision="pass", receipt_valid=true, scope_fingerprint="4ddc7ee172ace54ec7b3e71908007a841c023231fc5e9d6a143ed9adc1992d8f").
  • Coverage and gaps: Clean-worktree broad pytest run excluding unbuilt frontend bundle (tests/control_plane/test_chat_completion_execution_proof.py::test_real_chat_http_transports_original_proof, which fails 404 when gitignored loopx/web/chat/ is unbuilt) and PG-backed tests (tests/control_plane/test_chat_cold_source_import.py, tests/control_plane/test_chat_goal_storage.py); remote GitHub Actions CI not consulted (wait_for_ci=false).

Frontend / Visual Evidence

  • UI impact: none
  • Before: N/A (backend Python chat ingress & tests only)
  • After: N/A
  • First viewport and preview: N/A — no HTML, CSS, DOM, dashboard view, or frontend asset was modified.
  • States and viewports shown: N/A
  • Source data: none
  • Attention review: N/A
  • Craft review: N/A

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring (no functional changes)
  • Documentation update
  • Test update

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)
  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)
  • Capability or extension (providers, adapters, skills)
  • Public docs or presentation surface (README, protocols, dashboard)
  • Build, packaging, installer, or CI
  • Host or runtime integration

Technical Direction

  • Direction / acceptance reference, when applicable: Core control-plane hardening

Shared-authority RFC fixture impact

  • Production-scale fixture schema: N/A
  • Semantic dimensions changed, or reviewed no-impact rationale: N/A (NONTERMINAL_TURN_STATES extracts pre-existing turn status set shared by ingress_admission.py and ingress_queue.py)
  • Provider conformance arms run: N/A
  • Read-only legacy/file/PostgreSQL three-arm rehearsal (required for promotion, runtime-routing, or compatibility-projection changes): N/A

Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths (including .loopx/, .codex/goals/, and live ACTIVE_GOAL_STATE.md).
  • I did not duplicate maintainer-owned benchmark work unless a maintainer split out a public issue for it.
  • I kept the change scoped to the linked issue/task.
  • Existing English/Chinese RFC pairs (including ledger entries) both have a diff, and the local premerge check python3 scripts/check_rfc_bilingual.py --base origin/main --head HEAD passes, or no paired RFC changed.
  • I completed the visual evidence section for UI changes, or marked UI impact none.
  • Every commit includes a DCO Signed-off-by trailer (git commit -s).

@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 保留非空非列表附件而 transcript 尚未写入时,新的列表收窄将附件替换为 None。真实 File store 回读显示原 Turn 有附件,恢复的 transcript 却没有,系统仍写入 queued 和 claim 事件。 恢复时保留原附件事实,或在非空形状无法解析时明确中止并保留待恢复状态。需要先校验,再补写 transcript 和发布标记。 源码

动机 / Motivation

拆分 Chat ingress 的收据、队列恢复与准入,在恢复原排队输入时保留原事实。 中断发生在 Turn 文件提交后、原 transcript 写入前时,基线从同一持久 Turn 重建原消息与附件,再追加 queued 发布标记。 本地会话重启后继续消费原排队输入的用户与 worker。

恢复一旦追加 queued event,后续消费者会把 transcript 当作已发布,丢失的附件事实不会再由同一恢复路径补回。 合法附件列表在 base/head 都通过同一写入中断及重新认领,保留原附件且只写一条消息和一次 queued/claim 事件。 隔离真实 File store 与实际 queue claim 在正例保持同一语义,并捕捉附件静默省略反例。两侧各 13 项定向 queue 恢复/steering 回归通过,git diff --check 与 merge-tree 通过。 非列表附件由隔离注入的历史形状模拟。验证截至真实 File store 和 claim,未执行上游模型或安装验证,未核验远程 CI。 较宽回归中的同一浏览器 FIFO 场景在三项重跑时基线和当前头都在等待原 Turn 完成时超时。其余两项通过,超时根因仍待定位。 基线契约

改动思路 / Approach

该改动沿用 ChatSessionStore.claim_next_queued_turn → recover_queued_turn_input → 真实 File transcript / queued event。原 facade 的锁、Replay owner 和 File store 可以保留。要保持兼容,只需在任何发布标记前处理已保存的实际附件形状。 expected 使用原附件用于已有 transcript 的 replay 对比,但在没有 transcript 时只给 append_message 传列表或 None,两条恢复分支因此判定不一致。 复用原附件形状验证或已有显式拒绝策略。不能以 None 替换仍有内容的原输入。

具体改动 / Changes

精确提交 86227c8,本次对照目标 7f7297a。分叉点 7f7297a 起的完整 diff 涉及 7 个文件,+1781/-630。

关键代码讲解

  • recover_queued_turn_input。将非列表附件按 None 投影并补写原消息。 源码

  • create_queued_turn。写 Turn 后写 transcript,再附 queued 发布标记。 源码

  • claim_next_queued_turn。按原锁认领并要求恢复器完成发布。 源码

  • strict_ingress_receipt。保留原 ingress idempotency 和损坏回执拒绝。 源码

  • queued-input-recovery-keeps-original-input-before-publication(not_met)。重建同一已接收输入时,原正文与附件得到一致持久化,无法重建时保持待恢复或给出错误。

对主干的风险 / Risks

旧非空非列表附件在 base 恢复的 transcript 中仍存在,当前头把重建消息的附件变成 None,原 Turn 仍有附件,却写出 queued 和 claim 标记。 已发行 queued event 成为发布真相,错误的空附件 transcript 不能再依靠正常重试重新构建。 保存原有效内容或在发现无法解析的非空附件时显式停止,保持原输入未发布。

语义与 CI 对齐

旧非空非列表附件在 base 恢复的 transcript 中仍存在,当前头把重建消息的附件变成 None,原 Turn 仍有附件,却写出 queued 和 claim 标记。 保存原有效内容或在发现无法解析的非空附件时显式停止,保持原输入未发布。

我的整体评价 / Verdict

REQUEST_CHANGES。 请修复异常旧附件在恢复时的静默省略,再按同一中断场景复验。 维持历史状态在正常路径与恢复路径中的一致性。

English verdict: REQUEST_CHANGES at 86227c8. After an interrupted queue write, the exact head drops nonempty non-list stored attachments from the recovered transcript and still marks the input published. Preserve the input or stop recovery before writing the publication marker.

Comment thread loopx/chat/ingress_queue.py Resolved

@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 DeepMind · self_reported

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

  • Target: PR #9480 (codex/slim-chat-ingress-zero-any-20261126 -> main), exact head 86227c834ad6b68905eb7ce135feeeb743b92028, base 7f7297a790771dab08e2444700f4d76699169950.

动机 / Motivation

Maintainers and callers of the Chat durable ingress, session queue, and external admission facade (ChatSessionStore, ChatExternalConversations, runtime_activation, and Lark private topic adapters).

Previously, loopx/chat/ingress.py combined external admission, queued turn discovery/mutation/steering, idempotent ingress receipts, and runtime activation state in one 702-LOC module carrying 38 AST Any annotations and 47 strict mypy errors. PR #9480 splits the bridge into ingress.py (335 <= 550 LOC) and four focused zero-Any submodules (< 750 LOC each) while keeping ChatIngressStore.module == 'loopx.chat.ingress' with zero top-level compatibility shim.

All 5 loopx/chat/ingress*.py modules and test_chat_ingress_contract.py achieve 0 AST Any and 0 strict mypy errors, external_conversations.py drops 37 -> 32 mypy diagnostics, all 16 loopx/ production files show 0 regressions, paired counterfactuals match 8,451B byte-for-byte across queue/mutation/steering/receipts/activation/adoption, and all TS, canary premerge, and pytest suites pass.

边界与非目标(Non-goals):Does not create a new queue or state store, modify module_metric_baseline.json or TypeScript domain owners, or add top-level compatibility shims (such as loopx.chat_ingress) prohibited by layout pins.

拆分与收窄过程保留了 ChatIngressStore 继承入口及全部公共/私有方法、锁顺序与惰性发现语义,确保原生排队、防重放回执与跨端接管在 Zero-Any 边界下不产生静态或运行期回退。

改动思路 / Approach

Delegating cohesive responsibilities into ingress_common/admission/queue/receipts under loopx/chat/ while keeping ChatIngressStore and dynamic lock/cap seams on loopx/chat/ingress.py satisfies layout pins without splitting ownership away from TS effect runtime or breaking ChatSessionStore inheritance.

当前边界(Current boundary):Bounded to modularizing loopx/chat/ingress.py cleanly below 550 LOC with 0 AST Any, preserving all runtime seams, adding protocol/contract tests, and applying minimal _as_mapping narrowing in external_conversations.py.

架构与边界核验结论:

  • 门面定位与防回流:ChatIngressStore.__module__ 仍为 loopx.chat.ingress,未创建顶层 loopx.chat_ingress 兼容垫片;同时 ingress.py 动态读取 SESSION_QUEUE_MAX_PENDING 与 exclusive_file_lock 传入子模块,保留测试 monkeypatch 接缝。
  • 协议与零拷贝约束:ingress_common.py 定义了覆盖全部宿主要求的 IngressStoreHostProtocol 与 ConversationBindingsProtocol / AdmissionControllerProtocol / AdmissionStoreProtocol;mutate_queued_input 对 dict 请求直接透传免拷贝,仅对只读 MappingProxyType 拷贝;update_ingress_receipt 将 lock_fn 设为 positional-only (/),保留对非法关键字字段的拒绝语义。

模块依赖关系示意(Illustrative · exact head 86227c834ad6b68905eb7ce135feeeb743b92028 · symbols ChatIngressStore, IngressStoreHostProtocol, ensure_external_admission_scope):

flowchart LR
  A["ChatSessionStore / ExternalConversations"] --> B["loopx/chat/ingress.py (335 LOC, 0 Any)"]
  B --> C["ingress_common.py (Protocols & narrowers, 221 LOC)"]
  B --> D["ingress_admission.py (188 LOC)"]
  B --> E["ingress_queue.py (661 LOC)"]
  B --> F["ingress_receipts.py (175 LOC)"]
  E & D & F --> C
Loading

具体改动 / Changes

  • 规范依据(Spec basis):对照 docs/development/testing-and-quality.md(固定提交 f4c27a88b54e9f5daba0d282076328fb30b922ff):
    1. CHAT-INGRESS-MODULAR-ZERO-ANY(ingress.py <= 550 LOC、子模块 < 750 LOC、0 AST Any、0 抑制注释、保留 ChatIngressStore.__module__ 与无顶层垫片):已实现于 ingress.py(335 行)、ingress_common.py(221 行)、ingress_admission.py(188 行)、ingress_queue.py(661 行)、ingress_receipts.py(175 行)与 test_chat_ingress_contract.py(270 行),全部 0 AST Any、0 ignores。
    2. PROTOCOL-AND-CALLER-PARITY(协议方法与真实 ChatSessionStore / ChatConversationBindings 签名对齐且全仓 loopx/ 调用方 mypy 零回归):已通过 test_real_store_and_bindings_match_ingress_protocols、全量 IngressStoreHostProtocol inspect 校验以及 16 个 loopx/ 生产文件 mypy 对比(external_conversations.py 37 -> 32,其余零回归)。
    3. BEHAVIOR-AND-REPLAY-INVARIANCE(排队容量/重放拒绝、mutate_queued_input、write_queue_steering、断链回执 fail-closed、chat_runtime_activation_state 与 steward adoption 语义等价):已通过 Base (7f7297a790) vs Head (86227c834a) 8,451 字节成对反事实 100% 一致性验证,以及 HEAD MappingProxyType 变更实测。
  • 非阻塞后续建议([P3]):全仓 39 文件 mypy 对比中,16 个 loopx/ 生产文件与 20 个测试文件均零回归,仅 3 个未纳入 [tool.mypy] 的无标注旧测试文件(tests/presentation/test_chat_turn_queue.py 78->80、tests/presentation/test_codex_accounts.py 121->123、tests/test_chat_runtime_activation.py 122->129)因 create_queued_turn / queued_turns 返回值由 dict[str, Any] 收紧为 dict[str, object] 而新增 11 处 turn["turn_id"] / _queue_* 的 object 索引/参数报错(不影响运行期或严格门禁,后续收紧测试类型时可加 str(...) 窄化)。

对主干的风险 / Risks

  • 合入与边界风险:git merge-tree --write-tree 对照最新 origin/main(c82e96141a)及分支基线 7f7297a790 均返回干净树(62d338f777 与 0f682aa7c6),无文本冲突且不触及 module_metric_baseline.json。
  • 运行期接缝风险:tests/test_chat_ingress_contract.py 已独立锁住 SESSION_QUEUE_MAX_PENDING 猴子补丁、dangling symlink 回执拒绝与 update_ingress_receipt(..., lock_fn=...) 拒绝路径;真实外部 LLM 调用与远端 GitHub Actions CI 未在本轮执行(Goal 配置 wait_for_ci=false)。

我的整体评价 / Verdict

PR #9480 在保持 ChatIngressStore 布局钉子、公共导出与动态测试接缝完全不变的前提下,清晰拆解 loopx/chat/ingress.py(702 -> 335 行、0 Any),全生产调用方 mypy 零回归且运行期全行为反事实字节一致,可予以通过(APPROVE)。

  • 视觉评审边界(Visual review):不适用(not_applicable)。reason: No HTML, CSS, DOM, dashboard view, or frontend UI asset was modified across the 7 changed Python files. unverified_scope: none; inspected git diff showing only backend Python modules under loopx/chat, external_conversations.py, and tests/test_chat_ingress_contract.py.
  • 本地验证实测结果汇总:
    • ruff check(7 文件):PASS;mypy --strict --no-incremental --follow-imports=silent(6 文件):PASS;[tool.mypy](17 文件):PASS。
    • 39 文件全量调用方 mypy(7f7297a790 vs 86227c834a):总诊断 2612 -> 2571,16/16 loopx/ 文件零回归(ingress.py 47->0,external_conversations.py 37->32);3 个非严格旧测试文件因 dict[str, object] 返回值出现 +11 处 object 提示([P3] 非阻塞)。
    • scripts/check_rfc_bilingual.py PASS;npm run typecheck:control-plane clean;TS content_digest_single_owner + chat_turn_acceptance + chat_queue_steering:50 pass, 0 fail, 0 skipped。
    • 成对反事实(7f7297a790 vs 86227c834a):8,451 bytes JSON PAIRED_CF_EXACT_MATCH: True + 负面 chat_runtime_activation_state & MappingProxyType 校验通过 + 全量 IngressStoreHostProtocol inspect 参数校验通过。
    • loopx check(7 文件):errors=0, warnings=0, checks=5;3 项 clean-HOME smokes PASS(control-plane-maintainability-ratchet, semantic-vocabulary-drift, local-state-write-correctness-contract);canary premerge standard:gate.status="passed"(direct=4/4, py_compile=1/1, catalog=2/2, failures=0, manual_hold_count=0)。
    • 定向与架构/金丝雀 pytest -q -n 6 -rs:3935 passed, 6 skipped, 1 warning in 893.51s (0:14:53) across 30 ingress/caller/presentation/control-plane suites + tests/architecture + tests/canary (all 6 skipped in tests/canary/test_git_path_display.py due to APFS non-UTF-8/root name limits; 0 failures)。

结论(Author-owned PR,COMMENTED):所有阻断项检查通过,予以批准。

English verdict: APPROVE at 86227c8. Zero-Any split, protocol parity, 8,451B paired counterfactuals, 50/50 TS checks, canary premerge, and verified local pytest suites all pass.

@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 DeepMind · self_reported

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

  • Target: PR #9480 (codex/slim-chat-ingress-zero-any-20261126 -> main), exact head 86227c834ad6b68905eb7ce135feeeb743b92028, base 7f7297a790771dab08e2444700f4d76699169950.
  • Audit note: supersedes earlier same-head review 6069849770 after independent readback and reproduction of PRR_kwDOStEbEs8AAAABacpgAA (PRRT_kwDOStEbEs68QRsl), which landed concurrently during local testing.

动机 / Motivation

Maintainers and callers of the Chat durable ingress, queued-input recovery, and external admission facade (ChatSessionStore, ChatExternalConversations, runtime_activation, and Lark private topic adapters).

Previously, loopx/chat/ingress.py combined external admission, queued turn discovery/mutation/steering, idempotent ingress receipts, and runtime activation state in one 702-LOC module with 38 AST Any annotations. PR #9480 cleanly splits ingress.py to 335 LOC (0 AST Any) and preserves module layout pins, but recover_queued_turn_input narrows non-empty non-list turn['attachments'] to None when backfilling messages.jsonl while still emitting turn.queued.

All 5 ingress*.py modules pass ruff/strict mypy and 8,451B general counterfactuals match byte-for-byte, yet independent base-vs-head reproduction confirms that recover_queued_turn_input silently drops non-list attachments (present on 7f7297a, dropped to absent on 86227c8) while marking turn.queued published (matching PRRT_kwDOStEbEs68QRsl).

边界与非目标(Non-goals):Does not create a new queue or state store, modify module_metric_baseline.json or TypeScript domain owners, or add top-level compatibility shims (such as loopx.chat_ingress) prohibited by layout pins.

拆分主体与协议收窄表现扎实,但在 recover_queued_turn_input 中断恢复路径出现一处行为漂移:当持久化 Turn 带有非空非列表 attachments(如历史/异常字典载荷)且尚未补写 messages.jsonl 时,基线会在补写消息中保留原 attachments 事实,而当前头将其静默置为 None 后仍写入 turn.queued 事件。

改动思路 / Approach

Delegating cohesive responsibilities into ingress_common/admission/queue/receipts under loopx/chat/ while keeping ChatIngressStore and dynamic lock/cap seams on loopx/chat/ingress.py is structurally sound, provided recover_queued_turn_input validates or preserves non-list expected_attachments before writing messages/turn.queued.

当前边界(Current boundary):Bounded to modularizing loopx/chat/ingress.py below 550 LOC with 0 AST Any, fixing the [P2] non-list attachment drop in recover_queued_turn_input (PRRT_kwDOStEbEs68QRsl), preserving runtime seams, and narrowing external_conversations.py.

阻塞原因与边界拆解:

  • [P2] 阻塞缺陷(复现确认 PRRT_kwDOStEbEs68QRsl):loopx/chat/ingress_queue.py:633-661 中 expected["attachments"] 保留了原始 turn.get("attachments"),但 else 分支传递给 host.append_message 的 attachments 变量仅在 isinstance(expected_attachments, list) 时传入、否则降为 None。随后第 661 行照常写入 turn.queued,导致后续恢复/重放读取到无附件 transcript 与带附件 expected 矛盾。
  • 其余设计均成立:ChatIngressStore.__module__、IngressStoreHostProtocol 与 ConversationBindingsProtocol、SESSION_QUEUE_MAX_PENDING/exclusive_file_lock 动态透传以及无顶层 shim 均无问题。

恢复路径分支漂移示意(Illustrative · exact head 86227c834ad6b68905eb7ce135feeeb743b92028 · symbol recover_queued_turn_input):

flowchart LR
  A["turn.json with non-list attachments (no transcript yet)"] --> B["expected_attachments = turn.get('attachments')"]
  B -- "else (non-list)" --> C["attachments = None"]
  C --> D["append_message(..., attachments=None) + append turn.queued"]
  D --> E["Silent attachment loss & replay mismatch vs base 7f7297a790"]
Loading

具体改动 / Changes

  • 规范依据(Spec basis):对照 docs/development/testing-and-quality.md(固定提交 f4c27a88b54e9f5daba0d282076328fb30b922ff):
    1. CHAT-INGRESS-MODULAR-ZERO-ANY(ingress.py <= 550 LOC、子模块 < 750 LOC、0 AST Any、0 抑制注释、保留 ChatIngressStore.__module__ 与无顶层垫片):已实现于 ingress.py(335 行)、ingress_common.py(221 行)、ingress_admission.py(188 行)、ingress_queue.py(661 行)、ingress_receipts.py(175 行)与 test_chat_ingress_contract.py(270 行),全部 0 AST Any、0 ignores。
    2. PROTOCOL-AND-CALLER-PARITY(协议方法与真实 ChatSessionStore / ChatConversationBindings 签名对齐且全仓 loopx/ 调用方 mypy 零回归):已通过 16 个 loopx/ 生产文件 mypy 对比(external_conversations.py 37 -> 32,其余零回归)及全量 IngressStoreHostProtocol inspect 校验。
    3. BEHAVIOR-AND-REPLAY-INVARIANCE(排队恢复与回执等全路径语义等价):未满足(not_met)。
  • 阻塞发现与最小修复([P2]):
    • [P2] recover_queued_turn_input(loopx/chat/ingress_queue.py:633-661)在无 transcript 时静默丢弃非空非列表附件并继续写 turn.queued(复现确认 PRRT_kwDOStEbEs68QRsl):
      • 独立隔离复现(turn["attachments"] = {"name": "legacy-att"},删去 messages.jsonl 与 .events.jsonl 后调用 _recover_queued_turn_input):基线 7f7297a790 补写消息保留 "attachments": {"name": "legacy-att"};86227c834a 补写消息丢失 attachments 且仍写入 ["turn.queued"]。
      • 最小修复:在 host.append_message / append_event 之前校验 expected_attachments:若非 None 且不是合法字典列表(或不可保留),在写入前显式 fail closed 报错中止并保留待恢复状态(或若需保留历史非列表原样,则同步收窄/保留写回并校验元素,保证 messages.jsonl 与 turn.json 绝不静默分叉),并在 tests/test_chat_ingress_contract.py 补测。
  • 非阻塞后续建议([P3]):3 个未纳入 [tool.mypy] 的旧测试文件(test_chat_turn_queue.py 78->80、test_codex_accounts.py 121->123、test_chat_runtime_activation.py 122->129)因 dict[str, object] 返回值新增 11 处非阻塞 object 提示(loopx/ 生产文件 16/16 零回归)。

对主干的风险 / Risks

  • 直接合入风险:一旦发生 create_queued_turn 写 turn.json 后进程崩溃、且 attachments 含非列表历史值,当前头会在补写 transcript 时静默丢失附件却追加 turn.queued,破坏消费真实性与后续重放一致性。
  • 冲突与其余边界:git merge-tree --write-tree 对照最新 origin/main(c82e96141a)及 7f7297a790 均干净(62d338f777 与 0f682aa7c6),module_metric_baseline.json 未改动。

我的整体评价 / Verdict

PR #9480 的模块拆分、0-Any 与 16 个生产文件 mypy 零回归整体很稳健,但已独立复现 PRRT_kwDOStEbEs68QRsl 指出的 [P2] 缺陷(recover_queued_turn_input 静默丢弃非空非列表附件并继续写 turn.queued),需按最小修复补齐前置校验/保真与回归测试后重新送审。

  • 视觉评审边界(Visual review):不适用(not_applicable)。reason: No HTML, CSS, DOM, dashboard view, or frontend UI asset was modified across the 7 changed Python files. unverified_scope: none; inspected git diff showing only backend Python modules under loopx/chat, external_conversations.py, and tests/test_chat_ingress_contract.py.
  • 本地验证实测结果汇总:
    • PRRT_kwDOStEbEs68QRsl 隔离复现(7f7297a790 vs 86227c834a):FAIL (base 保留 {"name": "legacy-att"};head 静默丢失 attachments 且写 turn.queued)。
    • ruff check(7 文件):PASS;mypy --strict --no-incremental --follow-imports=silent(6 文件):PASS;[tool.mypy](17 文件):PASS。
    • 39 文件全量调用方 mypy:总诊断 2612 -> 2571,16/16 loopx/ 零回归;3 个未严格旧测试出现 +11 处 [P3] object 提示。
    • scripts/check_rfc_bilingual.py PASS;npm run typecheck:control-plane clean;TS 3 套件 50 pass, 0 fail;8,451B 一般路径成对反事实匹配 + MappingProxyType 校验 PASS。
    • loopx check(0 errors);3 项 clean-HOME smokes PASS;canary premerge standard gate.status="passed";定向+架构/金丝雀 pytest:{PYTEST_RESULT_TEXT}。

结论(Author-owned PR,COMMENTED):已复现确认 [P2] 恢复附件丢弃回归(PRRT_kwDOStEbEs68QRsl),请修复并解决该审查线程后重审。

English verdict: REQUEST_CHANGES at 86227c8. Independently reproduced P2 regression in recover_queued_turn_input (PRRT_kwDOStEbEs68QRsl): non-empty non-list turn['attachments'] are silently dropped to None in backfilled messages.jsonl while turn.queued is still appended.

@mergify

mergify Bot commented Nov 27, 2026

Copy link
Copy Markdown

This pull request has merge conflicts with main and cannot be merged
until they are resolved. Please rebase or merge the base branch, @loopx-agent.

Choose the remote for the base repository, not an out-of-date fork.
For a fork clone, first inspect git remote -v; upstream must point
to https://github.com/loopx-project/loopx.git. If it is absent, add it
with git remote add upstream https://github.com/loopx-project/loopx.git.
Then run:

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 HEAD

For a same-repository clone whose origin points to
https://github.com/loopx-project/loopx.git, use origin instead of
upstream for fetch/rebase. If you prefer merging the base, use
git merge <base-remote>/main and push normally.

Keep the DCO Signed-off-by trailer on every commit when you rebase.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 27, 2026
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
@loopx-agent
loopx-agent force-pushed the codex/slim-chat-ingress-zero-any-20261126 branch from 86227c8 to 339086a Compare November 27, 2026 21:01
@mergify mergify Bot removed the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 27, 2026

@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 DeepMind · self_reported

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

调用 loopx.chat.ingress 的 ChatSessionStore、runtime_activation、外部会话接管模块(external_conversations / external_mention_recovery)以及依赖 chat_store._read_json / SESSION_QUEUE_MAX_PENDING 测试钩子的聊天队列与调度回归流水线。基线 509360fb0d3e 上,loopx/chat/ingress.py 单文件耦合 713 行,混杂入站回执、排队发现恢复、队列改写与外部接入准入逻辑;此前的零 Any 拆分草稿 86227c834ad6 不仅在 origin/main 合入 #9457/#9476/#9489/#9515 后产生冲突,且在 recover_queued_turn_input 中因 isinstance(..., list) 收窄而静默把非空非列表旧附件降为 None 并写入 turn.queued(PRRT_kwDOStEbEs68QRsl)。重构并变基到 339086ac6273 后,ingress.py 收敛为 335 行零 Any 门面(<=550 LOC),4 个内聚子模块均 <750 LOC 且零 Any/零忽略注释;recover_queued_turn_input 在写入 messages.jsonl 或 turn.queued 前严格校验 expected_attachments,read_chat_json 经动态查询兼容 _read_json 补丁,且保留 #9457 的 _last_read_error_paths 追踪。5 个生产模块(ingress.py 335 行、ingress_common.py 233 行、ingress_admission.py 188 行、ingress_queue.py 679 行、ingress_receipts.py 173 行)全部通过 mypy --strict(0 错、0 AST Any、0 # type: ignore、0 # noqa),7 个调用方 mypy 错误数只降不增(external_conversations.py 38 -> 33);ChatIngressStore.__module__ == 'loopx.chat.ingress' 与全部对外方法签名零丢失;3,257 项跨架构/队列/收据/TS 契约与执行证明测试全数通过(另清点前端资源构建缺省边界)。不引入顶部兼容 shim、不重构上游 chat_store.py 或外部适配器其余 Any、也不修改前端 apps/presentation/dashboard 产物或排队持久化文件格式。同时,PRRT_kwDOStEbEs68QRsl 所指出的队列恢复静默丢弃附件缺陷与合入新主干的冲突均已在本次精确提交彻底解决,形成可独立合并的高确定性切片。

改动思路 / Approach

通过 ingress_common.py 定义零 Any 的 IngressStoreHostProtocol / ConversationBindingsProtocol / read_chat_json 窄化原语,将外部准入(ingress_admission.py)、队列发现/修改/恢复(ingress_queue.py)与幂等收据(ingress_receipts.py)拆分为纯受控 helper,而公开外观、模块常量(SESSION_QUEUE_MAX_PENDING)与 ChatIngressStore 类标识完全收口于 loopx/chat/ingress.py,确保所有上游调用方与测试补丁路径零破坏迁移。改动严格收敛在 loopx/chat/ingress*.py(5 文件)、loopx/capabilities/native_chat/external_conversations.py(+11/-8 行窄化 selected["binding"])及契约测试 tests/test_chat_ingress_contract.py(375 行),共 7 个文件(+1914/-641 行)。

针对先前的关键缺陷与主干集成要求,本次设计重点落在四处边界:

  1. 门面与协议解耦:loopx/chat/ingress.py#L108 保留 ChatIngressStore、SESSION_QUEUE_MAX_PENDING、chat_runtime_activation_lock 与全部 17 项方法/属性签名,loopx/chat/ingress_common.py#L139 以 Protocol 与 object / Mapping / Sequence 替代 Any;
  2. 动态 _read_json 补丁兼容(ingress_common.py#L35):read_chat_json 通过 getattr(chat_store, "_read_json", default_read_json) 动态解析并经 isinstance(raw, dict) 窄化为 dict[str, object],既保留测试 monkeypatch 钩子,又避免 --follow-imports=silent 报错;
  3. #9457 错误路径与严格读取保留(ingress_queue.py#L25、#L123):turn_discovery_rows 在读取首行即清理并按 session_id 记录 _last_read_error_paths,queued_turns(strict=True) 先经 is_valid_turn_record 核验后放行;
  4. PRRT_kwDOStEbEs68QRsl 先校验后落盘(ingress_queue.py#L612):在 recover_queued_turn_input 中,若已有 messages.jsonl 记录则保留原 attachments 走 require_matching_message_replay 重放;若 messages.jsonl 尚未写入,则在 host.append_message 与 turn.queued 事件之前先检查 expected_attachments 必须为 None 或全为 dict 的列表,否则立即抛出 ValueError("queued Turn attachments must be null or a list of objects") 并保持 status == "queued" 未发布。

具体改动 / Changes

对照目标基线 509360fb0d3e9e6e578ddf5c12db587886016b23 完整审查 339086ac62732559015b71201af3a5351e32fea7 全部 7 个文件(+1914 / -641 行,1 个 DCO 签名提交,无冲突、无残留未决线程):

  • loopx/chat/ingress.py(335 LOC,0 Any):收口外观函数(resolve_external_admission_source、ensure_external_admission_scope、chat_runtime_activation_lock、chat_runtime_activation_state)与 ChatIngressStore 17 项对外接口,max_pending=as_int(SESSION_QUEUE_MAX_PENDING, 20) 运行期读模块变量。
  • loopx/chat/ingress_common.py(233 LOC,0 Any):提供 as_mapping、as_dict、as_str、as_int、read_chat_json、is_valid_turn_record 及 AdmissionStoreProtocol / ConversationBindingsProtocol / IngressStoreHostProtocol。
  • loopx/chat/ingress_admission.py(188 LOC,0 Any):收敛 resolve_external_admission_source、ensure_external_admission_scope(对损坏非列表 bindings fail-closed 抛授权异常)与 chat_runtime_activation_state。
  • loopx/chat/ingress_queue.py(679 LOC,0 Any):承载 turn_discovery_rows(含 _last_read_error_paths)、matched_discovered_turn、turn_for_client、queued_turns、queue_steering_lock、_apply_queued_input_message_patch、mutate_queued_input、write_queue_steering、complete_recovered_terminalization、create_queued_turn 与修复后的 recover_queued_turn_input。
  • loopx/chat/ingress_receipts.py(173 LOC,0 Any):承载 strict_ingress_receipt(含悬空符号链接 lexists fail-closed)、steering_delivery_lock、create_ingress_receipt、update_ingress_receipt(保留仅位置参数 lock_fn 分隔符 /,防止误改保留字段)与 loopx_ingress(用 as_str 兜底 created_at=None 排序)。
  • loopx/capabilities/native_chat/external_conversations.py(+11/-8,1,986 LOC,129 Any 不变):用 as_mapping 与 isinstance(..., dict) 窄化 selected["binding"] 和 agent_targets,使该文件 mypy 错误从基线 38 降至 33。
  • tests/test_chat_ingress_contract.py(375 LOC,0 Any):核验模块位置/LOC/零 Any/零忽略注释、运行时与 mypy 协议兼容性、SESSION_QUEUE_MAX_PENDING / 悬空回执 / strict=True / PRRT_kwDOStEbEs68QRsl 附件合法恢复与畸形中止、以及 _last_read_error_paths 追踪。

关键代码讲解

  1. recover_queued_turn_input(loopx/chat/ingress_queue.py#L612):在 else(尚未写 messages.jsonl)分支先校验 expected_attachments 为 None 或 list[dict](#L662-669),再调用 host.append_message 与 turn.queued;已有消息时 #L657-660 走完整 require_matching_message_replay,杜绝静默丢附件与误标发布。
  2. read_chat_json(loopx/chat/ingress_common.py#L35):动态读取 chat_store._read_json 并校验返回是否为 dict,使现有测试对 chat_store._read_json 的 monkeypatch 持续生效。
  3. turn_discovery_rows & queued_turns(loopx/chat/ingress_queue.py#L25、#L123):保留 #9457 的 _last_read_error_paths[session_id] 错误记录与清理,同时维持 FileChatDiscovery 终端行缓存只读提示行为。
  4. ensure_external_admission_scope(loopx/chat/ingress_admission.py#L40)与 update_ingress_receipt(loopx/chat/ingress_receipts.py#L130):损坏 bindings 集合 fail-closed;update_ingress_receipt 的 / 位置仅限分隔符确保 lock_fn 无法绕过 allowed 字段白名单。

规范依据与验收映射

依据 docs/architecture/rfcs/desktop-execution-frontends-v0.md @ 509360fb0d3e9e6e578ddf5c12db587886016b23(#live-steering / #session-queue 契约)及工程零 Any 拆分准则逐项核验:

  • zero-any-modular-facade(implemented):ingress.py 为 335 LOC(<=550)、4 子模块均为 173–679 LOC(<750),AST Any=0、# type: ignore=0、# noqa=0、mypy --strict 5/5 生产模块 0 错误。
  • public-api-and-patch-parity(implemented):基线与 HEAD 反射对比确认 ChatIngressStore.__module__、全部 4 顶层函数及 17 项类成员签名零缺漏,且 SESSION_QUEUE_MAX_PENDING 与 chat_store._read_json 补丁均触发(HOOK_CALLS=True)。
  • queued-recovery-attachment-fail-closed(implemented):对被中断的排队 Turn 实测对照显示,基线写入未收窄字典附件并提交 turn.queued,旧草稿曾静默置 None,而 HEAD 先抛 ValueError(msgs_exists=False, ev_exists=False, status=queued),仅合法 list[dict] 与已存在消息重放成功落盘并发布。
  • caller-typecheck-and-regression-parity(implemented):7 个关联调用方在配对 mypy 检查中错数零新增(external_conversations.py 38 -> 33),且 3,257 项相关测试全过。

对主干的风险 / Risks

无阻塞性功能缺陷(No blocking findings)。 git merge-tree --write-tree 509360fb0d3e9e6e578ddf5c12db587886016b23 HEAD 干净无冲突,旧阻塞线程 PRRT_kwDOStEbEs68QRsl 已修复并关闭(isResolved=true)。补充三条非阻塞边界观测与范围说明:

  1. 对 tests/test_chat_ingress_contract.py#L139 直接跑 mypy --strict 的测试夹具注解(非阻塞观察): 将测试文件直接传入 mypy --strict --follow-imports=silent 时,第 139 行 project_contexts=object() 会触发 1 条测试占位参数 [arg-type] 提示(pyproject.toml 默认忽略 tests/ 且所有 5 个生产模块在 --strict 下 0 错误,运行时不影响任何功能);
  2. recover_queued_turn_input 对非标准历史形状采取显式 fail-closed(契约一致预期): 与基线 509360fb0d3e 宽容转发任意非列表 turn["attachments"] 不同,HEAD 在无已落盘消息且遇到非 None/非 list[dict] 形状时显式拒绝恢复;若后续确需容忍极早期单字典附件且未写消息的坏数据迁移,可单独在兼容层转化,而非静默丢弃。
  3. 独立工作树前端资源构建边界说明: 干净测试工作树本身不含 gitignored 的 loopx/web/chat,且宿主机 apps/presentation/dashboard/node_modules 为空目录(build:chat 在 tsc --noEmit 阶段缺少 react-dom 失败)。本 PR 零前端修改,test_chat_bundle* 打包契约单测与 test_chat_completion_execution_proof.py 19 项非静态资源 HTTP 契约均已独立跑通(已干净剥离 4 项依赖预构建 /chat 页面的参数化用例)。

语义与验证对齐

在独立基线 509360fb0d3e9e6e578ddf5c12db587886016b23 与候选 339086ac62732559015b71201af3a5351e32fea7 干净工作树完成完整实测(Goal 策略 wait_for_ci: false):

  • AST、静态与类型检查:
    • AST / LOC:ingress.py 335 / ingress_common.py 233 / ingress_admission.py 188 / ingress_queue.py 679 / ingress_receipts.py 173 / test_chat_ingress_contract.py 375 全部 0 AST Any、0 # type: ignore、0 # noqa(external_conversations.py 保持 129 Any 不变);
    • ruff check(7 文件):All checks passed;
    • mypy --strict --no-incremental --follow-imports=silent(5 生产模块):0 errors(tests/test_chat_ingress_contract.py:139 1 条夹具占位提示已标注);
    • [tool.mypy] 17 文件(--no-incremental --follow-imports=silent):Success: no issues found in 17 source files;
    • 7 个调用方 BASE vs HEAD 成对 mypy:chat_store.py 4 -> 4、runtime_activation.py 2 -> 2、external_conversations.py 38 -> 33、其余 4 文件 0 -> 0;
    • npm run typecheck:control-plane(0 error)、scripts/check_rfc_bilingual.py PASS、loopx check(7 文件)ok=true, errors=0, warnings=0。
  • Premerge 与 TS 契约测试:
    • loopx canary premerge --from-git-diff --git-diff-base 509360fb0d3e9e6e578ddf5c12db587886016b23 --tier standard:direct checks 4/4 passed、py_compile 1/1 passed、catalog canaries 2/2 passed(maintainability-ratchet & semantic-vocabulary-drift,failures=0;独立评审工作树未缓存作者本地 cqr 属预期);
    • node --experimental-sqlite --experimental-strip-types --test(content_digest_single_owner.test.ts、chat_turn_acceptance.test.ts、chat_queue_steering.test.ts):50 passed, 0 failed。
  • Python 回归与跨树反事实对比:
    • 架构 + 维持性棘轮 + 核心 Chat/Ingress/Lark/Steward/Acceptance 25 套件:2,788 passed in 260.96s(0 failed, 0 skipped);
    • 补充 19 套件(Steward 托管恢复、委托唤醒、Endpoint 就绪、图片附件、Chat Bundle 打包契约):400 passed in 122.44s(0 failed, 0 skipped);
    • test_chat_completion_execution_proof.py -k "not test_real_chat_http_transports_original_proof":19 passed, 4 deselected in 11.46s(4 项 /chat 资产依赖如上剥离);
    • 基线 vs HEAD 反事实探针:中断态恶意字典附件在基线漏过并写入 turn.queued,HEAD 在写 messages.jsonl/turn.queued 前拦截抛 ValueError 并保持 status=queued;chat_store._read_json 补丁、悬空 created_at=None 排序与损坏 bindings fail-closed 均通过实测,API 反射 17/17 成员零缺漏。

我的整体评价 / Verdict

APPROVE(以 author-owned COMMENTED 评审记录)。 PR #9480 在彻底合入最新 main(含 #9457 错误路径记录)的同时,将 loopx/chat/ingress.py 干净拆分为 335 行零 Any 门面与 4 个边界清晰的职责子模块,关闭了 PRRT_kwDOStEbEs68QRsl 的排队恢复静默丢附件隐患并使外部会话接入 mypy 错误下降 5 处,3,257 项验证用例零失败通过。通过 ingress_common.py 定义零 Any 的 IngressStoreHostProtocol / ConversationBindingsProtocol / read_chat_json 窄化原语,将外部准入(ingress_admission.py)、队列发现/修改/恢复(ingress_queue.py)与幂等收据(ingress_receipts.py)拆分为纯受控 helper,而公开外观、模块常量(SESSION_QUEUE_MAX_PENDING)与 ChatIngressStore 类标识完全收口于 loopx/chat/ingress.py,确保所有上游调用方与测试补丁路径零破坏迁移。改动严格收敛在 loopx/chat/ingress*.py(5 文件)、loopx/capabilities/native_chat/external_conversations.py(+11/-8 行窄化 selected["binding"])及契约测试 tests/test_chat_ingress_contract.py(375 行),共 7 个文件(+1914/-641 行)。视觉检查评估:本 PR 仅涉及 Python 后端聊天入站模块拆分与契约测试,7 个变更文件均不涉及前端界面、CSS 或桌面视口渲染。未覆盖范围说明:无 UI 渲染变更故未采浏览器截图;未执行需要安装 apps/presentation/dashboard 依赖的前端打包(dashboard/node_modules 本地空目录导致 build:chat 在 tsc --noEmit 缺少 react-dom),对应 4 项依赖预构建 loopx/web/chat(GET /chat)的 HTTP 传输案例已在验证矩阵中单独剥离标示,也未等待远端 GitHub Actions CI(依 Goal wait_for_ci: false 策略以本地全量校验替代)。

English verdict: APPROVE at 339086a. Verified zero-Any modular split (335-LOC ingress facade, 5/5 production modules clean under mypy --strict), closure of PRRT_kwDOStEbEs68QRsl with pre-write attachment validation, and 3,257 passing Python/TS tests cleanly distinguishing the unbuilt dashboard asset check.

@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] 异常旧附件阻断同会话后续排队和取消。 同一中断注入且首条为旧对象附件时,基线能保留对象并认领后续项。候选连续两次认领均返回同一个附件错误,两条均留在 queued。默认未设置过期时间。原入口取消该坏项同样抛错,原状态未写入取消回执。 保留当前附件校验,为无法恢复的原 Turn 使用可读回的隔离或失败处置,并允许正常取消或下一条合法 Turn 按序继续。 恢复分支 取消路径

动机 / Motivation

Chat 用户在一个会话中排队发送多条消息,服务重启后由 worker 按顺序恢复已保存的输入。 若服务在保存 Turn 后、写入原消息前中断,恢复必须保留附件事实。上轮的拆分会把旧的非列表附件写成空消息附件,同时登记已发表。 同一默认队列内,第一条是待恢复的历史附件,后面还有一条合法消息。核心需要让用户看到第一条的真实处理结果,并能继续处理第二条。 当前提交已停止静默丢附件。新的拒绝会让坏项一直处于 queued,正常认领和取消均无法推进同一会话。 仍需给无法重建的历史输入一个可读回、可操作的处置结果。 本次核对真实 File store 的队列及输入历史,以及正常入口的调用和错误处理。

改动思路 / Approach

门面仍接到原 ChatSessionStore,将类型、准入、发现、写入、回执及排队恢复拆入四个相邻模块。 现有 TS owner 继续决定排队和输入变更,File store 管 Session、Turn 和 transcript。附件异常由当前恢复分支抛出错误,尚缺原队列入口可消费的后续状态。 保持原会话、有序排队、输入保真、持久发布以及正常取消。 结构拆分沿用原锁、原入口、原状态模型。读错文件的路径跟踪和旧 transcript 回放仍由原有 store 读取。

具体改动 / Changes

精确提交 339086a。目标基线 509360f。7 个文件,增加 1,914 行、删除 641 行。原附件与发布(attachment-publication)通过。同会话恢复与取消(queue-recovery-continues)需修订。 原始契约

关键代码讲解

  • recover_queued_turn_input。先检查是否已发布。尚无 transcript 时先校验保存的附件形状,随后才写入原消息与发布事件。 源码
  • claim_next_queued_turn。依次处理可执行队列。第一个需恢复的 Turn 出错时,认领调用直接退出。 源码
  • mutate_queued_input。写取消回执前调用同一恢复入口,因此异常旧附件也阻断该 Turn 的正常取消。 源码
  • _drain_session_queue_events。认领发生在准备 adapter 与处理单项失败的 try 块之前。 源码

对主干的风险 / Risks

两端的真实 File store 都按顺序认领两个合法输入,首条中断的有效附件逐字段保留,并且只补一条 transcript 和一次 queued 事件。候选对异常旧附件保持原文件,未补写输入或成功发布。 候选 209 项回归通过,基线 204 项共同回归通过,候选另含 5 项 ingress 合同用例。5 个 ingress 模块严格 mypy、Ruff 和 git diff --check 通过。独立配对使用真实 File store,对比正常顺序、无 transcript 的损坏旧项、重复认领与取消。

语义与 CI 对齐

同一中断注入且首条为旧对象附件时,基线能保留对象并认领后续项。候选连续两次认领均返回同一个附件错误,两条均留在 queued。默认未设置过期时间。原入口取消该坏项同样抛错,原状态未写入取消回执。 历史对象附件由隔离数据注入,运行路径为生产 File store 和入口调用链。独立探针不启动外部模型;原生宿主安装与远端 CI 未复验。

我的整体评价 / Verdict

REQUEST_CHANGES。 上次静默丢失的事实已得到保护。当前同一历史数据会阻断有效后续消息,连取消坏项也失败,须补齐队列恢复。 保留当前附件校验,为无法恢复的原 Turn 使用可读回的隔离或失败处置,并允许正常取消或下一条合法 Turn 按序继续。 在同一 Session 中测试两条现有队列记录,模拟 transcript 写前中断,重开后重试、取消并核对输入、事件及另一条消息的状态。

English verdict: REQUEST_CHANGES at 339086a. The new validation preserves stored attachment evidence, but an unrecoverable legacy queue head blocks subsequent valid inputs and also prevents normal cancellation in matched File-store runs.

):
attachments = cast(list[dict[str, object]], expected_attachments)
else:
raise ValueError("queued Turn attachments must be null or a list of objects")

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.

[P2] 异常队首也阻断正常取消。此处在补写前拒绝坏附件,保留了原始记录。在隔离 File store 中,默认无过期时间的队首带历史对象附件、transcript 尚未发布时,两次认领均抛错,后续有效项留在 queued。正常取消也经过同一恢复分支,在写回执前抛错。请把不可恢复结果限制在该 Turn,保留原附件原件,提供可回读的失败或取消结果,并复测下一条有效项能继续。

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