Files
magpie/docs
yetone 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 6a6c06868: every package ok,
internal/gateway 755s and internal/agent 598s among them, except
internal/provider, which crashed on "close of synctest channel from
outside bubble" in filememo.Forget, open as #3632 and untouched here.
Rebased on 11dcc743f (one sessions commit). At the pushed head, stacked
with the next commit (7065e3734 before these bodies), the full suite ran
again while the disk was full (1 GB free, other sessions' runs and a
57 GB shared Go cache): pii, source and 68 more packages ok; agent,
gateway and library red only on "no space left on device"; provider on
#3632. So I reran internal/gateway at that head with -run
'FrequencyLimit|ShortReset|ReporterReset|SingleProvider|Patience|Busy|Replan|Rest|Quota|Rate|Credit|Failure': ok 58s.
gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./... clean; go build for darwin, linux (nogui) and
windows ok.

Not tried: the reporter's real aggregator; a Retry-After header alone on
a quota-worded 429 still doesn't make it a rate limit (only its words
do).
2026-10-27 13:20:52 +08:00
..