From 8ef9fc578ced531b7ca835a3133c37f608a70e6a Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 23 Oct 2026 18:01:39 +0800 Subject: [PATCH] provider: a message sent again to the ChatGPT backend goes without its status, as it goes without its id (Doby on Discord) 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. --- internal/gateway/pi_responses_test.go | 25 +++++++++++++++++++++- internal/provider/codex_request.go | 11 +++++++++- internal/provider/codex_request_test.go | 28 +++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/internal/gateway/pi_responses_test.go b/internal/gateway/pi_responses_test.go index 1830a6d27..176909c41 100644 --- a/internal/gateway/pi_responses_test.go +++ b/internal/gateway/pi_responses_test.go @@ -92,7 +92,7 @@ func TestPiResponsesRelayedToChatGPT(t *testing.T) { auth := fmt.Sprintf(`{"auth_mode":"chatgpt","tokens":{"id_token":%q,"access_token":%q,"refresh_token":"r","account_id":"acct-1"}}`, claims(map[string]any{"email": "me@example.com"}), claims(map[string]any{"exp": time.Now().Add(time.Hour).Unix()})) os.WriteFile(filepath.Join(home, ".codex", "auth.json"), []byte(auth), 0o600) - f := &fake{t: t, ctype: "none", reply: piReply} + f := &fake{t: t, ctype: "none", reply: piReply, refuse: codexBackendRefuses} up := httptest.NewServer(f) defer up.Close() old := provider.CodexBase @@ -112,6 +112,29 @@ func TestPiResponsesRelayedToChatGPT(t *testing.T) { } } +// codexBackendRefuses answers as the ChatGPT backend does an input item +// with a parameter its kind doesn't have: a message without its id is an +// input message, and an input message has no status (Doby on Discord, Pi +// 1.4.0 going on with a conversation: 400 "Unknown parameter: +// 'input[8].status'"). +func codexBackendRefuses(body []byte) (int, string) { + var q struct { + Input []map[string]any `json:"input"` + } + if json.Unmarshal(body, &q) != nil { + return 400, `{"error":{"message":"bad json","type":"invalid_request_error"}}` + } + for i, it := range q.Input { + _, id := it["id"] + _, status := it["status"] + if typ := it["type"]; status && !id && (typ == nil || typ == "message") { + p := fmt.Sprintf("input[%d].status", i) + return 400, fmt.Sprintf(`{"error":{"message":"Unknown parameter: '%s'.","type":"invalid_request_error","param":"%s","code":"unknown_parameter"}}`, p, p) + } + } + return 0, "" +} + // DeepSeek Harness on magpie's route switched to OpenAI Responses (its // llm-pi-ai plugin is pi-ai's openai-responses, so it asks as Pi does) // reaches a model served on Chat Completions alone, a DeepSeek one: the diff --git a/internal/provider/codex_request.go b/internal/provider/codex_request.go index 0f9e67299..89e15e164 100644 --- a/internal/provider/codex_request.go +++ b/internal/provider/codex_request.go @@ -380,7 +380,8 @@ func BoundCallID(id string) string { } // codexInput makes input items fit a request that keeps nothing: no -// references to stored items, no ids, a tool's output without its call +// references to stored items, no ids (nor a message's status, which goes +// with its id), a tool's output without its call // kept as a message saying what it was, and no system role, which the // backend rejects (developer keeps what it means in its place). func codexInput(input []any) []any { @@ -422,6 +423,14 @@ func codexInput(input []any) []any { continue } delete(it, "id") + // A message's status goes only with its id: without one, the + // backend reads it as an input message, which has no status, and + // turns the request away 400 "Unknown parameter: 'input[N].status'" + // (Doby on Discord: Pi gives each assistant message it sends again + // status "completed"). Codex's own reasoning items carry none. + if t := it["type"]; t == nil || t == "message" || t == "reasoning" { + delete(it, "status") + } switch t, _ := it["type"].(string); t { case "function_call_output", "custom_tool_call_output", "local_shell_call_output": id, _ := it["call_id"].(string) diff --git a/internal/provider/codex_request_test.go b/internal/provider/codex_request_test.go index 8567a7ebf..880088d44 100644 --- a/internal/provider/codex_request_test.go +++ b/internal/provider/codex_request_test.go @@ -375,3 +375,31 @@ func TestCodexBodyDropsPromptCacheOptions(t *testing.T) { t.Errorf("cache key lost: %v", m) } } + +// A message's status goes with its id, and Codex's reasoning items carry +// none, so both lose it with the id (Doby on Discord: Pi's assistant +// message sent again with status "completed" was refused 400 "Unknown +// parameter: 'input[8].status'"). A tool call keeps its status, as Codex +// sends it. +func TestCodexInputDropsStatusWithID(t *testing.T) { + in := []any{} + json.Unmarshal([]byte(`[ + {"role":"user","content":"hi","status":"completed"}, + {"type":"reasoning","id":"rs_1","summary":[],"encrypted_content":"e","status":"completed"}, + {"type":"message","role":"assistant","content":[{"type":"output_text","text":"ok","annotations":[]}],"status":"completed","id":"msg_1"}, + {"type":"function_call","id":"fc_1","call_id":"c1","name":"ls","arguments":"{}","status":"completed"}, + {"type":"local_shell_call","id":"lsh_1","call_id":"c2","status":"completed","action":{"type":"exec","command":["ls"]}}, + {"type":"function_call_output","call_id":"c1","output":"a"}, + {"type":"local_shell_call_output","call_id":"c2","output":"b"}]`), &in) + out := codexInput(in) + want := []bool{false, false, false, true, true, false, false} + if len(out) != len(want) { + t.Fatalf("items: %v", out) + } + for i, item := range out { + _, has := item.(map[string]any)["status"] + if has != want[i] { + t.Errorf("input[%d] status kept %v, want %v: %v", i, has, want[i], item) + } + } +}