sub2api icon indicating copy to clipboard operation
sub2api copied to clipboard

bug: WS v2 passthrough mode skips Codex image bridge

Open WesleyZiwen opened this issue 5 months ago • 0 comments

Summary

Codex image generation works on the normal WS v2 ingress path after #2937, but it is still skipped when an OpenAI account is configured to use WS v2 passthrough mode.

In passthrough mode, ProxyResponsesWebSocketFromClient returns early into proxyResponsesWebSocketV2Passthrough / openai_ws_v2_passthrough_adapter.go, so the Codex image bridge logic in openai_ws_forwarder.go is bypassed. The first upstream response.create frame is forwarded without the injected image_generation tool, even when:

  • the request is from a Codex client,
  • the group allows image generation,
  • codex_image_generation_bridge_enabled is enabled,
  • and the account has openai_apikey_responses_websockets_v2_mode or openai_oauth_responses_websockets_v2_mode set to passthrough.

Impact

Codex users routed through WS v2 passthrough mode can ask for image generation, but the upstream request does not receive the image_generation tool bridge. This makes image generation unavailable or unreliable only for passthrough-mode accounts, while non-passthrough WS v2 accounts may work.

Why this is different from #2937

#2937 injects the Codex image bridge in the regular WS ingress flow in openai_ws_forwarder.go.

Passthrough mode takes a separate path before that regular relay logic runs:

case OpenAIWSIngressModePassthrough:
    return s.proxyResponsesWebSocketV2Passthrough(...)

That adapter path currently applies fast-policy filtering, but does not apply the same Codex image bridge mutation before forwarding response.create frames upstream.

Reproduction shape

  1. Configure an OpenAI account with WS v2 passthrough mode, for example:
{
  "openai_apikey_responses_websockets_v2_mode": "passthrough",
  "codex_image_generation_bridge": true
}
  1. Use a Codex client request such as:
{
  "type": "response.create",
  "model": "gpt-5.1",
  "stream": false,
  "input": "generate an image"
}
  1. Observe that the frame sent upstream by the passthrough adapter has no tools[0].type == "image_generation".

Expected behavior

WS v2 passthrough mode should apply the same Codex image bridge behavior as the regular WS v2 ingress path:

  • inject image_generation tool for eligible Codex response.create frames,
  • normalize explicit image_generation tools,
  • preserve image usage/accounting metadata for generated image output.

Local validation

I reproduced this with a regression test around ProxyResponsesWebSocketFromClient in passthrough mode. On current upstream main, the test fails because the passthrough result has ImageCount == 0 and the captured upstream request lacks tools.0.type == "image_generation".

After applying the local fix, these checks pass:

go test ./internal/service -run TestOpenAIGatewayService_ProxyResponsesWebSocketFromClient_PassthroughModeInjectsCodexImageBridge -count=1
go test ./internal/service -run 'TestOpenAIGatewayService_ProxyResponsesWebSocketFromClient_(PassthroughMode|PassthroughHeaders)|TestPassthroughUsageMeta|TestPassthroughBilling|TestApplyCodexImageGenerationBridgeInstructions|TestEnsureOpenAIResponsesImageGenerationTool|TestNormalizeOpenAIResponsesImageGenerationTools' -count=1
go test ./internal/service -count=1

A fix has been proposed in #3160.

WesleyZiwen avatar Jun 09 '26 07:06 WesleyZiwen