Skip to content

fix(openai): preserve Codex image function tools during bridge injection#4346

Merged
Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
xiaohei210509:agent/handle-codex-image-function-tool
Jul 15, 2026
Merged

fix(openai): preserve Codex image function tools during bridge injection#4346
Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
xiaohei210509:agent/handle-codex-image-function-tool

Conversation

@xiaohei210509

Copy link
Copy Markdown
Contributor

Summary

  • recognize Codex client image tools serialized as flat or nested image_gen.imagegen functions
  • skip hosted image_generation, automatic tool_choice, and hosted-bridge instructions when that client function is already present
  • add helper, HTTP forwarding, and WebSocket ingress regression coverage

Root cause

PR #4104 made bridge injection reuse the image-tool detector for hosted tools and namespace/image_gen declarations. Some Codex clients and MCP adapters instead serialize the same client-side tool as one of these function shapes:

{"type":"function","name":"image_gen.imagegen"}
{"type":"function","function":{"name":"image_gen.imagegen"}}

Those forms are not OpenAI hosted tools and are intentionally not part of hasOpenAIImageGenerationTool. As a result, the bridge still appended a hosted image_generation tool to the same request, which OpenAI rejects with:

Function 'image_gen.imagegen' conflicts with a hosted tool in the same request.

This change reuses the existing exact-name function parser before applying any hosted bridge additions. Similar names such as image_gen.imagegenerator continue through the existing injection path.

This is a follow-up to #4104. Refs #4022 and #4249.

Validation

  • targeted helper, HTTP, and WebSocket regression tests
  • go test ./internal/service -count=1
  • go test ./... -count=1
  • go test -tags=unit ./... -count=1
  • go test -tags=integration across all packages except internal/pkg/tlsfingerprint
  • golangci-lint run ./... --timeout=30m (0 issues)

The full integration command was also run. Its only failure was the unrelated external TLS fingerprint endpoint intermittently returning unexpected EOF; all remaining integration packages passed locally.

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@xiaohei210509

Copy link
Copy Markdown
Contributor Author

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

github-actions Bot added a commit that referenced this pull request Jul 15, 2026
@xiaohei210509
xiaohei210509 marked this pull request as ready for review July 15, 2026 07:24
@Wei-Shaw
Wei-Shaw merged commit 651bb01 into Wei-Shaw:main Jul 15, 2026
9 of 10 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants