Skip to content

fix(codex): route native image edits through official fallback - #97

Draft
MattLYT wants to merge 3 commits into
BigStrongSun:mainfrom
MattLYT:codex/fix-image-route-fallback
Draft

MattLYT wants to merge 3 commits into
BigStrongSun:mainfrom
MattLYT:codex/fix-image-route-fallback

Conversation

@MattLYT

@MattLYT MattLYT commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Why

Native Codex image editing (POST /v1/images/edits, e.g. gpt-image-2) misses the compiled catalog in a schema-v2 MultiRouter containing only text models. Raw forwarding then selects the outer router's local URL, and the self-loop guard rejects the request before it reaches an upstream.

The observed log reported route_missed=true and effective_upstream_local_proxy_self_loop. Commit 8b29949 removed fallback from generic strict routing; image generations already use a separate image provider resolver, but image edits did not.

What changed

  • Apply the existing image provider resolver only to native Codex POST image edits, preserving explicit third-party image routes. Ordinary Responses and generic raw routing remain catalog-only.
  • Parse multipart model and stream fields using multer without rebuilding uploaded image/mask bytes or changing content type/query. Reject malformed, duplicate, file-valued, oversized, or invalid routing fields.
  • Support the existing Codex path alias and exact double-v1 image-edit alias. Exclude vendor suffix paths, other methods/endpoints, external API clients, xAI OAuth, and GitHub Copilot from the official image fallback.
  • Group the existing chat conversion helpers' public/upstream model parameters to resolve their two argument-count CI errors without lint suppression or behavior changes.

Verification

Regression tests cover strict routing boundaries, official image fallback, explicit image routes, external authentication precedence, malformed multipart input, and a local HTTP upstream receiving byte-for-byte image/mask uploads with the original content type/query. The official-route handler test reaches the deliberately missing test OAuth state instead of self-loop rejection.

Tests use isolated homes, in-memory databases, and synthetic uploads. No production credentials were used, the installed desktop app was not replaced, and a live authenticated image edit was not replayed.

On the merged upstream base aff5fa46, all 101 handler tests (including the 10 image-edit regressions) and 9 raw-passthrough tests passed; formatting also passed. Strict Clippy remains blocked by 13 existing diagnostics in unchanged history/usage modules, outside this PR. The full default-parallel test build exhausted local memory/pagefile; the scoped tests above were successfully compiled and run with -j 1. Full-suite success is not claimed.

Reuse image provider selection for native image edits while preserving raw uploads and explicit third-party routes. Parse multipart routing fields, normalize edit aliases, and exclude non-OpenAI managed accounts from official fallback.

Validation: 26 targeted tests and cargo fmt passed. Strict Clippy exposes two unchanged upstream too_many_arguments warnings; no unrelated source changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant