Commit Graph
2 Commits
Author SHA1 Message Date
yetone e9ae12f8c4 gateway: a tool with a union at its root, refused in OpenAI's wording, is asked again folded (#1493, jevejoze)
Codex desktop's mcp__codex_app__automation_update has an anyOf root.
An upstream that validates tools the way OpenAI does refuses it with
"schema must have type 'object' and not have
'oneOf'/'anyOf'/'allOf'/'enum'/'const'/'not' at the top level" (the
reporter's message). OpenAI's own API refuses it with "schema must be a
JSON Schema of 'type: \"object\"', got 'type: \"None\"'" (asked today
with the fixture's schema, its bytes in the test). rootUnionRefusal
knew only xAI's and Anthropic's wordings, so these 400s went to the
agent. Both OpenAI wordings now match, so the request is folded and
retried as it already is for xAI and Anthropic. The retries only fire
when folding changes the request.

jevejoze's branch proposed the same regex change for the first wording.

Run:
- TestRootUnionFoldedWhereRefused now runs xAI, OpenAI-compatible and
  OpenAI refusals, passed through and translated.
- New TestRootUnionRefusalWordings, including two unrelated
  invalid-schema 400s that must not match.
- Break check: reverting object_root.go turns the four new subtests and
  the wording test red.
- Sandbox magpie on a real api.openai.com key: direct, the union gets
  400 (wording above). Through the gateway, the folded retry passed
  validation and reached the account's billing check (429 billing not
  active). No answer was possible on that key.
- go test ./internal/gateway: ok. gofmt -l: clean. GOOS=linux and
  GOOS=windows go vet: clean.
2026-10-10 18:54:16 +08:00
yetone c8ac18a2ca gateway: Grok on a relay's key or xAI's own API gets a tool's root-union parameters folded to an object, so Codex's turns aren't refused (#1271)
Only the Grok subscription's requests were folded (grokBody). Grok
anywhere else refused Codex desktop's automation_update the same way:
AiHubMix's grok-4.7 on its Chat API answered the real schema 400
"Failed to start sampling: [invalid_client_tool_schema] ... tool parameter
root must be an object type" (2026-10-08) and 200 once folded; xAI's API
(api.x.ai) had no fold at all. OpenRouter's x-ai/grok-4.7 takes the union.

xAI's API now gets such tools folded from the first request. Any other
upstream that refuses one for its root ("tool parameter root must be an
object type", or Anthropic's "does not support oneOf, allOf, or anyOf at
the top level" behind a relay's Chat API) is asked once more with them
folded, passed through or translated, and that model is folded from then
on. An upstream that takes the union gets it as sent.

TestRootUnionFoldedWhereRefused (Responses passed through, and Codex's
Responses translated to a Chat-only relay, with AiHubMix's bytes) fails
without the gateway.go change: the client gets the 400. TestRootUnionFoldedForXAI
checks xAI's host is folded and another isn't. go test -tags nogui ./...
in a temp HOME: all pass but the root package and internal/gui under load,
which pass rerun alone; vet for darwin, linux and windows; builds for all three.
2026-10-08 17:01:22 +08:00