Skip to content

[codex] Detach image upstream context#3365

Draft
cyeinfpro wants to merge 1 commit into
Wei-Shaw:mainfrom
cyeinfpro:codex/detach-image-upstream-context
Draft

[codex] Detach image upstream context#3365
cyeinfpro wants to merge 1 commit into
Wei-Shaw:mainfrom
cyeinfpro:codex/detach-image-upstream-context

Conversation

@cyeinfpro

Copy link
Copy Markdown

Summary

  • Detach OpenAI Images API key upstream requests from the client request context.
  • Add a regression test covering non-stream image forwarding after the client context is canceled.

Why

For non-stream OpenAI Images requests, the upstream request used the client request context. If the client or an intermediate proxy disconnected before the upstream image generation completed, the upstream request was canceled with context canceled. That prevented the gateway from receiving a successful image response and skipped the existing RecordUsage billing path, even though the upstream provider could already have accepted the request.

Streaming image requests and the Responses-based image path already use detached upstream contexts. This change makes the API key non-stream Images path consistent with those flows.

Validation

go test ./internal/service -run 'TestOpenAIGatewayServiceForwardImages_APIKey(GenerationUsesConfiguredV1BaseURL|NonStreamDetachesUpstreamContext|StreamJSONResponseBillsImage|StreamingDrainsAfterClientDisconnect)$'

Also ran git diff --check.

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA).

To sign, please reply with the following comment:

I have read the CLA Document and I hereby sign the CLA

You only need to sign once — it will be valid for all your future contributions to this project.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@cyeinfpro cyeinfpro force-pushed the codex/detach-image-upstream-context branch from 88a266f to 165ddc8 Compare June 19, 2026 02:21
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