Skip to content

refactor(native_chat): modularize conversation bindings with Zero-Any strict typing - #9453

Merged
huangruiteng merged 2 commits into
mainfrom
codex/slim-conversation-bindings-zero-any-20261126
Nov 26, 2026
Merged

huangruiteng merged 2 commits into
mainfrom
codex/slim-conversation-bindings-zero-any-20261126

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

Modularizes loopx/capabilities/native_chat/conversation_bindings.py (1,160 LOC / 69 AST Any on 50aa5b4fd1 -> 630 LOC / 0 AST Any) and companion OriginalConversationRequests into cohesive, strictly typed modules under loopx/capabilities/native_chat/ with zero Any and zero # type: ignore / noqa suppressions across all 9 PR files.

Module Decomposition & Budget (<= 650 main, < 750 all files, 0 AST Any, 0 # type: ignore)

  • loopx/capabilities/native_chat/conversation_bindings.py (630 LOC): preserves ChatConversationBindings, validate_external_agent_turn, OriginalConversationRequests re-export, _atomic_write_json, _read_json, exclusive_file_lock, _host_ref, _host_audiences, _core, stop_recoveries, and direct resolve() -> observe() caller frame.
  • loopx/capabilities/native_chat/conversation_binding_contracts.py (425 LOC): strict BindingPayload, BindingPayloadView, dict wrappers (BindingRowDict, BindingStateDict, ResolvedBindingDict, AppStewardTargetDict, LocalSessionSnapshotDict), Protocols (BindingAuthorityProtocol, ProjectContextsProtocol, BindingSessionStoreProtocol, BindingControllerProtocol, NativeSessionProtocol, LockFn, ObserveAudienceFn), and shared effect/observation helpers.
  • loopx/capabilities/native_chat/conversation_binding_agents.py (538 LOC): steward executor reconciliation, revocation turn interruption, attached-host observation/candidate discovery, and validate_external_agent_turn_flow.
  • loopx/capabilities/native_chat/conversation_binding_flows.py (619 LOC): binding configure/publish/disconnect/app-steward selection, row lookup & resolved-binding builder, local-session discovery, created-goal adoption, and agent-target switching.
  • loopx/capabilities/native_chat/conversation_binding_delivery.py (270 LOC): app-steward target/session lookup, input_context_flow, goal_scope_ids_flow, delivery_channels_flow, ensure_delivery_scope_flow, apply_delivery_scope_flow, and session_source.
  • loopx/capabilities/native_chat/original_conversation_requests.py (538 LOC): OriginalConversationRequests orchestrating _policy, _observation, _recipient, _source, _fenced, publish, _enqueue, _stop_turns, _resume, _entry, _view, _inbox and delegating management/control/execution.
  • loopx/capabilities/native_chat/original_conversation_views.py (466 LOC): as_string_dict, configure_original_grant_flow, original_management_view_flow (reading entry_fn once per request row rather than per reply), discover_original_recipients_flow, and control_original_request_flow.
  • loopx/capabilities/native_chat/original_conversation_execution.py (280 LOC): validate_original_turn_flow, validate_current_original_flow, complete_original_answer_flow, and execute_original_request_flow (single guarded_entry read in start_guard).
  • tests/capabilities/test_conversation_bindings_contract.py (704 LOC): size/0-Any/0-suppression audit, monkeypatch & resolve() frame seam checks, dict/JSON round-trips, key-presence vs None (goal_scope, collaboration_request), legacy missing-file / projects=None handling, malformed-input fail-closed checks, and single-entry-read regressions.

Preserved Semantics & Boundary Safety

  • Zero caller mypy regression (21/21 loopx/ callers <= baseline; chat_server.py 28->23, session_queue.py 2->0, chat_runtime.py 27->25).
  • Compatibility preserved verbatim: monkeypatchable _atomic_write_json, _read_json, and exclusive_file_lock seams; direct resolve() caller frame for observe(); key-presence checks ("goal_scope" in previous, "collaboration_request" not in turn); lazy "entry" access in control() inspect; delayed _require_projects checks in select_app_steward(None) / agent_candidates.
  • Untouched loopx/canary/module_metric_baseline.json; top-level loopx/*.py == 112.

Verification (Clean Detached 9f8581704c)

  • ruff check (9/9): passed.
  • mypy --strict --no-incremental --follow-imports=silent (9/9): 0 errors; bare mypy --no-incremental (9/9): 0 errors; mypy --config-file pyproject.toml: 0 errors (17 files); all 21 loopx/ callers <= baseline.
  • Paired origin/main (50aa5b4fd1) vs HEAD (9f8581704c) differential parity probe (configure/resolve/local_session_snapshot/select_app_steward/input_context/_policy/disconnect): 5,900 bytes identical (0 diff).
  • npm run typecheck:control-plane + TS tests (conversation_binding.test.ts, content_digest_single_owner.test.ts): 87 passed, 0 failed.
  • pytest -n 6 -rs:
    • tests/capabilities/test_conversation_bindings_contract.py + tests/test_chat_conversation_bindings.py + tests/control_plane/{test_bound_owner_web_input,test_peer_source_store,test_original_conversation_peer}.py + tests/test_lark_private_{conversations,ingress}.py + tests/test_native_steward_{private,monitor,reports}.py + tests/test_chat_{ordinary_project,transport_composition,file_discovery,http_runtime_scope,manager_model_adoption}.py + tests/test_private_chat_backlog_projection.py + tests/test_steward_pr_merge_and_review_signal.py: 1,546 passed (0 failed, 0 skipped).
    • tests/architecture/ + tests/canary/: 2,065 passed, 6 skipped (6 expected macOS APFS non-UTF-8 filename skips in tests/canary/test_git_path_display.py, 0 failed).
  • scripts/check_rfc_bilingual.py, semantic-vocabulary-drift-smoke.py, control-plane-maintainability-ratchet-smoke.py (unreviewed: 0, magnitude_regressions: 0), git merge-tree origin/main HEAD, public boundary scan (9/9 clean, 0 warnings/errors), exact-scope change-quality receipt, and premerge canary gate (direct_failure_count=0, run_failure_count=0, manual_hold_count=0, catalog_run=2/2, merge_gate_passed=true): all passed.

… strict typing

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

缩小 native conversation binding 的单模块依赖与重复读取,保留原会话的来源授权、状态、结果和恢复身份。 原模块集中维护绑定配置、Session 读取、steward 兼容和请求回传。同一个 start guard 多次读取同一请求。 已有本地 App/Web 或绑定渠道会话的人,以及向原会话授权委派和读取结果的 Agent。

File、SQLite 均在授权前无可发现收件人。批准后通过原 Session 开始一次 native Turn,management view 与 requester Inbox 回读同一个 revision 1 结果,同 ID 重试复用原轮。未创建新 Goal Session。 原结果写入失败可在同一 Session 和 Turn 修复,无额外模型执行。 真实 Python/TypeScript Core、File/SQLite、绑定文件、队列及结果 Inbox 运行于隔离样例,只有模型 transport 为合成。独立探针两版各 2 项。同一 journey 套件基线通过 112 项,候选加 8 项新契约共通过 120 项。另选 10 项绑定观察、重配、撤销和 steward 回归,两版全通过。 独立证据覆盖本地实际持久状态和合成模型 transport。当前安装版 App、真实 Lark 或供应商身份服务和远程 CI 未核验。 基线契约

改动思路 / Approach

该改动沿用 原 Chat/Session → binding 或 OriginalConversationRequests → TypeScript Core → Session 与源 Inbox 回读。保留单一授权 owner 和公开门面,按配置发布、接收方检查、作用域、原请求与回复组织能力内实现。 当前请求 revision、digest 与现有锁承载语义。原有 project_grant、Session binding、队列和返回路线仍由既有 Core 验证。 仅抽辅助函数仍会重复读请求。沿现有 fence 复用同一请求版本可减少 IO,无跨请求缓存。

具体改动 / Changes

精确提交 9f85817,分叉基线 50aa5b4。9 个文件 +4,401 / −1,091。分出 binding contracts、agents、flows、delivery、原请求适配器和契约测试,保留原门面。

关键代码讲解

  • configure_binding_flow。保留现有 scope、provider/operator 基准检查和绑定发布读回。 源码

  • validate_external_agent_turn_flow。在原工作队列和 Host 附件边界内复核授权。 源码

  • input_context_flow。读取来源、重验当前 binding 并保持既有请求准入 fence。 源码

  • original_management_view_flow。按请求复用 entry 读取,继续核对队列和回复。 源码

  • execute_original_request_flow。在 fenced start guard 内核对收件人及 revision/digest,保存答复后再返回。 源码

  • original-session-identity-and-result-preserved(implemented)。binding admission 和结果继续在原 Session、原请求 revision 上回读,撤销后失败关闭。

对主干的风险 / Risks

未获明确 grant 时拒绝请求。配对故障用例在模型写入前撤销 grant 后无 turn/start。丢失结果写入可由已保存答案恢复,仍只执行一次。 真实 Python/TypeScript Core、File/SQLite、绑定文件、队列及结果 Inbox 运行于隔离样例,只有模型 transport 为合成。独立探针两版各 2 项。同一 journey 套件基线通过 112 项,候选加 8 项新契约共通过 120 项。另选 10 项绑定观察、重配、撤销和 steward 回归,两版全通过。 独立证据覆盖本地实际持久状态和合成模型 transport。当前安装版 App、真实 Lark 或供应商身份服务和远程 CI 未核验。

我的整体评价 / Verdict

APPROVE。 配对调用保持授权、撤销、回传和单次执行。类型拆分留在原适配器,沿用规则 owner 和持久版本。 原结果写入失败可在同一 Session 和 Turn 修复,无额外模型执行。

English verdict: APPROVE at 9f85817. Paired File and SQLite journeys preserve explicit grant checks, original-session identity, and one result after replay.

@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.

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

Reviewer: model_agent · Gemini · Google · self_reported
Target: PR #9453 (9453@9f8581704ca0ac60a3a549944c9020a7490d1867)

Blocking Finding (Findings First)

  1. [P2] BindingControllerProtocol.project_contexts 不变量属性破坏真实 ChatRuntimeController 调用方 mypy 兼容性(loopx/capabilities/native_chat/conversation_binding_contracts.py#L306)
    • 触发条件:任意生产期或测试代码将真实控制器 ChatRuntimeController(其 project_contexts 类型为满足 ProjectContextsProtocol 的具体类 ChatProjectContexts)传入 OriginalConversationRequests(controller) 或赋值给 bindings.controller。
    • 实际影响:PR 描述声称 21/21 调用方报错数只降不增、零回归,但总错误数下降实际只是新类型签字消除了旧的 no-untyped-call,掩盖了两条真实生产调用线与两条测试路径上新增的 [arg-type] / [assignment] 报错(loopx/chat_runtime.py:908、loopx/chat_server.py:1339、tests/control_plane/test_bound_owner_web_input.py:50、tests/control_plane/test_original_conversation_peer.py:427 与 523);契约单测中的 _DummyController(test_conversation_bindings_contract.py#L232)因手动写成 self.project_contexts: ProjectContextsProtocol 而漏过了真实控制器验证。
    • 最小修复:在 loopx/capabilities/native_chat/conversation_binding_contracts.py#L306 将 project_contexts: ProjectContextsProtocol 改为协变只读 @property(def project_contexts(self) -> ProjectContextsProtocol: ...)并在契约测试中补上真实 ChatRuntimeController 协议一致性检查。已通过 mypy --shadow-file 实测验证:修复后 ChatRuntimeController -> BindingControllerProtocol 与 mypy --strict 均为 0 报错,上述全部调用方的协议 [arg-type] / [assignment] 报错立即消除。

动机 / Motivation

ChatConversationBindings 与 OriginalConversationRequests 是私有会话绑定、App Steward 会话发现以及跨对话原会话协作请求的唯一 Python I/O 门面,仓库内共有 23 个生产模块(涵盖 loopx/chat_runtime.py、loopx/chat_server.py、session_queue.py、steward_turn.py、private_conversation_api.py 及 examples/)与 21 个测试模块直接导入或构造它们。此前 conversation_bindings.py 单文件膨胀至 1,160 行并包含 69 处 Any 注解,且 OriginalConversationRequests.management_view 对每条回执都重复读取磁盘上的 request entry JSON、execute 中的 start_guard 也重复 3 次读盘校验同一 entry;本次 PR 将其按领域拆分为 8 个零 Any 零抑制注释模块(主入口收窄至 630 行)并在 management_view(3 条回执读取从 4 次降至 1 次)与 start_guard 中消除重复读盘,同时保留猴子补丁接口、resolve() 直接调用栈帧及键存在性(key-presence)语义,但在新增 BindingControllerProtocol 时将 project_contexts 声明为了可变不变量属性,导致生产期真实 ChatRuntimeController 调用方在 mypy 下出现新的 [arg-type] 类型冲突。运行期全部绑定、组身份钉住、App Steward 选源、原会话协作请求/恢复与去重读取(management_view 4->1)在基线 50aa5b4fd1 与精确头 9f8581704c 上保持 100% 行为等价(指纹 807c5861128b71a0),3,611 项 pytest 与 113 项 TS 测试全部通过;但真实控制器类型 ChatRuntimeController 传入 OriginalConversationRequests(...) 时在 loopx/chat_runtime.py:908 与 loopx/chat_server.py:1339 触发了新增的 mypy [arg-type] 回归。本 PR 不改动 TypeScript 侧 collaboration.conversation.* / collaboration.project.* 规则实现,不重构 23 个生产调用方源码或测试夹具中的历史类型错误,也不修改 module_metric_baseline.json。虽然运行期行为与单次读盘优化已完整验证,但 BindingControllerProtocol.project_contexts 在 loopx/capabilities/native_chat/conversation_binding_contracts.py#L306 使用了可变不变量属性而非 @property,导致真实 ChatRuntimeController 调用方(loopx/chat_runtime.py:908、loopx/chat_server.py:1339)在 mypy 下出现新的 [arg-type] 类型冲突。

对于 native_chat 这类衔接 HTTP 入口、队列调度与 TypeScript Core 权威规则的适配层,真正有价值的优化不只是把 1,160 行拆成 8 个小文件并清理 69 处 Any,更必须确保在零修改调用方源码的前提下,既不破坏运行时隐含的栈帧(resolve() -> observe())、猴子补丁锚点与键存在性边界,也不在 Protocol 抽象上把具体子类型属性写死为不可变字段从而反向污染真实控制器 ChatRuntimeController 的类型检查。本 PR 的运行期行为和单文件读盘优化质量很高,但前述 [P2] 协议属性声明问题在合并前需要一并修正。

改动思路 / Approach

采用三组正交边界拆分:第一组 conversation_binding_contracts 收口共享数据结构与 Protocol,第二组 conversation_binding_{agents,flows,delivery} 与主入口 conversation_bindings 承接绑定生命周期与安全边界,第三组 original_conversation_{requests,views,execution} 承接原项目协作请求编排;主文件显式重导出全部历史符号并内联保留 resolve() -> self.observe() 调用栈帧与 _atomic_write_json / _read_json / exclusive_file_lock 补丁点。变更严格限定在 loopx/capabilities/native_chat/{conversation_binding*,original_conversation*}.py 8 个模块及契约测试 tests/capabilities/test_conversation_bindings_contract.py,不触碰 loopx/chat_runtime.py、loopx/chat_server.py、project_context.py、顶层 loopx/*.py(112)或基线配置文件。

围绕拆分结构、热点消重与类型边界,关键设计核查如下:

  1. 三组单向拆分与兼容门面:conversation_binding_contracts 定义类型包装字典(BindingRowDict、BindingStateDict、ResolvedBindingDict、AppStewardTargetDict、LocalSessionSnapshotDict)与协议接口;conversation_binding_{agents,flows,delivery} 分别承担 Steward 执行器对账/撤销停单、配置/发现/目标切换以及投递作用域与输入准入上下文;original_conversation_{requests,views,execution} 分层承载原会话协作请求状态流转。主文件 conversation_bindings.py 维持 630 行并原名重导出 _atomic_write_json、_read_json、exclusive_file_lock、OriginalConversationRequests、_host_ref、_host_audiences、ChatConversationBindings._core 与 stop_recoveries,且把 self.observe(...) 直接留在 resolve() 体中以保证 sys._getframe(1).f_code.co_name == "resolve"。
  2. 热路径单次 entry 读盘消重:original_management_view_flow(original_conversation_views.py#L251-L260)与 execute_original_request_flow 的 start_guard(original_conversation_execution.py#L238-L246)将单请求多回执/多校验阶段的重复 _entry 磁盘读取收敛为单次读取(3 条回执下读取次数从 4 -> 1),且管理视图在只读扫描场景下不会引入陈旧写入风险。
  3. 运行期细节精确保真 vs 协议协变缺失:configure_binding_flow 继续用 "goal_scope" in previous 精准区分键缺失与 None、validate_original_turn_flow 用 "collaboration_request" not in turn 拦住显式空协作负载、agent_candidates_flow 保留 projects 延迟判空顺序;然而 conversation_binding_contracts.py#L306 将 BindingControllerProtocol.project_contexts 声明为普通可变属性而非 @property,造成具体类 ChatProjectContexts 与协议之间发生不变量冲突。
检查维度 基线 50aa5b4fd1 当前精确头 9f8581704c 结论
绑定全链路与原会话协作反事实(cf_9453w8.py) 指纹 807c5861128b71a0 指纹 807c5861128b71a0 运行期 100% 行为等价
management_view 3 条回执 _entry 读盘次数 4 次 1 次 减少冗余磁盘 I/O 75%
resolve() 栈帧与 goal_scope key-presence ["resolve"] / False ["resolve"] / False 隐式契约完全保留(敏感性变异可检出)
真实 ChatRuntimeController 传入 BindingControllerProtocol no-untyped-call 新增 [arg-type] / [assignment] [P2] 阻塞项(@property 修复可清零)

具体改动 / Changes

依据 50aa5b4fd1c88b7225fc30e58423120e3ad5d426 到 9f8581704ca0ac60a3a549944c9020a7490d1867 的 git diff --stat 与 AST 检查,本次涉及 9 个文件(+4,401 / -1,091),全部维持 0 AST Any 与 0 实际 # type: ignore / noqa(测试文件 #L279 为反向断言字符串):

  • loopx/capabilities/native_chat/conversation_bindings.py(+561 / -1,091,630 LOC <= 650):收敛为薄门面与稳定重导出入口,保留 resolve() 栈帧与所有测试补丁点。
  • loopx/capabilities/native_chat/conversation_binding_contracts.py(+425 / -0,425 LOC):定义结构化字典子类、协议接口(含需修复的 BindingControllerProtocol#L306)与 core_effect / host_ref / host_audiences 纯辅助函数。
  • loopx/capabilities/native_chat/conversation_binding_agents.py(+538 / -0,538 LOC):承担 Steward 执行器对账、撤销停单/恢复计数、附加 Host 发现与外部 Agent Turn 校验。
  • loopx/capabilities/native_chat/conversation_binding_flows.py(+619 / -0,619 LOC):承担绑定配置/发布/断开、App Steward 选择、本地会话快照及目标切换。
  • loopx/capabilities/native_chat/conversation_binding_delivery.py(+270 / -0,270 LOC):承担 App Steward 目标、输入上下文准入、投递频道与范围约束。
  • loopx/capabilities/native_chat/original_conversation_requests.py(+538 / -0,538 LOC):承载 OriginalConversationRequests 编排方法、锁隔离与续跑入口。
  • loopx/capabilities/native_chat/original_conversation_views.py(+466 / -0,466 LOC):承载授权配置、管理视图(单次 entry 读盘)、接收者发现与控制指令。
  • loopx/capabilities/native_chat/original_conversation_execution.py(+280 / -0,280 LOC):承载 Turn 校验、回答完成回写与 start_guard 执行流。
  • tests/capabilities/test_conversation_bindings_contract.py(+704 / -0,704 LOC):验证体量、零 Any、补丁点、栈帧、键存在性、边界拒接与单次读盘回归。

关键代码讲解

  1. loopx/capabilities/native_chat/conversation_binding_contracts.py 中的 BindingControllerProtocol 与 core_effect(#L300-L322、#L360-L378):前者抽象了 ChatRuntimeController 所需的 Store/Registry/ProjectContexts 边界但第 306 行缺少 @property 导致具体属性协变失败;后者统一将 TS Core EffectRuntimeRejected 规范化为 ValueError 并做键序列化浅拷贝。
  2. loopx/capabilities/native_chat/conversation_bindings.py 中的 ChatConversationBindings.resolve(#L284-L325):保留 self.observe(...) 在方法体内直接触发以满足调用方栈帧约定,并完成观察前后的版本一致性防并发篡改复核后才交由 build_resolved_binding 组装。
  3. loopx/capabilities/native_chat/conversation_binding_flows.py 中的 _publish_configured_binding(#L103-L265):在锁内精确保留 "goal_scope" in previous 语义、agent_targets / managed_actor 延续以及先校验全部通道策略再发布的新授权顺序。
  4. loopx/capabilities/native_chat/original_conversation_views.py 中的 original_management_view_flow(#L240-L270):将原本置于每条回复 result_paths 循环内的 _entry 读盘提升至外层按每条请求执行一次,消除多余文件 I/O。
  5. loopx/capabilities/native_chat/original_conversation_execution.py 中的 execute_original_request_flow(#L232-L280):在 start_guard 内复用同一次 guarded_entry 读取同时完成 validate_current_fn、continuation 校验与版本控制检查。

规范对齐与验收准则对照

依据主干 50aa5b4fd1c88b7225fc30e58423120e3ad5d426 下既有的异步会话绑定与原项目协作设计规范 docs/architecture/rfcs/app-conversation-and-async-inbox-v0.md(参考第 1054–1120 行)逐项评估如下:

  • ACAI-BOUND-OWNER(origin=web、组身份钉住、App Steward 选源与绑定锁内复核均经由 TS Core 裁决而非缓存授权):implemented,由 conversation_bindings.py#observe/#resolve、conversation_binding_flows.py 与 conversation_binding_delivery.py 实现,经 cf_9453w8.py 与 TS 套件验证。
  • ACAI-ORIG-RECIPIENT(原项目协作请求严格验证 source_session_v1、锁隔离、不可变路由与修订/摘要一致性的 start_guard 推进):implemented,由 original_conversation_requests.py、_views.py 与 _execution.py 实现,经 test_original_conversation_peer.py 与单次读盘计数测试验证。
  • ACAI-CALLER-TYPING(拆分与类型收窄对全仓库既有的生产期 OriginalConversationRequests / ChatConversationBindings 调用方保持类型兼容):not_met,loopx/capabilities/native_chat/conversation_binding_contracts.py#L306 的不变量属性破坏了 loopx/chat_runtime.py:908 与 loopx/chat_server.py:1339 的真实 ChatRuntimeController 类型兼容性,最小修复为改用 @property def project_contexts(self) -> ProjectContextsProtocol: ...。

对主干的风险 / Risks

对主干稳定性、静态兼容与验证结果核查如下:

  1. 已定位风险(阻塞):在 loopx/chat_runtime.py:908、loopx/chat_server.py:1339、tests/control_plane/test_bound_owner_web_input.py:50 及 tests/control_plane/test_original_conversation_peer.py:427 / 523 处,真实 ChatRuntimeController 因 BindingControllerProtocol.project_contexts 的不变量声明而触发 mypy [arg-type] / [assignment] 报错。同时附带说明(非阻塞):由于原无类型返回值转为 dict[str, object] / BindingPayload,test_original_conversation_peer.py:437/439/524、test_chat_conversation_bindings.py:1331... 与 test_chat_transport_composition.py:157 中的无类型字典解包测试在单独检查测试文件时会出现额外的 object/Collection[str] 提示;但生产模块本身在 @property 修复后 mypy 可恢复零新增报错。
  2. 运行期反事实与兼容性:cf_9453w8.py 在 50aa5b4fd1 与 9f8581704c 之间验证了真实 TS Core 绑定发布、组身份钉住、直接 resolve() 栈帧、Steward goal_scope 键存在性(及变异检出)、validate_turn 失败边界和 management_view 读盘 4 -> 1 优化,全部 18 项共享观测输出完全一致(obs_fp = 807c5861128b71a0)。23 个生产调用方除上述 BindingControllerProtocol 外其余 21 个文件零新增报错(session_queue.py 降至 0)。default_off_isolation 与 authority_semantics 为 not_applicable。
  3. 本地全套验证结果:
    • ruff check(9 文件):PASS;mypy --strict --no-incremental --follow-imports=silent(9 文件):PASS(0 errors);全仓库 python -m mypy(17 模块):PASS;23 个生产调用方 mypy:在 chat_runtime.py 与 chat_server.py 发现前述 [P2] [arg-type] 回归(其余 21 个生产文件 0 新增错误)。
    • npm run typecheck:control-plane 与 5 组 TS 测试套件(conversation_binding.test.ts 等):113 passed, 0 failed;check_rfc_bilingual.py:PASS。
    • Goal 绑定 loopx check(9 扫描路径,0 error / 0 warning):PASS;Goal 绑定 canary premerge --from-git-diff --git-diff-base 50aa5b4fd1c88b7225fc30e58423120e3ad5d426:PASS(direct_checks 6/6、catalog_run 2/2 通过,manual_holds=[])。
    • pytest:聚焦 test_conversation_bindings_contract.py 8 passed in 0.97s;扩域 -n 6 套件(17 个领域与契约套件 + tests/architecture/ + tests/canary/):3,611 passed, 6 skipped in 1452.29s(6 项 macOS APFS 文件名拒绝跳过,0 失败)。

我的整体评价 / Verdict

  • 长程与用户体验影响:long_horizon 与 user_experience 均为 preserved。绑定校验、队列恢复与原项目协作轮次状态在两版本间运行结果完全等价且降低了管理视图和重入守护的磁盘读取负担;该 PR 仅重构 Python 后端会话绑定与原会话请求 I/O 模块并补强静态类型协议,未改动任何前端、桌面端或富终端视觉界面。 未验证视觉范围:none(纯后端 native_chat 绑定与协作请求模块拆分,无 UI 视图变更)。
  • 代码体量、架构拟合与兼容决策:code_volume 判定为 necessary 且兼容性策略选择 retain(主门面重导出所有历史接口确保零调用方代码改写);change_proportionality 与嵌套 architecture_assessment 判定为 proportionate / retain;default_off_isolation、authority_semantics 与 semantic_alignment 均为 not_applicable。
  • 最终结论:运行期拆分质量扎实、反事实与 3,611 项 pytest 全绿,但 conversation_binding_contracts.py#L306 存在 [P2] 协议属性不变量回归(破坏生产调用方 chat_runtime.py 与 chat_server.py 的 mypy 校验且被测试桩 _DummyController 遮蔽)。请按上述最小 @property 方案修正并补充真实控制器协议回归断言后再审。

English verdict: REQUEST_CHANGES

…read-only property

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

缩小 native conversation binding 的单模块依赖与重复读取,保留原会话的来源授权、状态、结果和恢复身份。 原模块集中维护绑定配置、Session 读取、steward 兼容和请求回传。同一个 start guard 多次读取同一请求。 已有本地 App/Web 或绑定渠道会话的人,以及向原会话授权委派和读取结果的 Agent。

File、SQLite 均在授权前无可发现收件人。批准后通过原 Session 开始一次 native Turn,management view 与 requester Inbox 回读同一个 revision 1 结果,同 ID 重试复用原轮。未创建新 Goal Session。 实际 controller 可继续使用类型检查,原 Session 的同一 Turn 重试只回传一次。 精确基线和当前各 2 项独立原会话 File/SQLite 探针通过。精确旧头与当前另做严格 mypy 对照。当前绑定与原会话定向套件 238 项通过。 配对探针运行实际 Python/TypeScript Core、File/SQLite、Session 和 Inbox,模型 transport 使用测试实现。安装版 App、真实 Lark、真实模型执行和远程 CI 未核验。 基线契约

改动思路 / Approach

该改动沿用 原 Chat/Session → binding 或 OriginalConversationRequests → TypeScript Core → Session 与源 Inbox 回读。保留单一授权 owner 和公开门面。binding 协议只声明消费者读取的接口,实际 ChatRuntimeController 仍持有具体 ChatProjectContexts。 Protocol 的 project_contexts 用只读属性表达协变返回值。运行时仍由原 binding、source policy fence 和 request revision 管控。 将协议成员声明为 getter 即可表达只读关系,适配器可以直接接收实际 controller。

具体改动 / Changes

精确提交 2167a73,分叉基线 50aa5b4。9 个文件 +4,423 / −1,091。自上次审核修改 2 个文件 +23 / −1,将 controller 协议成员改为只读属性并在测试中使用实际实现。

关键代码讲解

  • BindingControllerProtocol.project_contexts。getter 允许真实 controller 以更精确的类型实现读取协议。 源码

  • configure_binding_flow。保留现有 scope、provider/operator 基准检查和绑定发布读回。 源码

  • validate_external_agent_turn_flow。在原工作队列和 Host 附件边界内复核授权。 源码

  • input_context_flow。读取来源、重验当前 binding 并保持既有请求准入 fence。 源码

  • original_management_view_flow。按请求复用 entry 读取,继续核对队列和回复。 源码

  • original-session-identity-and-result-preserved(implemented)。binding admission 和结果继续在原 Session、原请求 revision 上回读,撤销后失败关闭。

对主干的风险 / Risks

独立严格 mypy 检查把真实 ChatRuntimeController 赋给协议并传入 OriginalConversationRequests。旧提交仅有 1 条 assignment 错误,明确指出 project_contexts 期望 ProjectContextsProtocol;当前提交零错误。File 和 SQLite 缺 grant 时均没有可发现收件人。 精确基线和当前各 2 项独立原会话 File/SQLite 探针通过。精确旧头与当前另做严格 mypy 对照。当前绑定与原会话定向套件 238 项通过。 配对探针运行实际 Python/TypeScript Core、File/SQLite、Session 和 Inbox,模型 transport 使用测试实现。安装版 App、真实 Lark、真实模型执行和远程 CI 未核验。

我的整体评价 / Verdict

APPROVE。 上一版的实际 controller 结构化类型错误已消除。File、SQLite 配对证据保留原授权、Session 与一次回传。 实际 controller 可继续使用类型检查,原 Session 的同一 Turn 重试只回传一次。

English verdict: APPROVE at 2167a73. The concrete controller now satisfies the read-only protocol. Paired File and SQLite checks preserve explicit grants, original-session identity, and a single result on replay.

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

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

动机 / Motivation

Chat 运维者、真实控制器 ChatRuntimeController、项目上下文管理器 ChatProjectContexts、OriginalConversationRequests 与 Lark 私有会话渠道都依赖会话绑定模块完成渠道授权校验、Audience 证明与原会话协作投递。

改动前,50aa5b4fd1 将全部绑定存储、状态流转、投递作用域与原会话请求执行耦合在 1,160 行单文件中(在 conversation_bindings.py 存在 84 处 mypy 类型缺陷,且缺少 project_contexts 时抛出内部 AttributeError);中间提交 9f8581704c 又曾将控制器协议中的 project_contexts 误写成可写属性,导致只提供只读属性的真实 ChatRuntimeController 无法通过静态类型检查。改动后,2167a73b49 将全模块拆分为 8 个小于 640 行的强类型协作文件,消除全部 Any 与 # type: ignore,并将协议改为只读 @property,真实控制器类型检查与配对生命周期行为全部恢复正常。

全部 8 个生产模块与契约测试均达到 0 AST Any 与 0 # type: ignore 并通过 mypy --strict,全仓 loopx/ 调用方新增 mypy 错误为 0(同时清零基线 84 处错误),真实 ChatRuntimeController 协议检查零报错,且 20 项绑定生命周期配对反事实与基线完全一致(缺少 project_contexts 改为显式 ValueError)。 本 PR 不修改 TypeScript collaboration.conversation.* 规则、不更改持久化 JSON 结构或原会话队列所有权,也不改动未纳入 [tool.mypy] 的遗留测试文件。

改动思路 / Approach

继续由 TypeScript Core effect(collaboration.conversation.* 与 collaboration.original.*)担任唯一决策与授权所有者,Python 侧仅承担文件锁、原子 JSON 持久化、Provider 观察注入与宿主回调编排,不引入平行决策器,仅拆分为内聚强类型子模块并修复只读 @property 协议(retain 既有分层架构)。

当前 PR 边界严格限定于 loopx/capabilities/native_chat/ 下这 8 个会话绑定与原会话协作模块,以及配套的 tests/capabilities/test_conversation_bindings_contract.py。所有跨模块协议与数据结构统一收敛至 conversation_binding_contracts.py 中的 TypedDict、Protocol 与显式收窄函数;针对上一版阻塞真实控制器接入的 [P2] 缺陷,在 2167a73b49fe76c6be81dca412a381e6b37a0c7c 将 BindingControllerProtocol.project_contexts 改为 PEP 544 只读 @property,并以真实 ChatRuntimeController 与 ChatProjectContexts 回归测试验证协变满足性。

具体改动 / Changes

精确提交 2167a73b49fe76c6be81dca412a381e6b37a0c7c(基于基线 50aa5b4fd1c88b7225fc30e58423120e3ad5d426),遵循规范 docs/architecture/rfcs/app-conversation-and-async-inbox-v0.md(评审基准修订 50aa5b4fd1c88b7225fc30e58423120e3ad5d426:RFC-CB-OWNERSHIP implemented、RFC-ORIG-CONTROLLER implemented、RFC-TYPED-MODULAR-BOUNDARY implemented)。

关键代码讲解

  • BindingControllerProtocol.project_contexts:改为 PEP 544 只读 @property def project_contexts(self) -> ProjectContextsProtocol: ...,允许只暴露只读属性的真实 ChatRuntimeController 协变满足协议;若退回属性注解则在真实控制器上立即触发 arg-type/assignment 失败(已用 --shadow-file 反事实复现)。
  • ChatConversationBindings:保留全部对外方法、文件锁与兼容重导出(仅移除未使用的 Any/Callable/logging/hashlib/uuid/EffectRuntimeRejected/effect_runtime_result/TERMINAL_TURN_STATES,全仓零外部引用),将具体流转委托给 conversation_binding_flows、conversation_binding_delivery、conversation_binding_agents 与 original_conversation_*。
  • _require_projects:在 configure_binding_flow 与依赖上下文流程入口统一校验 projects is not None,将未绑定上下文时的内部 AttributeError 收敛为显式 ValueError("bound conversation project contexts are unavailable")。
  • OriginalConversationRequests.__init__:在真实控制器依赖注入处验证 controller.project_contexts.conversation_bindings 已绑定并保留 BindingAuthorityProtocol 接口契约,同时新增 test_real_chat_runtime_controller_satisfies_binding_controller_protocol 锁定真实控制器回归。

对主干的风险 / Risks

loopx/ 全仓静态调用面(chat_runtime.py、chat_server.py、project_context.py、transports.py、codex_adapter.py、private_conversation_api.py 等所有 loopx/ 调用方)跨 50aa5b4fd1 -> 2167a73b49fe76c6be81dca412a381e6b37a0c7c 新增 mypy 错误为 0(并在 conversation_bindings.py 清除 84 处基线错误);使用真实 ChatRuntimeController 与旧/新 conversation_binding_contracts.py 联合静态检查确认 BindingControllerProtocol.project_contexts 不匹配已完全清零(shadow 旧版复现 chat_runtime.py:908 与测试 :720/:722 失败,现均消除)。未修改的遗留测试文件(tests/test_chat_conversation_bindings.py 等未纳入 [tool.mypy])存在预期的 dict[str, object] 未收窄告警,不影响运行时语义。本地隔离测试与运行边界中:loopx-steward-managed-chat-smoke.py 因未安装可选 deepseek-harness-sdk 跳过;loopx-chat-server-smoke.py 因纯源码 worktree 未执行前端静态构建缺少 loopx/web/chat/index.html(基线 50aa5b4fd1 同样缺失,与本 PR 无关);pytest 下 test_git_path_display.py 有 6 例 APFS 文件名跳过及 1 例既有 daemon 线程清理 warning(全部测试仍通过)。

我的整体评价 / Verdict

APPROVE。 长程(long_horizon: preserved)与用户体验(user_experience: preserved,visual_review: not_applicable,仅涉及内部 Python 能力模块与契约测试,未改动 loopx/web/ 或 CLI 渲染面;unverified_scope: none)均保持兼容。在独立清洁 worktree(2167a73b49fe76c6be81dca412a381e6b37a0c7c,与 origin/main 及 50aa5b4fd1c88b7225fc30e58423120e3ad5d426 git merge-tree 均无冲突、2/2 DCO 提交、9 文件最大 724 < 750 LOC、0 AST Any、0 # type: ignore)验证:ruff 9/9 通过,mypy --strict --follow-imports=silent 9/9 通过,repo [tool.mypy] 17/17 通过;跨 50aa5b4fd1 与 2167a73b49fe76c6be81dca412a381e6b37a0c7c 的 21 项真实控制器+生命周期+错误路径配对反事实运行显示 20/21 完全一致,no_proj 由 AttributeError 改善为显式 ValueError;TS typecheck:control-plane、content_digest_single_owner.test.ts(17/17)与 conversation_binding.test.ts(70/70)全通过;相关 smokes(loopx-steward-channel-binding、periodic-report-bindings、loopx-chat-actions、maintainability-ratchet [unreviewed=0]、semantic-vocabulary-drift、peer-agent-continuation-state-machine)通过;pytest -n 6 -rs 跨绑定/Web输入/原会话/Steward/Lark/tests/canary//tests/architecture/ 共 2,993 passed, 6 skipped;Goal loopx check(5 项 0 错)与 canary premerge(ok=true, direct=6/6, catalog=2/2, manual_holds=0)全绿。

English verdict: APPROVE at 2167a73. Approve. Verified the BindingControllerProtocol.project_contexts read-only @Property fix against real ChatRuntimeController, zero loopx/ caller mypy regressions, paired counterfactual parity across binding lifecycles, TS control-plane suites (17/17 + 70/70), and 2,993 passing pytest items.

@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.

Chat 运维者、真实控制器 ChatRuntimeController、项目上下文管理器 ChatProjectContexts、OriginalConversationRequests 与 Lark 私有会话渠道都依赖会话绑定模块完成渠道授权校验、Audience 证明与原会话协作投递。

改动前,50aa5b4fd1 将全部绑定存储、状态流转、投递作用域与原会话请求执行耦合在 1,160 行单文件中(在 conversation_bindings.py 存在 84 处 mypy 类型缺陷,且缺少 project_contexts 时抛出内部 AttributeError);中间提交 9f8581704c 又曾将控制器协议中的 project_contexts 误写成可写属性,导致只提供只读属性的真实 ChatRuntimeController 无法通过静态类型检查。改动后,2167a73b49 将全模块拆分为 8 个小于 640 行的强类型协作文件,消除全部 Any 与 # type: ignore,并将协议改为只读 @property,真实控制器类型检查与配对生命周期行为全部恢复正常。

全部 8 个生产模块与契约测试均达到 0 AST Any 与 0 # type: ignore 并通过 mypy --strict,全仓 loopx/ 调用方新增 mypy 错误为 0(同时清零基线 84 处错误),真实 ChatRuntimeController 协议检查零报错,且 20 项绑定生命周期配对反事实与基线完全一致(缺少 project_contexts 改为显式 ValueError)。 本 PR 不修改 TypeScript collaboration.conversation.* 规则、不更改持久化 JSON 结构或原会话队列所有权,也不改动未纳入 [tool.mypy] 的遗留测试文件。

改动思路 / Approach

复核字段:criterion=binding-authority-preserved architecture_reason=职责沿现有调用、provider 和持久化边界拆分,公共入口保持。 current_pr_boundary=仅 loopx/capabilities/native_chat/conversation_binding_agents.py, loopx/capabilities/native_chat/conversation_binding_contracts.py, loopx/capabilities/native_chat/conversation_binding_delivery.py, loopx/capabilities/native_chat/conversation_binding_flows.py, loopx/capabilities/native_chat/conversation_bindings.py, loopx/capabilities/native_chat/original_conversation_execution.py, loopx/capabilities/native_chat/original_conversation_requests.py, loopx/capabilities/native_chat/original_conversation_views.py, tests/capabilities/test_conversation_bindings_contract.py。

继续由 TypeScript Core effect(collaboration.conversation.* 与 collaboration.original.*)担任唯一决策与授权所有者,Python 侧仅承担文件锁、原子 JSON 持久化、Provider 观察注入与宿主回调编排,不引入平行决策器,仅拆分为内聚强类型子模块并修复只读 @property 协议(retain 既有分层架构)。

当前 PR 边界严格限定于 loopx/capabilities/native_chat/ 下这 8 个会话绑定与原会话协作模块,以及配套的 tests/capabilities/test_conversation_bindings_contract.py。所有跨模块协议与数据结构统一收敛至 conversation_binding_contracts.py 中的 TypedDict、Protocol 与显式收窄函数;针对上一版阻塞真实控制器接入的 [P2] 缺陷,在 2167a73b49fe76c6be81dca412a381e6b37a0c7c 将 BindingControllerProtocol.project_contexts 改为 PEP 544 只读 @property,并以真实 ChatRuntimeController 与 ChatProjectContexts 回归测试验证协变满足性。

具体改动 / Changes

精确提交 2167a73b49fe76c6be81dca412a381e6b37a0c7c(基于基线 50aa5b4fd1c88b7225fc30e58423120e3ad5d426),遵循规范 docs/architecture/rfcs/app-conversation-and-async-inbox-v0.md(评审基准修订 50aa5b4fd1c88b7225fc30e58423120e3ad5d426:RFC-CB-OWNERSHIP implemented、RFC-ORIG-CONTROLLER implemented、RFC-TYPED-MODULAR-BOUNDARY implemented)。

关键代码讲解

  • BindingControllerProtocol.project_contexts:改为 PEP 544 只读 @property def project_contexts(self) -> ProjectContextsProtocol: ...,允许只暴露只读属性的真实 ChatRuntimeController 协变满足协议;若退回属性注解则在真实控制器上立即触发 arg-type/assignment 失败(已用 --shadow-file 反事实复现)。
  • ChatConversationBindings:保留全部对外方法、文件锁与兼容重导出(仅移除未使用的 Any/Callable/logging/hashlib/uuid/EffectRuntimeRejected/effect_runtime_result/TERMINAL_TURN_STATES,全仓零外部引用),将具体流转委托给 conversation_binding_flows、conversation_binding_delivery、conversation_binding_agents 与 original_conversation_*。
  • _require_projects:在 configure_binding_flow 与依赖上下文流程入口统一校验 projects is not None,将未绑定上下文时的内部 AttributeError 收敛为显式 ValueError("bound conversation project contexts are unavailable")。
  • OriginalConversationRequests.__init__:在真实控制器依赖注入处验证 controller.project_contexts.conversation_bindings 已绑定并保留 BindingAuthorityProtocol 接口契约,同时新增 test_real_chat_runtime_controller_satisfies_binding_controller_protocol 锁定真实控制器回归。

对主干的风险 / Risks

loopx/ 全仓静态调用面(chat_runtime.py、chat_server.py、project_context.py、transports.py、codex_adapter.py、private_conversation_api.py 等所有 loopx/ 调用方)跨 50aa5b4fd1 -> 2167a73b49fe76c6be81dca412a381e6b37a0c7c 新增 mypy 错误为 0(并在 conversation_bindings.py 清除 84 处基线错误);使用真实 ChatRuntimeController 与旧/新 conversation_binding_contracts.py 联合静态检查确认 BindingControllerProtocol.project_contexts 不匹配已完全清零(shadow 旧版复现 chat_runtime.py:908 与测试 :720/:722 失败,现均消除)。未修改的遗留测试文件(tests/test_chat_conversation_bindings.py 等未纳入 [tool.mypy])存在预期的 dict[str, object] 未收窄告警,不影响运行时语义。本地隔离测试与运行边界中:loopx-steward-managed-chat-smoke.py 因未安装可选 deepseek-harness-sdk 跳过;loopx-chat-server-smoke.py 因纯源码 worktree 未执行前端静态构建缺少 loopx/web/chat/index.html(基线 50aa5b4fd1 同样缺失,与本 PR 无关);pytest 下 test_git_path_display.py 有 6 例 APFS 文件名跳过及 1 例既有 daemon 线程清理 warning(全部测试仍通过)。

我的整体评价 / Verdict

APPROVE。 长程(long_horizon: preserved)与用户体验(user_experience: preserved,visual_review: not_applicable,仅涉及内部 Python 能力模块与契约测试,未改动 loopx/web/ 或 CLI 渲染面;unverified_scope: none)均保持兼容。在独立清洁 worktree(2167a73b49fe76c6be81dca412a381e6b37a0c7c,与 origin/main 及 50aa5b4fd1c88b7225fc30e58423120e3ad5d426 git merge-tree 均无冲突、2/2 DCO 提交、9 文件最大 724 < 750 LOC、0 AST Any、0 # type: ignore)验证:ruff 9/9 通过,mypy --strict --follow-imports=silent 9/9 通过,repo [tool.mypy] 17/17 通过;跨 50aa5b4fd1 与 2167a73b49fe76c6be81dca412a381e6b37a0c7c 的 21 项真实控制器+生命周期+错误路径配对反事实运行显示 20/21 完全一致,no_proj 由 AttributeError 改善为显式 ValueError;TS typecheck:control-plane、content_digest_single_owner.test.ts(17/17)与 conversation_binding.test.ts(70/70)全通过;相关 smokes(loopx-steward-channel-binding、periodic-report-bindings、loopx-chat-actions、maintainability-ratchet [unreviewed=0]、semantic-vocabulary-drift、peer-agent-continuation-state-machine)通过;pytest -n 6 -rs 跨绑定/Web输入/原会话/Steward/Lark/tests/canary//tests/architecture/ 共 2,993 passed, 6 skipped;Goal loopx check(5 项 0 错)与 canary premerge(ok=true, direct=6/6, catalog=2/2, manual_holds=0)全绿。

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

English verdict: APPROVE at 2167a73. Approve. Verified the BindingControllerProtocol.project_contexts read-only @Property fix against real ChatRuntimeController, zero loopx/ caller mypy regressions, paired counterfactual parity across binding lifecycles, TS control-plane suites (17/17 + 70/70), and 2,993 passing pytest items.

@huangruiteng
huangruiteng merged commit efb6ec3 into main Nov 26, 2026
38 of 49 checks passed
@huangruiteng
huangruiteng deleted the codex/slim-conversation-bindings-zero-any-20261126 branch November 26, 2026 12:26
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