Commit Graph
3 Commits
Author SHA1 Message Date
yetone 4fbb75c3a8 gateway: Codex's 507 "exceeded request buffer limit" is asked again and told as a 503, not relayed as it came (#2034, sparrowu93)
sparrowu93's pi, on a ChatGPT account, stopped on
"Codex: 507 Insufficient Storage: exceeded request buffer limit while
retrying upstream". That text is Envoy's (ChatGPT's front): its first
try at the backend failed, and the body was more than it buffers to
try again. It is the same backend failure as #1628's 503 "reset before
headers", which magpie already asks again for without resting anybody,
only for a body the front couldn't retry itself. magpie relayed the 507
as it came; pi's _isRetryableError (pi-coding-agent 0.73.0,
agent-session.js) matches 503 but not 507 or these words, so the turn
just ended.

codexDropped now reads that 507 (by Envoy's words alone, any size, since
the 507 itself says the body was large) the way it reads the large
request's 503: the accounts loop asks the next account and the last one
again, nobody rests, and the agent is told a 503 with Envoy's words and
what may help (/compact, fewer or smaller images). The relayed path
(codexUpstreamOn, Codex's own sign-in) asks again the same way: the two
share edgeMayDrop/edgeSaidDrop. A 507 in other words is relayed as it
came. gateway-routing.md says so.

Run:
- New TestCodexUnbufferedAskedAgain, TestCodexUnbufferedTold503,
  TestCodexUnbufferedRelayed, TestCodexOther507Stays, with the
  reporter's literal Envoy text as the fixture. On the old code the first
  three fail: "status 507, want 200 pong: {...\"message\":\"Codex: 507
  Insufficient Storage: exceeded request buffer limit while retrying
  upstream\"...}" (the reporter's message byte for byte), and
  "507 once: 507 ... tried [acct-1]". With edgeSaidDrop matching every
  507, TestCodexOther507Stays fails. Restored, all pass, with #1628's
  TestCodexReset* tests.
- go test -tags nogui ./internal/gateway/ (sandbox HOME, pinned caches),
  gofmt -l, go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet
  (with and without nogui) on internal/gateway.
Not tried: a real 507 from ChatGPT (it needs the backend to fail a
request over Envoy's buffer, which can't be made to happen on purpose).
2026-10-14 05:37:00 +08:00
yetone 8029d98b7e gateway: a large Codex request ChatGPT closes on is asked again, not told 413 (#1628, ScarfQian)
ScarfQian (#1628, v0.1.1184, Codex desktop computer use on a ChatGPT
subscription): a 1.1 MiB turn answered with ChatGPT's 503 "upstream
connect error or disconnect/reset before headers. reset reason: remote
connection failure" came back as a2b96139c's 413 "dropped this 1.1 MiB
request ... magpie didn't retry it". Codex doesn't retry a 4xx, and every
later turn carries the same screenshots, so each one got one try and the
same 413 and the conversation was stuck.

a2b96139c took that 503 as deterministic for bodies of 1 MiB or more from
one report (ylorn: every turn past ~1 MiB, also without magpie). The
evidence says it isn't the request's: from here a Pro account answered
bodies of 0.5 to 20 MiB (a2b96139c's own body); Codex's own client sends
>1 MiB computer-use turns to the same endpoint; ScarfQian's other tool got
a 200 on the 9th try after 8 of these 503s; and "remote connection
failure" is Envoy failing to reach the backend, not a size check. So it is
transient, on some networks/times more than others. Nothing was remembered
per session or size: the "session keeps failing" was the history carrying
the images into every next turn, each refused 413 at once.

Now codexDropped leaves the 503 a 503, with a message that says the
backend closed the connection on this N MiB request, that magpie asked
again without resting the account, and, if it keeps happening, /compact or
shrink the images. In the accounts loop a large request's reset moves to
the next account without resting this one (ylorn's acct-1 rest stays
fixed); the last one left is asked again as for any 503 (lastRetries). On
the passthrough (Codex's own sign-in alone) it is asked again up to
lastRetries times after retryPause<<n. Codex then asks again itself for
the 503. A small request's reset is unchanged.

Tests (codex_dropped_test.go, a backend answering the literal 503 to
bodies over 1 MiB the first N times):
- TestCodexResetBigBodyAskedAgain: two accounts, closed on twice then
  served: 200, asked acct-1,acct-2,acct-2, nobody rests. Old code: 413
  after one try.
- TestCodexResetBigBodyStays503: closed on always: 503 with the advice,
  asked acct-1 then acct-2 3x, nobody rests; the next turn as large goes to
  acct-1 and is answered once the backend takes it. Old code: 413.
- TestCodexResetBigBodyRelayed: sign-in alone, closed once: 200 on the
  2nd try; always: 503 after 3 tries. Old code: 413 after one.
Broken by hand: old code -> all three red; the no-rest branch off -> acct-1
rests (and the next turn goes to acct-2); the passthrough retry off ->
Relayed red.

Run: go test -tags nogui ./internal/gateway, gofmt -l, go vet -tags nogui
with GOOS=linux and windows on ./internal/gateway. Not tried: the
reporter's network or a real ChatGPT reset (none reproduces on demand);
what Codex desktop shows after its own retries of the 503.
2026-10-11 22:54:49 +08:00
yetone a2b96139c9 gateway: a Codex request ChatGPT drops for its size is told as too large, not retried or rested (ylorn on Discord)
ylorn (Discord #general, v0.1.1179): through a ChatGPT account, every
turn a PNG screenshot took past about 1 MiB was answered

  HTTP/2 503  content-type: text/plain  server: cloudflare
  upstream connect error or disconnect/reset before headers. reset reason: remote connection failure

also without magpie, and the same screenshot as a JPEG went through.
magpie took that 503 as the backend's trouble: with two accounts on, the
turn was asked of acct-1, then of acct-2 three more times, acct-1 rested
for it, and the next turn moved to acct-2. The same bytes are dropped
the same way on every account, so none of that could help, and the
agent was handed a 503 it retries again with the same body.

codexDropped (codex_dropped.go) makes a 503 whose body says "upstream
connect error or disconnect/reset before headers", to a request of
1 MiB or more, the 413 it stands for, with a message saying the request
was dropped for its size (in MiB), that magpie didn't retry it or rest
the account, and to /compact or remove or shrink the images (a JPEG in
place of a large PNG screenshot). It runs on a ChatGPT account's replies
in forwardOnce (the accounts loop, any agent) and on the ChatGPT
passthrough in codexUpstreamOn (Codex's own sign-in alone). A 413
already skips the other accounts of the same provider and rests nobody,
and Codex doesn't retry a 4xx. The same 503 to a smaller request stays
the 503 it is, retried as before.

1 MiB isn't the backend's limit for everyone: from here, on a Pro
account, gpt-6-astra direct to chatgpt.com/backend-api/codex/responses
answered 200 to bodies of 0.5 to 20 MiB, plain and zstd, and to
3456x2234 PNG screenshots up to 5.6 MiB. So nothing is refused before
sending; only this drop, on a body this large, is taken as the
request's.

Tests (codex_dropped_test.go), with an httptest backend that answers
ylorn's literal 503 (text/plain, Server: cloudflare) to bodies over
1 MiB:
- TestCodexDroppedBigBodyIsTheRequests: two accounts, a 1.2 MiB turn is
  413 with the message, asked of acct-1 once, nobody rests, and the next
  small turn goes to acct-1. On the old code: 503, asked
  [acct-1 acct-2 acct-2 acct-2], acct-1 rested, next turn on acct-2.
- TestCodexDroppedBigBodyRelayed: Codex's sign-in alone, 413 with the
  message (old code: the 503 relayed).
- TestCodexEdgeResetSmallBodyStays503: a small body's 503 is relayed.

Run: go test -tags nogui ./internal/gateway (new tests red before, green
after), gofmt -l, go vet -tags nogui with GOOS=darwin, linux and windows
on ./internal/gateway. Not tried: ylorn's own network or account, where
the drop happens.
2026-10-11 14:32:57 +08:00