Skip to content

fix(chat): compact restored native history before the first question - #8167

Merged
loopx-agent merged 1 commit into
mainfrom
codex/native-history-compaction-20261106
Nov 6, 2026
Merged

loopx-agent merged 1 commit into
mainfrom
codex/native-history-compaction-20261106

Conversation

@loopx-agent

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

Copy link
Copy Markdown
Collaborator

Large restored Chat transcripts could exceed the native model window on the first question, before automatic compaction had a usage observation. Restore bounded UTF-8 history prefixes and wait for the exact native compaction item and successful terminal Turn before injecting the next prefix. Keep Core’s full transcript, original roles, provenance and existing retry budgets.

The native provider owns restoration and compaction. Slow preparation checks the original source grant, configuration and Goal guard; queued Stop and idle Close can interrupt that preparation. All prefixes share the configured hard time budget. Small restores, resumed threads, attached hosts and native Goal execution keep their existing path. No additional consumer, queue, feature flag or context-version bump.

Validation: 704 focused lifecycle, native-agent, history, model-adoption, background-stop and HTTP tests passed. Real Codex 0.166.0-alpha.5.1 against an isolated local synthetic Responses service restored 500 × 1,000-character messages and answered within the fixture’s finite input window; the immutable prior implementation failed before answering. This is protocol acceptance, not evidence of real-model summary quality, latency or monetary savings. Public-boundary, bilingual RFC, syntax and semantic-vocabulary checks are included in the local premerge run.

The final local premerge gate passes without changing module ceilings or quality exceptions. Its global maintainability diagnostic still identifies the unchanged _admitted_interaction_next_cli_actions debt (62 decision points, limit 60), independently reproduced on clean target main; the gate treats this inherited finding as advisory. Normal installation and live real-model acceptance are separate subsequent steps.

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; OpenAI; self_reported (runtime observation unavailable).

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

动机 / Motivation

使用已有长聊天的管家和 Chat 用户。旧路径把全部历史注入新线程,首个问题可能在自动压缩前就超限;新路径先分批恢复并等待原生压缩完成,再启动该问题。本地真实 Codex 协议实验中,同样的长历史由首次请求失败变为成功回答,原始 Core 正文和角色没有被删改。不新增消费者、恢复重试预算、上下文版本、业务授权或常规润色调用。实际安装采用、真实模型摘要质量与费用,以及所有历史欠答的业务闭环,仍须分别验收。

改动思路 / Approach

历史模型 IO 和临时恢复检查集中在既有 native_chat provider,Core 继续独占原会话、排队 Turn 与停止状态;因此无需第二套恢复队列。当前 PR 交付首次长历史恢复这一可独立回滚的切片,不扩大原请求重放或业务执行范围。“原生压缩”是 Codex app-server 自有的上下文整理过程,并不是 LoopX 新建的摘要模型。先前一次性注入的历史尚无 usage 观察,单靠自动阈值不能保护首个超限请求;本次沿现有入口分批注入,每批之间等待真正完成,随后才发布会话绑定。小历史、已有原生线程、attached 宿主和原生 Goal 执行保留原路径。

具体改动 / Changes

验收依据为改动前的 docs/architecture/rfcs/app-conversation-and-async-inbox-v0.md,固定版本 7bdae359e66c007eddbf7672578016298c8ac8e4。该节未编号,以下为本评审的描述标签:native-history-once 对应完整正文、角色和旧身份保留;original-source-recovery 对应原来源、授权和无未知效果重放;native-goal-isolation 对应原生 Goal/attached 隔离。前三项均由本次对应路径及回归覆盖,未拿修改后的 RFC 反向定义验收。

关键代码讲解

  1. _history_batches 对导入正文设输入预算,单条长文本按 UTF-8 边界拆分,完整 Core 正文不变。
  2. compact_native_history 匹配确切原生 Turn、contextCompaction item 和成功终态。ACK、外来 Turn、未知工具、缺失 item、失败或中断均不能放行下一批。
  3. NativeHistoryRestoration 复用既有迁移条件并持续核对原会话、来源 grant、设置和 Goal guard;所有批次共用配置的硬时限。
  4. _ensure_adapter_locked 在检查成功后才发布新原生身份,失败关闭未发布的 adapter。interrupt_turn 仅在长历史准备期间提前 CAS 排队停止;空闲 Close 同样让关闭先可见,普通停止、准备中接收和完成竞争沿原逻辑处理。

对主干的风险 / Risks

未发现阻断性代码问题。最强反例是压缩仍在运行却把 ACK 当完成,或者长准备锁挡住停止,再或提前停止破坏原来的持久接收。704 项最终源码测试覆盖这些路径以及配置变化、撤权、重启、UTF-8、未知结果和累计时限;原有断言和质量上限未被放宽。

同一真实 Codex 版本配本地模拟 Responses 服务,旧实现的长历史首请求失败,新实现完成五次窗口内模型请求后回答,最大输入 333,475 字节。这证明协议和边界,不证明真实模型摘要保真、价格或延迟。最终 native premerge 为 PASS;未改动主分支的 62/60 决策点告警在独立副本复现,门禁保留为 advisory,未增加例外或降低上限。

语义与 CI 对齐

复用现有 Core/native 状态与原来源权限,没有新共享协议或业务授权。差异扫描未发现新闭集词汇,双语 RFC、编译、公开边界及合并前本地检查通过。当前策略不查询或等待远端 CI,未据此声称远端检查通过。

我的整体评价 / Verdict

这是合理的独立增量:长程上改善首次恢复后的继续执行,并保留完整正文、原失败和重试边界;用户路径无需重发信息或新增确认,Stop/Close/撤权可中断长准备。本次只有原生 provider 和运行时生命周期变化,没有新增页面、卡片或排版;检查了原有 Chat/Lark 入口及 Stop/Close 调用路径。未验证范围:真实模型摘要质量和本机安装后的自然会话采用不由协议测试证明。历史模型 IO 和临时恢复检查集中在既有 native_chat provider,Core 继续独占原会话、排队 Turn 与停止状态;因此无需第二套恢复队列。当前 PR 交付首次长历史恢复这一可独立回滚的切片,不扩大原请求重放或业务执行范围。原管家已有答案的实际送达和这份修复的安装采用仍分开验收,不能由通过测试或合并推定全部历史欠答已清。

English verdict: APPROVE this bounded provider/lifecycle repair; retain real-model and deployment acceptance as separate follow-up.

@loopx-agent
loopx-agent merged commit d648c70 into main Nov 6, 2026
20 of 26 checks passed
@loopx-agent
loopx-agent deleted the codex/native-history-compaction-20261106 branch November 6, 2026 04:57
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