Skip to content

[PR] fix: keep hosted web_search_call in the same run as its reasoning (#7296) - #7302

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-11-19_fix-7296-hosted-call-ordering
Open

ranxianglei wants to merge 1 commit into
masterfrom
2026-11-19_fix-7296-hosted-call-ordering

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

A follow-up turn after a hosted web search was rejected:

Item 'ws_fixture' of type 'web_search_call' was provided without its required 'reasoning' item: 'rs_fixture'.

The wire order turned from user → reasoning → web_search_call into user → reasoning → <synthetic user separator> → web_search_call.

Root cause

responsesToCore (kernel) flattens every hosted-call item — web_search_call, file_search_call, mcp_call, computer_call/_output, image_generation_call, code_interpreter_call — into a core with contentType: "reasoning" (the raw item rides the rawResponsesItem sidecar). The host-side ordering repair repairResponsesAssistantOrdering classified that core as a second reasoning item, and its run-boundary rule (reasoning after phase > 0 / already-seen reasoning ⇒ insert a user separator) then split the assistant run between the real reasoning and the hosted call. A web_search_call separated from its reasoning is rejected by the Responses server.

Fix

Host-side (no kernel change): a contentType: "reasoning" core whose rawResponsesItem sidecar carries a hosted-call wire type is now classified as tool-call (phase 2) instead of reasoning. The reasoning → hosted call run stays intact; the separator still lands between distinct runs (genuine second reasoning / message-after-tool-call), which the new second test pins.

Classification keys off the sidecar's wire type only — never the core text or id (both are codec-re-derived and client-shapeable).

Tests

  • tests/issue564-responses-ordering.test.ts: two new regression cases — (1) user → reasoning → web_search_call renders as one intact run with zero separators; (2) two distinct runs (run 1 = reasoning + hosted call, run 2 = reasoning + message) still get exactly one separator, placed after the hosted call and before run 2's reasoning.
  • Targeted runs green: issue564-responses-ordering (24), issue2627-turn-sep-coverage, issue5139-turn-separator-ranges, invariant-judge-continuity-owned-separators, fold-round2-shape, codex-responses-ws. Full-suite verdict from CI on the pushed head.

Closes #7296

)

responsesToCore flattens hosted calls (web_search_call, file_search_call, mcp_call, ...) into contentType:"reasoning" cores. The Responses ordering repair classified them as a second reasoning item and inserted a user separator between the real reasoning and the hosted call, splitting the assistant run — the server then rejects the web_search_call "without its required 'reasoning' item".

Classify a flattened hosted-call core (whose rawResponsesItem sidecar carries a hosted-call wire type) as tool-call (phase 2) so the reasoning -> hosted call run stays intact. The separator still lands between distinct runs.

Closes #7296
@ranxianglei ranxianglei added bug Something isn't working codex p2 scope/wiring labels Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-11-19_fix-7296-hosted-call-ordering (2a2a9e9)

Latest build — install this exact version

npm install -g billion-context@0.0.10986-pr.7302.474fc5b

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

Recent builds (commit → version)

