Commit Graph
3 Commits
Author SHA1 Message Date
yetone 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.
2026-10-13 07:30:06 +08:00
yetone 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.
2026-10-12 03:30:25 +08:00
yetone 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.
2026-10-10 17:49:07 +08:00