diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index d3e7e1f2c..469576d44 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -3756,9 +3756,12 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro // rests as they did: the relay's moment of 503 had the agent told // it, or the last one's 429, while the relay would answer a moment // on (dbydd on Discord: an in-order group of sub2api relays, a - // Codex account out of its quota last) + // Codex account out of its quota last). One already resting out of + // its allowance, asked only as the one back soonest, isn't: the + // members before it were asked again as the last that may answer + // (spentAfter) and the agent is told theirs lastSpent := last && isGroup && len(busyNow) > 0 && !hw.passing && hw.failed() && !busy(hw.code(), hw.errBody()) && - slices.Contains([]string{failQuota, failCredit}, failure(hw.code(), hw.errBody())) + slices.Contains([]string{failQuota, failCredit}, failure(hw.code(), hw.errBody())) && !spentAfter([]candidate{c}) if _, same := passing(hw.code(), hw.header, hw.errBody(), again); last && patience > 0 && !protected && !hw.turnedAway && !hw.refused && hw.failed() && (busy(hw.code(), hw.errBody()) || lastSpent) && (isGroup || !codexReset(hw.code(), hw.errBody())) && (len(busyNow) > 0 || waitsOf(c.patience, patienceFallback) > 0 && !same) { @@ -3886,15 +3889,17 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro continue } } - if last && !held && !hw.passing && hw.failed() && quotaStatus(hw.code()) && (try.Fail == failQuota || try.Fail == failCredit || failure(hw.code(), hw.errBody()) == failQuota || failure(hw.code(), hw.errBody()) == failCredit) { + if last && !held && !hw.passing && hw.failed() && quotaStatus(hw.code()) && (c.p.Account == nil || !hw.turnedAway && try.Fail != failPrompt) && (try.Fail == failQuota || try.Fail == failCredit || failure(hw.code(), hw.errBody()) == failQuota || failure(hw.code(), hw.errBody()) == failCredit) { // the last key left is out of its allowance: it rests as the // ones before it did, for the next request to be answered // from the rests until the first of them is back (#1772). An // account too: not resting, it stayed the one a relay's moment // of failure went on to, and its 429 the agent's, request // after request, while the relay before it would answer - // (dbydd on Discord). quotaHeld still holds keys alone, and - // autoReset lifts the rest of an account it spends a reset of + // (dbydd on Discord), once its own refusal is read as out of + // quota or credit (not Antigravity's 429 to a prompt). + // quotaHeld still holds keys alone, and autoReset lifts the + // rest of an account it spends a reset of rest := s.restAfterMarked(c, hw.code(), hw.header, hw.errBody(), hw.sharedPool) try.Fail, try.Rest = rest.Why, &rest }