Commit Graph
6 Commits
Author SHA1 Message Date
yetone 74d1cda421 gateway: a rate limit with a bracketed reset time rests the model until then, and says rate limited
taoxiaoxin on Discord (v0.1.2992, WorkBuddy China, plugin 0.2.24):
deepseek-v4.1-flash got 429

  {"error":{"code":null,"message":"WorkBuddy: 您的使用量已超出频率限制,将在
  2026-11-06 17:13:04 (UTC+8) 重置,您也可以切换其他模型继续使用。",
  "param":null,"type":"rate_limit_error"}}

with credits left, and Routing showed the account as 额度用尽.

Cause: WorkBuddy now writes the offset in brackets, "(UTC+8)".
resetsWhen read "UTC+8" only bare, so the reset time went unread, the
refusal fell to plannedWords (用量) as failQuota with no time, and the
whole account rested a quarter of an hour as quota used up. With the time
read, the existing path (resetsWhen + otherModels) rests only that model
on that account until 17:13.

- resetsWhen takes an optional ASCII or fullwidth bracket round the
  offset (zh and en forms); a body cut inside or after the bracket,
  before 重置, still reads no time.
- Rest.Rate (and provider.KeyRest.Rate): a refusal read as out of quota
  until a named time whose words say rate/frequency limit. Routing is
  unchanged (it rests as the quota it is until then); the Providers row,
  Routing's stage row, its Accounts line and the account tallies (live
  and the day's, history.go) say "rate limited" (限流, 限流, レート制限,
  Rate-Limit; strings already translated) with "back at {time}".
- workbuddy-ai gets the same: one path, tested for both ids. The plugin
  (opencode-workbuddy-auth) already reads the bracketed time; no plugin
  version or mover min.

Run (mote, at this tree):
- go test ./internal/gateway -run 'TestDayTallies|TestResetsWritten|
  TestWrittenReset|TestBracketedReset|TestMonthlyWritten|
  TestRateLimitBelieves': ok
- go test ./internal/gui ./internal/provider: provider ok; gui red only
  in TestMainWindowCorners/macOS_26_SDK, #3949 (macOS 27, untouched)
- go vet (darwin) gateway, gui, provider; GOOS=linux and GOOS=windows
  go vet gateway, provider: ok; gofmt -l clean
- node --test account-rate-rest (new; chromium + webkit, en zh zh-TW ja
  de, 1100 and 420px): 10/10
