ac4af582301a4e8a29245dbba767eba31334ddf9
12
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
859b292d91 |
gateway: the Qoder plugin's queue answer ends a group's patience rounds (#5346)
#5346, hardy20260000: a Qoder route of 217 accounts (routing=order) asked one request up to 656 times, 20 GB of re-uploaded bodies a day. When magpie has another candidate, the Qoder plugin answers Qoder's queue code 10605 at once with a 503 + Retry-After (#4049). busy() took that for a moment's trouble, so once every member had given way the group's patience asked all of them again, one whole round after another, re-sending the body on every account each round. Now busy() leaves the plugin's queue answer alone: each member is asked once, and the last one, asked untold, has the plugin wait the queue out as Qoder's own client does (polling its queue status, not re-sending the body), then gets its same-one retries. Changed from ggbdpq's patch: it matched `\bqueue|排队` in any provider's 5xx. A relay's "Request queue is full" or "当前排队人数较多" is the overload a pause mends, and would have lost its patience. The match is the plugin's own words now ("queued the request", "this plan's queue:"), and the tests use the plugin's real errorResponse body for both its forms (isQueued, and the service out as in testdata/qoder_queued_10605.json) instead of an invented message. Not changed: the walk itself. With patience=off (the reporter's setting now) a request still asks each account once until one answers, ~20x on this route; that is the routing group finding a free account, and a per-request attempt budget is a separate decision. Run (mote, -tags nogui, sandboxed by the package's TestMain): - TestQueuedGroupAsksEachMemberOnce/{queued,busy}: 5 asks, 503 told. - TestOverloadedGroupStillReplans/{overloaded,queue full,排队}: ok. - Broken by hand: without `!queued(body)` both queued cases FAIL "a queued group asked 39 times, want 5 at most"; with the patch's broad regex, "queue full" and 排队 FAIL "asked 5 times, want more than 5". Restored, green. - -run Queued|Overloaded|Plugin|Qoder|Patience|Replan|Single|Busy| Fallback|Nested|Affinity|Codex busy|Shared|Retry: ok. - gofmt -l clean; go vet -tags nogui, GOOS=linux -tags nogui and GOOS=windows vet of internal/gateway: clean. Not tried: a real Qoder queue on a many-account route; the full suite. Co-authored-by: ggbdpq <ggbdpq@gmail.com> |
||
|
|
d45e74d89f |
gateway: a length cut that said nothing is not a completed reply (#2972)
What changed: a Chat reply cut at its length having said nothing — no
text and no call, only thinking, or nothing at all — fails at once, on
the translated paths and on the passthrough Chat→Chat relay, asked
again nowhere: the error in the client's own protocol, a group's next
member asked, nobody rested, and the same one not asked again after a
moment (the void fails the same every ask, as one that didn't stream
does). It fails only past a short probe's worth: a reply that spent no
more than cutVoidTokens, of a request capped at no more, is a probe's
answer — a title's cut is wanted, the response.incomplete it was
(#1466) — and goes as it came. A length cut that said something is
still the truncation it always was.
Why: qoder/dfmodel ended four replies of one dsh turn with 48,000
output tokens each, every one of them reasoning — out == reasoning
exactly each time, 192,000 tokens and 919 seconds for nothing — and dsh
speaks openai-completions while the qoder plugin serves Chat, so all
four were relayed as they came. The relay reads its end now: a stream's
tail is held from the chunk that says why it ended while nothing has
been said in it, and a void fails with the error event in its place, no
finish_reason the agent reads as "continue" having gone out. A reply
asked whole is written once it has ended, for the same verdict. On the
translated paths the check sits beside answersNothing (cutVoidAt,
cutVoid), and holds the end events as the empty reply's already are. The
verdict sits at the reply's end, so a streamed one costs no second read.
What the review asked, and where each landed:
- the reporter's own route: the passthrough Chat→Chat relay fails the
void too, streamed (the error event and [DONE] instead of the finish)
and whole (the error with the status)
- no in-place re-ask: the void's branch is the empty reply's error
without the emptyRetries, and the same-one retries and the patience's
rounds pass it by (cutVoidWords beside didNotStream in passing and
busy), so the upstream is asked once — every test here holds the fix
to that
- a deliberately small max_tokens is no void: the gate is spent past
cutVoidTokens, or the request hadn't capped its reply small
(probeTranslated asks 16, a title less than that)
The repo's own recorded ClinePass stream (16 tokens, all reasoning,
testdata/clinepass_stream.sse) is relayed as it was, on the relay and
translated alike.
Run:
- go test -tags nogui ./internal/gateway/... -count=1: ok
- go test -race -tags nogui ./internal/gateway/ -count=1 (the stream
relays and holds among it): ok
- the five tests of chat_length_nothing_test.go red on the branch's
parent, green here; TestClinePassUpstreamRecorded green before and
after
- gofmt -l clean; go vet clean on darwin, linux, windows
- builds: darwin and windows ok; linux ok for internal/... but the wails
v3 beta 24 module's own linux files (pre-existing, untouched here)
Fixes #2972
Reviewed and ported: rebased on
|
||
|
|
7818dc316a |
gateway: a relay's Cloudflare 520 to 524 is asked again before the agent sees it, as a 502 or 503 is (vdaoren)
vdaoren on Discord: an API-key provider's 4xx/5xx now and then went
straight to the agent; they asked for retries on chosen status codes.
What a single API-key provider already did: the last one left is asked
again after a failure that passes (passing, fallback.go): 408, 500, 502,
503, 504 and 529 twice (lastRetries), a 429 that is a short rate limit
three times (rateRetries), pauses 1s, 2s, 4s or a Retry-After up to 8s,
then within the provider's patience (singlePatience, 60s by default,
`magpie provider set <id> patience=`) in rounds (busy, patience.go), all
while the reply is held and nothing has gone to the agent. A plan used
up, no balance, a 401, a request the vendor refuses for its content and a
conversation too long are the agent's at once.
What was missing: Cloudflare's own 520 (unknown error), 521 (origin
down), 522 (connection timed out), 523 (origin unreachable) and 524
(timeout), which a relay behind Cloudflare gives now and then, were in
neither list. Such a 5xx moved on to another member in a group, but on a
lone provider it reached the agent after one try. busyStatus now holds
the one list passing and busy read, with 520 to 524 added. No setting:
the default serves it, and patience= already exists for the length.
TestCloudflareErrorIsTriedAgain (retry_test.go): each of 520 to 524, as
Cloudflare words it to an API client ("error code: 520") and as its HTML
page, twice and then 200, is answered 200 after 3 tries; a stream's 524
then an SSE reply reaches the agent with nothing of the 524 in it; a 401
invalid key and a 400 content_policy_violation are tried once.
Broken by hand (busyStatus's list back to 408..529): red, every 52x case
"520 after 1 tries" and the stream "524 after 1 tries"; the 401/400 cases
pass either way.
Run on mote at this tree (base origin/main
|
||
|
|
067e4c4846 |
gateway: Raccoon's token wall (user_model_rate_limited) isn't asked again in place (plugins#512)
SenseTime Raccoon answers an account whose token throughput is used up
with 429 {"error":{"code":"user_model_rate_limited","message":"您的模型请
求频率超限,请稍后重试","type":"rate_limit_error"}} and no Retry-After.
Its words read as a short rate limit, so the lone account was asked again
by the same-one retries (passing: 1, 2, 4s) and then by the plain
provider's patience (busy/replan: 2, 4, 8, 16s): eight asks in ~38s,
each one resending the whole ~88k-token request into the bucket it was
waiting on (cycocyco's numbers in plugins#512).
A 429 whose error.code is in wallCodes (only user_model_rate_limited) is
now neither passing nor busy. It still reads as failRate and rests as one
(a minute, doubled each time it comes back, up to 30 min, rateRest), so a
group's next member or the provider's next account is asked, and a lone
one hands the agent the vendor's error after one ask. The code is matched
at error.code only, not as words anywhere in the body. Other rate limits,
the same Chinese words under another code included, are retried as
before. The plugin passes the vendor's body through unchanged, so this is
the place for it.
Run (mote, at this change on origin/main
|
||
|
|
df64b62525 |
gateway: a 429 that says it is back in a minute is a rate limit waited out, not a used-up plan (zoecats on Discord)
zoecats's LAN aggregator answered 429 "Usage has exceeded the frequency
limit. We will switch you to another model. Your usage limit for the
original model will reset in 1 minutes." magpie handed it straight to the
agent. Its words matched plannedWords/usedUpWords ("usage limit",
"exceeded ... limit"), so failure() called it failQuota and busy() was
false: no wait, no retry, and the provider rested as a used-up plan.
Fix, no setting:
- failure(): a 429 that says it is back within soonest (PatienceLongest,
240s) and isn't about money (creditWords) is failRate, whatever plan
words it has besides (backSoon/backIn). One back in hours stays
failQuota; "insufficient balance ... try again in 30 seconds" stays
failCredit.
- rateWords takes "frequency limit"; resetsAfter also reads seconds and
N 秒/分钟后 (soonWords), so restAfter rests about what it says.
- replan: a vendor's time is read in whole seconds, so a member back
within one second past its budget is asked as the budget ends, and the
budget check is inclusive. Without it the reporter's own minute
(Retry-After 60 from keepRetry) landed a hair past a lone provider's
default 60s patience and was dropped.
- docs/subsystems/gateway-routing.md says both.
Tests (internal/gateway/frequency_limit_test.go, the reporter's literal
body): TestShortResetIsARateLimit (rate for the literal body, seconds,
Chinese; quota for hours, Cline's 23h 59m, a bare usage limit and the
billing quota; credit for money; a 403 is not rate),
TestShortResetRestsWhatItSays (rests ~1 min as failRate),
TestReporterResetFitsTheDefaultPatience (Retry-After 60, replan keeps it
with singlePatience; 1.5s or 1h past the budget is dropped),
TestSingleProviderWaitsOutAFrequencyLimit (end to end through the
gateway: 429 then 200, asked twice, after its 2s). single_busy_test's
TestSingleProviderPassesALongLimitThrough gets a "reset in 5 hours" case
that still goes straight to the agent.
Broken by hand, each red then restored: the backSoon case off (three of
the new tests red); the replan clamp off
(TestReporterResetFitsTheDefaultPatience red, "replan [] 0s false");
soonWritten out of resetsAfter (the seconds/Chinese cases and the end to
end test red).
Run: the full suite (go test -tags nogui -timeout 45m ./..., sandbox
HOME) at 8d55158fc, this change on
|
||
|
|
d56c14e953 |
gateway: a single provider's busy or briefly rate-limited reply is waited out, for its own Patience (zoecats)
zoecats on Discord: a request to one provider (not a group) got a local
relay's short 429 straight back in Claude Code once the few same-one
retries were spent. A group would have held the agent and asked again.
A plain provider now takes the group's replan path (patience.go: replan,
pauseAlive, the held writer) once passing's same-one retries are spent:
its accounts take turns as members do, each pause never shorter than the
Retry-After, and a streaming agent gets keepalives past keepHeldAfter.
- Zero-config: unset, it waits singlePatience, PatienceDefault (60s),
counted from when the agent would have had the error.
- The user's value wins: Provider.Patience, the same values as a group's
Patience, set with `magpie provider set <id> patience=2m|off|default`
(at most 4m). The provider editor has no row for it (no new UI), and its
save keeps it. A group the provider is in keeps the group's own.
- Not retried: a Retry-After past the budget, quota/credit/plan limits,
401/403, refusals, response protection, didNotStream, and an agent
that has gone (499, try marked Gone).
- The try is traced with Again alone, so the Routing page tells it as
"tried again in …".
- codexReset (ChatGPT's 503 for a large request) is left out of the
plain-provider replan, so Codex still gets its 503 with advice.
- Codex's own one-account relay (codexUpstreamOn) does not join. It is
relayed outside the candidate loop, and its backend 429 is always the
plan's usage limit (codexBusy never retries one), so the short rate
limit this waits out doesn't arise there. Its overloads keep
lastRetries and then fallbacks.
longestPause became a var so tests can scale it. Tests updated for the
new count (1 + retries + replanRounds when it never clears):
- TestLastOneLeftIsTriedAgain
- TestRateLimitIsWaitedOut
- TestQueuedStreamFailureIsTheStreamsError
- TestOverflowTheVendorDidntSay
New tests, through the server with a fake upstream and injected
durations, waiting on trace state, not a duration:
- TestSingleProviderWaitsOutAShortRateLimit (stream and whole: 200,
keepalive before the answer, asked twice)
- TestSingleProviderPassesALongLimitThrough (an hour, quota, 401)
- TestSingleProviderAgentGoneInTheWait
- TestSingleProviderOwnPatienceWins (off, shorter and longer than the
default)
- TestPatiencePair (cli)
- TestProviderSaveKeepsPatience (gui)
Broken by hand, each red, then restored:
- singlePatience fallback 0 for a plain provider: WaitsOut stream and
whole got 429, and AgentGone never paused.
- replan's budget check off: PassesALongLimitThrough/an_hour, "magpie
waits to ask again".
- pauseAlive's ctx.Done case removed: AgentGone, "route done false
status 0".
- The gateway ignoring Provider.Patience: OwnPatienceWins off, shorter
and longer all red.
- The GUI save not keeping Patience: TestProviderSaveKeepsPatience,
"patience 0 … want -1 kept".
Run in this tree, before the rebase:
- go test ./internal/gateway ./internal/cli ./internal/gui: ok.
- ./internal/provider: ok with -skip TestUnreadLogins. That test crashes
with "close of synctest channel from outside bubble", the known #3632,
in filememo and not touched here.
- gofmt -l: clean.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
vet ./...: all 0.
- go build for darwin, linux (nogui) and windows: ok.
Run again after rebasing on origin/main
|
||
|
|
2a27fb8da8 |
gateway: a request's body is looked at for web search without a copy, and not parsed for a provider that searches by itself
attempt() asked searchAsked first, on every relayed request, and only
then whether the provider searches by itself. searchAsked looked for
three words with strings.Contains(string(body), …), each conversion a
copy of the whole body (a 211KB body: ~640KB and ms a request), and a
body offering web_search was then parsed whole: Codex offers it on
every turn, so each relayed Codex turn was parsed only to be told
"Codex searches by itself". searchedForIt now asks what is known of the
provider and model first, and searchAsked looks with bytes.Contains.
The same copy in the siblings that look at an error body
(fallback.passing, patience.busy, routing.failure's insufficient_quota)
goes too. lan.go's and the lower-cased look-ups in gateway.go need the
string they make and are left as they are.
Test: TestSearchAskedLooksCheaply. Broken by hand (string(body) and the
old order put back): red, "a 211KB body with no search in it: 3
allocations, want 0" and "a provider that searches by itself: 29
allocations, the body parsed".
BenchmarkSearchedForIt (211KB Responses body; load average ~450):
codex-asks old 2.55-5.02 ms/op 665KB/op 29-30 allocs/op
new 0.1-1.9 us/op 0B/op 0 allocs/op
other-plain old 1.6-4.8 ms/op 663KB/op 3 allocs/op
new 0.26-1.15 ms/op 0B/op 0 allocs/op
Run: go test ./internal/gateway -run
'TestSearchAskedLooksCheaply|TestWebSearchAskedOfEachAPI|Search|Busy|
Passing|Failure|Credit|Quota' -count 1: ok (140s).
|
||
|
|
df341e7671 |
gateway: a member that answers a stream request with a whole reply is asked once, not again and again (#2455)
An upstream that answers stream:true with a whole JSON reply (a relay that doesn't speak SSE) fails as a 502 "did not stream". magpie read that 502 as a failure a moment may mend: the same-one retries (passing) asked it twice more, then a group's patience (busy, #1418) kept asking it until the budget was spent. The failure is the same however often it is asked. With production pauses that is about 7 requests and 60s at the default Patience, about 14 at 240s; the test's 1ms pauses let the 12 replan rounds run out first, 15 requests (ggbdpq's correction on the issue). busy() and passing() now leave a body that says didNotStream alone, and the four places that word the error (translate, streamTranslated, askTranslated, holdWriter.settle) share that constant. A group still moves on to the next member, whose API may stream; retryable() is unchanged. Patch by ggbdpq (f9e09ca7), applied on main with the docs sentence placed by hand (the hunk no longer applied). Run: - TestStreamlessMemberIsAskedOnce with both exclusions taken out: FAIL, whole and stream ("asked 15 times"); with only busy()'s: FAIL ("asked 13 times"); with only passing()'s: FAIL ("asked 3 times"). Restored: ok (asked once, the agent gets the 502 naming "did not stream"). - TestStreamlessMemberHandsOnToTheNextMember (b, which streams, answers after a): ok. - TestQuietNotAReplyLastFails, TestPatience*, TestStreamOverflow*, TestCodexOverflowInGroupNotAskedAgain, TestAgentGoneInTheRetryPause, TestRelayInputCap, TestOverflowGoesToAMemberWithRoom: ok. - Full suite, go test -tags nogui -timeout 45m ./... (set -o pipefail, sandbox HOME, load ~350) at 0224e826f (these four commits on |
||
|
|
ae98cda651 |
gateway: an inner group's own Patience waits out its busy members through an outer group (#2410)
serve read Patience only from the group the request named (g.Waits()). planLevel stamped a nested group's FirstToken (#2246) on its candidates but not its Patience, so an inner group's budget was never read through an outer one: an inner 4 min under an outer default gave up at 1 min, and an inner Off was still asked again for 60s. Each candidate carries the innermost Patience that is set on its way down (innerPatience, as innerFirstToken). waitsOf reads it as Group.Waits does, falling back to the asked group's when unset; PatienceOff keeps the member out of replan. replan counts each member's budget from waitFrom and asks again only those with budget left past the pause; the hold on the last failure lasts while any member's may (maxWaits), and the trace's Patience is the member's own. With no nested Patience set, every member's budget is g.Waits(), as before. Patch by ump45nose (61b1c17c); ggbdpq checked it against main on the issue. Review changes: the docs sentence was placed by hand (the docs hunk no longer applied), and the tests' budgets moved from inner 8s / outer 3s to 10s / 4s, so every round's pause ends 2s or more from a budget line (it was 1s from the 3s line), as a timing test leaves room on both sides. Run: - With fallback.go, gateway.go, patience.go and patience_test.go put back to main: TestNestedGroupPatienceThroughOuter FAIL ("a.n=2, want 3 — the inner group's 10s budget was not read"), TestNestedGroupPatienceInnerOff FAIL ("code=529 a.n=13 (want 529, 1 — no replan)"). With replan reading only the fallback budget: ThroughOuter FAIL the same. Restored: ok. - TestNestedGroupPatienceFallsBackToOuter, TestGroupWaitsOut*, TestPatienceIsUsedUp: ok. - Full suite, go test -tags nogui -timeout 45m ./... (set -o pipefail, sandbox HOME, load ~350) at 0224e826f (these four commits on |
||
|
|
4a6c81e038 |
gateway: a group's Patience is waited out in full, not cut at 90s by the round count (#1418)
A group asks its busy members again after pauses of 2s, 4s, 8s, 16s, then 30s, for as long as its Patience lasts, but replanRounds stopped it after 6 rounds: 90s of pauses whatever the group was set to. real-jacket's trace on #1418 shows patience=240 with replan=6 and ~103s in all. replanRounds is now 12, a backstop sized so that the pauses alone reach PatienceLongest (240s) in 11 rounds, and the patience is what ends the wait. It stays bound by kept.tooQuiet, as before. The longest pause is now 30 x retryPause (30s in use), so the tests' 1ms retryPause doesn't grow a 4s pause at round 12. Run: TestPatienceIsUsedUp (new) counts replan's pauses for 30s to 240s of patience, and TestReplanRoundsOutlastPatience (new) sums the backstop's schedule. With replanRounds back at 6, both fail: patience 3m0s and 4m0s pause 1m30s. go test ./internal/gateway -run 'Overload|Patience|Replan|WaitsOut|Busy|Codex' is green. Not tried against a real overloaded vendor for 240s. |
||
|
|
34ce89945b |
gateway: an error that escapes its Chinese as \uXXXX is read as one that doesn't, for why it failed and when it's back (#1669, Natsumeretsu)
Every word list that decides why a reply failed (creditWords, brokeWords, rateWords, plannedWords, usedUpWords, quotaCodes) and af0558e6d's resetsWhen were matched against the raw body. A JSON error whose encoder escapes what isn't ASCII (Python's json.dumps by default) carries 用量 as 用量, so none of the Chinese words matched: WorkBuddy's escaped refusal read as a 1-minute rate limit with no reset time, Zhipu's escaped 1113 "余额不足…请充值" as a rate limit instead of out of credit, a sub2api key's escaped "7天限额已用完" as a rate limit instead of out of quota. wordsOf is the one shared point: a JSON body containing \u has its string values decoded and put after it, one to a line; any other body is matched as it is. failure() matches its words on it, resetsWritten reads the reset from it, the per-model rest's otherModels check uses it, and the two creditWords checks beside failure() (fallback.go's same-one retry, patience.go's busy) use it too. Tests: TestResetsWritten gains the reporter's Chinese refusal escaped (read, 3h16m2s) and escaped-but-cut-short (not read); TestWrittenResetRestsUntilThen rests the escaped refusal's model until then; TestFailureReadsEscapedWords: escaped Zhipu 1113 is credit, escaped sub2api 7天限额已用完 is quota, escaped WorkBuddy is quota. With wordsOf returning the body unchanged, all three fail. internal/gateway passes; go test -tags nogui ./... under a temp HOME; gofmt -l, go vet darwin, GOOS=linux, GOOS=windows on internal/gateway. |
||
|
|
c43681d64c |
gateway: a group whose every member is busy asks them again within a budget, 1 minute by default, instead of ending the agent's turn on the last one's error (#1418, Aliceonly)
Aliceonly's Codex turns ended on server_is_overloaded when plus-B and sub2api were both overloaded, to be told "continue" by hand. #1421 promised a group-wide budget for errors that pass. This builds it. When every member of a group has failed in a way that passes (busy: 408/500/502/503/504/529 that isn't a proxy, quota or response protection; a 429 that is a short rate limit, not a plan or credit), and nothing of the reply has been sent, the members that failed so are asked again in turn after a pause (replan). The pause starts at 2s, doubles each round up to 30s, and is never shorter than the soonest Retry-After; a member still asking for time goes after the others. At most 6 rounds, and only while the group's Patience lasts, counted from the first time every member had failed (provider.Group.Patience: 0 = 60s default, -1 off, at most 240s). While another member is busy too, the last one isn't first retried alone (passing): the members take turns. The last member's failure is held while the budget lasts, and a streaming agent gets SSE keepalives through the pause (pauseAlive). The trace's try says Again (the pause), Replan (how many) and Patience. Plain providers are unchanged. GUI: the group editor's "Every member busy" row (Off / 1 min / 2 min / 4 min) and the trace's line for a replanned try, in en, zh, zh-TW, ja and de. Run: - TestGroupWaitsOutEveryMemberOverloaded, TestCodexStreamWaitsOutOverloadedGroup (new): both fail with patience forced to 0 (the old behaviour: the 529, and the response.failed stream, reach the agent), pass now. - go test -tags nogui ./... under a temp HOME: all ok. - gofmt -l: clean. go vet (darwin, GOOS=linux, GOOS=windows) on internal/gateway and internal/provider: clean. - GUI: group-patience (new), group-first-token, i18n-keys, gui-ja, gui-de in Chromium and WebKit: 15/15 pass. - Real use: a sandbox `magpie serve` on 127.0.0.1:3782 under a scratch HOME, group/sol of two Responses providers on a fake upstream that sends 200 + response.created/in_progress, pings, and 20s later response.failed server_is_overloaded. curl streaming /v1/responses: plus-B failed at 20s (held, not let through), sub2api at 40s, 2s pause, plus-B asked again answered "hello from a"; the client saw only keepalives and the reply. Trace: plus-B 529, sub2api 529 with again 2000 replan 2 patience 60, plus-B 200. With both always overloaded the request ended after 3 rounds (127s) with the vendor's response.failed. |