Files
Aether/crates/aether-ai-formats
mayrain 65e3b6f3da fix(codex): trigger image override only on explicit tool_choice
The codex `apply_codex_openai_responses_special_body_edits` override
previously triggered whenever the `tools` array contained an
`image_generation` entry, regardless of whether the caller actually
asked to use it. Codex CLI advertises `image_generation` alongside
~20 other tools under `tool_choice: "auto"`, so every routine codex
conversation was being rewritten into image-generation-only form:

  - `model` forced to `gpt-5.4-mini` (CODEX_OPENAI_IMAGE_INTERNAL_MODEL)
  - `stream` forced to `true`
  - `tools` truncated to a single `image_generation` entry
  - `tool_choice` overwritten to `{"type":"image_generation"}`

The upstream ChatGPT codex backend then rejected the request with
`400 Tool choice 'image_generation' not found in 'tools' parameter`,
which the gateway surfaced as a retryable 503 to clients. The bug
reproduced on every codex CLI session that included the image tool
in its tool catalogue, even though the user never requested image
generation.

Narrow the trigger to the caller's actual selection. The new helper
`codex_openai_responses_tool_choice_references_image_generation`
matches only the explicit string `"image_generation"` or the object
form `{"type":"image_generation"}`. The pre-existing
`is_openai_image_request(provider_api_format)` branch still handles
genuine `openai:image` traffic, so true image-generation flows are
unaffected.

Tests:
  - lock the regression: `tool_choice: "auto"` with image_generation
    in tools must not trigger the override (model/tools preserved)
  - lock variants: string `"image_generation"` and object form both
    still trigger; other tool_choice values and an absent
    `tool_choice` do not
2026-05-20 09:52:39 +08:00
..