Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

gateway: a large passing reply is not read for why it failed, so a 24MB JSON reply reaches its client again (#2551)

yetone7ac20247a9c1
diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go
index 63fe7f7e3..b389f5abe 100644
--- a/internal/gateway/gateway.go
+++ b/internal/gateway/gateway.go
@@ -3231,8 +3231,11 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
continue
}
}
- if f := failure(hw.code(), hw.errBody()); last && len(small) > 0 && pin == "" && other == nil && hw.failed() && !hw.passing && !hw.turnedAway && !hw.refused && !outgrew &&
- (f == failQuota || f == failCredit || try.Fail == failQuota || try.Fail == failCredit) {
+ // the body is read for why last, once the try is known to have
+ // failed: a reply held whole that passed is the whole reply, and
+ // failure over a 24MB one held its client past its timeout
+ if last && len(small) > 0 && pin == "" && other == nil && hw.failed() && !hw.passing && !hw.turnedAway && !hw.refused && !outgrew &&
+ (try.Fail == failQuota || try.Fail == failCredit || slices.Contains([]string{failQuota, failCredit}, failure(hw.code(), hw.errBody()))) {
// every one with room is out of its allowance: those roomy
// left out as too small for the request are asked after all,
// those not resting, for the agent to be told to compact