Repository navigation
refactor(native-chat): eliminate Any and converge codex_adapter helpers - #9281
loopx-agent wants to merge 2 commits into
Conversation
|
This pull request has merge conflicts with Choose the remote for the base repository, not an out-of-date fork. git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEADFor a same-repository clone whose Keep the DCO |
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google · self_reported
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机
- 受影响调用方与维护者:在 native chat(Lark 私聊与本地 steward 会话)中维护会话恢复、工作上下文注入、回合终态读回与失败观察的维护者和静态类型检查工具,均依赖
codex_adapter.py暴露给chat_runtime.py、chat_store.py与测试测试桩的公共接口。 - 改造前后对比场景:重构前,该模块共 1,476 行并包含 71 处
Any注解与多组结构高度重复的字典校验、历史摘要、回合读回及普通消息发送逻辑,任何新增字段或状态分支都要在多处同步修改,类型检查无法提前捕获键名或负载类型漂移;重构后,模块收敛至 1,262 行并将Any降至 0,重复读回和发送路径合并为统一内部 helper,所有对外符号签名、异常类型和回退语义保持不变。 - 可观测结果:
loopx/capabilities/native_chat/codex_adapter.py的行数由 1,476 降至 1,262(净减 214 行,+693/-907),any_count由 71 降至 0,dict_any_count与# type: ignore保持为 0;15 个公共符号签名与改造前完全一致,严格mypy(17 个核心文件及独立--follow-imports=silent)与 17 个关联 pytest 测试套件(2,586 条用例)全部通过。 - 非目标(Non-goals):本 PR 不改变 Codex app-server 线协议字段、native history 恢复或压缩门限、Lark 私聊路由器策略,也不顺带迁移同一目录下的
external_conversations.py或调整仓库全局 maintainability ratchet 基线。
改动思路
为了在不改变运行期行为和对外签名的前提下消除全部 71 处 Any 并把单文件压回到可维护规模,作者采取“先建强类型契约与守卫、再收敛重复逻辑、最后保留原有测试接入缝”的三段式重构:
| 维度 | origin/main 基线 (4ae2844cd0) |
PR e3e6bde4fe |
变化 |
|---|---|---|---|
| 模块行数 | 1476 |
1262 |
-214 (+693/-907) |
any_count / dict_any_count |
71 / 0 |
0 / 0 |
-71 / 0 |
# type: ignore |
0 |
0 |
0 |
| 公共符号签名一致性 | 15 个既有公共导出 | 15 个完全一致 | 无破坏性变更 |
- 边界类型精确化:引入内部
JsonDict/JsonMap别名、_WorkingCheckpointTypedDict,以及面向动态模块加载结果的_BindingsStore、_ApiKeysProvider、_NativeAccountsProvider、_OpenAIRelayProvider四个Protocol和 5 个TypeGuard(_is_dict、_is_nonempty_str、_is_int、_is_valid_provider、_is_bare_sha256)。 - 内部路径收敛:将工作区校验、
NativeHistoryRestoration内部绑定读取与失效清理、三套回合终态读回(completed_work_readback/completed_result_review_readback/interrupted_result_readback)、普通回合/带附件回合发送(_send_ordinary_turn)以及失败观测补充(_enrich_failed_observation)抽为单一共享 helper。 - 架构评估结论(retain):本改动仅保留一个局部 TypedDict / Protocol / TypeGuard 类型边界与内部共用 helper(如
_read_terminal_inventory、_read_validated_turn、_send_ordinary_turn),未引入新持久化格式、新运行时层或外部依赖,全部复杂度严格局限于单个适配器模块内部并净减少 214 行代码,因此直接保留当前设计(retain)是最稳妥且可逆的边界。 当前边界:仅重构loopx/capabilities/native_chat/codex_adapter.py单个文件,保留所有 15 个既有公共符号签名、延迟导入(lazyimportlib.import_module)与测试 monkeypatch 注入点(如_loopback_relay_transport_ready、subprocess.Popen、time.monotonic)。
具体改动
- 规范依据(spec_basis: no_spec / spec_source: none):这是一个单文件内部类型消除与重复 helper 收敛重构(maintainability / zero-Any refactor),未对应独立设计 RFC 或新协议规范,因此以既有公共符号契约与行为等价性作为验收基线(spec_source: none)。
关键代码讲解
validate_native_working_update(loopx/capabilities/native_chat/codex_adapter.pyL133-L175):由loopx/chat_store.py在 Session 锁下调用。改动后使用模块级闭集常量_CHECKPOINT_KEYS、_PARKED_WORKING_KEYS与_is_codex_steward_working、_is_valid_provider、_is_bare_sha256、_is_int等收窄函数替代零散Any检查;面对不合法的 checkpoint 字段、空字符串或非 64 位小写 hex 摘要,依然精准抛出原语义的ValueError。NativeHistoryRestoration(loopx/capabilities/native_chat/codex_adapter.pyL186-L406):统一抽离_read_binding(L203-L208)与_invalidate(L210-L212),并将_working_suffix(L302-L332)和prepare_working_context(L346-L356)收拢;check()(L379-L402)改由_TURN_CHECK_KEYS数据驱动拼接检查记录字典,避免手工字段遗漏。_loopback_relay_transport_ready与_restore_native_history(loopx/capabilities/native_chat/codex_adapter.pyL541-L573, L439-L465):保持原有的模块级_loopback_relay_transport_ready调用点和importlib.import_module延迟加载顺序,使既有 monkeypatch 测试桩与动态HostError捕获维持原行为;通过_OpenAIRelayProvider/_NativeAccountsProviderProtocol返回强类型结构,彻底去掉Any。_read_terminal_inventory、_validate_turn_items与_read_validated_turn(loopx/capabilities/native_chat/codex_adapter.pyL589-L612, L714-L759):将completed_work_readback(L762-L792)、completed_result_review_readback(L795-L816)和interrupted_result_readback(L819-L832)之前高度相似的“读取终态盘点 -> 校验无异常 -> 提取有效项”流程合并为两条正交组合 helper,消除了状态字段漂移风险,同时维持各自特有的未完成项检测与空项回退消息。CodexAppServerAdapter._send_ordinary_turn与failed_request_observation(loopx/capabilities/native_chat/codex_adapter.pyL1043-L1067, L923-L964):将start_turn与start_turn_with_attachments的超时/异常分类及session.send分派收敛到_send_ordinary_turn(已核实loopx/chat_agent.py中CodexChatAgentSession.send接受对应可选None参数);failed_request_observation抽离_enrich_failed_observation(L835-L865)复用终态/事件文本抽取并保留原有优先回落顺序。
对主干的风险
- 已验证覆盖:在精确提交
e3e6bde4fe6186f405f1b5b9cdec86099d532780的独立隔离 worktree 中直接执行并通过以下验证:- 静态与类型检查:
ruff check loopx/capabilities/native_chat/codex_adapter.py(0 issues)、严格mypy(17 个核心文件 0 errors)、mypy --follow-imports=silent loopx/capabilities/native_chat/codex_adapter.py(0 errors)、公共边界扫描loopx check --scan-path loopx/capabilities/native_chat/codex_adapter.py(public boundary scan clean: 1 file),以及 canary premerge direct checks 6/6 与 catalog canaries 2/2(control-plane-maintainability-ratchet-smoke.py、semantic-vocabulary-drift-smoke.py)全部通过。 - 回归测试套件:运行全部 17 个相关测试文件共 2,586 passed(
pytest -n 2 -q)。运行过程中观测到tests/test_lark_private_conversations.py::test_admitted_topic_mention_hint_cannot_supply_control_authority退出清理后残留后台线程触发PytestUnhandledThreadExceptionWarning(测试自身Codex app-server timed out.在用例拆毁删掉 turn 记录后回调chat_store.update_turn抛出KeyError),与codex_adapter.py改动路径无关,测试本身仍判定通过。 - 独立对偶/签名探针:脚本核对全部 15 个公共符号的
inspect.signature与origin/main一致,并针对validate_native_working_update正常与异常输入、_is_bare_sha256、NativeHistoryRestoration绑定/摘要/checkpoint 状态转移及_read_validated_turn对origin/main与HEAD运行配对行为对比,全部通过。
- 静态与类型检查:
- 已知边界与残余风险:本评审遵循本地优先策略未等待远端 GitHub CI(
wait_for_ci: false);CodexAppServerAdapter.start对接真实外部codex app-server二进制的端到端长跑未在本轮单独拉起真实子进程,依赖现有 17 个适配器与运行时测试套件中的 fake app-server 覆盖;本工作区本地运行canary premerge显示change_quality_qualification处于工作区隔离导致的未关联状态,不影响代码正确性结论。
我的整体评价
- UI 与视觉评审(visual_review: not_applicable):仅涉及后端 Python 适配器
loopx/capabilities/native_chat/codex_adapter.py的内部类型收紧与函数合并,未改动任何前端 UI、页面布局或终端交互渲染文本。 unverified_scope: none。 - 架构与边界评估(architecture_assessment: retain):本改动仅保留一个局部 TypedDict / Protocol / TypeGuard 类型边界与内部共用 helper(如
_read_terminal_inventory、_read_validated_turn、_send_ordinary_turn),未引入新持久化格式、新运行时层或外部依赖,全部复杂度严格局限于单个适配器模块内部并净减少 214 行代码,因此直接保留当前设计(retain)是最稳妥且可逆的边界。 当前边界:仅重构loopx/capabilities/native_chat/codex_adapter.py单个文件,保留所有 15 个既有公共符号签名、延迟导入(lazyimportlib.import_module)与测试 monkeypatch 注入点(如_loopback_relay_transport_ready、subprocess.Popen、time.monotonic)。 - 总体结论:这次重构在不牺牲公共接口兼容性、运行时容错和动态测试注入点的前提下,干净清零了模块内的 71 处
Any并把单文件体量从 1,476 行压降至 1,262 行,所有类型、边界扫描、配对等价探测及 2,586 条测试均稳定通过,未发现 P0/P1/P2 缺陷或隐私路径泄漏,可以合并。
English verdict: APPROVE at e3e6bde (author-owned PR; published as COMMENTED fallback with 0 P0/P1/P2 findings).
e3e6bde to
325bef5
Compare
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google · self_reported
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机
- 受影响调用方与维护者:在 native chat(Lark 私聊与本地 steward 会话)中维护会话恢复、工作上下文注入、回合终态读回、历史压缩预算与失败观察的维护者和静态类型检查工具,均依赖
codex_adapter.py暴露给chat_runtime.py、chat_store.py、external_conversations.py与测试桩的公共接口。 - 改造前后对比场景:重构前,该模块共 1,478 行并包含 71 处
Any注解与多组结构高度重复的字典校验、历史摘要、回合读回及普通消息发送逻辑,新增字段或状态分支需要在多处同步修改且无法由严格类型检查提前捕获;本次基于最新main(完整保留 #9276 默认交互空闲超时去除与可选check参数修复)重构后,模块收敛至 1,266 行并将Any降至 0,重复读回和发送路径合并为统一内部 helper,所有 15 个既有公共符号参数契约、异常类型和回退语义保持不变。 - 可观测结果:
loopx/capabilities/native_chat/codex_adapter.py行数由 1,478 降至 1,266(+693/-905,净减 212 行),any_count由 71 降至 0,dict_any_count与# type: ignore为 0;15 个公共符号参数/默认值与新基线完全一致(仅将dict[str, Any]返回注解精确收紧为JsonDict),严格mypy(17 个核心文件及独立--follow-imports=silent)与 18 个关联 pytest 测试套件(2,611 条用例)全部通过。 - 非目标(Non-goals):本 PR 不改变 Codex app-server 线协议字段、#9276 交互空闲/硬超时与错误栏栅策略、Lark 私聊路由器策略,也不顺带修改同目录其他文件或调整仓库 maintainability ratchet 基线。
改动思路
本 PR 在前一次评审(e3e6bde4fe)暴露出合入冲突后已重新变基至最新 origin/main(833a3b50f9),完整并入 #9276 的无默认交互空闲超时与可选 check 参数修复。整体采用“强类型守卫先行 + 重复逻辑内聚收敛 + 保留现有接入缝”的策略:
| 维度 | origin/main 基线 (833a3b50f9) |
Rebased PR 325bef5ae1 |
变化 |
|---|---|---|---|
| 模块行数 | 1478 |
1266 |
-212 (+693/-905) |
any_count / dict_any_count |
71 / 0 |
0 / 0 |
-71 / 0 |
# type: ignore |
0 |
0 |
0 |
| 15 个公共符号参数签名与默认值 | 既有导出(含 idle_timeout_sec=None) |
完全一致(返回注解收窄为 JsonDict) |
无破坏性变更 |
- 边界类型精确化:引入内部
JsonDict/JsonMap别名、_WorkingCheckpointTypedDict、4 个动态加载Protocol(_BindingsStore、_ApiKeysProvider、_NativeAccountsProvider、_OpenAIRelayProvider)和TypeGuard守卫(_is_dict、_is_nonempty_str、_is_int、_is_valid_provider、_is_bare_sha256)。 - 内部路径收敛与变基保真:把工作区校验、
NativeHistoryRestoration绑定读取/失效、三套回合终态读回(completed_work_readback/completed_result_review_readback/interrupted_result_readback)、普通/附件回合发送以及失败观测补充收敛为单一共享 helper,同时在compact_native_history与CodexAppServerAdapter.start中完整保留idle_timeout_sec: float | None = None与check is None无空洞透传。 - 架构评估结论(retain):仅保留单文件局部 TypedDict / Protocol / TypeGuard 类型边界与内部共用 helper(如
_read_terminal_inventory、_read_validated_turn、_enrich_failed_observation、_send_ordinary_turn),未引入新持久化格式、新运行时层或外部依赖,全部复杂度局限于单个适配器内部并净减少 212 行代码,因此保留当前设计(retain)是最稳妥且可单提交回滚的边界。 当前边界:仅重构loopx/capabilities/native_chat/codex_adapter.py单个文件,完整保留 15 个公共符号参数列表与默认值、#9276 的idle_timeout_sec: float | None = None/ 可选check预算路径、延迟导入(lazyimportlib)与既有测试 monkeypatch 缝。
具体改动
- 规范依据(spec_basis: no_spec / spec_source: none):这是一个基于当前主干基线的单文件内部
Any清零与重复 helper 收敛重构,未对应独立新增设计 RFC 或新线协议,以既有公共参数契约、#9276 超时预算规则和运行期行为等价性作为验收基线(spec_source: none)。
关键代码讲解
validate_native_working_update(loopx/capabilities/native_chat/codex_adapter.pyL133-L175):由loopx/chat_store.py在 Session 锁下调用。使用模块级闭集常量_CHECKPOINT_KEYS、_PARKED_WORKING_KEYS及_is_codex_steward_working、_is_valid_provider、_is_bare_sha256、_is_int等收窄函数替代松散Any检查;对于合法 checkpoint 正常放行,对非 64 位小写 hex 摘要或越界条件仍精确抛出原语义的ValueError。NativeHistoryRestoration(loopx/capabilities/native_chat/codex_adapter.pyL186-L406):统一抽离_read_binding(L203-L208)与_invalidate(L210-L212),并将_working_suffix和prepare_working_context收拢;check()改用_TURN_CHECK_KEYS数据驱动组装检查记录,消除手工字段不一致隐患。compact_native_history与CodexAppServerAdapter.start(loopx/capabilities/native_chat/codex_adapter.pyL479-L523, L984-L1042):变基后完整继承idle_timeout_sec: float | None = None(L987)及基于deadlines列表与check is None条件分派的预算等待逻辑(L489-L494);同时通过_is_int与_as_dict替代散落的Any判空,已通过配对探针证实idle_timeout_sec=None/hard_timeout_sec/check=None三组组合下的deadline行为与主干完全一致。_loopback_relay_transport_ready(loopx/capabilities/native_chat/codex_adapter.pyL545-L577):保留原有模块级名称和importlib.import_module延迟导入顺序,确保已有测试 monkeypatch 桩与动态HostError捕获持续有效,同时借助_OpenAIRelayProvider/_NativeAccountsProviderProtocol消除动态属性Any。_read_terminal_inventory、_validate_turn_items与_read_validated_turn(loopx/capabilities/native_chat/codex_adapter.pyL593-L616, L718-L763):统一支撑completed_work_readback(L766-L796)、completed_result_review_readback(L799-L820)与interrupted_result_readback(L823-L836),消除三处终态/中断回合读取、校验与未完成项拒收的重复代码,同时保留各自摘要哈希与错误回落语义。
对主干的风险
- 已验证覆盖:在精确提交
325bef5ae14b9a3f7cff0032e928b0a43e869ddb的独立隔离 worktree 中直接执行并通过全部验证:- 代码规范与类型:
ruff check(0 issues)、严格mypy(17 核心文件 0 errors)、mypy --follow-imports=silent loopx/capabilities/native_chat/codex_adapter.py(0 errors)、loopx check --scan-path公共边界扫描干净(1 file;两个历史归档 todo 注册表报错来自无关主干现状,非本文件引入);Goal 绑定canary premergedirect checks 6/6 与 catalog canaries 2/2(ratchet smoke +semantic-vocabulary-drift-smoke.py)全部通过;title/body/diff 隐私扫描干净。 - 全量回归测试:在精确 head
325bef5ae14b9a3f7cff0032e928b0a43e869ddb上独立重跑全部 18 个相关测试套件(含 16 个codex_adapter引用套件、tests/test_chat_long_running.py与tests/canary/test_maintainability_ratchet.py),共 2,611 passed(pytest -n 2 -q, 0 failures, 0 warnings),含tests/test_native_steward_reports.py在内稳定一次性全绿。 - 独立签名与配对探针:验证全部 15 个公共导出符号及类方法参数列表/默认值与新基线
833a3b50f9完全一致(仅返回注解从dict[str, Any]收紧为JsonDict);针对compact_native_history(idle_timeout_sec=None、hard_timeout_sec、check=None/callable)、validate_native_working_update正常与非法sha256、completed_work_readback/completed_result_review_readback/interrupted_result_readback的基线 vs HEAD 配对测试全部通过。
- 代码规范与类型:
- 已知边界与残余风险:未等待远端 GitHub CI(
wait_for_ci: false);真实外部codex app-server二进制的线上长时间网络回合未在本轮独立拉起外部进程,依赖既有 fake app-server 测试覆盖;与此前类似,隔离审查 worktree 本地预检中的change_quality_qualification归因于作者原工作区指纹。
我的整体评价
- UI 与视觉评审(visual_review: not_applicable):仅重构后端 Python 适配器
loopx/capabilities/native_chat/codex_adapter.py的内部类型与辅助函数,未改动任何前端 UI、页面布局或展示文本。 unverified_scope: none。 - 架构与边界评估(architecture_assessment: retain):仅保留单文件局部 TypedDict / Protocol / TypeGuard 类型边界与内部共用 helper(如
_read_terminal_inventory、_read_validated_turn、_enrich_failed_observation、_send_ordinary_turn),未引入新持久化格式、新运行时层或外部依赖,全部复杂度局限于单个适配器内部并净减少 212 行代码,因此保留当前设计(retain)是最稳妥且可单提交回滚的边界。 当前边界:仅重构loopx/capabilities/native_chat/codex_adapter.py单个文件,完整保留 15 个公共符号参数列表与默认值、#9276 的idle_timeout_sec: float | None = None/ 可选check预算路径、延迟导入(lazyimportlib)与既有测试 monkeypatch 缝。 - 总体结论:变基后的 PR
325bef5ae1已消除此前阻塞合并的冲突(目前MERGEABLE),同时干净继承了 #9276 的idle_timeout_sec=None与可选check修复,在不改动公共参数契约的前提下实现 71->0Any清零和 1,478->1,266 行瘦身;独立重跑的 2,611 条测试、配对探针、类型与 canary 检查全部通过,无 P0/P1/P2 缺陷,可以合并。
English verdict: APPROVE at 325bef5 (author-owned PR; published as COMMENTED fallback with 0 P0/P1/P2 findings).
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Request changes conclusion (author-owned PR; GitHub blocks formal self-review)
[P2] 让新类型覆盖原会话恢复与历史补答的实际调用
新注解让两个现有 caller 无法通过共享边界的类型检查。原 Session 恢复仍从 ChatSessionLifecycleMixin 传 self 给 NativeHistoryRestoration;历史补答仍把原返回的 message 当作 str 拼接,改成 JsonDict 后该字段成了 object。 配对跨文件 mypy 在候选报告上述新增错误,相同 caller 和命令在基线没有这些诊断。现有静态检查的其他错误不归因于本 PR。 按实际宿主收窄恢复构造参数,复用既有 mixin 和 controller 类型。在普通回答的返回契约保留 message: str,或在现有历史补答投影查验实际返回后收窄;同一步运行现有 caller 的跨文件检查。 改动位置 Session 恢复 历史补答拼接 native 答复返回
动机 / Motivation
通过本地 Codex Chat 恢复原会话、压缩历史或读回原 Turn 结果的用户。 在 native adapter 中,多份读取函数各自验证终态、Turn ID、item ID、effect 和原文。分支容易因细小差异积累漂移。 目标 Turn 和 item 的归属保持可验证,工作续跑仍限于原活体 adapter 的已结算效果,cold reader 仅供只读证据。历史在绑定发布前保存,撤销和预算耗尽仍停下。 只改 native Chat 适配器,保留 app-server DTO 及 ChatSessionStore。没有新增用户入口或开关。 验证使用本地 app-server 协议夹具。正式 app-server 账户路由和安装行为未独立执行。 新注解让两个现有 caller 无法通过共享边界的类型检查。原 Session 恢复仍从 ChatSessionLifecycleMixin 传 self 给 NativeHistoryRestoration;历史补答仍把原返回的 message 当作 str 拼接,改成 JsonDict 后该字段成了 object。
改动思路 / Approach
把 summary/item 读取与格式判定统一进原 native adapter,Core 保留当前来源、续跑资格和副作用准入。 复用原来的本地持久绑定、native RPC 与绑定提交前 guard。 阶段或库存未知时不交付恢复授权,复用原已验证 binding 与 receipt。
具体改动 / Changes
关键代码讲解
完整头 325bef5。1 个生产文件 +693/-905,1478 → 1266 行。 本地基线 833a3b5。用 Invariants 和 Detection, containment and recovery evidence 核对原身份、权威读回和产生副作用前的恢复条件。 原 RFC
- NativeHistoryRestoration.check。重新核对 Session、排队 Turn、当前绑定和运行设置,再运行原 route guard。 代码
- _restore_native_history。先物化 thread,按 UTF-8 字节分批导入,必要时压缩并再次验明同一时间预算。 代码
- _validate_turn_items。检查精确归属、非空唯一 ID、单个用户输入,以及按 caller 要求的最终答案和 effect 状态。 代码
- completed_work_readback。活体 adapter 读两次库存和后续已知 Turn,验证后台空闲后返回旧协议的 SHA256。 代码
对主干的风险 / Risks
语义与 CI 对齐
FAIL。配对跨文件 mypy 在候选报告上述新增错误,相同 caller 和命令在基线没有这些诊断。现有静态检查的其他错误不归因于本 PR。 这些是实际消费路径的类型不匹配。独立运行生产入口的本地夹具时,测试没有复现这几项运行时错误。
PASS。目标 Turn 和 item 的归属保持可验证,工作续跑仍限于原活体 adapter 的已结算效果,cold reader 仅供只读证据。历史在绑定发布前保存,撤销和预算耗尽仍停下。 拒绝新绑定和复跑。对于稳定 inventory,结果审阅与可写续跑继续使用各自不同的 effect 与 final 条件。 配对执行原 Chat、实际 store 恢复、app-server RPC 和 native task 准入测试。将协议进程和计时作为可控夹具,既有生产入口和 guard 仍运行。 原生历史、失败读回与 Lark 恢复在基线 193 项、候选 193 项通过。 Ruff 和单模块严格 mypy 通过。标准 premerge 首次 6 项直接检查通过,两个目录检查在本地并行验证中超时。 当前候选与复核时主干的三方合成无冲突。 GitHub 报告 base dc90f1f,本轮采用实际 merge-base 833a3b5 做配对。
验证使用本地 app-server 协议夹具。正式 app-server 账户路由和安装行为未独立执行。 新注解让两个现有 caller 无法通过共享边界的类型检查。原 Session 恢复仍从 ChatSessionLifecycleMixin 传 self 给 NativeHistoryRestoration;历史补答仍把原返回的 message 当作 str 拼接,改成 JsonDict 后该字段成了 object。 代码限于原 Chat 屏幕背后的运行时和恢复入口,改动没有触及界面布局。
我的整体评价 / Verdict
维持现有原生验证,并补齐原调用者的类型边界,再复验当前入口。native checkpoint 与回执编码保持兼容,回退单适配器不改变有效绑定。
English verdict: REQUEST_CHANGES at 325bef5. Cross-file mypy checks found new type incompatibilities at existing Chat or Lark callers. Targeted runtime paths retained their observed behavior.
|
This pull request has merge conflicts with Choose the remote for the base repository, not an out-of-date fork. git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEADFor a same-repository clone whose Keep the DCO |
- Replace all 71 Any annotations with JsonDict, JsonMap, TypedDict, Protocol, and TypeGuard helpers while preserving public symbols and test seams. - Consolidate duplicate payload validation, working-checkpoint checks, history digest/restoration batching, turn item parsing, and error mapping, slimming codex_adapter.py from 1,478 to 1,266 lines (-212 LOC). Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
…view str(message), and probe callers Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
325bef5 to
2ac4aa1
Compare
|
Rebased onto
|
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
通过本次精确提交评审。
动机 / Motivation
Codex Chat 的用户在重启、补答或恢复原工作时依赖原会话和原生记录。 核心 native adapter 对三条读取路径分别实现库存与 item 检查,上一候选还在恢复及补答两个现有调用方新增 mypy 诊断。 同一原生历史进入只读补答与可写工作续接。两条路径必须各自验证 Turn、来源、作用域和效果是否终结。 恢复对象通过实际 Mixin 和 Runtime Controller 的检查,补答拼接保留原文本路径。原 native 读取形式、已结算回执和权限条件保持。 作用域是已存在的 Codex native adapter 和调用方。权限、锁、持久绑定及重放由原有 owner 执行。
改动思路 / Approach
把三处原生库存检查收敛到共享读,再用不同参数明确只读结果和可写续接的专属条件。用结构 Protocol 表达恢复实际需要的接口。 Chat 授权、会话和原 Task 仍由现有 Core 与 Host 管理。Adapter 收敛读取和类型。 原会话绑定、原副作用身份、既有授权及可用消费者类型。 候选的缩减行数来自现有适配器内合并重复检查,没有新增状态、开关或安装要求。
具体改动 / Changes
精确提交 2ac4aa1。目标基线 509360f,复审对照 509360f。4 个文件,增加 915 行、删除 915 行。评审条件 native-history-recovery、actual-callers-types、read-only-and-working-route。 原始契约
关键代码讲解
- NativeHistoryRestoration.check。在重新导入历史及发布绑定前查验当前 Session、Turn、原 Binding 和宿主关闭状态。 源码
- completed_work_readback。只从原活体适配器读已结算的副作用,复核库存与后台工作。 源码
- completed_result_review_readback。保留原只读审阅、项目来源和冻结输出。 源码
- _send_ordinary_turn。保留普通调用、附件、文档回复和当前 read-only guard 的分支。 源码
- ChatExternalConversations。原 history_review 消费者在落旧前缀时收窄 message 的表示。 源码
对主干的风险 / Risks
同一 11 文件 mypy 对照显示适配器诊断 23→0。两个旧 P2 的实际 caller 没有新增诊断,首轮的类型范围保持。独立 native RPC 队列夹具得到字节一致的历史读回与摘要,后台工作仍拒绝可写续接。 候选 686 项、基线 684 项 Chat 历史、协议与 Lark 恢复回归通过。单模块 strict mypy、Ruff 和 git diff --check 通过。
语义与 CI 对齐
原工作和只读补答的资格保持区分。另一个 Antigravity 适配器的绝对阈值用例在基线和候选均以 38≤37 的同一断言失败,两个版本出现完全同样的现有错误信息。 可验证范围为本机的实际调用者、原生 RPC 与 Chat/Lark 隔离夹具。生产账户、已安装宿主和远端 CI 本轮未执行。
我的整体评价 / Verdict
APPROVE。 原 P2 关闭,继续沿原有 native 路径执行。独立配对检查验证了有区别的两类恢复和附件透传。 让类型跟随已有消费者,按各原生读取入口核验回退和权限,保留既有拒绝与原 receipts。 将同一诊断归一到文件、消息和代码,比较真实 caller 的差值。对照基线和候选 RPC 的原始摘要与只读字段。
English verdict: APPROVE at 2ac4aa1. The original Chat and Lark callers retain their type boundaries, and paired native readback preserves the settled effects and read-only recovery rules.
Summary
Rebased onto
origin/main(509360fb0d3e9e6e578ddf5c12db587886016b23), preserving#9276(idle_timeout_sec: float | None = None),#9321(reply_documents: bool = FalseandattachmentsonCodexAppServerAdapter.start_turn/_send_ordinary_turn/native_turn_response),31afb1a8a74(loopx.chat.codex_goal), and55a294175b8(CODEX_APP_SERVER_HOST_CAPABILITIES), while resolving all findings from review6017057522:loopx/capabilities/native_chat/codex_adapter.py(1,343LOC vs1,490onmain,0ASTAnyvs72,0 # type: ignore,0 # noqa,23 -> 0strict mypy errors):72ASTAnyoccurrences viaJsonDict(dict[str, object]),JsonMap(Mapping[str, object]),_WorkingCheckpoint,TypeGuardhelpers, and dynamic-providerProtocolboundaries while preserving all15public exports and monkeypatch seams._ClosedFlag,_HistoryStore,_HistoryProjectContexts, and_HistoryControllerProtocols onNativeHistoryRestoration.controller(checkinggetattr(controller, "closed", None)via_ClosedFlagincheck()), so bothChatSessionLifecycleMixin(loopx/chat/session_open.py#L984) andChatRuntimeControllersatisfy the boundary with zero caller regressions.#9321'sattachmentsandreply_documentsparameters in_send_ordinary_turn,start_turn,start_turn_with_attachments, andnative_turn_response, keeping the single-on_eventfast path intact when optional flags are absent.loopx/capabilities/native_chat/external_conversations.py(#L1277): narrowsprefix + "\n\n" + str(response["message"])(matching PR#9286) sohistory_reviewresponse assembly staysbase=38 -> head=38under cross-filemypy(0new errors).loopx/capabilities/native_chat/report_failure_probe.py(369LOC,0ASTAny,#L165): removes the now-redundantcast(ProofObject | None, proof)afterCodexAppServerAdapter.failed_request_observation(...)became-> JsonDict | None(base=2 -> head=2).tests/test_chat_codex_history.py: addstest_codex_adapter_start_turn_forwards_reply_documents_and_attachments(#9321+CODEX_APP_SERVER_HOST_CAPABILITIES) andtest_codex_adapter_zero_any_and_cross_file_caller_mypy_contract(0ASTAny/# type: ignore/# noqa, plus realmypyverification acrosscodex_adapter.py,session_open.py,external_conversations.py, andreport_failure_probe.py).Verification (
HEAD 2ac4aa19c4de0cd09c4cbe77aed79cebc790c531onorigin/main509360fb0d3e9e6e578ddf5c12db587886016b23)ruff checkon all 4 changed files:All checks passed!mypy --config-file pyproject.toml --strict --no-incremental --follow-imports=silent loopx/capabilities/native_chat/codex_adapter.py:Success: no issues found in 1 source filemypy --config-file pyproject.toml --follow-imports=silent(17 configured files):Success: no issues found in 17 source filesmypy(codex_adapter.py+ 10 caller modules vsorigin/main):codex_adapter.py23 -> 0,session_open.py28 -> 28,external_conversations.py38 -> 38,report_failure_probe.py2 -> 2,model_settings.py2 -> 2,queued_admission.py15 -> 15,steward_turn.py54 -> 54,coordination.py1 -> 1,chat_agent.py9 -> 9,chat_runtime.py25 -> 25,chat_store.py4 -> 4(0new errors across all 10 callers).npm run typecheck:control-plane+tests/control_plane_ts/conversation_binding.test.ts: passed (70 passed,0failed,0skipped).pytest -n 6 -qacross all 22 suites (tests/architecture/,tests/canary/test_maintainability_ratchet.py,tests/hosts/test_host_harness_capabilities.py,tests/control_plane/test_goal_session_check_preparation.py,tests/control_plane/test_replan_staged_read.py,tests/test_antigravity_steward_adapter.py,tests/test_chat_agent.py,tests/test_chat_codex_history.py,tests/test_chat_conversation_bindings.py,tests/test_chat_long_running.py,tests/test_chat_manager_model_adoption.py,tests/test_lark_private_conversations.py,tests/test_lark_private_recovery_progress.py,tests/test_native_steward_private.py,tests/test_native_steward_reports.py,tests/test_native_steward_turn_host.py,tests/test_private_chat_routing_recovery.py,tests/test_steward_interrupted_answer.py,tests/test_steward_report_recovery_and_validator.py,tests/test_steward_team_plan_preview.py,tests/extensions/test_lark_private_conversations_equivalence.py,tests/extensions/test_lark_event_timing.py):4,385 passed(0failed,0skipped;1pre-existing teardownPytestUnhandledThreadExceptionWarningintest_delivered_quota_failure_stays_pending_across_restart_without_replaying[cyberPolicy-0]).tests/test_antigravity_adapter_contract.pyseparately:6 passed, 1 failedsolely on pre-existingorigin/mainexternal_conversations.py:27loopx.chat_store._read_jsonre-export (38 <= 37, tracked in#9521).scripts/check_rfc_bilingual.py --base origin/main --head HEAD: passed;loopx check --scan-path ...:errors=0, warnings=0(4files).change-quality: receiptcqr_7182488f564cd12272b4(status="valid",decision="pass",scope_fingerprint="7182488f564cd12272b475fd83a32deb2f17c6b92deb178b113576fafaa96cf1").loopx canary premerge --from-git-diff --git-diff-base origin/main --tier standard:gate.status="passed",merge_gate_passed=true(6/6direct checks,2/2catalog canaries,0failures,0manual holds).