Skip to content

refactor(control_plane): eliminate Any typing and redundant copies in chat_turn_acceptance - #9476

Merged
loopx-agent merged 2 commits into
mainfrom
codex/slim-chat-turn-acceptance-zero-any-20261126
Nov 27, 2026
Merged

loopx-agent merged 2 commits into
mainfrom
codex/slim-chat-turn-acceptance-zero-any-20261126

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Summary

Eliminates all 39 Any annotations (0 AST Any, 0 # type: ignore, 0 # noqa) and all 4 baseline mypy no-any-return errors in loopx/control_plane/chat_turn_acceptance.py (408 -> 417 <= 450 LOC), removes repeated intermediate allocations and projections while leaving loopx/control_plane/turn_driver/chat_turn_acceptance.ts untouched (loopx/*.py == 112).

Changes

  • Zero-Any & Typed Planning Boundaries (loopx/control_plane/chat_turn_acceptance.py):
    • Replaced all dict[str, Any] / Any signatures with covariant Mapping[str, object] / Sequence[Mapping[str, object]] read-only inputs and typed dict[str, object] / QueuedChatMutationPlan (TypedDict) returns matching loopx/chat/ingress.py and loopx/capabilities/native_chat/queued_admission.py.
    • Validated all effect_runtime_result boundaries via _as_object_dict, _required_bool, _required_string, _decode_mutation_event, and list[str] element checks in queued_chat_turn_ids (fixing all 4 baseline no-any-return errors).
    • Extracted shared _session_projection, _turn_status_projection, _queued_turn_base, and _single_match helpers, eliminated temporary multi-match list allocations in _transcript_facts / _queued_event_facts / _prepared_turn_facts, cached _EMPTY_TEXT_DIGEST & _NULL_JSON_DIGEST fast paths, and added MappingProxyType / tuple read-only safety in _json_digest without recursion on unserializable objects.
    • Preserved all exported constants, dataclasses, ManagedTurnReplayConflictError, and functions cleanly.
  • Contract & Parity Tests (tests/control_plane/test_chat_turn_acceptance_contract.py, 280 LOC, 0 AST Any):
    • Verifies LOC/AST 0-Any/0-ignore/export invariants, digest fast paths & MappingProxyType / unserializable-object parity, single-pass 0/1/2+ match counts, real TypeScript round-trips across all entrypoints, rejection decoding for all error codes, and malformed effect-result rejection.

Verification

  • ruff check (2/2 files): passed.
  • mypy --strict --no-incremental --follow-imports=silent & repo [tool.mypy] (chat_turn_acceptance.py, test_chat_turn_acceptance_contract.py): 0 issues (chat_turn_acceptance.py baseline 4 -> 0; zero caller regressions across chat_store.py, chat_runtime.py, chat/ingress.py, chat_loopx_mode.py, chat_server.py, queued_admission.py).
  • Paired 57c4c43b52 vs c50bb15dcb counterfactual across digests, queue selection, mention ingress, queued steering, queued edit/cancel/conflict mutations, execution/recovery allowances, managed turn acceptance, and all rejection codes: 100% exact parity.
  • npm run typecheck:control-plane clean + node --experimental-strip-types --test (chat_turn_acceptance.test.ts, chat_queue_steering.test.ts, chat_mode.test.ts, chat_session_lifecycle.test.ts, content_digest_single_owner.test.ts): 63/63 passed.
  • scripts/check_rfc_bilingual.py --base origin/main --head HEAD passed; git merge-tree --write-tree origin/main HEAD clean (34a77ac1844efa7d9869d8af01b7665c4570de5f against 7f7297a790).
  • 4/4 clean-HOME smokes passed (loopx-chat-runtime-smoke.py, loopx-chat-actions-smoke.py, semantic-vocabulary-drift-smoke.py, control-plane-maintainability-ratchet-smoke.py).
  • pytest sequential tests/test_chat_agent.py (566 passed) + parallel tests/control_plane/test_chat_turn_acceptance_contract.py, tests/control_plane/test_creation_task_queue.py, tests/test_chat_conversation_bindings.py, tests/test_lark_private_conversations.py, tests/architecture/, tests/canary/ (2,817 passed, 6 skipped [APFS skips]): 3,383 passed, 6 skipped, 0 failed.
  • Pre-merge canary gate (standard tier): passed (direct_checks=4/4, python_compile=1/1, catalog_run=2/2, risk_profile_run=8/8, failures=0, manual_hold_count=0).

@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 loader 核对 schema 版本后原样返回 payload。隔离 File store 中,非空附件对象或文本在基线得到 queue_steering_attachments_unavailable,当前头将两者计为 0 并返回 dispatch。调用者随后只传正文,排队输入可能失去附件信息。 让只有确证为空且可发送的附件状态获得零计数。非空异常形状保留原拒绝,或在构成投影前明确失败。 源码

动机 / Motivation

收紧 Chat Turn 在 Python 与 TypeScript 间的验收接口,保持现有 admission、重放和排队转发边界。 基线从持久 Turn 读取附件,非空值会计入文本 steering 的拒绝条件。PR 对普通 JSON 处理保留原规则,同时把非序列附件统一计为零。 继续排队消息、重放原请求回复,以及恢复本地持久排队 Turn 的 Chat 用户。

如果调度把有非空附件事实的 Turn 当作纯文本,用户看见已转发而有效输入被跳过,恢复会失去原队列状态。 隔离实际 File store 和 TypeScript planner 的基线与当前头都保留同 client_turn_id 只写一条原消息和 queued event,改正文重放拒绝。无附件可生成 dispatch 计划,非空规范附件列表仍被拒绝。 以目标基线和精确头各运行实际 ChatSessionStore、TypeScript effect planner 两个正例和两个持久形状反例,反例差异在同目标基线上仅切换所改精确模块时也复现。git diff --check 与针对当前目标的 git merge-tree 静态校验通过。 精确头另有 4 项定向契约测试通过。 异常附件来自隔离构造的旧形态。真实 planner 已核验,测到 dispatch 计划为止,未调用外部 Agent。安装与远程 CI 未核验。 较宽本地回归已出现其他失败,归因仍开放。 基线契约

改动思路 / Approach

该改动沿用 ChatSessionStore → queued_admission.steer_queued_turn → plan_queued_chat_steering → TypeScript chat.queue.steer。保留 TypeScript owner 与现有 File store 的正确分界。局部修正投影即可维持旧拒绝,不需要新的队列或回执 schema。 被测试的唯一改变是 Python 附件数量投影。TypeScript 消费同一字段,zero 才允许当前文本 steering。持久读取没有额外规范化这类形状。 复用现有附件检查,仅在空值或确证空集合时归零。非空异常形状走原拒绝,或在存储反序列化边界 fail closed。

具体改动 / Changes

精确提交 c50bb15,分叉基线 7f7297a。相对分叉点 57c4c43 的 PR 差分为 2 个文件 +516/-227。当前目标为 7f7297a,两者之间的独立 Steward 变更已核对并通过静态 merge-tree。

关键代码讲解

  • plan_queued_chat_steering。把持久 Turn 的附件形态转为 TypeScript 可用的计数。 源码

  • plan_queued_chat_mutation。验证原队列 mutation plan 并送回既有存储 owner。 源码

  • plan_managed_turn_acceptance。保留原请求摘要、回执绑定和可恢复写入。 源码

  • _json_digest。构造同一请求身份所用的 JSON digest。 源码

  • queued-live-steering-retains-nonempty-attachment-facts(not_met)。文本 steering 无法携带附件时保留排队输入并明确拒绝。边界与原有效请求及状态重放保持一致。

对主干的风险 / Risks

持久 Turn 读取核对 schema 版本,旧资料的非空非列表附件可以到达 planner。对象和文本两例在基线均返回 queue_steering_attachments_unavailable,当前头却返回 dispatch。真实调用方随后只传入 message,存在忽略已保存内容的风险。 默认零计数会丢掉真实输入形态;原 loader 不能依靠 Python 函数注解排除旧记录。 保留原非空状态的拒绝,或在形成 steering payload 前明确拒绝非预期形状。

语义与 CI 对齐

持久 Turn 读取核对 schema 版本,旧资料的非空非列表附件可以到达 planner。对象和文本两例在基线均返回 queue_steering_attachments_unavailable,当前头却返回 dispatch。真实调用方随后只传入 message,存在忽略已保存内容的风险。 保留原非空状态的拒绝,或在形成 steering payload 前明确拒绝非预期形状。

我的整体评价 / Verdict

REQUEST_CHANGES。 请先保持非空持久附件的原拒绝。本地 File store 和实际 TypeScript planner 已定位两例非预期 dispatch。 保留原请求的内容与身份,避免迁移或损坏形态在重新调度时失去附件。

English verdict: REQUEST_CHANGES at c50bb15. The real planner preserves normal attachments and request replay, but now plans text dispatch for two nonempty stored attachment shapes the base rejected. Retain fail-closed steering for unknown attachment shapes.

@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 runtime queue, steering, mention ingress, and managed turn acceptance callers across chat_store, chat_runtime, chat.ingress, and queued_admission, plus operators steering queued web turns. Before this change, chat_turn_acceptance.py carried 39 AST Any annotations and 4 mypy errors, and an intermediate zero-Any draft dropped non-empty dict/str attachments in persisted turns to attachment_count=0 (bypassing queue_steering_attachments_unavailable); at head 712f75f, AST Any is 0, mypy errors in the module drop 4->0, non-empty Sized attachments reject with queue_steering_attachments_unavailable matching origin/main, and empty non-sequence shapes raise ValueError before TS evaluation. chat_turn_acceptance.py maintains 425 <= 450 LOC with 0 AST Any, 0 ignores, 0 mypy strict errors, full parity against main 7f7297a across digests, TS queue/mutation/acceptance round-trips, and real ChatSessionStore persisted non-empty attachments, plus fail-closed ValueError on malformed empty/scalar attachment shapes. Does not rewrite TypeScript turn_driver/chat_turn_acceptance.ts logic, migrate legacy caller modules like chat_store.py off dict[str, Any], or change steering semantics for valid attachments.

改动思路 / Approach

Keeps all policy/decision authority inside TypeScript turn_driver handlers while turning the Python bridge into a strict-typed, zero-Any boundary with fail-closed validation and zero duplicate authorities. Scoped strictly to loopx/control_plane/chat_turn_acceptance.py typing, helper consolidation, fail-closed attachment count, and contract tests; TypeScript files and legacy callers remain unmodified. 相比使用 cast 或抑制注解来消解 no-any-return,本 PR 在 Python-TS 边界统一采用只读 Mapping[str, object] / Sequence[Mapping[str, object]] 入参并显式校验返回值字段,同时复用公共投影帮助函数和空值摘要常量,且保留 AcceptedManagedTurn.turn: dict[str, object] 以兼容尚未迁移的 chat_store.create_turn 返回签名。

具体改动 / Changes

精确头 712f75f646c3cca064616a6ee98b4ec5e24917f0(基于 7f7297a790771dab08e2444700f4d76699169950)改动 2 个文件(+621/-227)。no written specification exists;本 PR 不改动 TypeScript turn_driver 规范语义,仅对齐既有接口行为与零 Any 类型收紧。

关键代码讲解

  1. loopx/control_plane/chat_turn_acceptance.py#L262-L291(_steering_attachment_count 与 plan_queued_chat_steering):修复此前候选版本的 [P2](PRRT_kwDOStEbEs68Od7a),仅对 None 与非字符串/字节类空 Sequence 返回 0,非空 Sized 附件(含 dict、MappingProxyType、str、bytes、set)返回正计数以保留 queue_steering_attachments_unavailable 拒绝语义,并对空非法容器或标量提前抛出 ValueError。
  2. loopx/control_plane/chat_turn_acceptance.py#L302-L328(plan_queued_chat_mutation):逐项核对并验证 TS chat_queue_steering.ts#L180-L225 返回的全部 6 个字段(action、error_code、receipt、message_patch、turn_patch、event),零字段遗漏。
  3. loopx/control_plane/chat_turn_acceptance.py#L237-L254(queued_chat_turn_ids):以 Mapping、list 与逐元素 str 校验替代直接下标返回,消除基线 no-any-return。
  4. loopx/control_plane/chat_turn_acceptance.py#L46-L68(_json_digest):缓存空字符串与 null 摘要,并在不无限递归的前提下支持顶层只读 MappingProxyType 与序列内 Mapping 哈希。

对主干的风险 / Risks

所有验证均在 712f75f646 上通过:ruff(2/2 PASS)、mypy --strict(2/2 零错误)、[tool.mypy](17/17 PASS)、TypeScript typecheck:control-plane 与 5 组 TS 测试(63/63 PASS)、4 项独立 HOME smoke(PASS)、loopx check(0 errors)、canary premerge --profile standard(direct 6/6, catalog 2/2, risk_profile 8/8, failures=0)、test_chat_agent.py(566 passed)及 20 组并行套件(3,332 passed, 6 skipped,6 项均为 macOS APFS test_git_path_display.py 跳过)、配对 7f7297a790 vs 712f75f646 反事实(2,968B 与 ChatSessionStore 持久化附件场景全一致)及注入 [P2] 变异测试按预期失败(rc=1)。唯一非阻塞类型细节:将 AcceptedManagedTurn.turn 收紧为 dict[str, object] 后,未做零 Any 改造的调用方 loopx/chat_store.py#L1117 因局部无注解字面量字典不变性在 --follow-imports=silent 下多出 1 条提示(2 -> 3,全局调用方总数 192 -> 189,[tool.mypy] 零错误且运行时零影响;又因 chat_store.create_turn 返回 tuple[dict[str, Any], bool],不可放宽为 Mapping),可留待后续清理 chat_store.py 时顺手为局部 payload 补全注解。

我的整体评价 / Verdict

整体结论为 APPROVE。该 PR 完整消除 chat_turn_acceptance.py 全部 39 处 AST Any 与 4 条基线 mypy 错误,并经真实持久化 ChatSessionStore、Node TS 运行时及变异对比证明 [P2] 附件保护已严格修复,对长程调度边界与用户体验无退化。Control-plane Python bridge and contract tests only; no HTML, CSS, dashboard layout, or rendered UI presentation changed. 未验证范围:none(tests/canary/test_git_path_display.py 6 项仅因 macOS 大小写不敏感文件系统跳过)。

English Verdict: APPROVE

@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

收紧 Python 到 TypeScript 的 Chat Turn 验收接口,维持同请求恢复和文本 steering 的内容保护。 目标基线已经拒绝非空持久附件。前一个候选把部分非空异常形状计成零,可能只转发正文;当前修复恢复原拒绝。 继续排队消息、重放原请求回复,以及恢复本地持久排队 Turn 的 Chat 用户。

如果调度把有非空附件事实的 Turn 当作纯文本,用户看见已转发而有效输入被跳过,恢复会失去原队列状态。 真实 File store 和 TypeScript planner 对同一 client_turn_id 重放都只保留一条消息和一个 queued event,改正文会冲突。None 和空列表可生成转发计划,规范非空附件仍被拒绝。 目标基线与精确头各 5 项相同的 HTTP 排队、mutation 恢复及目标校验回归通过。精确头新增 5 项接口契约测试通过,实际 File store 的 3 项自建 HTTP 拒绝测试通过。git diff --check 与当前目标 merge-tree 通过。 异常附件形状来自隔离持久夹具。真实 File store、HTTP 路由和 TypeScript planner 已覆盖。测试替身记录外部转发调用,拒绝测试观测到零调用。安装、真实上游和远程 CI 未核验。独立结论覆盖指定路径,完整套件未重跑。 基线契约

改动思路 / Approach

该改动沿用 ChatSessionStore → queued_admission.steer_queued_turn → plan_queued_chat_steering → TypeScript chat.queue.steer。路由、File store 和 TypeScript 决策 owner 仍通过已有结构化 effect 连接。Python 在原桥接边界同时验证节点和投影附件存在性。 Python 使用结构化事实、摘要和可验证的 planner 输出。对异常空对象、空字符串和布尔值采用显式拒绝;普通空列表、附件拒绝、mutation 和同请求重放维持原规则。 保留现有 attachment_count 和错误码。只在明确无附件时计零,非空异常形状沿用既有拒绝,无法归类的空容器提前失败。

具体改动 / Changes

精确提交 712f75f,本次对照目标 7f7297a。相对真实分叉点 57c4c43 的 PR 差分为 2 个文件 +621/-227。当前目标 main 为 7f7297a。

关键代码讲解

  • _steering_attachment_count。None 与规范空列表仍计零,有内容的历史异常形状保留正计数。 源码

  • plan_queued_chat_steering。由现有 TypeScript owner 检查预期目标及附件后决定转发或拒绝。 源码

  • plan_queued_chat_mutation。核对既有 event、patch 与 receipt 字段给 File store 应用。 源码

  • plan_managed_turn_acceptance。使用规范摘要和现存的原请求、消息与事件事实恢复。 源码

  • _json_digest。沿用规范 JSON 摘要,支持新的只读容器边界。 源码

  • queued-live-steering-retains-nonempty-attachment-facts(implemented)。文本 steering 无法携带附件时保留排队输入并明确拒绝。边界与原有效请求及状态重放保持一致。

对主干的风险 / Risks

持久非空对象和字符串在当前目标基线与修复头均返回 queue_steering_attachments_unavailable。精确头 HTTP 分别验证两例 409 与空对象 400,原 Turn 和转发观测文件保持字节一致。 当前生产者持久化规范附件列表。若存在旧来源写入空对象或空文本,它们请求文本 steering 时会收到错误,原内容仍在队列中。 仅对明确无附件的规范输入放行,非空异常形态由原 owner 拒绝,空异常形态显式失败。

我的整体评价 / Verdict

APPROVE。 旧候选的附件误判在本提交已关闭。基线对照、实际 HTTP 反例与相同操作恢复通过,范围见上。 持久输入保留附件事实和原请求身份,使拒绝后的队列仍可由正常路径继续处理。

English verdict: APPROVE at 712f75f. The exact fix restores rejection of nonempty malformed stored attachments. Paired replay and queue tests passed, and the isolated HTTP path rejected malformed input without changing the stored Turn or invoking transport.

… chat_turn_acceptance

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
@loopx-agent
loopx-agent force-pushed the codex/slim-chat-turn-acceptance-zero-any-20261126 branch from 712f75f to dd450ee Compare November 27, 2026 16:27

@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 · deepseek-flash · DeepSeek · runtime_reported · high

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

动机 / Motivation

收紧 Python 到 TypeScript 的 Chat Turn 验收接口,维持同请求恢复和文本 steering 的内容保护。 目标基线已经拒绝非空持久附件。前一个候选把部分非空异常形状计成零,可能只转发正文;当前修复恢复原拒绝。 继续排队消息、重放原请求回复,以及恢复本地持久排队 Turn 的 Chat 用户。

如果调度把有非空附件事实的 Turn 当作纯文本,用户看见已转发而有效输入被跳过,恢复会失去原队列状态。 真实 File store 和 TypeScript planner 对同一 client_turn_id 重放都只保留一条消息和一个 queued event,改正文会冲突。None 和空列表可生成转发计划,规范非空附件仍被拒绝。 目标基线与精确头各 5 项相同的 HTTP 排队、mutation 恢复及目标校验回归通过。精确头新增 5 项接口契约测试通过,实际 File store 的 3 项自建 HTTP 拒绝测试通过。git diff --check 与当前目标 merge-tree 通过。 异常附件形状来自隔离持久夹具。真实 File store、HTTP 路由和 TypeScript planner 已覆盖。测试替身记录外部转发调用,拒绝测试观测到零调用。安装、真实上游和远程 CI 未核验。独立结论覆盖指定路径,完整套件未重跑。 基线契约

改动思路 / Approach

该改动沿用 ChatSessionStore → queued_admission.steer_queued_turn → plan_queued_chat_steering → TypeScript chat.queue.steer。路由、File store 和 TypeScript 决策 owner 仍通过已有结构化 effect 连接。Python 在原桥接边界同时验证节点和投影附件存在性。 Python 使用结构化事实、摘要和可验证的 planner 输出。对异常空对象、空字符串和布尔值采用显式拒绝;普通空列表、附件拒绝、mutation 和同请求重放维持原规则。 保留现有 attachment_count 和错误码。只在明确无附件时计零,非空异常形状沿用既有拒绝,无法归类的空容器提前失败。

具体改动 / Changes

精确提交 dd450ee,本次对照目标 7f7297a。相对真实分叉点 57c4c43 的 PR 差分为 2 个文件 +621/-227。当前目标 main 为 7f7297a。

关键代码讲解

  • _steering_attachment_count。None 与规范空列表仍计零,有内容的历史异常形状保留正计数。 源码

  • plan_queued_chat_steering。由现有 TypeScript owner 检查预期目标及附件后决定转发或拒绝。 源码

  • plan_queued_chat_mutation。核对既有 event、patch 与 receipt 字段给 File store 应用。 源码

  • plan_managed_turn_acceptance。使用规范摘要和现存的原请求、消息与事件事实恢复。 源码

  • _json_digest。沿用规范 JSON 摘要,支持新的只读容器边界。 源码

  • queued-live-steering-retains-nonempty-attachment-facts(implemented)。文本 steering 无法携带附件时保留排队输入并明确拒绝。边界与原有效请求及状态重放保持一致。

对主干的风险 / Risks

持久非空对象和字符串在当前目标基线与修复头均返回 queue_steering_attachments_unavailable。精确头 HTTP 分别验证两例 409 与空对象 400,原 Turn 和转发观测文件保持字节一致。 当前生产者持久化规范附件列表。若存在旧来源写入空对象或空文本,它们请求文本 steering 时会收到错误,原内容仍在队列中。 仅对明确无附件的规范输入放行,非空异常形态由原 owner 拒绝,空异常形态显式失败。

当前 exact head 复核 / Rebased-head validation

PR #9476 已无冲突 rebase 到 origin/main 2302e42d9cad35a8a4150e24496ffecfbfdce8cb,当前精确头为 dd450ee28134be2aba543af99cb9c6ce7187db54。本轮在新 base 上重新执行定向测试、静态检查和 diff 级 premerge。

最终 exact head 复核:5 项 chat turn acceptance 合约测试通过;核心 Python 文件的严格 mypy、Ruff、diff 检查和标准 premerge 的 10 项选定检查全部通过。TS 侧 canonical export 与 digest 所有者保持不变。

我的整体评价 / Verdict

APPROVE。 旧候选的附件误判在本提交已关闭。基线对照、实际 HTTP 反例与相同操作恢复通过,范围见上。 持久输入保留附件事实和原请求身份,使拒绝后的队列仍可由正常路径继续处理。

English verdict: APPROVE at dd450ee. The exact fix restores rejection of nonempty malformed stored attachments. Paired replay and queue tests passed, and the isolated HTTP path rejected malformed input without changing the stored Turn or invoking transport.

@loopx-agent
loopx-agent merged commit fc5f363 into main Nov 27, 2026
18 of 22 checks passed
@loopx-agent
loopx-agent deleted the codex/slim-chat-turn-acceptance-zero-any-20261126 branch November 27, 2026 16:33
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