gateway: an overload told in Codex's stream says server_is_overloaded (wjh66)
wjh66 on Discord (Windows, v0.1.2710, Codex on the ChatGPT sign-in, gpt-6.1-sol): every turn showed "reconnecting 5/5", and app.log had the backend's "Our servers are currently overloaded" again and again. With one ChatGPT account, magpie asks an overloaded turn again (lastRetries) and keeps Codex alive past keepHeldAfter with the stream's 200 and comments. When the retries ran out, the backend's busy status (529, or a 503 saying overloaded) went to Codex in that stream as response.failed with code server_error. Codex reads server_error as Retryable (codex-rs codex-api sse/responses_error.rs) and sent the turn five more times, each one asked three times by magpie: 18 asks of an overloaded model, then the last error alone. The backend itself says an overload in a stream as server_is_overloaded (#1418), which Codex reads as ServerOverloaded: "Selected model is at capacity. Please try a different model.", without the reconnects. streamError now gives a Responses client server_is_overloaded when the status is 529, or a 5xx whose words say overloaded (saidOverloaded). Other failures keep server_error, which Codex retries. A routing group or the codex subscription's fallbacks still take an overload before any of this, as before. This does not explain the earlier "error decoding response body". Codex says that only when the body of a 2xx fails to read. magpie's streams read clean over real TCP in every overload shape tried (see07f4d46c5, which logs a reply cut early). Ran on mote at this change rebased on1cb4d4301: gofmt; go vet darwin, GOOS=linux -tags nogui, GOOS=windows; go test -count=1 -timeout 45m ./internal/gateway: ok but for TestCodexPoolSaysTheClientsVersion, the known #4807 (the machine's own Codex 0.165.0 identity reaches it). At the pushed head (rebased onf95bacdfb, whose new commits add hub_mcp.go to the gateway, nothing of streamError): go vet darwin, linux, windows, and the overload, StreamError and Hub tests: ok. On Windows (win-run): TestCodexKeptAliveOverload*, TestStreamErrorOverloadOnly, TestCodexOneAccount*, TestCodexOwnModel*, *Overload*, *StreamError*, TestCodexReplyBrokenOffLogged, TestCodexClientGoneLogged: ok, 50 tests. Broken by hand: with the else-if turned off, TestCodexKeptAliveOverloadSaysServerIsOverloaded is red in both subtests (503 message, 529): code "server_error". Not tried: a real ChatGPT account or the real Codex client against this build. Whether gpt-6.1-sol is busy for this account only, or the same request without magpie. The Windows system proxy between Codex and 127.0.0.1 as the cause of the decode error.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,77 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// The ChatGPT backend too busy for a turn, said as a status, once Codex
|
||||
// has been kept alive with the stream's headers, reaches it as the
|
||||
// backend says an overload in a stream: response.failed with
|
||||
// server_is_overloaded, which Codex shows as the model at capacity. As
|
||||
// server_error, Codex took it for a dropped stream and sent the turn
|
||||
// five more times ("reconnecting 5/5", wjh66 on Discord).
|
||||
func TestCodexKeptAliveOverloadSaysServerIsOverloaded(t *testing.T) {
|
||||
for name, failed := range map[string]reply{
|
||||
"503 message": {503, "application/json", `{"message":"Our servers are currently overloaded. Please try again later."}`},
|
||||
"529": {529, "application/json", overloadedStatus},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
k, w := keepHeldAfter, watchEvery
|
||||
keepHeldAfter, watchEvery = time.Millisecond, time.Millisecond
|
||||
t.Cleanup(func() { keepHeldAfter, watchEvery = k, w })
|
||||
o := &overloadedBackend{replies: []reply{failed}}
|
||||
oneCodexAccount(t, o)
|
||||
retryPause = 20 * time.Millisecond // past keepHeldAfter: Codex is sent the headers
|
||||
code, body := codexPost(t, oneAccountTurn)
|
||||
if code != 200 || o.asked() != 1+lastRetries {
|
||||
t.Fatalf("%d %q, asked %d times", code, body, o.asked())
|
||||
}
|
||||
var got string
|
||||
for _, l := range strings.Split(body, "\n") {
|
||||
data, ok := strings.CutPrefix(l, "data: ")
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
var ev struct {
|
||||
Type string `json:"type"`
|
||||
Response struct {
|
||||
Error struct{ Code, Message string } `json:"error"`
|
||||
} `json:"response"`
|
||||
}
|
||||
if json.Unmarshal([]byte(data), &ev) == nil && ev.Type == "response.failed" {
|
||||
got = ev.Response.Error.Code
|
||||
if !strings.Contains(ev.Response.Error.Message, "overloaded") {
|
||||
t.Errorf("message %q", ev.Response.Error.Message)
|
||||
}
|
||||
}
|
||||
}
|
||||
if got != "server_is_overloaded" {
|
||||
t.Fatalf("response.failed code %q, want server_is_overloaded:\n%s", got, body)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Only an overload is said as one: another failure told in a stream
|
||||
// keeps server_error, which Codex retries.
|
||||
func TestStreamErrorOverloadOnly(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
status int
|
||||
msg string
|
||||
want bool
|
||||
}{
|
||||
{529, "busy", true},
|
||||
{503, "Our servers are currently overloaded.", true},
|
||||
{503, "Service Unavailable", false},
|
||||
{502, "upstream connect error", false},
|
||||
{429, "overloaded with requests", false},
|
||||
{400, "overloaded", false},
|
||||
} {
|
||||
if got := saidOverloaded(c.status, c.msg); got != c.want {
|
||||
t.Errorf("%d %q: %v, want %v", c.status, c.msg, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8872,6 +8872,15 @@ func streamError(w http.ResponseWriter, proto provider.Protocol, model string, s
|
||||
overflow := tooLong(status, msg)
|
||||
if overflow {
|
||||
ev.Code = "context_length_exceeded"
|
||||
} else if proto == provider.Responses && saidOverloaded(status, msg) {
|
||||
// The ChatGPT backend says its overload in a stream as
|
||||
// response.failed with server_is_overloaded (#1418), which Codex
|
||||
// reads as the model at capacity and stops on (codex-rs codex-api
|
||||
// sse/responses_error.rs). A busy status told once Codex has the
|
||||
// stream's headers went as server_error, which Codex retries as a
|
||||
// dropped stream: five more turns, each asked again by magpie,
|
||||
// "reconnecting 5/5" and the last error alone (wjh66 on Discord)
|
||||
ev.Code = "server_is_overloaded"
|
||||
}
|
||||
// A 413 before the headers go out is typed request_too_large
|
||||
// (writeErrorSaid). Once they have, Pi reads only this event's text
|
||||
@@ -8897,6 +8906,12 @@ func streamError(w http.ResponseWriter, proto provider.Protocol, model string, s
|
||||
makeEncoder(proto, sw, &Request{Model: model}).event(ev)
|
||||
}
|
||||
|
||||
// saidOverloaded says a failure is the vendor too busy for the request:
|
||||
// a 529, or a 5xx whose words say overloaded.
|
||||
func saidOverloaded(status int, msg string) bool {
|
||||
return status == 529 || (status >= 500 && strings.Contains(strings.ToLower(msg), "overloaded"))
|
||||
}
|
||||
|
||||
// passingSaid matches the words an agent that reads only an error's text
|
||||
// takes for a failure worth asking again (Pi's isRetryableError, #2372):
|
||||
// one of the usual statuses, a timeout, a rate limit, a busy or
|
||||
|
||||
Reference in New Issue
Block a user