provider, gateway: rest-cap off never rests a provider's keys after an unknown failure (Kismet Alan on Discord)

A relay or account pool fails now and then with errors that say nothing
of why (a 5xx, a dropped connection), and the next request often goes
through. Every such failure rested the key or account a minute, doubling
up to 10, and `rest-cap` could only move that cap (1 minute at least;
`off` read as `default`).

`magpie provider rest-cap <id> off` (provider.RestCapOff, restCap: -1 in
providers.json) now has a failure that says nothing of why (failOther)
rest nobody and not count toward the backoff: restAfterMarked returns a
Rest by "off" with no time left. What says why still rests as before: a
401 or 403, a model not served (restID), an account's window full, a
rate limit (magpie's own 30-minute cap; RestCapOr treats off as unset),
quota, credit, a restriction. `rest-cap <id> 30s` is turned away and names
1m and off (the first rest is a minute already). The Routing page tells a
try rested by "off" as not resting (one new string, zh/zh-TW/ja/de).
No "fail N times before switching" counter: a failed try already moves
the same request on to the next key or member, so a count would only
keep requests on a failing upstream longer.

Run:
- TestRestCapOff (gateway), TestRestCapCmd (cli), TestOwnRestCap: pass;
  each goes red with the change taken out by hand (the early return
  disabled: "#1 500: rests 59.99s by backoff"; restMinutes in place of
  restCapMinutes: "off: <nil> 0").
- routing-rest-off.test.cjs: 20/20 (chromium, webkit; 1100, 420; en zh
  zh-TW ja de); red 10/10 with the "off" case renamed.
  routing-wb-restricted 20/20. rest-try-now and routing-model-rest fail
  a varying few under load average 200-420 here, and fail more on
  origin/main 331c27703 run at the same time; neither reads "off".
- gofmt -l clean; go vet darwin (provider, gateway, cli, gui), GOOS=linux
  -tags nogui and GOOS=windows (provider, gateway, cli).
- go test ./... with pipefail, sandbox HOME: every package ok except
  agent, gateway and library, which hit the 10m timeout under load
  average ~200 (no test hung: each stack shows a different test seconds
  in). Rerun with a longer -timeout: library ok (603s), gateway ok
  (1572s) and agent ok (1457s).
Not tried: a real relay; the change is in the rest bookkeeping only.
This commit is contained in:
yetone
2026-10-14 20:49:20 +08:00
parent d692b25481
commit 22512cde53
11 changed files with 253 additions and 14 deletions
+7 -1
View File
@@ -1441,7 +1441,13 @@ minutes. Out of credit rests half an hour. Any other failure rests a minute, lon
again, up to 10 minutes; a subscription that fails with a window used up
rests until that window renews. `magpie provider rest-cap <id> 4h` moves
both of those caps, 30 and 10 minutes, for one provider's keys and
accounts, up to 8 days; `default` gives them back.
accounts, from 1 minute (every rest a minute) up to 8 days; `default` gives
them back. `magpie provider rest-cap <id> off` is for a relay or an account
pool whose unknown errors come now and then: a key or account of it that
fails without saying why (a 5xx, a dropped connection) doesn't rest at all,
and the next request asks it again. A refused key (401, 403), a model it
doesn't serve, being out of quota or credit, or a rate limit still rests
it as above.
**When the safety filter refuses.** A reply the vendor's safety filter
refuses before any of it is said rests nobody: it is about what was asked,
File diff suppressed because one or more lines are too long
+25 -5
View File
@@ -74,10 +74,13 @@ const providerUsage = `usage:
without saying when it is back (default: 15 minutes; at most 8 days),
or until the time of day a daily allowance comes back, on this
computer's clock or at the vendor's offset from UTC
magpie provider rest-cap <id> [30m|6h|1d|default]
magpie provider rest-cap <id> [1m|30m|6h|1d|off|default]
the most a key or account sits out while it keeps failing or being
rate limited, its rest doubling each time from a minute (default:
10 minutes for a failure, 30 for a rate limit; at most 8 days)
10 minutes for a failure, 30 for a rate limit; at most 8 days);
off: one that fails without saying why (a relay's 5xx) doesn't
rest at all, while out of quota, its key refused or rate limited
still rests it
magpie provider listed <id> yes|no no: its models serve only through routing groups, not in the list
magpie provider off|on <id> switch it off (kept, but no agent or request uses it), or on again
magpie provider test <id> [--as codex|claude-code] [model…]
@@ -1655,14 +1658,14 @@ func quotaRestCmd(rest []string) error {
// while they keep failing or being rate limited (#2008).
func restCapCmd(rest []string) error {
if len(rest) < 1 || len(rest) > 2 {
return fmt.Errorf("magpie provider rest-cap <id> [30m|6h|1d|default]")
return fmt.Errorf("magpie provider rest-cap <id> [1m|30m|6h|1d|off|default]")
}
p, err := provider.Find(rest[0])
if err != nil {
return err
}
if len(rest) > 1 {
minutes, err := restMinutes(rest[1])
minutes, err := restCapMinutes(rest[1])
if err != nil {
return err
}
@@ -1673,7 +1676,9 @@ func restCapCmd(rest []string) error {
return err
}
}
if p.RestCap > 0 {
if p.NoFailRest() {
fmt.Printf("%s · a key or account that fails without saying why doesn't rest: the next request asks it again. Out of quota or credit, its key refused or its model not served still rests it; rate limited, at most 30 minutes (magpie's own)\n", p.Name)
} else if p.RestCap > 0 {
fmt.Printf("%s · a key or account that keeps failing sits out at most %s\n", p.Name, restWords(time.Duration(p.RestCap)*time.Minute))
} else {
fmt.Printf("%s · a key or account that keeps failing sits out at most 10 minutes, 30 when rate limited (magpie's own)\n", p.Name)
@@ -1681,6 +1686,21 @@ func restCapCmd(rest []string) error {
return nil
}
// restCapMinutes reads a rest cap as restCapCmd takes it: as restMinutes
// does, but off (or never) is provider.RestCapOff, no rest after an
// unknown failure, and a cap under a minute is turned away with what to
// set instead, as the first rest is a minute already.
func restCapMinutes(s string) (int, error) {
switch strings.ToLower(strings.TrimSpace(s)) {
case "off", "never", "no":
return provider.RestCapOff, nil
}
if d, err := time.ParseDuration(strings.TrimSpace(s)); err == nil && d > 0 && d < time.Minute {
return 0, fmt.Errorf("the shortest rest cap is 1m, which rests a minute every time, not longer; off doesn't rest after an unknown failure at all")
}
return restMinutes(s)
}
// restMinutes reads a rest as quotaRestCmd takes it: default (0), a
// number of minutes, a Go duration (90m, 6h) or a number of days (7d).
func restMinutes(s string) (int, error) {
+15
View File
@@ -76,4 +76,19 @@ func TestRestCapCmd(t *testing.T) {
if err := restCapCmd([]string{"xk", "default"}); err != nil || cap() != 0 {
t.Fatalf("default: %v %d", err, cap())
}
// Kismet Alan on Discord: a relay whose unknown errors pass is set
// never to rest after one, saved and read back so; a minute is the
// shortest cap, and under it is turned away, not read as default
if err := restCapCmd([]string{"xk", "off"}); err != nil || cap() != provider.RestCapOff {
t.Fatalf("off: %v %d", err, cap())
}
if p, _ := provider.Find("xk"); !p.NoFailRest() {
t.Fatal("off not read back as no rest")
}
if err := restCapCmd([]string{"xk", "1m"}); err != nil || cap() != 1 {
t.Fatalf("1m: %v %d", err, cap())
}
if err := restCapCmd([]string{"xk", "30s"}); err == nil || cap() != 1 {
t.Fatalf("30s taken: %v %d", err, cap())
}
}
+59
View File
@@ -50,3 +50,62 @@ func TestRestCapOr(t *testing.T) {
t.Error(d)
}
}
// Kismet Alan on Discord: a relay or account pool whose unknown errors
// come now and then, the next request often going through, is set never
// to rest after one (`magpie provider rest-cap <id> off`). Its 5xx and its
// dropped connection rest it no more, nor count toward a backoff; what
// says why still rests it as before: a rate limit (magpie's own 30
// minutes cap), out of quota, its key refused, its model not served.
func TestRestCapOff(t *testing.T) {
s := &Server{}
c := candidate{p: provider.Provider{ID: "nofail", Key: "k", RestCap: provider.RestCapOff}, model: "m", rest: "nofail#k"}
id := c.restKey()
t.Cleanup(func() {
clearRest(id)
clearRest(c.restID())
routed.Lock()
delete(routed.failures, id)
delete(routed.failures, c.restID())
routed.Unlock()
})
fail := `{"error":{"message":"upstream connect error","type":"api_error"}}`
for i, status := range []int{500, 502, 503, 504, 520} {
r := s.restAfter(c, status, http.Header{}, []byte(fail))
if r.Why != failOther || r.By != "off" || r.Until.After(time.Now()) {
t.Fatalf("#%d %d: rests %v by %s (%s), want no rest", i+1, status, time.Until(r.Until), r.By, r.Why)
}
if resting(c) {
t.Fatalf("#%d %d: set aside", i+1, status)
}
}
routed.Lock()
n := routed.failures[id]
routed.Unlock()
if n != 0 {
t.Fatalf("%d failures counted", n)
}
// what says why rests it still
for _, k := range []struct {
status int
body string
why string
}{
{401, `{"error":{"message":"invalid api key","type":"api_error"}}`, failOther},
{403, `{"error":{"message":"forbidden","type":"api_error"}}`, failOther},
{429, `{"error":{"message":"Too many requests","type":"rate_limit_error"}}`, failRate},
{429, `{"error":{"message":"You exceeded your current quota, please check your plan","type":"insufficient_quota"}}`, failCredit},
{404, `{"error":{"message":"The model m does not exist or you do not have access to it","type":"invalid_request_error"}}`, failOther},
} {
clearRest(id)
clearRest(c.restID())
r := s.restAfter(c, k.status, http.Header{}, []byte(k.body))
if r.Why != k.why || r.By == "off" || !r.Until.After(time.Now()) || !resting(c) {
t.Fatalf("%d %s: rests %v by %s (%s), want a rest as %s", k.status, k.body, time.Until(r.Until), r.By, r.Why, k.why)
}
}
// a rate limit's cap is magpie's own 30 minutes, not none
if d := c.p.RestCapOr(longestRateRest); d != longestRateRest {
t.Fatalf("rate cap %v", d)
}
}
+13 -1
View File
@@ -380,7 +380,9 @@ type Rest struct {
// (the allowance window it filled renews), "quota" (no word of when),
// "cooldown" (a minute), "backoff" (longer each time it fails again,
// or is rate limited again as soon as it is back), "restricted" (the
// vendor restricted the account: two hours, or until lifted by hand).
// vendor restricted the account: two hours, or until lifted by hand),
// "off" (no rest: its provider is set not to rest after an unknown
// failure, provider.RestCapOff).
By string `json:"by"`
Failures int `json:"failures,omitempty"` // in a row, for a backoff
// Key is what it rests by, for the app to lift the rest (Unrest)
@@ -699,6 +701,16 @@ func (s *Server) restAfterMarked(c candidate, status int, header http.Header, bo
}
r.Link, _ = provider.Verification([]byte(r.said))
default:
// the provider set never to rest after a failure that says nothing
// of why (provider.RestCapOff; Kismet Alan on Discord: a relay's
// or an account pool's unknown errors come now and then, and the
// next request often goes through): it isn't set aside, nor its
// failure counted. A key refused, a model not served, or a window
// full still rests it, as they say why
if c.p.NoFailRest() && why == failOther && !unserved && status != http.StatusUnauthorized && status != http.StatusForbidden && (c.p.Account == nil || c.full(now).IsZero()) {
r.By, r.Until = "off", now
return r
}
counted := c.restKey()
if unserved {
counted = c.restID()
+4
View File
@@ -3609,6 +3609,7 @@ const I18N = {
"It rests 15 minutes: out of quota, with no word of when it resets": "它休息 15 分钟:额度用尽,但没说何时重置",
"It has failed {n} times in a row: it rests {d}, longer each time": "它已连续失败 {n} 次:休息 {d},每次更久",
"It rests {d}, longer if it fails again": "它休息 {d},再失败就更久",
"It doesn't rest: its provider is set to ask it again after an error like this": "它不休息:它的提供方设为遇到这类错误后照常再问它",
"It rests {d}": "它休息 {d}",
"It cools down {d}: the vendor didn't say for how long": "它冷却 {d}:厂商没说要多久",
"It was rate limited again as soon as it was back ({n} times in a row): it rests {d}, longer each time until it answers": "恢复后立即再次被限流(连续 {n} 次):休息 {d},逐次延长,直到正常应答",
@@ -7790,6 +7791,7 @@ const I18N = {
"It rests 15 minutes: out of quota, with no word of when it resets": "它休息 15 分鐘:額度用盡,但沒說何時重置",
"It has failed {n} times in a row: it rests {d}, longer each time": "它已連續失敗 {n} 次:休息 {d},每次更久",
"It rests {d}, longer if it fails again": "它休息 {d},再失敗就更久",
"It doesn't rest: its provider is set to ask it again after an error like this": "它不休息:它的提供方設為遇到這類錯誤後照常再問它",
"It rests {d}": "它休息 {d}",
"It cools down {d}: the vendor didn't say for how long": "它冷卻 {d}:廠商沒說要多久",
"It was rate limited again as soon as it was back ({n} times in a row): it rests {d}, longer each time until it answers": "恢復後立即再次被限流(連續 {n} 次):休息 {d},逐次延長,直到正常應答",
@@ -11987,6 +11989,7 @@ const I18N = {
"It rests 15 minutes: out of quota, with no word of when it resets": "15 分休止します:クォータ切れで、リセット時刻の知らせがありません",
"It has failed {n} times in a row: it rests {d}, longer each time": "{n} 回連続で失敗しました:{d} 休止し、毎回長くなります",
"It rests {d}, longer if it fails again": "{d} 休止します。再び失敗するとさらに長くなります",
"It doesn't rest: its provider is set to ask it again after an error like this": "休止しません:このプロバイダーは、この種のエラーの後も次にそのまま尋ねる設定です",
"It rests {d}": "{d} 休止します",
"It cools down {d}: the vendor didn't say for how long": "{d} クールダウンします:ベンダーが期間を示しませんでした",
"It was rate limited again as soon as it was back ({n} times in a row): it rests {d}, longer each time until it answers": "復帰直後に再びレート制限されました({n} 回連続):{d} 休止し、応答するまで毎回長くなります",
@@ -16191,6 +16194,7 @@ const I18N = {
"It rests 15 minutes: out of quota, with no word of when it resets": "Es pausiert 15 Minuten: Kontingent aufgebraucht, ohne Angabe zum Zurücksetzen",
"It has failed {n} times in a row: it rests {d}, longer each time": "Es ist {n}-mal in Folge fehlgeschlagen: Es pausiert {d}, jedes Mal länger",
"It rests {d}, longer if it fails again": "Es pausiert {d}, länger bei erneutem Fehler",
"It doesn't rest: its provider is set to ask it again after an error like this": "Es pausiert nicht: Sein Anbieter ist so eingestellt, dass es nach einem solchen Fehler wieder gefragt wird",
"It rests {d}": "Es pausiert {d}",
"It cools down {d}: the vendor didn't say for how long": "Es kühlt {d} ab: Der Anbieter hat keine Dauer genannt",
"It was rate limited again as soon as it was back ({n} times in a row): it rests {d}, longer each time until it answers": "Es erhielt gleich nach der Rückkehr erneut ein Rate-Limit ({n}-mal in Folge): Es pausiert {d}, jedes Mal länger, bis es antwortet",
+3
View File
@@ -466,6 +466,9 @@
case "resets": return t("It rests until {time}, when the vendor says the limit resets", { time });
case "quota": return t("It rests 15 minutes: out of quota, with no word of when it resets");
case "verify": return t("The vendor wants the account verified first: it rests half an hour, or until you say it's verified");
// its provider set never to rest after an unknown failure
// (`magpie provider rest-cap <id> off`): asked again next time
case "off": return t("It doesn't rest: its provider is set to ask it again after an error like this");
// the vendor restricted the account itself (#1849): only its lifting,
// which the vendor's appeal asks for, brings it back
case "restricted": return t("The vendor restricted the account: it rests {d}, as only the vendor lifting the restriction brings it back. Appeal with the vendor; once it's lifted, try it again here", { d });
@@ -0,0 +1,102 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// A provider set never to rest after an unknown failure (`magpie provider
// rest-cap <id> off`; Kismet Alan on Discord: a relay's 5xx comes now and
// then and the next request goes through): the Routing page tells its 502
// as not resting, the request gone on to the next, and its row isn't shown
// resting — in every language the page speaks.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const now = new Date();
const day = [now.getFullYear(), now.getMonth() + 1, now.getDate()].map((n) => String(n).padStart(2, "0")).join("-");
const start = new Date(now.getTime() - 60e3).toISOString();
const a = { id: "relay#a", provider: "relay", name: "Relay", kind: "key", who: "key a", model: "glm-5" };
const b = { id: "relay#b", provider: "relay", name: "Relay", kind: "key", who: "key b", model: "glm-5" };
const rest = { why: "other", by: "off", status: 502, until: new Date(now.getTime() - 59e3).toISOString() };
const routes = [{
id: 100, seq: 100, time: start, agent: "codex", model: "relay/glm-5", provider: "relay",
order: [a, b],
tries: [
{ id: a.id, model: a.model, start, done: true, status: 502, ms: 900, fail: "other", rest, error: "Relay: upstream connect error" },
{ id: b.id, model: b.model, start, done: true, status: 200, ms: 1200 },
],
done: true, status: 200, ms: 2100,
}];
function serve(lang, lifted) {
const state = { agents: [{ id: "codex", name: "Codex", path: "/test/config.toml", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
return async (route) => {
const url = new URL(route.request().url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json(state);
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/gateway/trace") {
if (url.searchParams.get("wait")) await new Promise((r) => setTimeout(r, 20e3));
return json({ mine: true, now: now.toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
}
if (url.pathname === "/api/gateway/history") {
const d = url.searchParams.get("day");
return json({ cut: false, days: [{ day, requests: routes.length }], routes: d ? routes : [] });
}
if (url.pathname === "/api/gateway/unrest") {
lifted.push(JSON.parse(route.request().postData() || "{}"));
return json({ lifted: true });
}
if (url.pathname === "/api/groups") return json({ groups: [] });
if (url.pathname === "/api/providers") return json({ providers: [], excluded: [], gateway: { running: true, window: true } });
if (url.pathname.startsWith("/api/")) return json({});
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
await route.fulfill({ body: await fs.readFile(file), contentType });
};
}
const want = {
en: "It doesn't rest: its provider is set to ask it again after an error like this",
zh: "它不休息:它的提供方设为遇到这类错误后照常再问它",
"zh-TW": "它不休息:它的提供方設為遇到這類錯誤後照常再問它",
ja: "休止しません:このプロバイダーは、この種のエラーの後も次にそのまま尋ねる設定です",
de: "Es pausiert nicht: Sein Anbieter ist so eingestellt, dass es nach einem solchen Fehler wieder gefragt wird",
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of Object.keys(want)) {
for (const width of [1100, 420]) {
test(`${engine} ${lang} ${width}px: a key set never to rest after an unknown failure is told as not resting`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const context = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
const page = await context.newPage();
page.setDefaultTimeout(5000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, []));
t.after(async () => {
if (process.env.ARTIFACT_DIR) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-rest-off.png`), fullPage: true });
}
await browser.close();
});
await page.goto("http://magpie.test/?view=routing");
await page.locator(".rt-days .rt-day").nth(1).click();
await page.locator(".rt-req").first().waitFor();
await page.locator(".rt-req").first().click();
await page.locator(".rt-steps li").first().waitFor();
await page.waitForTimeout(300);
const steps = await page.locator(".rt-steps li").evaluateAll((ls) => ls.map((l) => l.textContent));
assert.equal(steps.filter((s) => s.includes(want[lang])).length, 1, JSON.stringify(steps));
if (lang !== "en") assert(!steps.some((s) => s.includes("doesn't rest")), JSON.stringify(steps));
// nobody's row is shown resting
assert.equal(await page.locator(".rt-act .st.rest").count(), 0);
assert(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth + 1), "the page scrolls sideways");
assert.deepEqual(errors, []);
});
}
}
}
+19 -4
View File
@@ -322,8 +322,23 @@ func SetQuotaResetAt(id, at string) error {
return Save(*p)
}
// RestCapOff is RestCap set to off (`magpie provider rest-cap <id> off`):
// a key or account of the provider that fails without saying why — a
// relay's or an account pool's 5xx, a dropped connection — doesn't rest at
// all, and is asked again by the next request as if it hadn't failed
// (Kismet Alan on Discord: an aggregator's unknown errors fail now and
// then, and the next request often goes through). What the vendor said
// plainly still rests it as ever: out of quota or credit, rate limited,
// its key refused (401, 403), its model not served, its window full.
const RestCapOff = -1
// NoFailRest says p's keys and accounts don't rest after an unknown
// failure (RestCapOff).
func (p Provider) NoFailRest() bool { return p.RestCap == RestCapOff }
// RestCapOr is the most one of p's keys or accounts sits out while it keeps
// failing: the user's RestCap, else the gateway's own def.
// failing: the user's RestCap, else the gateway's own def (RestCapOff
// included: it says nothing of a rate limit's rest).
func (p Provider) RestCapOr(def time.Duration) time.Duration {
if c := min(max(p.RestCap, 0), MaxQuotaRest); c > 0 {
return time.Duration(c) * time.Minute
@@ -333,10 +348,10 @@ func (p Provider) RestCapOr(def time.Duration) time.Duration {
// SetRestCap sets the most, in minutes, the provider's keys and accounts
// sit out while they keep failing or being rate limited, 0 for the
// gateway's own.
// gateway's own, RestCapOff for no rest after an unknown failure.
func SetRestCap(id string, minutes int) error {
if minutes < 0 || minutes > MaxQuotaRest {
return fmt.Errorf("the longest rest is from 0 (magpie's own) to %d minutes (8 days), not %d", MaxQuotaRest, minutes)
if minutes != RestCapOff && (minutes < 0 || minutes > MaxQuotaRest) {
return fmt.Errorf("the longest rest is from 0 (magpie's own) to %d minutes (8 days), or off, not %d", MaxQuotaRest, minutes)
}
p, err := Find(id)
if err != nil {
+5 -2
View File
@@ -186,7 +186,8 @@ type Provider struct {
// out while it keeps failing or keeps being rate limited as soon as
// its rest is over (#2008); 0 is the gateway's own, 10 minutes for a
// failure and 30 for a rate limit. The vendor's own "try again in"
// still stands over it.
// still stands over it. RestCapOff (-1): no rest at all after a
// failure that says nothing of why, a rate limit's as the gateway's own.
RestCap int `json:"restCap,omitempty"`
// PriceRate is what the provider charges against the official price
@@ -1172,7 +1173,9 @@ func normalize(p Provider) Provider {
p.QueueLimit, p.QueueWait = min(max(p.QueueLimit, 0), MaxQueueLimit), min(max(p.QueueWait, 0), MaxQueueWait)
p.MaxRPM = min(max(p.MaxRPM, 0), MaxRPMLimit)
p.QuotaRest = min(max(p.QuotaRest, 0), MaxQuotaRest)
p.RestCap = min(max(p.RestCap, 0), MaxQuotaRest)
if p.RestCap != RestCapOff {
p.RestCap = min(max(p.RestCap, 0), MaxQuotaRest)
}
if _, err := ParseResetAt(p.QuotaResetAt); err != nil {
p.QuotaResetAt = ""
}