Skip to content

fix(chat): restore migration history once in Codex threads - #6872

Merged
loopx-agent merged 1 commit into
mainfrom
codex/steward-context-window-20261019
Oct 19, 2026
Merged

loopx-agent merged 1 commit into
mainfrom
codex/steward-context-window-20261019

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

After a Codex model/context migration, LoopX embedded the entire visible conversation in the stable objective. Every later request reattached that transcript, growing native context until requests could fail before executing tools.

Restore the complete ordered user/assistant history once through Codex's native thread/inject_items, before Core publishes the replacement binding. Subsequent inputs contain the stable objective and current evidence. Restart/resume uses native persisted history, including a restart before the first request. Injection errors close the new adapter without replay, and unsupported hosts fail instead of silently losing early constraints.

This stays in the existing Python Codex transport. It also removes the unused shared transcript serializer. Core admission, scope, failed-request records and other providers retain their existing owners. No automatic retry or context truncation is added.

Validation:

  • 413 focused Chat, migration, model-adoption and project-scope tests passed; new regressions cover a large transcript, roles/spacing, resumed threads, higher-priority role rejection and ambiguous injection errors.
  • Real Codex 0.162.0-alpha.17.2 against a local synthetic Responses endpoint: restore, close before the first request, resume, then two requests. Each native input retained the original user/assistant messages exactly once; new prompts excluded the migrated transcript. No external model calls.
  • Ruff and mypy passed. Selected premerge validation passed all 6 direct checks and 14 selected checks, including maintainability, semantic vocabulary and repository boundary checks. CLI output-budget smoke and repository scan passed.
  • Full pytest stopped at an unchanged digest-ownership architecture failure: 1 failed, 1068 passed, 498 skipped, 1903 subtests. The same single architecture test reproduces the identical offending file/line/pattern map on immutable base 3a81641 and this head. The changed invariant also passed 130 adjacent native lifecycle, steering and activity tests (543 relevant tests in total).
  • Same real Codex/controller workload at base and head additionally reproduces the old repeated-input and pre-first-Turn restart-loss defects; the head preserves original roles/text once across all three requests.

This repairs future context transfer. Recovery and final replies for already failed live requests still require their original execution/return evidence. Codex hosts must support the documented native history injection RPC.

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.1-sol | OpenAI | runtime_reported | reasoning_effort=max | author self-review

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

动机

管家或项目助手切换模型、刷新上下文后,继续在原对话提问的用户。

旧版每次继续提问都会再次附上旧聊天记录,首次请求前重启还会丢失迁移历史;新版先持久保存一份历史,后续提问和重启继续使用该历史。

同一真实 Codex 本地合成工作负载下,连续两次提问与首次请求前重启均保留原消息各一份,新输入不再重复附带迁移记录。

本 PR 不重放已经失败的请求,不宣称线上消息已恢复,也不更改权限、配额或其他模型提供方。

代码交付还需合并与安装;既有失败请求仍需沿原消息取得真实业务结果。这里评审的是完整迁移历史的传输修复,不能从测试通过推断整个 Bot 交付已经完成。

改动思路

一次原生持久化同时解决重复输入和重启丢失;纯内存标记或截断都不能保留这两个约束。

仅修复 Codex 迁移历史传输,沿用 Core 准入、绑定和失败处理;部署及原业务答复由原维护任务继续。

Core 继续决定何时需要更换上游线程,并提供完整可见历史;已有 Codex 适配器负责转换为原生消息,成功持久化后才返回给 Core 更新绑定。这是现有 Python 提供方的传输职责,不新增共享控制面、状态库或配置开关。删除共享 objective 中已无调用需要的历史渲染,也避免保留两个不同的历史恢复规则。相关 #6860 的 Inbox 读取合并和 #6864 的来源授权收敛仍由各自所有者负责,不能代替原生会话历史恢复。

同一受控工作负载 改动前 当前 head
迁移后连续两次请求 新输入两次附带整段历史 原消息各一份,新输入不附带历史
首次请求前重启 原生记录中缺少迁移消息 恢复同一原生线程,原消息各一份
注入结果未知 无持久化注入流程 关闭新适配器,保持原绑定,不重试注入

表格描述已执行的原生协议比较。模型输出来自本地合成端点,验证的是消息、角色、顺序与持久化,未验证真实模型对历史的理解质量。

具体改动

