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.
This commit is contained in:
yetone
2026-10-31 11:12:56 +08:00
parent 65d6b1dee9
commit 394a92f0f3
3 changed files with 40 additions and 2 deletions
+4 -2
View File
@@ -1156,8 +1156,10 @@ func (s *Server) restAfterMarked(c candidate, status int, header http.Header, bo
// and none to tell from: the account rests, narrowed once read (#2036)
unread := why == failQuota && c.p.Account != nil && len(allowances(c.p.Account.UsageAgent())[c.p.Account.User]) == 0
// a model the key's plan doesn't serve rests alone, counted by itself
// (#1235): the key's other models are still served
unserved := why == failOther && (modelRefused(status, body) || codeAssistModelMissing(c.p, status, body))
// (#1235): the key's other models are still served. So does a ZCode
// trial entry zcode.z.ai's firewall blocked (zcodeTrialBlocked): the
// account's GLM Coding Plan goes to another host
unserved := why == failOther && (modelRefused(status, body) || codeAssistModelMissing(c.p, status, body) || zcodeTrialBlocked(c, status, body))
r := Rest{Why: why, Status: status, By: "cooldown"}
// out of allowance or credit for as long as magpie guessed: the vendor
// named no time, nor did the user (asksAt)
+21
View File
@@ -4,6 +4,8 @@ import (
"net/http"
"regexp"
"strings"
"github.com/yetone/magpie/internal/provider"
)
// zcodeEndedWords and zcodeSpentWords are the ZCode plugin's own answers
@@ -44,3 +46,22 @@ func zcodeTrialRefused(c candidate, status int, body []byte) bool {
}
return false
}
// zcodeTrialBlocked says c, a ZCode plugin account asked for one of its
// Start Plan trial entries, got zcode.z.ai's edge firewall's block page
// (Alibaba Cloud's 405, provider.EdgeBlocked, as the plugin's startBlocked
// words it). A trial entry is sent to zcode.z.ai alone; a dual account's
// plain models go to its GLM Coding Plan at api.z.ai, which answered while
// zcode.z.ai blocked the address (plugins#545, jinpy666). So the block
// rests the trial entry, and the account's plain model is still asked: on
// a gift-only account it goes to zcode.z.ai too, is blocked the same, and
// that rests the account (windy_66454 on Discord, 10-31: glm-trial's two
// members, GLM-5.3-Flash and GLM-5.3-Flash-Trial, shared one account rest
// and the plain one was never asked). ZCode's risk control blocking the
// account (code 3012, failRestricted) is the account's, and is read before.
func zcodeTrialBlocked(c candidate, status int, body []byte) bool {
if status < 400 || c.p.PluginProvider() != "zcode" || !strings.HasSuffix(strings.ToLower(c.model), "-trial") {
return false
}
return provider.EdgeBlocked(wordsOf(body)) && !restrictedSaid(status, wordsOf(body))
}
+15
View File
@@ -17,6 +17,12 @@ const (
zcodeFlashTrialEnded = `{"type":"error","error":{"type":"invalid_request_error","message":"ZCode has no active limited quota for GLM-5.3-Flash-Trial"}}`
zcodeTrialEnded = `{"type":"error","error":{"type":"invalid_request_error","message":"ZCode has no active limited quota for GLM-5.3-Trial"}}`
zcodeTrialSpent = `{"type":"error","error":{"type":"rate_limit_error","message":"ZCode's limited quota for glm-5.3 is exhausted or temporarily unavailable"}}`
// zcode.z.ai's edge firewall's block page, as the plugin's startBlocked
// puts it (windy_66454 on Discord, 10-31: "405 Method Not Allowed — the
// provider's network firewall blocked …"), and ZCode's risk control
// blocking the account (code 3012, plugins#348)
zcodeStartEdge = `{"type":"error","error":{"type":"permission_error","message":"405 Method Not Allowed — the provider's network firewall blocked requests from this IP; wait a while, or switch to another network or proxy"}}`
zcodeStartRisk = `{"type":"error","error":{"type":"permission_error","message":"request has been blocked due to unusual activity. (405, code 3012) — ZCode's risk control blocked this account for unusual activity (code 3012); it rests, and the group's other providers are used. If the ZCode app fails on this account too, only ZCode support can lift the block"}}`
)
// A ZCode account's Start Plan trial entry that ended, or whose bucket is
@@ -46,6 +52,15 @@ func TestZCodeTrialRefusalRestsTheTrialAlone(t *testing.T) {
{"not a trial", "zcode", "GLM-5.3", `{"type":"error","error":{"type":"invalid_request_error","message":"ZCode has no active limited quota for GLM-5.3"}}`, 400, false, true},
{"ended words on a 429", "zcode", "GLM-5.3-Trial", zcodeTrialEnded, 429, false, true},
{"another vendor's words", "factory", "GLM-5.3-Trial", zcodeTrialEnded, 400, false, true},
// a trial entry goes to zcode.z.ai's Start Plan, and a dual
// account's GLM Coding Plan to api.z.ai: zcode.z.ai's firewall
// blocking the trial says nothing of the plan's host, so the trial
// rests alone and the plan's model is asked. Blocking the plain
// model, or the account's own risk control, rests the account
{"trial edge block", "zcode", "GLM-5.3-Flash-Trial", zcodeStartEdge, 405, true, false},
{"plain edge block", "zcode", "GLM-5.3", zcodeStartEdge, 405, false, true},
{"trial risk control", "zcode", "GLM-5.3-Flash-Trial", zcodeStartRisk, 405, true, true},
{"another vendor's block", "factory", "GLM-5.3-Trial", zcodeStartEdge, 405, false, true},
} {
t.Run(tc.name, func(t *testing.T) {
// a ZCode list with no free model, which would rest a paid