1ccacad63281094de8a3372d5a507d38f9969e5c
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
59d9f5c7d9 |
gateway, redact: compile their 275 package-level regexps on first use, not at every start
magpie is one binary, so every package's init runs on every launch, including `magpie statusline`, which Claude Code runs on every message. internal/gateway and internal/redact compiled 275 patterns at init: 3.7 MB + 2.3 MB and ~38k allocations per launch, most of them for vendors and rules that launch never reaches. New internal/lazyre: RE holds the source and compiles it through a sync.Once on first use, with the *regexp.Regexp methods magpie calls delegating to it (Of wraps one already compiled, for the user's own privacy rules). A one-off Go AST rewrite turned every regexp.MustCompile in a package-level var (outside func literals) into lazyre.New; the struct fields, map and parameter that hold them took the new type. A bad pattern now panics on first use instead of at start, so TestAllCompile in gateway and redact compiles every registered one. Measured on mote (M5 Pro), sandbox HOME with a copy of real accounts, v0.1.3515 ( |
||
|
|
0978a68681 |
gateway: a ZCode trial entry's 3012 rests that entry, not the account
young02036 (Discord, 11-07): on an account with a GLM Coding Plan, GLM-5.3-Flash-Trial answered 405 code 3012 (ZCode's risk control) while the account's paid models worked. The plugin's 3012 words read as failRestricted, which rested the whole account for two hours (restrictedRest), so magpie stopped sending the paid models the account still served. A -Trial entry goes to zcode.z.ai's Start Plan, and a dual account's plain models to its GLM Coding Plan on api.z.ai, so the 3012 is zcode.z.ai's: zcodeTrialRestricted rests the entry alone (restID), as zcodeTrialBlocked already does for the edge block page. On a gift-only account the plain model goes to zcode.z.ai too, gets its own 3012 and rests the account, at the cost of that one more refused request per rest. riskRefused still walls the provider's other accounts off for the rest of the request. TestZCodeTrialRefusalRestsTheTrialAlone: "trial risk control" now wants the entry's rest and the account's GLM-5.3 served after it; new cases "plain risk control" and "another vendor's risk control" want the account's rest. docs/subsystems/gateway-routing.md says so. Run (mote): go test -count=1 -run 'TestZCode|TestRisk|TestRestricted|TestMovedZCode' ./internal/gateway/ ok; gofmt -l clean; GOOS=linux and GOOS=windows go vet ./internal/gateway/ ok. Broken by hand: the routing.go check removed, trial_risk_control red (rested "zcode@api key", want ".../GLM-5.3-Flash-Trial"), then restored. Not tried: a real 3012 account (the reporter's); the full suite runs after this push. Reported-by: young02036 |
||
|
|
394a92f0f3 |
gateway: a ZCode trial entry zcode.z.ai's firewall blocks rests alone
A -Trial entry goes to zcode.z.ai's Start Plan only. On an account with a GLM Coding Plan too, the plain models go to api.z.ai, which kept answering while zcode.z.ai served its block page (jinpy666, plugins#545). The block page on a Trial rested the whole account, so the coding plan's models stopped too. zcodeTrialBlocked now rests such a refusal on the account/model, like the Trial refusals of #3661. Unchanged: the block page on a plain model still rests the account (on a gift-only account, windy_66454's, the plain model is the same gift on the same host), 3012 risk control rests the account as restricted, and another vendor's block page rests its account. Run (mote, at this tree): - TestZCodeTrialRefusalRestsTheTrialAlone's new "trial edge block" case: red without the routing.go line (rested "zcode@api key", want "zcode@api key/GLM-5.3-Flash-Trial"), green now; "plain edge block", "trial risk control" and "another vendor's block" rest the account. - go test ./internal/gateway -run 'ZCode|Edge|Relay|Restricted|WorkBuddy|Blocked|Refusal': ok. - gofmt -l clean; go vet darwin/linux/windows ok. Not tried: a real dual account while zcode.z.ai blocks. |
||
|
|
65ee8c65c6 |
gateway: a ZCode Start Plan trial that ended or is spent rests that trial alone, not the account (#3661)
orion-nebula-dev's routing log: GLM-5.3-Flash-Trial and GLM-5.3-Trial,
whose Start Plan trial had ended, were refused by the ZCode plugin with
400 "ZCode has no active limited quota for GLM-5.3-Trial". The word
"quota" made it failQuota, and restAfterMarked rested the account
("zcode@zcode"), so the subscription's GLM-5.3 and GLM-5.3-Flash were
paused with it.
zcodeTrialRefused narrows that rest to the trial entry (restID) when the
candidate is a zcode plugin account, the model ends in -Trial, and the
refusal is the plugin's own words naming that model:
- 400 "ZCode has no active limited quota for <model>" (the trial ended);
- 429 "ZCode's limited quota for <bucket> is exhausted or temporarily
unavailable", where the bucket is the entry less -Trial (its bucket
spent). skygunner's patch covered the 400 only and kept this 429 as an
account rest; it is the trial bucket's, given by the plugin before
anything is sent, so it rests the entry too.
Another model named, a model without -Trial, the ended words on a 429,
the account's own quota (400 or 429) or key (401), and the same words
from another vendor still rest the account.
The plugin is not changed: zcode 0.1.31 already leaves ended trials out
of its model list and its two refusals are exact, and open plugins PRs
#395 and #421 hold zcode's next version. A member the user kept in a
group is still asked, refused locally, and asked again a minute on (a
guessed quota rest); the Routing page strikes such a member as
"skipped", which the gateway doesn't do: filed as #3805.
Ported from skygunner's e04a1b994 (branch
fix/r25-expired-model-not-account-fault): the test plugin's
FAKE_ZCODE_TRIAL and FAKE_NO_FREE fixture is his; the matcher, the 429
case and the test were rewritten. Reported by orion-nebula-dev.
Run:
- TestZCodeTrialRefusalRestsTheTrialAlone: 12 cases, the reporter's
literal plugin bodies. Each posts to a group of the trial then another
provider, checks the try's rest key, then posts to a group of the
account's GLM-5.3 then another provider: served by the account when
only the trial rests, by the other provider when the account does.
- Broken by hand: the routing.go hook off -> the four trial cases red
("refusal rested \"zcode@api key\", want \"zcode@api key/GLM-5.3-Trial\"");
the 429 branch off -> "trial spent" red; the zcode-only check off ->
"another vendor's words" red. Green again after each.
- gofmt -l clean; go vet ./... on darwin, GOOS=linux -tags nogui and
GOOS=windows; GOOS=linux go build -tags nogui ./...
- go test -timeout 45m -count=1 ./internal/gateway ./internal/plugin at
f34a9f8cf (this change on
|