Doby on Discord: Pi 1.4.0 on Codex through magpie 0.1.1327 is turned
away on every continued conversation:
400 {"code":"unknown_parameter","message":"Codex: Unknown parameter:
'input[8].status'.","param":"input[8].status","type":"invalid_request_error"}
Pi (pi-ai's convertResponsesMessages) sends each earlier assistant
message as the output item it was, {type:"message", role:"assistant",
id, status:"completed", content:[output_text]}. codexInput drops every
item's id, since the backend keeps nothing (store false), but kept the
status. A message with no id is read as an input message, which has no
status field, so the backend refused it. Codex itself sends status only
on the items whose schema has one: codex-rs/protocol/src/models.rs gives
Message an optional status beside its id, Reasoning none at all, and the
tool calls (function_call, custom_tool_call, local_shell_call, whose
status is required) their own.
codexInput now drops status from messages (typed or not) and reasoning
items, the kinds whose ids it drops, and leaves it on tool calls as Codex
sends them. Checked for the same gap: the gateway's own Codex relay
(codex_backend.go) keeps ids, so status stays valid there; the only other
id stripping (chat_call_ids.go) is chat tool_calls; no plugin serves
Codex.
Tests: TestCodexInputDropsStatusWithID (provider) covers each item kind.
TestPiResponsesRelayedToChatGPT's fake backend now refuses an item with
status and no id the way the backend does (codexBackendRefuses).
Run at 34ad18ed8 with this change:
- gofmt -l clean; go vet ./... (darwin), GOOS=linux go vet -tags nogui
./..., GOOS=windows go vet ./... clean
- go test -tags nogui -timeout 45m -count=1 ./internal/provider/
./internal/gateway/ in a sandbox HOME: ok 121.0s, ok 421.8s
Rebased on 243594410 (redact escapes and the remote guide's wording,
nothing on this path); at 087ad3935: gofmt -l and go vet on provider and
gateway clean, go test -run 'Codex|Pi' on both packages ok.
Broken by hand: on the old codexInput both new tests are red.
TestCodexInputDropsStatusWithID keeps input[0..2]'s status, and
TestPiResponsesRelayedToChatGPT gets 400 {"error":{"code":
"unknown_parameter","message":"Codex: Unknown parameter:
'input[3].status'.",...}}, the reporter's words.
Not tried: the real ChatGPT backend (the live ~/.codex sign-in is off
limits to this session); the theory that status needs its id fits
OpenAI's item schemas and the reporter's error, nothing more. The full
suite was not run, because another session's full go test ./... was
running on this machine at the time.
Savin (#help, magpie 0.1.1296, Codex 0.163.0-alpha.10.2, signed in with
ChatGPT): the turn failed with the ChatGPT backend's "a single request
can't contain both a client-declared function web.run and the hosted tool
web_search".
Who adds which:
- web.run is Codex's own. codex-rs/ext/web-search (tool.rs) declares it
as a function "run" in the "web" namespace, and spec_plan.rs's
hosted_model_tool_specs leaves the hosted web_search out whenever
web.run is registered: on a Responses Lite model (whose requests take
no hosted tools at all), or with the standalone_web_search feature on.
Codex never sends both itself.
- The hosted web_search was magpie's. provider.DeclareSearch (#1270)
adds the cached-only {"type":"web_search","external_web_access":false}
to any ChatGPT-bound request whose input replays a web_search_call
without declaring search. declaresSearch looked only for a web_search*
type, so a conversation that had searched with the hosted tool and
went on under web.run (a Lite model, a newer Codex, or magpie's own
searcher's web_search_call items) got web_search added beside web.run,
in the additional_tools item for Lite or in the tools. The backend then
refused the turn.
What changed: declaresSearch counts web.run as the conversation's search.
It matches the namespace "web" holding a function "run", and a function
named "web.run". DeclareSearch then leaves the body as Codex sent it.
This covers both routes that call it: codexBody (a ChatGPT account in
magpie) and codexUpstreamOn (Codex's own sign-in relayed). Nothing the
client declared is dropped. web.run is the tool the backend serves this
client (through /alpha/search), so magpie no longer adds the tool that
conflicts with it. A namespace other than "web" with a "run" function
still gets web_search declared.
Not verified: whether the ChatGPT backend accepts a replayed
web_search_call under web.run with no hosted tool. That is the request
the official Codex client sends to it directly. It was not probed on a
real account, and the test fake assumes it is accepted.
Tests:
- TestDeclareSearch: new cases cover web.run in Lite's additional_tools,
web.run among the tools, the flat "web.run" function, and another
namespace's run.
- TestSearchedConversationUnderWebRun: protectedSearch now refuses a
request that carries both tools, with Savin's error. The test covers
Lite on Codex's sign-in (relayed byte for byte) and two turns on a
ChatGPT account (Lite and tools).
- On ba319a758 without the codex_request.go change, both tests fail.
The gateway test gets the 400 with Savin's error. With the change,
both pass, along with TestSearchedConversation* and
TestUnsearchedConversationUnchanged.
docs/subsystems/gateway-routing.md says it next to #1270.
Run:
- gofmt -l: clean. go vet ./... passes on darwin, GOOS=linux -tags nogui
and GOOS=windows -tags nogui.
- `set -o pipefail; go test -timeout 45m ./...` at base ba319a758: every
package ok except internal/agent and internal/gateway. Both hit the 45m
package timeout with no test failing. The tests in flight at the panic
had run 5s and 0s, and four suites from other sessions were running on
the machine.
- Rerun of those two at -timeout 90m: gateway ok (2057s), agent ok
(2418s).
- Rebased onto c79400556, whose 4 new commits touch agent, library,
redact and provider. Rerun there: gofmt, vet on all three OSes,
./internal/provider ok, ./internal/redact ok, and
./internal/gateway -run 'Search|Codex|WebRun|Protect' ok.
- Rebased again onto e68a0b1db (4 commits in internal/sessions only).
go vet on sessions, provider and gateway passes there.
pi-ai sends {"prompt_cache_options":{"mode":"explicit"}} on the Responses
API. The ChatGPT backend behind a Codex subscription answers 400:
{"error":{"message":"prompt_cache_options is not supported on this
model","type":"invalid_request_error","param":"prompt_cache_options",
"code":"invalid_parameter"}}
Probed on 2026-10-14 with a read-only use of the owner's Codex token
(never refreshed or written): gpt-5.5, gpt-6-sol, gpt-6-astra,
gpt-6-luna and gpt-5.6-sol all refuse it, and the same requests without
the field return 200.
- codexBody drops prompt_cache_options with the other fields the backend
turns away. prompt_cache_key stays; the backend follows it (#1473).
- prompt_cache_options joins the gateway's optional fields. Its refusal
names the field bare, at the start of the message, which none of the
existing patterns read, so unsupportedOptionalField also takes
"<field> is not supported/unsupported" when the message starts with
it. Only at the start, so a field named inside an echo of the input is
not taken for it. As for the other optional fields, the refusal is
remembered per provider, though OpenAI's wording says "on this model";
the cost of that is a cache hint left off, never a failed request.
Run: go test -tags nogui for internal/gateway (40m timeout; load ~380
from other sessions), provider, catalog, codexcat and agent; gofmt -l;
go vet darwin, GOOS=linux -tags nogui, GOOS=windows. With each fix taken
out by hand, TestRefusedOptionalNamesOnlyUnsupportedFields,
TestPromptCacheOptionsRefusedRetried and
TestCodexBodyDropsPromptCacheOptions go red.
Not tried: pi-ai itself against a Codex subscription.
The ChatGPT backend looks up a conversation's prompt cache by the session
headers, not by the body's prompt_cache_key. I probed a real Pro account
(gpt-6.1-sol, 13 tools, about 7.6K-token prompt) directly:
- key in body only, 6 requests: cached 0 every time
- no key and no headers: 0 every time
- session-id + thread-id: 0, then 7552 x5
- old session_id/conversation_id: 0, then 7552
- a bare request with no tools: 4096 every time. That is the
instructions' shared cache, so #1473's "bare requests hit" pattern
fits this.
Codex CLI 0.162 (captured with codex exec against a fake server) now
sends only session-id and thread-id. It no longer sends the underscored
names, which a proxy may drop.
Changes:
- codexSign: sets session-id and thread-id from the prepared body's key
(sessionHeaders). It drops the underscored names. A keyless body keeps
the session the client named.
- codexHeader: relays session-id/thread-id from Codex clients.
- ChatGPT API (SIWC) provider: it sent only Authorization. Now it names
the conversation (conversationKey for keyless clients) and sends the
same session headers. Scallions' screenshots: chatgpt-api/ got 0%
cache where codex/ got 10-99%.
This was NOT tried against api.openai.com with a real ChatGPT API
sign-in, since none is available here. Left for the reporter to
confirm.
Run:
- Sandbox magpie on a real Codex account, client sending no key: old
build cached 0/7296 erratically; new build 0, 0, then 7296 x4.
- go test ./internal/provider ./internal/gateway: ok.
- Break check: reverting codex_request.go and chatgpt_api.go turns
TestCodexSignSessionHeaders, TestCodexSignAndBody and
TestChatGPTAPISession red.
- gofmt -l: clean. GOOS=linux and GOOS=windows go vet: clean.
base_instructions and the identity line are unchanged.
The ChatGPT backend answers HTTP 200 and only `event: error` "response
protection is unavailable" to any request whose input replays one of its
own web_search_call items while the request doesn't declare the web_search
tool. Probed on a real ChatGPT Pro account (gpt-6.1-sol, 2026-10-09) with
a real searched turn: refused with tools [], with function tools only and
with a compaction_trigger; answered once {"type":"web_search",
"external_web_access":false} is declared. A Responses Lite request refuses
a top-level web_search (400) but takes it in an additional_tools item. So
xjdata's case (Codex compacting a custom provider's conversation itself, a
plain /responses with tools [] that magpie's codexCompact never sees) failed
every time once the session had searched, and congee949's thread
descriptions too.
What changed:
- provider.DeclareSearch / declareSearch: when the input holds a
web_search_call and nothing declares search, add cached-only web_search to
the tools, or for Lite (header, reasoning.context all_turns, or an
additional_tools item present) to the additional_tools item (prepended
when there is none). With no tools offered, tool_choice becomes "none" so
the model can't search; a forced choice is kept. Otherwise the body is
unchanged (bytes untouched when no web_search_call is in it).
- codexBody (every ChatGPT account route: serveAgent, codexCompact, warmup,
magpie's codex/* models) calls it; codexUpstreamOn calls it for Codex's
own sign-in relayed to the backend's /responses.
- Not changed: siwc, API-key passthrough to api.openai.com, the legacy
/responses/compact endpoint (no evidence they are refused so; not probed).
- docs/subsystems/gateway-routing.md names the cause and the fix.
Tests: internal/gateway/search_history_test.go replays the backend's real
items from that probe against a fake that refuses as the backend did.
TestSearchedConversationCompactsOnAnAccount, ...FunctionTools and
...OnCodexSignIn fail on the old code with "event: error"; ...CompactionTrigger
fails with "asked 2 times, not once". TestUnsearchedConversationUnchanged
and provider TestDeclareSearch cover what's left alone.
Run: gofmt -l (clean); go vet, GOOS=linux go vet -tags nogui, GOOS=windows
go vet -tags nogui on internal/provider and internal/gateway; HOME=<temp>
go test -tags nogui ./internal/provider ./internal/gateway (ok). Real
account, sandbox magpie on 127.0.0.1:3491 under a scratch HOME, replaying
the real searched history: old binary -> /v1/responses codex/gpt-6.1-sol
text compaction with tools [] and /backend-api/codex/responses (standard
and Lite compaction_trigger) all "response protection is unavailable";
new binary -> all response.completed, Lite with a compaction item.
Codex CLI 0.161.0 end to end was not done: on a custom provider it
offered no web_search tool, so no search could get into its history.
Run: TestCodexPoolKeepsUltrafast fails on the old code (backend asked for <nil>) and passes now; go test ./internal/gateway ./internal/provider ./internal/codexcat pass; go vet clean. Not tried with a real account offering Ultrafast: the owner's accounts don't list it.