feat(runtime): add Codex server-side history compaction - #2993
Conversation
|
整体方向我认可:把 provider-native compaction 建模成带 coverage 的 checkpoint 投影,而不是伪造文本 summary;RuntimeEvents 继续作为事实源,公共生命周期继续负责 coverage、digest、持久化、rolling、replay 和模型切换。这一层抽象比较克制,V2 text / V3 provider-state 的 discriminated union 也比引入 provider registry 或通用 transport framework 更合适。 不过我建议合并前处理或明确以下几点:
从奥卡姆剃刀看,我认为工程问题定义正确,产品问题定义还需要收窄:
因此我建议把初始承诺定义为:Codex 可在能力确认且 native 调用成功时使用 provider-native checkpoint,否则复用现有文本 checkpoint;通过数据再决定是否默认开启。 本地验证:受影响的 387 个测试全部通过,Runtime Host typecheck 通过。整体实现质量不错,主要阻塞点是默认 rollout 和 fallback,而不是 V3 checkpoint 方向本身。 |
|
@likun666661 Thanks for the detailed review. I checked each point against the production path and the Codex reference implementation, and pushed the confirmed fix in English1. Default enablement and fallbackI am keeping provider-native compaction enabled by default for In Maka, The production path has been manually verified with a real Codex OAuth subscription, covering initial compaction, rolling compaction, and tool-bearing history. A native failure follows the existing source-derived fail-open path and cannot persist invalid provider state. Silently switching to a text checkpoint would introduce two continuation semantics behind the same default capability without evidence that such a fallback is needed. vercel/ai#18895 provides typed request support. Once released, it will allow the narrow transport compatibility layer to be removed, but it does not change this capability decision. 2. Test coverageThe missing direct coverage for compaction output extraction was valid. The new tests cover:
I did not add an injectable Existing tests continue to cover V3 checkpoint persistence, rolling coverage, native replay, model/provider switches, text-only replay fallback, overflow recovery, telemetry redaction, and settled hosted-tool pairing. 3. Request semantics and input capacityThe compaction request being able to exceed its own context window through a large Tool Result was a real issue and is fixed. The common compactor input now carries the active
The system prompt and tool catalog difference is intentional and is now documented in both architecture documents. Maka’s checkpoint contract covers history only: current instructions and tools are not frozen into checkpoint state, and the subsequent inference request always supplies their current versions. The existing text summarizer does not yet consume the new input budget. That behavior predates this PR and is not required for the Codex integration, so it is tracked separately in #3013 instead of expanding this PR. Verification
The remaining red CI check is the unrelated 中文感谢详细 review。我逐项对照了生产路径和 Codex 参考实现,并在 1. 默认启用与 fallback我会继续对 在 Maka 中, 生产路径已经使用真实 Codex OAuth 订阅完成手动验证,覆盖首次压缩、rolling compaction 和包含工具历史的压缩。native 调用失败时会进入现有的 source-derived fail-open 路径,无法持久化无效 provider state。在没有实际不支持证据的情况下静默切换到 text checkpoint,会让同一个默认能力背后出现两套 continuation 语义。 vercel/ai#18895 提供的是类型化请求支持。其发布后可以删除当前范围很窄的 transport 兼容层,但不会改变这里的 capability decision。 2. 测试覆盖缺少 compaction output 提取的直接覆盖是有效意见。新增测试覆盖了:
我没有增加 现有测试继续覆盖 V3 checkpoint 持久化、rolling coverage、native replay、模型/provider 切换、text-only replay fallback、overflow recovery、telemetry redaction,以及已结算 hosted-tool 的严格配对。 3. 请求语义与输入容量超大 Tool Result 可能让 compaction request 自身再次超出 context window,这是一个真实问题,现已修复。 公共 compactor input 现在会携带当前
system prompt 和 tool catalog 的差异是有意设计,并已补充到中英文架构文档。Maka 的 checkpoint contract 只覆盖历史;当前 instructions 和 tools 不会被冻结进 checkpoint,后续 inference request 始终使用它们当时最新的版本。 现有 text summarizer 尚未消费新增的 input budget。这是本 PR 之前就存在的行为,也不是 Codex 集成的必要范围,因此已单独记录为 #3013,不在本 PR 中扩大修改范围。 验证
目前剩余的 CI 红灯是 #2978 已记录的 |
Use provider-native opaque checkpoints for Codex subscription models by default while retaining text checkpoints for other providers. Keep trigger injection scoped to the dedicated compactor transport and preserve checkpoint identity across replay, model switches, and rolling compaction. The provider boundary lowers settled hosted tools into paired wire items and redacts only the exact compaction payload, avoiding dangling outputs and collateral telemetry mutation.
Pass the active history budget through the generic compactor contract and keep provider-native requests within it by omitting oversized historical tool payloads without breaking call/result pairs. Fail open before dispatch when the remaining projection cannot fit.
The upgraded OpenAI provider exposes compactionTrigger as a request-scoped option, so the dedicated fetch mutation layer is no longer needed.\n\nSet the option only in the Codex history compactor and retain wire-contract coverage that ordinary requests remain unchanged.
8eea9a9 to
5be99f3
Compare
|
I have manually reviewed the final implementation and its validation results. I am satisfied that this change is ready, take responsibility for the decision and its outcome, and have decided to merge this pull request. This work was completed with assistance from OpenAI Codex. I reviewed and approved the resulting changes; final responsibility remains mine. |
…recompression fixture The rebase onto apache#2993 brought a fixture that returns free-form text, which the validation this PR adds rejects by design. Same treatment as the other compaction fixtures: return the structured VALID_SUMMARY. Generated-by: Claude Code
…recompression fixture The rebase onto apache#2993 brought a fixture that returns free-form text, which the validation this PR adds rejects by design. Same treatment as the other compaction fixtures: return the structured VALID_SUMMARY. Generated-by: Claude Code
…recompression fixture The rebase onto apache#2993 brought a fixture that returns free-form text, which the validation this PR adds rejects by design. Same treatment as the other compaction fixtures: return the structured VALID_SUMMARY. Generated-by: Claude Code
…recompression fixture The rebase onto apache#2993 brought a fixture that returns free-form text, which the validation this PR adds rejects by design. Same treatment as the other compaction fixtures: return the structured VALID_SUMMARY. Generated-by: Claude Code
…recompression fixture The rebase onto apache#2993 brought a fixture that returns free-form text, which the validation this PR adds rejects by design. Same treatment as the other compaction fixtures: return the structured VALID_SUMMARY. Generated-by: Claude Code
English
Summary
Add provider-native server-side history compaction for OpenAI Codex subscription models and enable it by default for those models.
The implementation keeps the existing text-summary checkpoint for portable compaction and adds a distinct opaque provider-state checkpoint for Codex. The runtime owns the common checkpoint lifecycle—coverage, persistence, replay, rolling replacement, overflow recovery, and model-switch compatibility—while the Codex-specific compactor owns only the provider protocol and request options.
Key behavior:
providerOptions.openai.compactionTriggeronly on the dedicated compactor request, leaving ordinary model requests unchanged;store: falsenever produces dangling outputs;The abstraction is intentionally narrow: one discriminated checkpoint representation and one compactor contract, without introducing a provider registry or a generic transport framework before another integration requires one.
Upstream context
This work exposed a missing typed capability in the Vercel AI SDK. M4n5ter reported vercel/ai#18894, which directly prompted vercel/ai#18895. The upstream change has since been merged and released; Maka now uses the released
providerOptions.openai.compactionTriggersupport directly, with no compatibility transport layer.Verification
npm ci, including dependency patch application;npm run format:check;npm run build;npm run typecheck;npm test— 6,671 tests: 6,645 passed, 0 failed, 26 skipped;git diff --check;gpt-5.6-luna: initial compaction, rolling compaction from the previous opaque state, and ordinary provider-state replay all succeeded. The two compaction requests each carried exactly one terminal trigger; the replay request carried no trigger and recovered both facts from the compacted history.Checklist
AI disclosure
This change was completed with assistance from Codex. I have reviewed it and accept responsibility for the result.
中文
概要
为 OpenAI Codex 订阅模型接入 provider 原生的服务端历史压缩能力,并对这类模型默认启用。
实现保留现有可移植的文本摘要 checkpoint,同时为 Codex 增加独立的 opaque provider-state checkpoint。Runtime 负责公共生命周期,包括覆盖范围、持久化、回放、滚动替换、超窗恢复和模型切换兼容性;Codex 专用 compactor 仅负责 provider 协议和请求选项。
主要行为:
providerOptions.openai.compactionTrigger,普通模型请求不受影响;store: false产生 dangling output;抽象有意保持克制:当前只有一个可辨识联合 checkpoint 表示和一个 compactor contract;在出现第二个明确集成需求前,不引入 provider registry 或通用 transport framework。
上游背景
本次工作暴露了 Vercel AI SDK 缺少类型化显式压缩触发能力。M4n5ter 提交了 vercel/ai#18894,并直接促成了 vercel/ai#18895。该上游变更现已合并并发布;Maka 直接使用正式发布的
providerOptions.openai.compactionTrigger,不再保留兼容 transport 层。验证
npm ci,dependency patch 正常应用;npm run format:check;npm run build;npm run typecheck;npm test:共 6,671 项,6,645 passed、0 failed、26 skipped;git diff --check;gpt-5.6-luna和真实 Codex OAuth 订阅验证:首次压缩、基于旧 opaque state 的滚动压缩,以及普通 provider-state 回放均成功。两次压缩请求都只携带一个位于末尾的 trigger;回放请求不携带 trigger,并准确恢复了压缩历史中的两个事实。检查清单
AI 披露
本变更由 Codex 辅助完成。我已完成审核,并对最终结果负责。