- GUI routing-*, account-*, i18n*, key-rest*, rate-limited-* (194
  files, 3127 tests): 3086 pass, 41 red. Rerun at concurrency 2 here
  and at origin/main 8fbf8e0af: the same 9 files red on both, each
  filed: i18n-keys (#5332), routing-intent-entry (#5392),
  routing-rule-drag (#3789), routing-rule-remove (#3096, #4585),
  routing-row-swap (#3799), routing-steady (#3412, #1804),
  routing-steps-cap (#4628), routing-story-shrinks (#3954),
  routing-order-unknown (#4627). account-weight, routing-levels,
  rule-models, rules-line passed on the rerun.
- TestCoreScriptBudget: app.js under 1,533,802 without a raise

Broken by hand:
- old resetsWhen: TestResetsWritten's bracket cases and
  TestBracketedResetRestsTheModelRateLimited red ("rests 14m59.99s by
  quota (quota), want 5h13m0s by resets": the whole account, 15 min)
- Rate forced false: "a frequency limit not marked a rate limit"
- history.go's count off: TestDayTalliesCountARateLimitAsOne red
  ("tallied map[quota:3]")
- app.js and routing client.js at HEAD: account-rate-rest 10/10 red

Not tried: a real WorkBuddy account answering this 429 (the body is the
reporter's literal one); the live app.
2026-11-06 04:09:30 +08:00
yetone 63dc359fb4 providers: a subscription account's rest, or its model's, shows on its row (maxleebeta)
maxleebeta on Discord (#feedback): WorkBuddy answered 429
{"type":"rate_limit_error","message":"WorkBuddy: 您的使用量已超出频率限制,将在
2026-11-03 23:57:19 UTC+8 重置,您也可以切换其他模型继续使用。"} while the
provider's card said 1,934/2,350 credits left (82%), and nothing on the
Providers page said the account was held back.

Routing already handled the refusal: resetsWhen reads the time (UTC+8, the
space before 重置 included), failure() gives failQuota, and since it says
切换其他模型 the rest is that model's alone (restID), by "resets", till
15:57:19 UTC; the account's other models are still asked (#1669). What
was missing was the page: a key's rest showed on its row, an account's
never did.

- gateway.RestsUnder(prefix) lists the rests in force under a key prefix
  (provider@ for a subscription's accounts, provider@user/model for a
  model's), with Key and the rest's note (Model, By, Error).
- providerJSON.accountRests gives them by user in lower case, the model
  filled in from the key when the note has none; provider.KeyRest gains
  By, Model and Error.
- app.js: the account row in the provider editor gets a line per rest
  (accountRestLines): "<model> resting · 429 quota used up · back at
  <time>" or "Resting · …" for the whole account, the vendor's words
  beside it (shown whole when it names a time magpie couldn't read, so
  an unknown format still says why), and Try now (gateway/unrest by the
  rest's key). The key row's rest line is now the same helper
  (restLineOf), so app.js grows ~800 bytes, under the core budget.
- New strings in zh, zh-TW, ja and de. docs/subsystems/gateway-routing.md
  says where the Providers page reads them.

Not changed: the "-sg" maxleebeta saw in pi is WorkBuddy AI's own model
id (deepseek-v4.1-flash-sg, the paid Singapore id beside the free
deepseek-v4.1-flash); pi's footer and model picker show ids by design,
and the name magpie writes for it is the vendor's ("Deepseek-V4.1-Flash",
"(SG)" added by the plugin only where two ids share a name). Neither
magpie nor the plugin appends "-sg"; the CN build has no -sg ids.

Run (mote, through mote-run):
- go test ./internal/gateway ./internal/gui ./internal/provider at f0df4bb2b
  (base 06944e065): gateway ok (737s), provider ok, gui ok except
  TestMainWindowCorners/macOS_26_SDK, red on macOS 27 as on main (#3949).
- Rebased on 889767b7b: TestCoreScriptBudget, TestI18n*,
  TestAccountRestsInProviderState and the written-reset tests ok;
  gofmt -l clean. GOOS=linux and GOOS=windows go vet -tags nogui ok at
  f0df4bb2b, before the rebase. Then rebased once more onto 8ee172ca0,
  which changes only gateway search files; not re-run there.
- internal/gui/tests/account-rest.test.cjs: chromium and webkit, en, zh,
  zh-TW, ja, de, at 900 and 360px, ok. rest-try-now.test.cjs's 15 webkit
  reds fail the same on origin/main 06944e065 (#2564, #4127).
- Broken by hand: TestRateLimitedModelListedUnderAccount red with
  RestsUnder returning nothing, TestAccountRestsInProviderState red
  without accountRests, account-rest.test.cjs red without
  accountRestLines.

Not tried: a real WorkBuddy account hitting this 429, so the line has
not been seen on a live gateway; the whole GUI suite (mote under another
session's suite). The line shows in the provider editor's account rows,
not on the collapsed provider row.
2026-11-03 14:09:42 +08:00
yetone 3dc25a6168 tests: a plugin fake's vendor counts only its own test's requests (#3357)
Run 39913278700 at 65e80405b (ubuntu, Race): TestClinePluginPinsDeepSeekAndGLM
"the plugin sent 7 requests" for 6 asks, in 0.33s. #3347 was the same
class: TestPluginToldWhereTheAgentWorks got 2 for 1, in 0.66s.

Cause, as far as it is known. The extra request did not come from the
test's own route:
- not a gateway retry: retryPause is 1s, so a retried ask can't finish
  in 0.33s or 0.66s. #3347's "a first try failed with a 5xx and was
  retried" doesn't fit either run's time;
- not the plugin host: the gateway reaches the host over stdio JSON-RPC
  (no HTTP retry), and host.js fetchAs calls the loader's fetch once;
- a never-reset log of every request the cline test's vendor got showed
  exactly 12 (6 asks x 2 runs), all POST /v1/chat/completions from
  magpie/dev, with nothing in the background.
So the seventh came from outside the test. The likely sender is a late
request from another test, in this shard or another of race-shards.sh's
four processes, reaching a port the kernel handed to this test's
httptest server (the class d0ccbbebc met with a freed port). Which test
sent it is still unknown.

Fix the class: testenv.FakeVendor(t, h) serves a fake plugin's vendor
at $FAKE_BASE and sets $FAKE_RUN to a nonce made for the test. The fake,
renew and renewrace plugins send it as X-Fake-Run. A request without it
gets 421 and is logged with its method, URI, remote address, User-Agent,
Authorization and size, so the next one on CI names its sender. Every
gateway and plugin test that served the fake's vendor with
httptest.NewServer plus FAKE_BASE now uses it (10 gateway, 5 plugin
files). The cline test now counts against the asks' recorded tries, as
65e80405b did for the workdir test: it fails on a real duplicate and
logs each retry's status. No exactly-once guarantee was loosened.

Reproduction by injection, at be002aca0:
- a request to FAKE_BASE from outside the route, with the filter off:
  "the plugin sent 7 requests for 6 asks tried 6 times" (the CI shape);
  with it on, the test passes and logs the 421 line;
- the fake plugin fetching twice for glm-5.3 (a real duplicate) still
  fails: "sent 8 ... tried 6". Both breaks were restored.

Ran at be002aca0 (macOS, -tags nogui):
- gofmt -l clean; go vet ./... darwin, GOOS=linux -tags nogui, GOOS=windows ok;
- internal/plugin -race -count=20 ok (157.5s);
- the edited gateway files' tests -race -count=20 ok (93.1s);
Rebased on c8c6e7e23 (it brings TestPluginThinkingOff, on besideFake),
and ran there: gofmt -l clean; vet of the three packages for darwin,
linux nogui and windows ok; TestPluginThinkingOff, the cline and the
workdir tests -race -count=20 ok (18.3s); internal/gateway (363.6s),
internal/plugin (83.9s) and internal/testenv -timeout 45m ok, with no
421 line logged;
- a Linux container run of gateway.race in four shards like CI's,
  -test.v: ok, and no stray was seen.

Not tried: the stray was never caught in the act, here or in the
container, so the sender is a hypothesis. The count=20 run over all 142
besideFake tests hit 45m in TestPluginStreamLargeReplies (sizing, no
FAIL) and was narrowed to the edited files. No product code changed, so
the full ./... suite was not run.
2026-10-23 16:57:33 +08:00
yetoneandskygunner 8278fd9b0c gateway: Volcengine Ark's monthly 429 rests the key until the reset it writes (+0800 CST), not 15 minutes (#3251 CNife, #3276 wyx1818)
Ark's 429 for a used-up month says "You have exceeded the monthly usage
quota. It will reset at 2026-10-25 23:59:59 +0800 CST." with no
Retry-After. resetsWhen read an offset only after UTC or GMT, so nothing
read it, the key rested quotaRest and was asked again every 15 minutes
until the month turned. Two more limits stood behind that one: a written
reset over 7 days off (longestWritten) isn't read, and a quota rest is
held to 8 days (longestQuota), so wyx1818's reset 9 days off would still
have fallen to the 15-minute loop.

- resetsWhen also reads the time as Go prints one (Ark's): four offset
  digits, a space and the zone's name in capitals, then punctuation or
  重置. The offset is read, the name isn't (CST is more than one zone).
  The UTC/GMT form is unchanged; a bare offset with no zone's name, or
  "+08:00" without UTC, isn't read, as Ark doesn't send them.
- monthlyWords (monthly, 月度, 每月, 本月): a refusal that says its
  allowance is a month's has its written reset believed up to
  longestMonthly (35 days) instead of the week (longestSaid). That covers
  Zhipu's 1310 "Weekly/Monthly Limit Exhausted" too (resetsZhipu), the
  sibling held to the same week.
- In failQuota the 8-day cap is lifted to 35 days only when the rest
  came from the vendor's own reset ("resets") and the refusal is a
  month's. A window read full, a Retry-After and the user's own quota
  rest are held to 8 days as before.

Ported from skygunner's branch skygunner:fix/volcengine-resets (e6c2b6fb,
posted on both issues). Taken: the monthly trust window, longestMonthly,
monthlyWords, the reporters' bodies as fixtures and the shape of
TestMonthlyWrittenResetRestsTheMonth. Changed:
- its regex made UTC|GMT optional and took any 2 to 5 letters,
  case-insensitively, after any offset, for every vendor, so "reset at
  <date> +8 now." would read. Scoped here to Go's layout, the zone's
  name matched case-sensitively.
- it lifted the cap to 35 days whenever the body said monthly, whatever
  the rest came from (a window read full, the user's own rest); here
  only for the vendor's written reset.
- its resetsZhipu kept the week; here it shares longestSaid.
vincenty on Discord: no link to another fix is on either issue
(skygunner's commit is authored as "vincent").

Not changed: Ark's plan windows read by its AccessKey (volcPlanQuotas)
still reach only the usage card, not routing (layer 2 of #3251: the
quota is the account's, not one inference key's, and a provider has one
plan, #2849). #3251 stays open for it.

Tests (fixtures: #3251's and #3276's bodies byte for byte, #3276's as
its pretty-printed JSON):
- TestResetsWritten: ark (3 days), ark 9 days off, ark escaped, 35 days
  read and 36 not, past, cut after the offset / in the offset / before
  the full stop, without the zone, +9900, Ark's form without "monthly"
  9 days off (0: the week holds), WorkBuddy's en 9 days off (0: another
  vendor unchanged), "retry after … +0800 CST." (0). Every existing
  WorkBuddy and UTC/GMT case passes unchanged.
- TestResetsZhipu: 1310 9 days off read, 36 days not; 1308 over a week
  off still 0.
- TestMonthlyWrittenResetRestsTheMonth (new): Ark's 429 3d7h and 9d12h
  off reads failQuota and rests by "resets" till then, raw and as the
  agent's error with keepRetry's note; the same body without "monthly"
  rests quotaRest; a month's refusal with no time on an account whose
  window reads full 20 days off rests 8 days by "window".

Broken by hand, in the worktree:
- old routing.go with the new tests: TestResetsWritten (ark: 0s, want
  79h7m59s; 9 days, escaped, 35 days), TestMonthlyWrittenResetRestsTheMonth
  (79h0m0s off: rests 14m59.99s by quota) and TestResetsZhipu (1310, 9
  days off: 0s) red.
- cap not lifted: 228h0m0s off rests 191h59m59s by resets, red.
- longestSaid always the week: ark 9 days / 35 days and Zhipu 1310 red.
- zone's name made optional: "ark without the zone" reads 79h7m59s, red.
- skygunner's cap (any monthly body): window 20 days off rests 479h59m,
  want 192h, red.
Each restored, green.

Run at 268c1d34c (this change on origin/main 95be6bb75, unchanged at
push): gofmt -l prints nothing; go vet ./..., GOOS=linux go vet -tags
nogui ./..., GOOS=windows go vet ./... clean; go build, GOOS=linux go
build -tags nogui, GOOS=windows go build pass. set -o pipefail; go test
-tags nogui -timeout 45m ./... (no other suite on the machine): 69 ok,
no FAIL in the log (internal/gateway ok 571s).

Not tried: a real Ark key (none here), so not against the live API; the
bodies are the reporters' curl output. Not run: the GUI suite (no GUI
change).

Co-authored-by: skygunner <84759+skygunner@users.noreply.github.com>
2026-10-22 23:47:12 +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 af0558e6d0 gateway: a 429 that says in words when it's back rests until then, in Chinese as in English (#1669, Natsumeretsu)
WorkBuddy answers a frequency limit with the time it resets, in words:
"将在 2026-10-11 20:16:02 UTC+8重置" and "your usage will reset at
2026-10-11 12:37:53 UTC+8, ...". resetsAt read neither (only Claude
Code's "limit reached|<unix>" and ChatGPT's resets_at), so the Chinese
one rested quotaRest (15 min, matched 用量) and the English one
fallbackCooldown (1 min, no word list matched): the account was asked
again long before it was back, refused, and benched again.

- resetsWritten reads a time beside the reset phrasing (resetsWhen:
  "reset(s) at", 将在/将于), in the UTC/GMT offset it is written with.
  The offset must be followed by 重置 or punctuation, so a refusal cut
  after "UTC" or "UTC+" is never read as UTC; a date that isn't real,
  one past, or more than a week off (longestWritten) isn't read; another
  vendor's date in passing ("deprecated on ...", "retry after ...") is no
  reset. resetsAt falls back to it, so keepRetry notes it too.
- failure reads such a 429 as out of quota in either language.
- One that points to the account's other models ("切换其他模型",
  "switch to the other models") rests that model alone (restID), so
  the account's other models are still asked during an hours-long rest.
- rateRest: a reset time the refusal names (resetsAt, or as keepRetry
  noted it) is believed up to longestQuota, as the quota branch does,
  and the trace says "resets"; a Retry-After or rate-limit reset header
  stays held to longestWait. Decided: the stated time is the vendor's
  statement of when the account is back, and how far it is believed
  shouldn't hang on which word list the message happened to match
  (8 days as quota vs 1 hour as rate for the same words); a Retry-After
  is generic advice and keeps the hour.

The rest is the gateway's, so it holds for moved WorkBuddy users too:
the plugin (packages/workbuddy 0.1.14, explained()) passes a 429 that
isn't "unapproved channel"/14018 on as it came.
TestPluginWrittenResetRests shows a plugin-served 429 with the
reporter's refusal resting the model until the stated time.

Tests: TestResetsWritten (reporter's bytes in both languages, other
offsets, cut-short, garbled, past, >7 days, other vendors' dates),
TestWrittenResetRestsUntilThen (both languages rest the model by
"resets", noted path, cut-short falls back, other vendors' 429s
unchanged), TestRateLimitBelievesItsReset, TestPluginWrittenResetRests.
Broke each piece by hand (reader, classification, rate cap, model
scope, offset, the terminator) and each made one of them fail.
TestRateLimitBacksOffWhenItComesBack now expects "resets" for a noted
reset. go test -tags nogui ./... under a temp HOME, rebased
on 498b77fbc, passes but internal/provider's
TestCopilotSecretToolUsername, which this doesn't touch: it is #1627
(5s secret-tool bound under load) and fails alone 3 of 5 on this head
too. internal/gateway rerun after rebasing on 6ebe481f8; gofmt -l, go
vet for darwin, GOOS=linux and GOOS=windows on internal/gateway.
Not tried against WorkBuddy itself: its raw 429 JSON shape isn't
known beyond the message (err_type 6004), and a body that escapes the
Chinese as \uXXXX wouldn't be read (the reporter's classification by
用量 shows theirs isn't escaped).
2026-10-12 03:23:27 +08:00