sub2api icon indicating copy to clipboard operation
sub2api copied to clipboard

OpenAI WS http_bridge 把 Codex 预热(generate=false)当成空 input 请求转给上游 / http_bridge forwards Codex WS prewarm upstream as an empty-input request

Open Sterbennicht opened this issue 2 months ago • 1 comments

问题 / Problem

在 OpenAI WebSocket http_bridge 模式下,Codex 每个新 WS 会话的预热请求(response.create + generate: false + input: [])会被原样转发给上游 HTTP /v1/responses,上游必然拒绝。

With the OpenAI WebSocket http_bridge ingress mode, the Codex prewarm that opens every new WS session (response.create with generate: false and input: []) is forwarded to the upstream HTTP /v1/responses endpoint, which rejects it.

prepareOpenAIWSHTTPBridgeBody 只删掉了 generate 字段,于是上游收到的是一个空 input 请求。实际遇到的上游返回:

prepareOpenAIWSHTTPBridgeBody only deletes the generate field, so the upstream receives an empty-input request. Responses we see from upstreams:

  • 400 Too small: expected array to have >=1 items
  • 403 One of "input" or "previous_response_id" or 'prompt' or 'conversation' must be provided.

复现 / Reproduce

  • Sub2API v0.2.9, gateway.openai_ws.mode_router_v2_enabled: true
  • OpenAI API-key 账号 / account, openai_apikey_responses_websockets_v2_mode: http_bridge
  • Codex CLI / Desktop, provider supports_websockets = true
  • 开一个新会话发一条消息 / start a new session and send a message

影响 / Impact

  1. Codex 把预热当作 best-effort,只记一条 WARN 然后继续用 WS,所以功能不坏;但每个新会话都要白等一次失败的上游往返(我们这边 2–4 秒,触发换号时更久)。 Codex treats prewarm as best-effort (logs a WARN and keeps using WS), so nothing breaks functionally, but every new session waits for a failed upstream round trip (2–4 s for us, longer when it fails over to another account).
  2. 这次失败会记成账号的上游错误(ops 错误日志里 phase=upstream、error_owner=provider、request_type=3),拉低健康账号的成功率,影响按错误率做的监控/调度,也可能触发 failover。 The failure is recorded as an upstream/provider error on the account (phase=upstream, error_owner=provider, request_type=3), which drags down the success rate of healthy accounts, skews error-rate based monitoring/scheduling, and can trigger failover.
  3. 如果上游接受空 input,预热反而可能变成一次真实(计费的)生成。 If an upstream does accept the request, the prewarm could turn into a real (billed) generation.

期望 / Expected

HTTP Responses 没有 generate 语义。bridge 应把 generate: false 当作建连,本地回一个 response.created + 空输出的 response.completed,并把预热里带的 input 记入 replay 历史,下一轮用这个 response id 作 previous_response_id 时照常续接。

HTTP Responses has no generate semantics. The bridge should treat generate: false as connection setup: answer locally with response.created + a response.completed with empty output, keep any prewarm input in the replay history, and continue normally when the next turn uses that response id as previous_response_id.

#5307 修了原生 WS 路径上的预热续接;HTTP bridge 路径还没有对应处理。 #5307 fixed prewarm continuation on the native WS path; the HTTP bridge path has no equivalent yet.

Sterbennicht avatar Sep 28 '26 12:09 Sterbennicht

这个什么时候合并到主干呢?

bamzc avatar Nov 09 '26 01:11 bamzc