Commit Graph
2 Commits
Author SHA1 Message Date
yetone 84bc5fdad8 gateway: codex=as-sent holds when Codex offers web_search
A provider set codex=as-sent (#1758) is meant to get Codex's turn as
Codex sent it, its model name alone swapped. But Codex offers web_search
on every turn, and route() translated any request offering it to a model
that doesn't search by itself (searchedForIt) before passthrough's
as-sent branch was ever reached: the developer messages merged into
instructions, apply_patch sent as a function, web_search left out,
max_output_tokens 500000 added. So as-sent never applied to a real
Codex turn, and maralica's relay, which checks requests are Codex's own,
turned them away.

route() now leaves a Responses request relayed when it goes to an
as-sent provider from Codex (codexAsSent, the same test passthrough's
branch uses, now one helper): its web_search goes to the relay as sent.
A provider at the default is translated and searched for as before.

Not changed: spawnAgentModels still widens spawn_agent's description on
an as-sent turn; filed as #3793 (whether as-sent should skip it too).

Test: TestCodexAsSentWebSearch posts the captured Codex 0.162.0 turn
(testdata/workdir/codex-0.162.0.json: developer messages, web_search;
its spawn_agent tool dropped, #3793) to a fake Responses relay: at the
default the relay gets the translation (no web_search, max_output_tokens);
set as-sent, the body is byte-identical to Codex's but for the model id.
Docs: gateway-routing.md's as-sent paragraph.

Broken by hand: the codexAsSent guard in route() off: the test red
("differs from Codex's at byte 2 of 29291": client_metadata first, the
translation). Restored, green.

Run at this commit (worktree, go1.26.8): go test internal/gateway
(whole package, -timeout 45m) ok (464s, rebased on origin/main 6afbe3f30). gofmt -l clean; go vet
gateway+provider darwin/linux/windows clean; builds as before.
Not run: the full ./... suite (machine load). Not tried: maralica's real
relay, or a real Codex against an as-sent relay.
2026-10-27 03:30:57 +08:00
yetone af7d97fa2f gateway: a Responses provider set codex=as-sent gets Codex's requests as Codex sent them, for a relay that checks they are Codex's own (#1758)
A relay that checks a request is Codex's own answered magpie 400
"Codex 客户端请求特征无效" (10014). magpie fits every Codex request
for a Responses backend that isn't OpenAI's: Responses Lite's
additional_tools item is lifted into tools (#350), the tool search
goes as a function, and OpenAI-only fields such as
stream_options.reasoning_summary_delivery are left out. The reporter
found that the relay takes the request when additional_tools is left
as an input item, and that the lifted shape is what it refuses.

The lifting stays the default, because backends that aren't OpenAI's
refuse additional_tools or silently drop it (#350). A provider can now
opt out: `magpie provider set <id> codex=as-sent` (`codexAsSent` in
providers.json; `codex=default` turns it back off). With it on, a
request from Codex (fromCodex: Codex's User-Agent or originator) goes
as Codex sent it, with only its model name swapped. Codex's own
headers go with it as before. A subscription account is never sent
this way, and the GUI's provider save keeps the setting.

What was run:
- TestCodexAsSent: by default the request is still fitted; with
  codexAsSent the upstream gets exactly what Codex sent, with model
  m1, X-Codex-Turn-Metadata and the Responses Lite header. It fails
  on the old gateway.go and passes now. TestAdditionalTools and the
  gateway's Codex tests pass.

Not verified: not tried against the reporter's relay. Their check
was made by hand outside magpie, so which other fields that relay
looks at is not known. There is no GUI control for the setting
(CLI or providers.json only).
2026-10-12 22:42:47 +08:00