From 6d7862769337d07d28464cbb64e02f3936b4826e Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 11 Nov 2026 03:16:59 +0800 Subject: [PATCH] gateway: an empty reply on two accounts of a model ends the request there (vhjjkkhg on X) Alma on Responses to Antigravity's Gemini 3.8 Flash got "an empty reply" now and then in multi-turn tool turns, and each account's in-place re-asks plus the next account took 8 to 9 tries over 10+ minutes. A reply that said nothing on a second account of the same provider's model is about the request, not the account: the model's remaining accounts are not asked (emptyAccounts = 2, `emptied` in the candidate loop). Other providers and a group's other members still are, and nobody rests (the #1221 branch is unchanged). Cause of the empty reply itself: NOT found. Chat and Responses build byte-identical Code Assist contents for a tool conversation (compared), and about 50 real-account runs in a sandbox HOME (Antigravity login only) across efforts none to xhigh, multi-user-turn tool loops over both protocols, gave no empty reply. It looks like upstream's occasional behaviour (#667 / #1221), so this commit bounds the cost and does not claim a translation fix. Run (mote-run): TestEmptyReplyOnTwoAccountsEndsTheRequest (Responses and Chat; 5 accounts), TestGeminiEmpty*, TestLateRests*, full ./internal/gateway, gofmt, go vet darwin/linux/windows (nogui). Broken by hand: with gateway.go's change reverted the new test is red (12 asks, 5 accounts tried; 8 asks and 2 accounts with it). Not tried: a real Alma turn on an account that returns the empty reply. --- docs/subsystems/gateway-routing.md | 1 + .../gateway/antigravity_empty_bound_test.go | 58 +++++++++++++++++++ internal/gateway/continuation.go | 7 +++ internal/gateway/gateway.go | 28 +++++++-- 4 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 internal/gateway/antigravity_empty_bound_test.go diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md index 2e4b5f1fb..61d6910bd 100644 --- a/docs/subsystems/gateway-routing.md +++ b/docs/subsystems/gateway-routing.md @@ -226,6 +226,7 @@ recorded as a prediction failure (`noPrediction`). - The agent's request headers a provider passes on (`PassHeaders`, see [providers and accounts](providers-accounts.md); 3jRzfF52Qx on X) go with every try `forwardOnce` makes, so chat, responses, messages, count_tokens, a group's members, fallbacks, signed-in accounts and a plugin's fetch all take them: `forwardOnce` puts the agent's headers in the try's context under the try's provider id (`provider.WithClientHeaders`), and `Provider.Sign` passes the ones that provider lists and no other's. Not carried: embeddings, images, video and the Codex backend relay, which don't go through `forwardOnce`. `TestPassHeadersReachTheProvider`, `TestPassHeadersOnlyToTheirProvider`. - A streamed request is never left silent while its vendor says nothing. `holdWriter.watch` runs beside each try: past `keepHeldAfter` (3s) it sends a held try's agent the stream's 200 and SSE comments (`keepAlive`), one every `keepHeldEvery` (5s), none of the try, so another candidate may still answer in the same stream. It was 15s, and a proxy between the agent and magpie that hangs up on a request with nothing back for about 10s ended every turn slower to its first event: Codex on Windows sends 127.0.0.1 through a Clash-style app's system proxy, `127.*` in its bypass list or not, and its turns ended 499 (mrten_95615 on Discord; `TestHeldStreamHeardBeforeAProxyCuts`). A failure before it is still a status; once the reply passes, it puts a comment between two of its lines after `keepaliveEvery` of quiet. It stops after `keepaliveLongest` (5 minutes) with nothing from the vendor. A translated stream (`streamTranslated`) whose upstream has begun its reply and then says nothing at all, not even a comment (a relay that sends the rest of a long reply in one burst at its end), is kept alive in the client's own protocol by a ticker beside its reader (`keepThroughSilence`): every `keepaliveEvery` it sends the client's keepalive (`enc.keepalive`: a ping for Anthropic, `response.in_progress` for Responses, a comment for Chat, nothing for Gemini), which also counts as the try heard from, so the held stream's comments go on too; it stops once the upstream has been silent for `translatedQuietLongest` (30 minutes), past the 10 minutes `upstreamHeaderWait` gives a vendor to begin and long enough for a long reasoning turn sent whole at its end, after which the client's own timeout ends the wait (youyo.p on Discord: before, Claude Code heard only comments, which its event watchdog doesn't count, and gave up 300s on; `TestTranslatedSilenceKeptAliveForABound`). An upstream that has answered its headers but sent no byte yet is still waited for under the held stream's comments alone (`notAnAPIReply` reads its first bytes before the reply is translated). An Anthropic client is sent a ping at most once each `pingEvery` (1 minute), comments between, and none before `message_start`: Claude Code's watchdog counts only 30 pings in a row as life, and a ping on every upstream keepalive spent them in the first minute; the SDKs' `MessageStream` fails on any event before `message_start` (`anthropicEncoder.keepalive`, `TestTranslatedStreamKeepsClientAlive`). A try waiting for its key's or account's slot or for room in its minute (`lanes.take`, `rpms.wait`) is kept alive the same way (`keepQueued`), for as long as it waits; once the 200 is out, the try is held, and its failure or its queue turning it away reaches the agent as the stream's error (`failTo`), not a status (coeo91 on Discord). A wait shorter than `keepHeldAfter` sends nothing, so its 429 keeps its `Retry-After`. A proxy in front such as Cloudflare (125s) otherwise ends the request (#947). Gemini streams get no comments (#934). A vendor that then ignores `stream:true` and answers 200 with its reply whole has it sent as the agent's stream (`wholeAsStream`: Chat, Responses, Anthropic), not as the stream's error, while a reply under a type that says neither JSON nor a stream is held as a stream when its first bytes are one (`sseStart`), read event by event like one that says so, so an error among its frames still goes to the next candidate (#1418: it went through at once); a Chat stream a vendor ends with `finish_reason:"error"` — WorkBuddy's and a DeepSeek harness's word for a turn it failed, not finished (#2471) — is the failure the word says, held for the group's next candidate, and nobody rests, as an empty reply's (`TestFinishReasonErrorFailsOver`); a 200 that is no reply of the protocol's fails as a translated reply that didn't stream does (502, "… did not stream"), for the next candidate to answer, and the last one's reaches the agent as the stream's error. A held stream that has sent nothing but the frames before a reply (`response.created`, `response.in_progress`, `codex.rate_limits`, pings, an empty part begun, and any event `streamEvent` doesn't know to carry text, reasoning, a call or a reply's end (`replyEvent`), or an item not known that isn't a call or a tool's (`streamPart.said`): `eventLead`; Aliceonly on #1418: an unknown event was taken for content and let a frames-only 200 through, and its `server_is_overloaded` reached Codex with five candidates left) stays held as long as its agent is kept alive, up to `holdLead` (4 minutes, under the 300s Codex waits for an event; `keptQuiet`), so a `server_is_overloaded` that comes after it is a failure the next candidate answers (#1418: let through at 15s, the ChatGPT backend's failure 36s in ended Codex's turn with sub2api, next in the group, never asked). A stream whose agent can't be kept alive (Gemini's) is let through after `holdLongest` (15s), as before. Codex counts only events toward that 300s, not comments, so the bound is the request's, not each try's: once Codex on Responses has heard no event for `agentQuietMost` (4 minutes) since the request began or its last event (`keptAlive.tooQuiet`), the try in hand is let through (`scan`, `keepQuiet`), and no group replan or same-one retry is taken whose pause would end past it (fadenoob on Discord: held tries and replan pauses added up past 300s and Codex reconnected on "idle timeout waiting for SSE"). A translated reply whose upstream stream stops before it said its reply had — an Anthropic one with no stop_reason and no message_stop, a Responses one with no `response.completed`, the same two a relayed one is told by (`sniff.whole`; a Chat stream may end without `[DONE]` and be whole), a Gemini or Code Assist one whose last chunk has no candidate's `finishReason` (`geminiEnds`, #1643: `usageMetadata` is no end, Vertex AI sends it on every chunk; a chunk with no candidate at all is the empty reply's to answer, #667), and a relayed Gemini one told the same way (#1644; it ends in Gemini's own `{"error":{"code":502,…,"status":"UNAVAILABLE"}}` data line from `streamFailure`, `TestGeminiRelayEndedShort`; whatever a relayed stream gets appended, that error or a filled-in `finish_reason`, begins after a blank line, two newlines when the upstream's last write stopped inside a line, so it is an event of its own rather than more of the half-written one, and the half event itself is dropped: a relayed stream holds the line the upstream never ended back, puts it out when the reply ends whole or is gathered (`TestGrokPluginNonStreamLastLineUnended`), and throws it away when a failure is appended in its place, for no client can parse it — pi read "malformed server-sent event JSON" off a stream Z.ai reset mid-line, and died before the error after it; a line whose data parses (its JSON whole, or `[DONE]`) is no half event and goes out before the failure (#2446, #2580, `TestPassthroughStreamCutMidLine`, `TestChatStreamCutMidLineLeavesNoHalfEvent`, `TestChatStreamCutAfterWholeEventKeepsIt`, `TestGeminiCompatFinishAfterPartialLine`), and a Chat one from Gemini's OpenAI-compatible API (`geminiCompat`) with no `finish_reason`, relayed or translated (`saysItsEnd`; Linka on Discord: the upstream hung up between a whole function call and its `finish_reason`, and Pi threw the call away as "Stream ended without finish_reason"; that API counts the usage only once the generation is done, so when the last chunk carried it only the `finish_reason` was lost and it is filled in, `tool_calls` after a call and `stop` otherwise, as a relayed chunk before `[DONE]` or a translated reply's end, and the reply counts as whole (`chatTail`); only one with no usage at its end is a cut, `TestGeminiCompatRelayEndedShort`, `TestGeminiCompatTranslatedEndedShort`) — ends the turn with "the reply ended before it was complete" (`errEndedShort`, `TestResponsesUpstreamEndedShort`, `TestGeminiUpstreamEndedShort`), asked again in place where the upstream goes on from a prefill (`continuation.go`). only one with no usage at its end is a cut, `TestGeminiCompatRelayEndedShort`, `TestGeminiCompatTranslatedEndedShort`), and a Chat one from Command Code's API (`commandCodeHost`), whose slow starts a killed worker ends with no closing chunk at all, relayed (esp32gallery on #2471: 20 of 665 requests in a day, every ledger row a 200 with no stop and no error while the client read "Stream ended without finish_reason"; `TestCommandCodeRelayEndedShort`, `TestCommandCodeTaillessFailsOver`) — ends the turn with "the reply ended before it was complete" (`errEndedShort`, `TestResponsesUpstreamEndedShort`, `TestGeminiUpstreamEndedShort`), asked again in place where the upstream goes on from a prefill (`continuation.go`). A client that asked for no stream is told the same 502 of such a cut (`translate`, `TestNonStreamEndedShort`, `TestGeminiNonStreamEndedShort`), rather than handed what came as its whole reply. One such ending is not a cut: a request capped at a short probe's worth (`cutVoidTokens`, 1024) whose reply spent some of it (thought, said or called something) and then ended cleanly with no end said ended at its length (`endsAtProbeCap`), and goes as a `length` stop, translated whole or streamed, and as a `response.incomplete` at `max_output_tokens` when a Responses plugin's stream is asked whole (`gathered`). Open Design's glm-5.3-flash always thinks, spent a model test's 16 tokens on it and ended after `content_block_stop`, so every plain test of it was this 502, waited out through the patience (plugins#827; `TestProbeCapEndsAtLength`, `TestGatheredProbeCapIncomplete`). A reply asked for more, one that spent nothing, or a Gemini or Code Assist one (Gemini ends every reply with its finishReason, `MAX_TOKENS` included, so one without it was cut: `TestGeminiUpstreamEndedShort` asks for 256) is still the cut. A relayed stream (passthrough to an agent of the same protocol) is still relayed as it came, with no end added (#5736). A translated reply from an Anthropic or Responses upstream that ended but said nothing (no text, call, search or image) and counted no token at all is no reply either, whatever its end says (`repliesCounted`, #2086: an Anthropic-compatible proxy's 200 ended a Codex turn as `response.completed` with no output, no usage and no served model, and Codex didn't ask again). It is the empty reply's to answer (#667): asked again in place, then failed with "an empty reply", streamed or not, for every client (`TestUncountedEmptyReplyFails`, `TestUncountedEmptyReplyFailsEveryClient`). Claude's own empty `end_turn` counts its prompt and stays a whole reply (`TestWellFormedStreamsStillComplete`). A relayed one is read the same way once: a Responses stream whose `response.completed` carries no output and counted no token is no reply either, failed before it is let through, held for the group's next candidate, and nobody rests (#2471, MurmuredVelpro: WorkBuddy AI's account ended Codex's turn completed with `output: []` and all-zero usage three times running, the healthy members never asked; `TestEmptyCompletedFailsOver`). A reply passed through in its own protocol isn't read this way, but for that completed. - A vendor whose API is the client's own (a relayed request, or a translated one whose upstream error shape is the client's: Chat and Responses share OpenAI's) has its JSON error body go to the client as it came (`writeVendorErrorFrom`, ne9ko9 on Discord): its status, its own `type`, a numeric `code`, `param`, `request_id` and every field magpie knows nothing of. Only `error.message` is magpie's: the provider's name before the vendor's words (a describer asking for another model, the Claude sign-in rewording in `claude_signin.go` and the agent read it there), with a note where magpie has one (an account's `Explain`, a region note, the wrong-endpoint note, `saysBusy`, a 413's byte-limit hint). And a prompt too long for the model (`tooLong`) sets only the fields that make the client's agent compact: status 400, and `type`/`code` (OpenAI's `context_length_exceeded`), `type` and the "prompt is too long: " lead (Anthropic's), `code`/`status` (Gemini's), each spliced in place (`setErrorField`) so every other byte stays. A body that isn't JSON, or not in the client's shape, and another API's error are rebuilt in the client's shape (`writeVendorError`) as before. An error status the hold reads as the safety filter's refusal (`policyRefusal`) is still told in magpie's words once no one else answers ([`kept_error_test.go`](../../internal/gateway/kept_error_test.go)). +- A reply that said nothing (`emptyReply`, #667) on `emptyAccounts` (2) accounts of one provider's model running is about the request, not the account: the candidates of that model that remain aren't asked (`emptied` in the candidate loop; other providers and the group's other members still are), and nobody rests (vhjjkkhg on X: Alma's Responses turns to Antigravity's Gemini 3.8 Flash went round 8 to 9 accounts over 10+ minutes). `TestEmptyReplyOnTwoAccountsEndsTheRequest` in `internal/gateway/antigravity_empty_bound_test.go`. - A provider of a key whose errors the user leaves to the client (`errors=pass`, `Provider.PassErrors`, set in its editor's Advanced "Errors" menu or with `magpie provider set errors=pass`; `TakesPassErrors` keeps it to a provider of a key, never a signed-in account or a plugin's; ne9ko9 on Discord) is asked once. The candidate loop's `holdWriter` holds nothing for it (`pass := c.p.PassesErrors()` at the hold choke point; only a stream already begun is held), so no retry, wait, re-plan, refusal handover or next member answers for it; `forward` asks once after `dsRetryGone` (magpie's own file ids), `passthrough` and `forwardTranslated` return the first failure without a re-ask in another shape, `streamTranslated` neither continues nor asks again after an empty reply, and `restAfterMarked` rests none of its keys. Its error goes through `passError` (`pass_errors.go`): on the client's own API the vendor's status, Content-Type and body as sent; on another, the client's shape with the vendor's status, type, code (a number too), param and words, nothing inferred (no too-long, busy or 413 words). Retry-After and the rate-limit headers go with it. `TestPassErrorsAskedOnce`, `TestPassErrorsNotInferred`, `TestPassErrorsOtherAPI` in `internal/gateway/pass_errors_test.go`. - A vendor's error keeps its `code` and `param` on its way to an OpenAI-shaped client (`writeVendorError`), where `writeError` used to set both to null: a status error relayed or translated, and a request refused inside a Responses stream. A Responses stream's `error` event or failed response whose error is of type `invalid_request_error` is the request at fault (`requestRefused`, read by its type, not its words): its `Event` carries status 400 and the vendor's error (`Event.Said`), so a client answered whole gets the vendor's 400 with its code and param (the whole-translated path wrote 502 `api_error`), a reply cut by it isn't resumed (`continuation.again`), and a translated stream's error says the vendor's type, code and param (`saidError`), so `holdWriter` reads it as the 400 it is. Before, the hold read magpie's `api_error` as a 502: the same request was sent three times, then to the other accounts, and every one rested (magpie-releases#18: the ChatGPT backend answers `access_programs` naming a program the workspace hasn't got with a 200 stream whose error is `access_program_not_enabled`). Asked once, nobody rests ([`codex_access_programs_test.go`](../../internal/gateway/codex_access_programs_test.go)). - An error that reaches the agent in a stream already begun can't carry its status, so `streamError` says it in the words (`saysPassing`, #2372, zminds): for a status that may pass (408, 429, 5xx) whose text names none of the words a text-judging agent retries on (Pi decides by its `errorMessage` alone), it appends `(: you can retry your request)`; a request's own fault (400, 401, 404 …) and a text that already says so are left as they were. `TestStreamErrorSaysItPasses` holds Pi's own lists; `TestGroupLastFailureInStreamSaysItPasses` runs a group whose last member fails after the keepalive. A 413 byte cap in that stream says `request_too_large` in the error text, and Chat and Anthropic name that type, so Pi compacts; Gemini keeps its own status shape (`TestStreamedByteCapSaysRequestTooLargeToPi`, `TestStreamErrorByteCapInEveryShape`). Responses' `response.failed` code for it is `context_length_exceeded`, the one code Codex compacts on: with `server_error` it sent the same body five more times ("reconnecting 5/5"), each refused, and never compacted (celestial_eagle_99230 on Discord, an nginx 413 page in front of a DeepSeek model; `TestCodexByteCapInStreamCompacts`). An overload told so (a 529, or a 5xx whose words say overloaded, `saidOverloaded`) is `server_is_overloaded` there, as the ChatGPT backend says one in a stream: Codex shows the model at capacity and stops, where `server_error` had it reconnect five times, each turn asked again by magpie, and end on the last error alone (wjh66 on Discord; `TestCodexKeptAliveOverloadSaysServerIsOverloaded`). Codex reads a 413, or a 400 `context_length_exceeded`, told by HTTP status as an unexpected status or an invalid request and compacts on neither, so when Codex (`fromCodex`) asked for a stream, a byte cap or an overflow is told in a stream even before one began (`keptAlive.compactsInStream`, `failTo`; `TestCodexByteCapBeforeStreamCompacts`). Another client keeps its status (`TestByteCapBeforeStreamStaysStatusForOthers`), and so does magpie's own summary ask for a compaction (`keptAlive.whole`, set for `wantsWhole`), which is never sent a 200 or a keepalive either: `codexCompact` reads a 413 as its cue to ask the conversation as text and then compact without a model, and told in a stream it failed 502 instead (#4862, `TestCompactionOverByteCapEveryTime`, `TestCompactionOverByteCapSlowFitting`). Nobody rests for either. Wherever the protocol says a model with the error (Chat's first chunk, Anthropic's `message_start`, Responses' `response.created` and the events after it), it is the model the agent asked for, as `serve` has it, an effort on it kept (`keptAlive.model`; on Codex's own sign-in, the one Codex wrote) (#3728, jilen: with `"model":""` fx took Chat's first chunk for a broken one and stopped there; `TestStreamErrorNamesTheModel`, `TestKeptAliveChatErrorNamesTheModel`, `TestKeptAliveChatOnCodexErrorNamesTheModel`, `TestKeptAliveCodexErrorNamesTheModel`). An error after a reply that already went, a loop cut's, still starts a message of its own after the vendor's, under a new id and no model (#3792). diff --git a/internal/gateway/antigravity_empty_bound_test.go b/internal/gateway/antigravity_empty_bound_test.go new file mode 100644 index 000000000..546fdfc0b --- /dev/null +++ b/internal/gateway/antigravity_empty_bound_test.go @@ -0,0 +1,58 @@ +package gateway + +import ( + "io" + "net/http" + "net/http/httptest" + "strconv" + "strings" + "sync/atomic" + "testing" +) + +// A reply that said nothing on two accounts running is about the request, +// not the account: the third, fourth and fifth aren't asked, as each ask +// (an in-place retry or two, then the next account) took minutes on a long +// conversation (vhjjkkhg on X: 8 to 9 tries, 10+ minutes, from Alma on +// Responses). No account rests for it. +func TestEmptyReplyOnTwoAccountsEndsTheRequest(t *testing.T) { + users := []string{"u1@example.com", "u2@example.com", "u3@example.com", "u4@example.com", "u5@example.com"} + for _, path := range []string{"/v1/responses", "/v1/chat/completions"} { + t.Run(path, func(t *testing.T) { + var asked atomic.Int32 + s, _ := antigravityGroupFor(t, users, "gemini-3.8-flash", func(w http.ResponseWriter, r *http.Request) { + asked.Add(1) + w.Header().Set("Content-Type", "text/event-stream") + io.WriteString(w, sse( + `data: {"response":{"candidates":[{"content":{"role":"model","parts":[{"text":"thinking...","thought":true}]}}]}}`, + `data: {"response":{"candidates":[{"content":{"role":"model","parts":[]},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":10,"thoughtsTokenCount":5}}}`)) + }) + body := `{"model":"antigravity/gemini-3.8-flash","stream":true,"input":"hi","messages":[{"role":"user","content":"hi"}]}` + rec := httptest.NewRecorder() + s.Handler().ServeHTTP(rec, httptest.NewRequest("POST", path, strings.NewReader(body))) + if !strings.Contains(rec.Body.String(), "an empty reply") { + t.Fatalf("not told the empty reply: %d %s", rec.Code, rec.Body.String()) + } + // two accounts, each asked again in place a few times (the old + // code asked all five: 12 asks) + if n := asked.Load(); n > 8 { + t.Errorf("an empty reply went round %d asks, over two accounts' worth", n) + } + r := lastRoute(s) + accounts := map[string]bool{} + var ids []string + for _, x := range r.Tries { + accounts[x.ID] = true + ids = append(ids, x.ID+"/"+strconv.Itoa(x.Status)) + } + if len(accounts) > 3 { // the group's own entry, and two accounts + t.Errorf("%d tries: %v", len(r.Tries), ids) + } + for _, u := range users { + if _, ok := restOf("antigravity@" + u); ok { + t.Errorf("antigravity@%s rested for an empty reply", u) + } + } + }) + } +} diff --git a/internal/gateway/continuation.go b/internal/gateway/continuation.go index 974cf6207..60cefcf20 100644 --- a/internal/gateway/continuation.go +++ b/internal/gateway/continuation.go @@ -56,6 +56,13 @@ func emptyRetries(w http.ResponseWriter, ctx context.Context) int { return streamRetries } +// emptyAccounts is how many accounts of one model may answer a request +// with a reply that said nothing before the rest of its accounts aren't +// asked: the same conversation ends empty on whichever account it is sent +// to, and each ask took minutes on a long one (vhjjkkhg on X: 8 to 9 tries +// over 10+ minutes). The others of its group, and other providers, are. +const emptyAccounts = 2 + // loopReasks is how many times a reply whose reasoning was stuck in a // loop (loopGuard) before it said anything is asked again in place, rather // than ended with the loop's error. diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index fdc16f5d0..e9a715dcb 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -3327,12 +3327,13 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro roomFor, roomCap := "", 0 // the key or subscription account the last try went to (#557) providerKeyID, providerKeyName, providerAccount := "", "", "" - var other *Try // the first failure that wasn't an allowance run out - var forbade []forbidden // the plain 403s and 5xx rested so far (forbiddenAlike) - sameRefusal := false // the last try's 5xx was a mate's word for word: the request's - autoReset := resetFirst != nil // a Codex or Claude reset looked at, once a request - creditsAsked := map[string]bool{} // Codex accounts asked again onto their credits, once each (creditsAgain) - regionAsked := map[string]int{} // a provider's model refused for where the request came from, times this request (#5182) + var other *Try // the first failure that wasn't an allowance run out + var forbade []forbidden // the plain 403s and 5xx rested so far (forbiddenAlike) + sameRefusal := false // the last try's 5xx was a mate's word for word: the request's + autoReset := resetFirst != nil // a Codex or Claude reset looked at, once a request + creditsAsked := map[string]bool{} // Codex accounts asked again onto their credits, once each (creditsAgain) + emptied := map[string]map[string]bool{} // a provider's model's accounts whose reply said nothing, this request (emptyAccounts) + regionAsked := map[string]int{} // a provider's model refused for where the request came from, times this request (#5182) // the subscription/model pairs an account refused as a model it doesn't // serve, for the accounts whose own list lacks it to be asked next // (unlistedNext); none for a request pinned to an account, a @@ -4829,6 +4830,21 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro skipped = append(skipped, c.label()+": "+call.Error) continue } + if !last && hw.failed() && strings.Contains(call.Error, emptyReply) { + // said by a second account of the model, it is about the + // request and no account: the rest of that model's accounts + // are not asked (emptyAccounts); other providers and models + // still are + ek := c.p.ID + "\x00" + c.model + if emptied[ek] == nil { + emptied[ek] = map[string]bool{} + } + emptied[ek][c.who()] = true + if len(emptied[ek]) >= emptyAccounts { + cands = append(cands[:i+1:i+1], notMates(cands[i+1:], c)...) + last = i == len(cands)-1 + } + } if !last && hw.failed() && strings.Contains(call.Error, emptyReply) { // a reply that said nothing is a failure of the model or // request, not the account (#1221): the account doesn't rest,