Skip to content

fix: mirror the codex CLI wire shape in preflight summary calls for codex clients (#2733) - #2735

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-11_preflight-codex-shape
Oct 12, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-11_preflight-codex-shape

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What & why

Part of #2733 (issue stays open — the D1 nudge-suppression facet awaits owner sign-off and the codex-side window-divergence facet awaits the reporter's codex --version/config).

Root cause (proven from the issue log + upstream sources): new-api / anyrouter-family codex relays validate inbound /v1/responses calls as legitimate Codex requests — input must be typed message items AND carry include:["reasoning.encrypted_content"] (the real codex CLI's signature, sent unconditionally by codex-rs/core/src/client.rs); anything else is HTTP 400 invalid_responses_request. bili's main path forwards real codex bytes verbatim so it is unaffected — but bili's own side-channel preflight summary call built a minimal payload (input:[{role:"user",content}], no include) and was rejected 100% on such relays (12/12 in the issue log, session 01a1250d). The preflight lane was therefore dead there, and codex's local auto-compaction won every race it entered.

Evidence: sylearn/AIUsage documents the exact validator behavior + minimal accepted body; caidaoli/ccLoad tests use the identical error body for the anyrouter codex channel; the issue log shows the exact 400 body {"error":{"message":"invalid codex request (request id: …)","type":"new_api_error","code":"invalid_responses_request"}} on every summary attempt (stream AND non-stream).

Change

src/preflight.ts — summaryPayload() gains an optional codexClient flag; when true, the Responses-protocol summary payload mirrors the real CLI shape:

- input: [{ role: "user", content }]
+ input: [{ type: "message", role: "user", content: [{ type: "input_text", text: content }] }]
+ include: ["reasoning.encrypted_content"]

Detection reuses isCodexClient(deps.headers) (same UA predicate as prepare-responses / overflow-target logic) at the single call site in requestSummary(). The operator-configured external-summary lane (src/external-summary-http.ts) intentionally keeps the legacy shape — that endpoint is an explicit operator choice.

Behavior change disclosure (old → new)

For codex clients only, bili's internal summarization call now sends typed input items + the include signature instead of the minimal item. Non-codex clients and all other protocols are byte-identical. No config surface, persistence, or main-path wire change. Rationale: without this, preflight compression is silently unusable behind strict codex relays and codex native compaction takes over (lower fidelity, full cache bust).

Verification

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-11_preflight-codex-shape (6c63047)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2979-pr.2735.bb97d0e

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr2735.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 已按 [PR] 流程完成核验(不重做):拉取分支 2026-10-11_preflight-codex-shape(单 commit 6c630478b,基于当前 master aad0fee20,无落后),逐行读了 diff,本地跑了定向验证。

核验证据

结构化八问

  1. 是什么问题:严格校验型 codex 中转(new-api/anyrouter 族)把 bili 旁路摘要请求当作非法 Codex 请求 100% 拒绝,preflight 压缩通道整体失效,codex 本地 auto-compaction 接管竞态。
  2. 什么原因导致的:摘要 payload 构造处用了最小 Responses 形态({role,content}、无 typed items、无 include 签名),而该族中转按真实 codex CLI 线形(typed message items + include:["reasoning.encrypted_content"])校验;主路径字节级转发客户端原始请求所以不受影响——缺陷只存在于 bili 自产的旁路调用这一层。
  3. 影响范围与严重程度:仅上游为严格校验型 codex 中转且启用 ACP 压缩的用户;严重度较高(preflight 完全不可用,只能靠 codex 本地 compact 兜底:保真度低 + 全量缓存失效)。直连 OpenAI 及其他协议零行为变化。
  4. 怎么修复的:在源头(payload 构造点)对 codex 客户端发真实 CLI 线形;codex 身份复用既有 isCodexClient UA 谓词(prepare-responses/overflow 同一判定),单调用点传入;operator 配置的 external-summary 通道显式保持旧形态。是修产生缺陷的构造逻辑,不是下游过滤/重试打补丁。
  5. 是否有回归问题:逐项审过——非 codex responses 客户端 byte-identical(test 2 钉住,且 revert-and-run 证明修复前就已如此);anthropic/openai/google 三个分支在改动代码之前提前返回,未触碰;external-summary 调用点不传新 flag,形态不变;主路径 wire、会话持久化、配置面均无变化(config-surface-guard/kernel-guard CI 绿)。高危模式逐项过:无 fail-fast 变吞错、无阈值/时序漂移;唯一输出格式变化即已披露的 codex-only 摘要形状。一处描述不准确需更正:PR 正文称真客户端 e2e「CI will run it」——但 .github/workflows/ci-e2e.yml(及 codex-persona)的 paths 触发列表不含 src/preflight.ts,本 PR 只动 preflight.ts + 非 e2e 测试,CI 不会自动跑 e2e-codex。reference/testing.md 记载的触发清单与工作流一致(都漏了 preflight),而 AGENTS.md §3 明确把 "preflight/compact paths" 列为请求管线热文件——这是仓库级 CI 覆盖缺口,不是本 PR 引入的。处置建议二选一,等你拍板:①合并前对本 PR 手动 dispatch 一次 ci-e2e(needs secrets,hosted runner 可跑);②follow-up 把 preflight/compact 相关文件补进 e2e 触发列表并同步 testing.md(涉及触发面扩大与 runner 成本,属你的决定,我未擅自动 workflow;按 loop guard 此发现记录在本线程,不另行立项)。
  6. 是否破坏缓存:不。只改旁路摘要请求形状,主路径字节与缓存键不变;修复后 preflight 恢复反而减少 codex 原生 compact 的全量缓存失效。
  7. 是否改了设计方向:否。
  8. 是否引入新的配置:否。

行为变更披露复核(与 PR 一致,确认成立):仅 codex 客户端的 bili 内部摘要请求从 {input:[{role:"user",content}]} 变为 {input:[{type:"message",role:"user",content:[{type:"input_text",text}]}], include:["reasoning.encrypted_content"]};原因:旧形状在该族中转被 100% 拒绝,preflight 静默死亡。直连 OpenAI 上该新形状即真实 CLI 所发,兼容性有依据。

收工判定:代码与测试质量达标,方向正确(修根因、单 facet、不越界到 #2733 其余两个待决 facet);等最后一个 windows-22 CI job 转绿即可合并,合并前建议顺手解决第 5 问的 e2e 覆盖缺口(手动 dispatch 或 follow-up)。合并动作本身留给人工:#2735

@ranxianglei
ranxianglei merged commit 5cf0717 into master Oct 12, 2026
15 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.321-master.5cf0717 (rolling master tag).

npm install -g billion-context@0.0.321-master.5cf0717  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

@ranxianglei
ranxianglei deleted the 2026-10-11_preflight-codex-shape branch October 15, 2026 05:33
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