Skip to content

refactor(native-chat): eliminate Any and converge codex_adapter helpers - #9281

Open
loopx-agent wants to merge 2 commits into
mainfrom
codex/l0-codex-adapter-zero-any-20261122
Open

loopx-agent wants to merge 2 commits into
mainfrom
codex/l0-codex-adapter-zero-any-20261122

Conversation

@loopx-agent

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

Copy link
Copy Markdown
Collaborator

Summary

Rebased onto origin/main (509360fb0d3e9e6e578ddf5c12db587886016b23), preserving #9276 (idle_timeout_sec: float | None = None), #9321 (reply_documents: bool = False and attachments on CodexAppServerAdapter.start_turn / _send_ordinary_turn / native_turn_response), 31afb1a8a74 (loopx.chat.codex_goal), and 55a294175b8 (CODEX_APP_SERVER_HOST_CAPABILITIES), while resolving all findings from review 6017057522:

  • loopx/capabilities/native_chat/codex_adapter.py (1,343 LOC vs 1,490 on main, 0 AST Any vs 72, 0 # type: ignore, 0 # noqa, 23 -> 0 strict mypy errors):
    • Eliminates all 72 AST Any occurrences via JsonDict (dict[str, object]), JsonMap (Mapping[str, object]), _WorkingCheckpoint, TypeGuard helpers, and dynamic-provider Protocol boundaries while preserving all 15 public exports and monkeypatch seams.
    • Adds _ClosedFlag, _HistoryStore, _HistoryProjectContexts, and _HistoryController Protocols on NativeHistoryRestoration.controller (checking getattr(controller, "closed", None) via _ClosedFlag in check()), so both ChatSessionLifecycleMixin (loopx/chat/session_open.py#L984) and ChatRuntimeController satisfy the boundary with zero caller regressions.
    • Preserves #9321's attachments and reply_documents parameters in _send_ordinary_turn, start_turn, start_turn_with_attachments, and native_turn_response, keeping the single-on_event fast path intact when optional flags are absent.
  • loopx/capabilities/native_chat/external_conversations.py (#L1277): narrows prefix + "\n\n" + str(response["message"]) (matching PR #9286) so history_review response assembly stays base=38 -> head=38 under cross-file mypy (0 new errors).
  • loopx/capabilities/native_chat/report_failure_probe.py (369 LOC, 0 AST Any, #L165): removes the now-redundant cast(ProofObject | None, proof) after CodexAppServerAdapter.failed_request_observation(...) became -> JsonDict | None (base=2 -> head=2).
  • tests/test_chat_codex_history.py: adds test_codex_adapter_start_turn_forwards_reply_documents_and_attachments (#9321 + CODEX_APP_SERVER_HOST_CAPABILITIES) and test_codex_adapter_zero_any_and_cross_file_caller_mypy_contract (0 AST Any / # type: ignore / # noqa, plus real mypy verification across codex_adapter.py, session_open.py, external_conversations.py, and report_failure_probe.py).

Verification (HEAD 2ac4aa19c4de0cd09c4cbe77aed79cebc790c531 on origin/main 509360fb0d3e9e6e578ddf5c12db587886016b23)

  • Lint & Typecheck:
    • ruff check on 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 file
    • mypy --config-file pyproject.toml --follow-imports=silent (17 configured files): Success: no issues found in 17 source files
    • Cross-file mypy (codex_adapter.py + 10 caller modules vs origin/main): codex_adapter.py 23 -> 0, session_open.py 28 -> 28, external_conversations.py 38 -> 38, report_failure_probe.py 2 -> 2, model_settings.py 2 -> 2, queued_admission.py 15 -> 15, steward_turn.py 54 -> 54, coordination.py 1 -> 1, chat_agent.py 9 -> 9, chat_runtime.py 25 -> 25, chat_store.py 4 -> 4 (0 new errors across all 10 callers).
    • npm run typecheck:control-plane + tests/control_plane_ts/conversation_binding.test.ts: passed (70 passed, 0 failed, 0 skipped).
  • Pytest:
    • pytest -n 6 -q across 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 (0 failed, 0 skipped; 1 pre-existing teardown PytestUnhandledThreadExceptionWarning in test_delivered_quota_failure_stays_pending_across_restart_without_replaying[cyberPolicy-0]).
    • tests/test_antigravity_adapter_contract.py separately: 6 passed, 1 failed solely on pre-existing origin/main external_conversations.py:27 loopx.chat_store._read_json re-export (38 <= 37, tracked in #9521).
  • Boundaries, CQR & Premerge:
    • scripts/check_rfc_bilingual.py --base origin/main --head HEAD: passed; loopx check --scan-path ...: errors=0, warnings=0 (4 files).
    • Goal change-quality: receipt cqr_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/6 direct checks, 2/2 catalog canaries, 0 failures, 0 manual holds).

@mergify

mergify Bot commented Nov 22, 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 22, 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 · 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 个完全一致 无破坏性变更
  1. 边界类型精确化:引入内部 JsonDict / JsonMap 别名、_WorkingCheckpoint TypedDict,以及面向动态模块加载结果的 _BindingsStore、_ApiKeysProvider、_NativeAccountsProvider、_OpenAIRelayProvider 四个 Protocol 和 5 个 TypeGuard(_is_dict、_is_nonempty_str、_is_int、_is_valid_provider、_is_bare_sha256)。
  2. 内部路径收敛:将工作区校验、NativeHistoryRestoration 内部绑定读取与失效清理、三套回合终态读回(completed_work_readback / completed_result_review_readback / interrupted_result_readback)、普通回合/带附件回合发送(_send_ordinary_turn)以及失败观测补充(_enrich_failed_observation)抽为单一共享 helper。
  3. 架构评估结论(retain):本改动仅保留一个局部 TypedDict / Protocol / TypeGuard 类型边界与内部共用 helper(如 _read_terminal_inventory、_read_validated_turn、_send_ordinary_turn),未引入新持久化格式、新运行时层或外部依赖,全部复杂度严格局限于单个适配器模块内部并净减少 214 行代码,因此直接保留当前设计(retain)是最稳妥且可逆的边界。 当前边界:仅重构 loopx/capabilities/native_chat/codex_adapter.py 单个文件,保留所有 15 个既有公共符号签名、延迟导入(lazy importlib.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)。

关键代码讲解

  1. validate_native_working_update(loopx/capabilities/native_chat/codex_adapter.py L133-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。
  2. NativeHistoryRestoration(loopx/capabilities/native_chat/codex_adapter.py L186-L406):统一抽离 _read_binding(L203-L208)与 _invalidate(L210-L212),并将 _working_suffix(L302-L332)和 prepare_working_context(L346-L356)收拢;check()(L379-L402)改由 _TURN_CHECK_KEYS 数据驱动拼接检查记录字典,避免手工字段遗漏。
  3. _loopback_relay_transport_ready 与 _restore_native_history(loopx/capabilities/native_chat/codex_adapter.py L541-L573, L439-L465):保持原有的模块级 _loopback_relay_transport_ready 调用点和 importlib.import_module 延迟加载顺序,使既有 monkeypatch 测试桩与动态 HostError 捕获维持原行为;通过 _OpenAIRelayProvider / _NativeAccountsProvider Protocol 返回强类型结构,彻底去掉 Any。
  4. _read_terminal_inventory、_validate_turn_items 与 _read_validated_turn(loopx/capabilities/native_chat/codex_adapter.py L589-L612, L714-L759):将 completed_work_readback(L762-L792)、completed_result_review_readback(L795-L816)和 interrupted_result_readback(L819-L832)之前高度相似的“读取终态盘点 -> 校验无异常 -> 提取有效项”流程合并为两条正交组合 helper,消除了状态字段漂移风险,同时维持各自特有的未完成项检测与空项回退消息。
  5. CodexAppServerAdapter._send_ordinary_turn 与 failed_request_observation(loopx/capabilities/native_chat/codex_adapter.py L1043-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 个既有公共符号签名、延迟导入(lazy importlib.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).

@loopx-agent
loopx-agent force-pushed the codex/l0-codex-adapter-zero-any-20261122 branch from e3e6bde to 325bef5 Compare November 22, 2026 16:29
@mergify mergify Bot removed the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 22, 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 · 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) 无破坏性变更
  1. 边界类型精确化:引入内部 JsonDict / JsonMap 别名、_WorkingCheckpoint TypedDict、4 个动态加载 Protocol(_BindingsStore、_ApiKeysProvider、_NativeAccountsProvider、_OpenAIRelayProvider)和 TypeGuard 守卫(_is_dict、_is_nonempty_str、_is_int、_is_valid_provider、_is_bare_sha256)。
  2. 内部路径收敛与变基保真:把工作区校验、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 无空洞透传。
  3. 架构评估结论(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 预算路径、延迟导入(lazy importlib)与既有测试 monkeypatch 缝。

具体改动

  • 规范依据(spec_basis: no_spec / spec_source: none):这是一个基于当前主干基线的单文件内部 Any 清零与重复 helper 收敛重构,未对应独立新增设计 RFC 或新线协议,以既有公共参数契约、#9276 超时预算规则和运行期行为等价性作为验收基线(spec_source: none)。

关键代码讲解

  1. validate_native_working_update(loopx/capabilities/native_chat/codex_adapter.py L133-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。
  2. NativeHistoryRestoration(loopx/capabilities/native_chat/codex_adapter.py L186-L406):统一抽离 _read_binding(L203-L208)与 _invalidate(L210-L212),并将 _working_suffix 和 prepare_working_context 收拢;check() 改用 _TURN_CHECK_KEYS 数据驱动组装检查记录,消除手工字段不一致隐患。
  3. compact_native_history 与 CodexAppServerAdapter.start(loopx/capabilities/native_chat/codex_adapter.py L479-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 行为与主干完全一致。
  4. _loopback_relay_transport_ready(loopx/capabilities/native_chat/codex_adapter.py L545-L577):保留原有模块级名称和 importlib.import_module 延迟导入顺序,确保已有测试 monkeypatch 桩与动态 HostError 捕获持续有效,同时借助 _OpenAIRelayProvider / _NativeAccountsProvider Protocol 消除动态属性 Any。
  5. _read_terminal_inventory、_validate_turn_items 与 _read_validated_turn(loopx/capabilities/native_chat/codex_adapter.py L593-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 premerge direct 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 预算路径、延迟导入(lazy importlib)与既有测试 monkeypatch 缝。
  • 总体结论:变基后的 PR 325bef5ae1 已消除此前阻塞合并的冲突(目前 MERGEABLE),同时干净继承了 #9276 的 idle_timeout_sec=None 与可选 check 修复,在不改动公共参数契约的前提下实现 71->0 Any 清零和 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 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] 让新类型覆盖原会话恢复与历史补答的实际调用

新注解让两个现有 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.

@mergify

mergify Bot commented Nov 23, 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 23, 2026
- 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>
@loopx-agent
loopx-agent force-pushed the codex/l0-codex-adapter-zero-any-20261122 branch from 325bef5 to 2ac4aa1 Compare November 27, 2026 20:25
@loopx-agent

Copy link
Copy Markdown
Collaborator Author

Rebased onto origin/main (509360fb0d3e9e6e578ddf5c12db587886016b23) and resolved review 6017057522 at exact HEAD 2ac4aa19c4de0cd09c4cbe77aed79cebc790c531:

  1. NativeHistoryRestoration.controller boundary (codex_adapter.py#L72-L106, #L226, #L427): Replaced ChatRuntimeController on NativeHistoryRestoration.controller with _HistoryController (_HistoryStore, _HistoryProjectContexts, lock, compacting_history, plus optional _ClosedFlag check in check()), eliminating the ChatSessionLifecycleMixin [arg-type] incompatibility at loopx/chat/session_open.py#L984 (29 -> 28).
  2. Historical answer message narrowing (external_conversations.py#L1277) & probe cast cleanup (report_failure_probe.py#L165): Narrowed str(response["message"]) in external_conversations.py#L1277 (39 -> 38, matching PR #9286) and removed the now-redundant cast(ProofObject | None, proof) at report_failure_probe.py#L165 (3 -> 2).
  3. Merged-main L0 preservation (#9321 + 31afb1a8a74 + 55a294175b8): Preserved attachments and reply_documents: bool = False across start_turn, _send_ordinary_turn, start_turn_with_attachments, and native_turn_response, loopx.chat.codex_goal.UPSTREAM_MODE, and CODEX_APP_SERVER_HOST_CAPABILITIES; added test_codex_adapter_start_turn_forwards_reply_documents_and_attachments and test_codex_adapter_zero_any_and_cross_file_caller_mypy_contract in tests/test_chat_codex_history.py.
  4. Cross-file mypy & regression verification @ 2ac4aa19c4de: codex_adapter.py (1,343 LOC vs 1,490 on main, 0 AST Any, 0 # type: ignore, 23 -> 0 strict mypy errors) + 0 new errors across all 10 caller modules; ruff check (4/4), [tool.mypy] (17/17), npm run typecheck:control-plane, conversation_binding.test.ts (70 passed), 4,385 passed across 22 suites (0 failed, 0 skipped, 1 pre-existing teardown warning in test_lark_private_conversations), loopx check (errors=0, warnings=0), CQR cqr_7182488f564cd12272b4 (valid), and canary premerge --tier standard (gate.status="passed", merge_gate_passed=true).

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

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