Repository navigation
Conversation
|
All contributors have signed the CLA. ✅ |
I have read the CLA Document and I hereby sign the CLA |
|
I have read the CLA Document and I hereby sign the CLA |
…_call ChatGPT's Codex endpoint now fails the stream with "response protection is unavailable" when input replays a hosted web_search_call item but the request declares no web_search tool. Codex compaction (local compact with tools:[] and remote compaction v2 with compaction_trigger) hits this after any web search in the session, so the session keeps reconnecting. Ported from Wei-Shaw/sub2api#7939 (IrisRainbowNeko, still open upstream): for OAuth accounts on /responses (transform, passthrough and WebSocket), inject {"type":"web_search"} at top level, or into input additional_tools for Responses Lite (kept ahead of a trailing compaction_trigger), and pin tool_choice to "none" when the caller offered no tools. /responses/compact and API key accounts are untouched. Fork adjustments: - passthrough call site adapted to the fork's Copilot SDK guard - injected tool omits external_web_access, which this fork already strips from native Codex requests as an unknown parameter (c034d73) - errcheck fixes for golangci-lint v2.13 Co-Authored-By: IrisRainbowNeko <rainbow-neko@outlook.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_call
ChatGPT Codex upstream now rejects requests whose input replays hosted
web_search_call items without declaring a web_search tool, failing the
stream with "response protection is unavailable". Codex local compaction
sends the full history with tools: [], so any session that used web
search can no longer compact and gets stuck reconnecting.
For OpenAI OAuth requests (Codex transform, HTTP passthrough and WS),
when input contains web_search_call and no web_search* tool is declared,
inject {"type":"web_search","external_web_access":false} (into
additional_tools for Responses Lite, before compaction_trigger) and pin
tool_choice to "none" when the caller had no tools. The /responses/compact
endpoint and API key accounts are untouched.
Ported from Wei-Shaw#7939 (fixes Wei-Shaw#7927).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…_call ChatGPT's Codex endpoint now rejects requests whose input replays a hosted web_search_call item unless tools declares web_search, failing the stream with "response protection is unavailable". Codex local context compaction sends the full history with tools:[], so every compaction after a web search fails and the session gets stuck in a reconnect loop. For OAuth transform, passthrough and WebSocket paths, append a cached-only web_search tool when the history contains web_search_call and no web_search tool is declared. When the caller offered no tools, pin tool_choice to "none" so the injected tool cannot be invoked. The /responses/compact wire shape is left untouched. Fixes Wei-Shaw#7927
Responses Lite rejects hosted tools at the top level ("responses Lite does
not support top-level tool type web_search"), so Lite requests now carry the
injected web_search tool in an input additional_tools item: extend the
caller's first additional_tools item, or insert one before a trailing
compaction_trigger so the v2 compaction wire keeps the trigger last.
The HTTP passthrough path also runs the shared compatibility normalizer on
/responses/compact; thread the compact flag through so that endpoint is
left untouched, and drop the now-redundant call from the passthrough OAuth
body normalizer.
97e4857 to
85e3110
Compare
问题
OpenAI OAuth 账号下,Codex 在使用过网页搜索的会话里触发上下文压缩时,流会以如下错误中断,Codex 反复重连后放弃,整个会话卡死:
{"type":"response.failed","error":{"type":"internal_error","code":"upstream_error","message":"response protection is unavailable"}}日志表现为
openai.forward_failed ... upstream response failed: response protection is unavailable,客户端为stream disconnected before completion: response protection is unavailable。根因
ChatGPT Codex 上游(约 2026-10-06 起)对 input 中回放了 hosted
web_search_call历史项、但请求未声明web_search工具 的请求直接返回上述错误。Codex 对自定义 provider 使用本地压缩(
codex-rs/core/src/compact.rs中Prompt { ..Default::default() }),压缩请求携带完整历史但tools: [];而普通轮次会带{"type":"web_search"}。因此普通请求正常,只要历史里有搜索记录,之后的每一次压缩都会失败——与 #7927 中“压缩就报错”“去掉 web_search_call 就成功”的对照结论一致。tools为空的 remote compaction v2(compaction_trigger)请求同样会失败。通过本地日志代理抓取 Codex(0.159.0-alpha)真实请求,并经网关打到真实上游的复现:
web_search_calltools含web_searchresponse.completedtools: []response protection is unavailable[web_search]+tool_choice:"none"response.completed[function]response protection is unavailableweb_search[function, web_search]response.completedcompaction_trigger),tools: []response protection is unavailable[web_search]+noneresponse.completed,输出compaction项web_search,本 PR 不改动)response.completed,输出compaction项response protection is unavailabletools:[web_search]responses Lite does not support top-level tool type "web_search"additional_tools置于 trigger 之前)input[].additional_toolsresponse.completed,输出compaction项web_search_call的 id 换成伪造值或去掉 id 结果不变,说明触发条件是“历史有搜索项而请求未声明搜索工具”,与具体 id 无关。上表中“本 PR 改写”的请求体均由本 PR 代码实际生成后发往真实上游。改动
新增
ensureOpenAIOAuthWebSearchToolForHistory(map 版,用于 Codex OAuth transform)/...Body(gjson/sjson 版,用于透传与 WS,避免全量解码),接入 OAuth 链路:applyCodexOAuthTransformWithOptions,在 input 过滤之后执行;新增ResponsesLite选项,由Forward传入)normalizeOpenAIResponsesWebSocketCompatibilityBody(抽出normalizeOpenAIResponsesCompatibilityBodyWithOptions,透传调用点传入Compact,原函数签名与行为不变)规则:
type=web_search_call项,且tools与input[].additional_tools均未声明web_search*时生效;tools追加{"type":"web_search","external_web_access":false}(仅缓存搜索);additional_tools项;没有时插入{"type":"additional_tools","role":"developer","tools":[...]},若末尾是compaction_trigger则插在它之前,保证 v2 压缩的 trigger 仍为最后一项;additional_tools均为空),且tool_choice缺省 /auto/none,则固定为"none",保证注入的工具不会被调用、请求维持“无工具”语义;调用方本身带了工具时不改tool_choice;/responses/compact端点(transform 与透传)与 API Key 账号不受影响。验证
tools缺省 / null / 已声明 /web_search_preview/additional_tools已声明 / 字符串 input 等边界;Lite 下插入位置(trigger 之前、无 trigger 时末尾)、扩展已有additional_tools、空additional_tools、不污染顶层tools;map 版与 body 版输出一致;注入工具对象不共享。httpUpstreamRecorder):transform / passthrough × 标准 / Lite 四种组合,断言发往chatgpt.com/backend-api/codex/responses的请求体声明了web_search(Lite 在additional_tools)、tool_choice=none、compaction_trigger仍为最后一项;回退接线后测试失败。go test -tags=unit ./...(go1.27.0)全部通过;go build ./...、go vet、gofmt、git diff --check通过。Fixes #7927