gateway: only a relay whose list draws a GPT Image takes the family (#4432)

34199952b let any keyed provider at a Responses base draw every
gpt-image-* name. Its body says "a Codex backend relay whose model list
carries any gpt-image* name", but the code read no list: a chat-only
relay ahead of one that draws took a bare gpt-image-2 and failed it at
its vendor, and a Codex turn on a chat-only relay lost the Settings pick
it drew with before. The patch changed TestCodexDrawingFallsBackToImage-
Setting's expectations (and moved its "off" checks to no turn) to fit.

drawsFamily now takes a keyed Responses relay only when its own Drawers
hold one gpt-image-* already, as the patch's description had it. Both of
the patch's tests stay green; TestCodexDrawingFallsBackToImageSetting is
back to its form before the patch, and TestRelayDrawingNoGPTImageClaims-
NoneOfTheFamily covers the chat-only relay.

Run on mote: go test -tags nogui ./internal/gateway/ -run
'Draw|Drawing|Relay' ok. Broken by hand: the case returning true for any
gpt-image-* (the patch's rule) fails the new test (plain/gpt-image-2)
and TestCodexDrawingFallsBackToImageSetting (text-only/gpt-image-2);
the case removed fails the patch's two tests and the new one.
Not tried: a real sub2api relay (loscoy's), whose list magpie_image
drew from per the report.
This commit is contained in:
yetone
2026-11-02 07:40:21 +08:00
parent 7e44e57b4e
commit a130035a0d
3 changed files with 40 additions and 15 deletions
+9 -7
View File
@@ -175,19 +175,21 @@ func resolveDrawing(id string) (provider.Provider, string, bool) {
// drawsFamily is whether a subscription whose image models magpie lists
// itself (codexDrawers, grokDrawers) draws id, a model of the family those
// are of: any grok-imagine-image* on a Grok subscription, any gpt-image-*
// on a ChatGPT account, and any gpt-image-* a Codex backend relay (sub2api)
// is asked through, at the images API it serves beside its Responses (#870).
// The vendor's newer ones work before magpie names them, as
// grok-imagine-video* do for videos; one it doesn't serve is refused by the
// vendor, in its own words.
// on a ChatGPT account, and any gpt-image-* on a keyed relay at a Responses
// base (a Codex backend relay such as sub2api) whose own list draws one of
// that family already (#4432). The vendor's newer ones work before magpie
// names them, as grok-imagine-video* do for videos; one it doesn't serve is
// refused by the vendor, in its own words. A relay whose list draws no
// GPT Image isn't taken to: a Codex turn on it draws with the Settings
// pick, as it did (TestCodexDrawingFallsBackToImageSetting).
func drawsFamily(p provider.Provider, id string) bool {
switch {
case drawsGrok(p):
return strings.HasPrefix(id, grokDrawerFamily)
case drawsCodex(p):
return strings.HasPrefix(id, codexDrawerFamily)
case p.Account == nil && p.Base(provider.Responses) != "":
return strings.HasPrefix(id, codexDrawerFamily)
case p.Account == nil && p.Base(provider.Responses) != "" && strings.HasPrefix(id, codexDrawerFamily):
return slices.ContainsFunc(Drawers(p), func(m catalog.Model) bool { return strings.HasPrefix(m.ID, codexDrawerFamily) })
}
return false
}
+27
View File
@@ -147,6 +147,33 @@ func TestRelayDrawsTheGPTImageFamilyByItsBareName(t *testing.T) {
}
}
// A keyed relay whose list draws no GPT Image is not taken to draw one by
// its bare name: a chat-only relay ahead of the one that draws would take
// every gpt-image-* and fail it at its vendor (#4432).
func TestRelayDrawingNoGPTImageClaimsNoneOfTheFamily(t *testing.T) {
fresh(t)
plain := drawingRelay(t, "plain")
painter := drawingRelay(t, "painter", "gpt-image-2.5-flare")
s := New()
code, a, raw := postImages(t, s, "/v1/images/generations", "application/json", `{"model":"gpt-image-2","prompt":"a magpie"}`)
if code != 200 || a.Model != "painter/gpt-image-2" {
t.Fatalf("%d %s", code, raw)
}
if got := plain.got("/v1/images/generations"); len(got) != 0 {
t.Fatalf("the chat-only relay was asked: %v", got)
}
if got := painter.got("/v1/images/generations"); len(got) != 1 {
t.Fatalf("painter asked %v", got)
}
if err := provider.Delete("painter"); err != nil {
t.Fatal(err)
}
code, _, raw = postImages(t, s, "/v1/images/generations", "application/json", `{"model":"gpt-image-2","prompt":"a magpie"}`)
if code != 404 || len(plain.got("/v1/images/generations")) != 0 {
t.Fatalf("chat-only relay alone: %d %s", code, raw)
}
}
// Codex's native image tool asks its turn's provider for the one it names
// (gpt-image-2, #870): on a Codex backend whose list names another of the
// family, it draws there as the one it asked for, not as magpie's pick
+4 -8
View File
@@ -200,12 +200,8 @@ func TestCodexDrawingFallsBackToImageSetting(t *testing.T) {
s := New()
drawingMainTurn(t, s, "text-only/text", "session", "turn", "", "magpie-codex")
for _, test := range []struct{ model, session, turn, want string }{
// the turn's own provider is a Codex backend, which draws the same
// for any gpt-image-* name (#1865): codex's own model draws there,
// list or no list (#4432)
{"gpt-image-2", "", "turn", "text-only/gpt-image-2"},
{"gpt-image-future", "", "turn", "text-only/gpt-image-future"},
// no turn of its own to follow: the Settings' pick
{"gpt-image-2", "", "turn", st.ImageGen},
{"gpt-image-future", "", "turn", st.ImageGen},
{"gpt-image-2", "", "unknown-turn", st.ImageGen},
{"gpt-image-2", "", "", st.ImageGen},
{"gpt-image-2", "session", "unknown-turn", st.ImageGen},
@@ -221,7 +217,7 @@ func TestCodexDrawingFallsBackToImageSetting(t *testing.T) {
if err := settings.Save(st); err != nil {
t.Fatal(err)
}
code, _, raw := drawingToolCall(t, s, "/v1/images/generations", "gpt-image-2", "", "", "magpie-codex")
code, _, raw := drawingToolCall(t, s, "/v1/images/generations", "gpt-image-2", "", "turn", "magpie-codex")
if code != 400 || !strings.Contains(raw, "Settings") {
t.Fatalf("fallback off: %d %s", code, raw)
}
@@ -229,7 +225,7 @@ func TestCodexDrawingFallsBackToImageSetting(t *testing.T) {
if err := settings.Save(st); err != nil {
t.Fatal(err)
}
code, answer, raw := drawingToolCall(t, s, "/v1/images/generations", "gpt-image-2", "", "", "magpie-codex")
code, answer, raw := drawingToolCall(t, s, "/v1/images/generations", "gpt-image-2", "", "turn", "magpie-codex")
if code != 200 || answer.Model != AutoDrawer() {
t.Fatalf("automatic fallback: %d %s", code, raw)
}