Commit Graph
1 Commits
Author SHA1 Message Date
yetone 3ec45e7155 gateway: a json_schema an upstream turns away is asked for as a JSON object, the schema in the system prompt, before the format is told in words alone (#2126)
klarkxy's Codex on Xiaomi MiMo's Token Plan got back "text.format type
'json_schema' is not supported, only 'text' and 'json_object' are
supported" and the turn ended there. Codex's /responses reaches the
upstream by passthrough when the protocols match, and passthrough never
looked at a format refusal; the translated path did, but only by moving
the whole format into the system prompt, which drops the object
requirement the vendor would have kept.

Now, on either path, a json_schema the upstream turns away is asked
again as {"type":"json_object"} with the schema appended to the system
prompt (Responses instructions, Chat's first system/developer message,
Anthropic system). If json_object is turned away too, the format field
goes and only the words stay. Each step is remembered per provider,
model and protocol once a request with it is taken, so later turns go
out already rewritten. Anthropic's output_config.format has no object
mode, so it goes straight to words. DeepSeek, which takes json_object
only, gains the same middle step on the translated path.

Run:
- format_refused_test.go, new:
  - TestPassthroughSchemaRefusedAskedAsObject replays the reporter's
    exact error and probe body through /backend-api/codex/responses.
    It covers object taken (2 asks, then json_object) and object refused
    too (3 asks, then no format). Turn 2 is checked to take 1 ask, the
    instructions to keep "You are Codex." first, and the input to be
    unchanged.
  - TestPassthroughFormatRefusedChatAndAnthropic.
- TestRefusedFormatToldInWords was rewritten for both outcomes on the
  translated path.
- Break check: with the old gateway.go, the passthrough test gets back
  the reporter's exact error.
- gofmt -l is clean. go vet passes for darwin, GOOS=linux -tags nogui
  and GOOS=windows. go test ./internal/gateway/ -count=1 is ok (1017s).

Not tried: a real Xiaomi MiMo key (none here; the error envelope is
assumed to be OpenAI's), and Gemini passthrough, which has no rewrite.
2026-10-14 16:42:56 +08:00