评审 head:7b26c6d264d1c1455c26fbb1d3893d6277ec8661。依据改动前的 docs/reference/protocols/manager-evidence-and-continuity-v0.md,spec_revision 为 3a816411785fea545c379769a1ff98f5e881bd5d,不是用本 PR 新增的解释段落反向定义要求。

  • Ownership and defaults:已实现。逻辑 Session 与可替换执行线程分开;历史写入完成后才发布替换绑定。模型切换与失败保留测试覆盖该边界。
  • Global conversation initialization:已实现。当前 Core 证据仍逐次提供,旧对话不作为当前工作状态的 authority;稳定指导和历史传输分开。
  • Requests, authority, and recovery:已实现。原权限和失败记录保持;不因历史迁移自动重放失败请求。RPC 拒绝、超时和非法角色分别有回归。

关键代码讲解

  • ChatRuntimeController._session_objective 保留 manager/project 的稳定指导,删除整段历史的字符串渲染。没有缩短原有权限、停止或恢复指令;历史内容通过另一条已有提供方边界完整交付。
  • ChatRuntimeController._start_adapter 在 Codex 分支传入已有 history 参数。原模型迁移和项目上下文刷新继续决定是否新建线程;普通 resume 与其他提供方的职责不变。两项既有迁移测试改为检查原文是否完整进入历史参数,而非再次进入 objective。
  • CodexAppServerAdapter.start 校验 user/assistant 角色,保留原文和空白,将非空消息一次写入新线程。恢复已有线程时不注入;未知错误沿既有关闭路径返回,不转为新的模型请求。新增测试用较大历史检查早期约束与完整顺序,并检查两个错误分支及高优先级角色拒绝。

对主干的风险

主要风险是宿主兼容性:不支持 thread/inject_items 的 Codex 不能完成新线程迁移,需要升级。这里选择明确失败并保留原绑定,避免静默丢掉约束或用 fallback 重新执行用户请求。没有加入系统角色、沙箱变更、第二消费者、配额状态或新工作流;普通恢复仍沿既有原生线程继续。回滚只需撤销本次传输改动,Core 的原消息与失败记录不需要重写。

验证包含 413 项相关测试、130 项邻接生命周期/steering/activity 测试,Ruff、mypy、CLI 输出预算、仓库扫描及 exact-head premerge 均通过。实际 Codex 0.162.0-alpha.17.2 的比较使用相同合成输入与同一脚本;早期消息包含换行和空白,消息内容没有被归一化。原生启动、落盘与恢复是真实实现;模型回答为合成,因此不把本地比较当作线上模型质量或部署验收。

语义与 CI 对齐

复用既有原生 message/role 词汇;没有新共享生命周期或权限语义。默认行为从重复附带历史改为一次原生持久化,已经在协议文档及回归中明确。当前 Goal 规定使用本地证据,未读取或等待 GitHub CI。

全量 pytest 并未通过:停止时为 1 failed、1068 passed、498 skipped、1903 subtests。失败是 test_only_the_owner_module_states_a_whole_value_digest_shape,涉及未改动的 goal_source.py 与 checkpoint_retention.py。相同单测在不可变基线和当前 head 均复现相同文件、行号及摘要形状;本次传输改动不在其因果路径。保留这一主干问题,既不放宽断言,也不将 skip 或未运行项记为通过。此归因允许独立评价本 PR,合并资格仍需单独核验。

我的整体评价

结论为当前 head 的 APPROVE,属于有明确剩余部署边界的有效增量。long_horizon 与 user_experience 均改善:后续请求不再反复扩大历史输入,重启也保留原约束;正常路径没有新增导航、复制或确认轮次。改动落在现有提供方,删除多余渲染,未用新配置或第二套状态增加维护成本。未知结果不重放、宿主兼容性和线上质量的限制仍明确保留。

这是作者的模型自审,不是独立人工批准,也不等于 GitHub 正式 approval 或合并授权。当前实际原会话恢复与最终答复仍由原维护任务验收。

English verdict: APPROVE. Head 7b26c6d restores complete visible history once through the existing native transport, preserves restart continuity, and avoids unknown-effect replay. Native base/head counterfactuals and 543 focused/adjacent tests cover the changed invariant. The identical pre-existing digest-ownership failure is retained separately; merge readiness and live deployment remain distinct.

@loopx-agent
loopx-agent merged commit 2d94432 into main Oct 19, 2026
13 of 35 checks passed
@loopx-agent
loopx-agent deleted the codex/steward-context-window-20261019 branch October 19, 2026 10:38
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