commit version build
2a2a9e9 billion-context@0.0.10986-pr.7302.474fc5b build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix: keep hosted web_search_call in the same run as its reasoning (#7296) [PR] fix: keep hosted web_search_call in the same run as its reasoning (#7296) Nov 19, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

查重: 不重复 — no parallel [PR] targets this thread; #7302 is the only PR for #7296.

Reviewed the PR head (2a2a9e92, branch 2026-11-19_fix-7296-hosted-call-ordering) against current master.

Code review

The fix is correct and well-targeted.

  • src/server/responses-ordering.ts: the new isHostedCallCore classifies a contentType: "reasoning" core as a tool-call only when its rawResponsesItem sidecar carries one of the 7 hosted-call wire types. I cross-checked that set against the kernel codec: kernel/src/wire/responses.ts:545-566 (responsesToCore) flattens exactly those 7 types into contentType: "reasoning" cores, and custom_tool_call is not flattened (correctly excluded from the set). coreToResponses (lines 991-993) re-emits the sidecar verbatim for reasoning cores, so the classification key matches what the codec actually produces. Keying off the sidecar wire type only (never core text/id) is the right trust boundary — both are codec-re-derived and client-shapeable.
  • Separator semantics: a hosted call now lands in phase 2 (tool-call), so reasoning → hosted call stays one intact run (zero separators), while a genuine second reasoning or a message-after-tool-call still gets its separator. The new test 2 pins exactly that (two runs → exactly one separator, placed after the hosted call, before run 2's reasoning).
  • Tests have teeth: test 1 directly encodes the reported repro from [Bug]: Codex Responses ordering inserts a user separator before a hosted web search call #7296 (the broken wire order); test 2 guards the adjacent two-run behavior so the fix can't over-suppress. I ran the targeted suite locally: tests/issue564-responses-ordering.test.ts 24/24 green.

One narrow edge case found (repro'd, filed as drive-by #7312):
A hosted call that is the sole survivor of its run (reasoning + text folded away, the call kept) is now kept on the wire with no reasoning in its run → the Responses server rejects the request ("provided without its required 'reasoning' item"). Pre-fix, the lone-reasoning drop rule (src/server/responses-ordering.ts:192) accidentally dropped it (clean wire by luck). Trigger shape: [reasoning, message, hosted-call] with a fold covering [reasoning, message]. The realistic [reasoning, hosted-call, message] shape is protected — a single contiguous fold cannot orphan a middle item. Root cause is kernel-side: computeTurnGroups (kernel/src/turn-integrity.ts) treats a hosted-call core as "orphan reasoning" (no turn group), so the fold-integrity gate never protects it. This host-side PR cannot fix kernel grouping, so it is tracked separately: issue #7312 (bug, p3, scope/kernel) with option A (kernel grouping fix, recommended, human-gated) / B (host-side drop, a mask — not recommended).

CI & base freshness

  • CI is not a clean green: on head 2a2a9e92, 56 check-suites → 23 success, 33 cancelled, 0 failure. The full-suite verdict is not established — CI needs a re-run before merge.
  • The branch is 50 commits behind master, but I verified master made no changes to either PR file, the two kernel files the fix depends on (kernel/src/wire/responses.ts, kernel/src/turn-integrity.ts), or the repair call sites in src/server.ts — a rebase should be a clean no-conflict move.

八问

  1. 是什么问题: 宿主 web 搜索(web_search_call 等 hosted tool)被拒后,下一轮出站 wire 在 reasoning 和 hosted call 之间被插入了合成 user 分隔符,Responses 服务端拒绝整个请求。
  2. 什么原因导致的: kernel responsesToCore 把所有 hosted-call item 压平为 contentType: "reasoning" 的 core(原始 item 挂 rawResponsesItem sidecar);host 侧 repairResponsesAssistantOrdering 把它当成"第二个 reasoning",run 边界规则(reasoning 之后已见 reasoning ⇒ 插 user 分隔符)在真 reasoning 与 hosted call 之间切断了 assistant run。
  3. 影响范围与严重程度: 用 Responses hosted tool(web_search/file_search/mcp_call 等)且会话发生折叠的 codex 类用户;触发后该轮请求被拒,该 fold 解决前会话不可用。PR 标 p2,我同意(有明确触发条件,非全量不可用)。
  4. 怎么修复的: host 侧分类修正——contentType: "reasoning" 的 core 若 sidecar 携带 7 种 hosted-call wire type 之一,按 tool-call(phase 2)分类;reasoning → hosted call 保持同一 run,分隔符仍落在不同 run 之间。分类只信 sidecar wire type,不信 core 文本/id(均 codec 重推导、客户端可塑形)。
  5. 是否有回归问题: 逐项审过既有行为——① 真 reasoning 的分隔符规则: 不变(新测试 2 钉住);② message-after-tool-call 分隔符: 不变;③ lone-reasoning 丢弃规则(line 192): 对真 reasoning 不变,但 hosted call 不再落入该规则(从"意外丢弃"变"保留")——这正是发现的窄回归: [reasoning, message, hosted-call] 形状下 hosted call 成唯一幸存者时被保留 → 孤儿 hosted call 被拒(已复现,kernel 侧根因,已立 [Drive-by] kernel: a partial fold can orphan a hosted web_search_call from its reasoning, and the server then rejects the request #7312);④ Compression breaks Responses assistant history ordering, causing repeated invalid_assistant_history 400s #564/[Bug][Responses] acp_turn_sep 合成分隔符进入持久压缩覆盖集合,导致重复历史漂移误报 #2627 的 producer-owned separator 溯源代码(carrier 对象身份、resolveSeparatorIndexes、reanchor、judge): PR 未触碰;⑤ kernel codec: 未触碰(host 侧 PR)。
  6. 是否破坏缓存: 不涉及——纯 wire 顺序修复,不动缓存键/前缀/重试策略。
  7. 是否改了设计方向: 不涉及——host 侧单文件修复,无 kernel 变更,与既有分类/分隔符机制同向。
  8. 是否引入了新的配置: 不涉及。

结论

代码正确、测试有牙、diff 干净(2 文件 +88/-1,无跑题改动)。可合,前提: ① CI 重跑确认全量绿(当前 33/56 suite 被 cancel,判定未建立);② 窄边缘场景已由 #7312 跟踪(kernel 侧、人工门禁),不阻塞本 PR。分支落后 master 50 个提交但相关文件零 churn,rebase 应为无冲突。

标签: 源 issue 已打 bug / codex / p2 / scope/wiring(与 PR 现有标签一致);#7312 已打 bug / codex / p3 / scope/kernel。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: vllm-qwen/qwen3.8-27b)

Superseded by #7322 — this fix was cherry-picked (commit 2a2a9e9, -x, authorship preserved) into the root-cause aggregation PR #7322 (codex-lane batch, aggregation #7314), rebased onto current master. #7322 is now the delivery vehicle for this fix; this PR is marked superseded and should not be merged on its own.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Supersession acknowledged — verified live:

Carry-over notes for #7322 (my review findings, same code):

  1. CI: on [PR] fix(codex-lane): context-only prewarm probe relay + hosted web_search_call ordering (#4594, #7296) #7322 head 6da9871e232 → 13 success, 16 cancelled, 1 in progress — not yet a definitive green. The "CI re-run before merge" condition from my review now applies to [PR] fix(codex-lane): context-only prewarm probe relay + hosted web_search_call ordering (#4594, #7296) #7322.
  2. Edge case [Drive-by] kernel: a partial fold can orphan a hosted web_search_call from its reasoning, and the server then rejects the request #7312 (orphaned hosted call after a partial fold; kernel-side root cause in computeTurnGroups) remains open and is unaffected by the supersession — it is a kernel change (human-gated) and is not part of [PR] fix(codex-lane): context-only prewarm probe relay + hosted web_search_call ordering (#4594, #7296) #7322's host-side batch. I updated its found-in reference to point at [PR] fix(codex-lane): context-only prewarm probe relay + hosted web_search_call ordering (#4594, #7296) #7322.

No further action on this thread.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Codex Responses ordering inserts a user separator before a hosted web search call

1 participant