zcode 0.1.27: the Start Plan's 405 code 3012 says ZCode's risk control blocked the account, not a network block (#348)

zcode.z.ai answers {"code":3012,"msg":"request has been blocked due to
unusual activity."} with 405. Since 10-24 many accounts get it on every
request, and on several of them ZCode's own app (3.16.3) gets the same 405;
ZCode's support bot calls 3012 platform risk control on the account. The
plugin used to put "though magpie sends it as the ZCode app does; it can
be a network block of this IP" after it, and read that JSON as the edge
firewall's page (EDGE_BLOCKED matched "request has been blocked"), so
ZCode's own words and code were dropped.

Now: ZCode's words with the status and code, then provider
ZCodeRestrictedHint word for word ("ZCode's risk control blocked this
account for unusual activity (code 3012); it rests, and the group's other
providers are used. ..."), which magpie's gateway reads as the account
restricted (2h rest, next member asked) from the next magpie release on.
Only an HTML / errors.aliyun.com block page says the network's address
(provider.BlockedHint's words).

Compared with ZCode 3.16.3's glm/zcode.cjs (downloaded from
cdn-zcode.z.ai, the latest on zcode.z.ai): the Start Plan is sent
unsigned there too (requiresClientRequestSigning is false for
zhipu-account start-plan, off-peak and highspeed; X-Client-Sig/Pow apply
to coding-plan keys on the paas origin), and the headers plugins#348's
curl shows are the plugin's set. No request difference was found that
explains 3012; not tried against a real blocked account.

Run: packages/zcode, Bun 1.4.2, sandbox HOME: 102 pass, 0 fail. The new
start.test.mjs case is red on 0.1.26's index.mjs (1 fail, the 3012
message). bun scripts/check.mjs ok.
This commit is contained in:
yetone
2026-10-24 23:28:48 +08:00
parent c9a0215f31
commit 28f9cbb3b2
4 changed files with 62 additions and 36 deletions
+8 -6
View File
@@ -25,12 +25,14 @@ over Anthropic's Messages API. Provider id: `zcode`.
agent's system prompt at the end of the third (a fourth block is
refused, #343), the day in a `<system-reminder>` turn before the agent's
turns, and the sign-in's device id in `metadata.user_id`. GLM Coding
Plan and team requests go as the agent sent them. One it still turns
away (a 405, the block page or code 3012) comes back with what to do
about it, as magpie's built-in said: "ZCode's Start Plan still turned
this request away, though magpie sends it as the ZCode app does; …
Use an account with a GLM Coding Plan, or add another provider to this
group".
Plan and team requests go as the agent sent them. zcode.z.ai also
answers 405 code 3012 to every request of an account its risk control
blocked, ZCode's own app's included (plugins#348). That answer comes
back as ZCode's words, then "ZCode's risk control blocked this account
for unusual activity (code 3012); …", which magpie reads as the account
restricted: it rests, and the group's other providers are used. Only
ZCode support lifts such a block. A block page from ZCode's edge
firewall says this network's address was blocked instead.
- The Start Plan's token can't be refreshed. When it runs out, sign in
again.
- **ZCode: a team's GLM Coding Plan**
+31 -19
View File
@@ -1438,39 +1438,51 @@ function model(m, url) {
}
// ---- the Start Plan's requests ----------------------------------------------------
// zcode.z.ai serves the Start Plan only to what looks like ZCode's own
// request, and turns others away with 405 "request has been blocked due to
// unusual activity" (code 3012). A Start Plan request goes as the plugin
// zcode.z.ai answers 405 "request has been blocked due to unusual
// activity" (code 3012) to a request that doesn't look like ZCode's own
// (#343: the agent's system prompt as a fourth block), and to every
// request of an account its risk control blocked, ZCode's own app's too
// (plugins#348). A Start Plan request goes as the plugin
// the plan serves (ARNO's "Freeflow", provider zcode-start) sends it: its
// headers (startHeaders) and its body (dress). The texts are prompt.mjs.
// START_BLOCKED is what the Start Plan still turning a request away means,
// word for word magpie's provider.ZCodeStartBlockedHint (#425), which
// magpie's Routing page knows and says in the user's language. It is put
// in place of the block page, whose words magpie would otherwise read as a
// network firewall's (provider.BlockedHint).
const START_BLOCKED = "ZCode's Start Plan still turned this request away, though magpie sends it as the ZCode app does; it can be a network block of this IP, or ZCode checking for something new. Use an account with a GLM Coding Plan, or add another provider to this group"
const EDGE_BLOCKED = /request has been blocked|errors\.aliyun\.com/i
const START_REFUSED = /unusual activity|"code"\s*:\s*"?3012\b/i
// START_RESTRICTED is what ZCode's 3012, "request has been blocked due to
// unusual activity", means: ZCode's risk control blocked the account
// (ZCode's support says so, and ZCode's own app gets the same 405 on such
// an account, plugins#348), not that the request was sent wrong. Word for
// word magpie's provider.ZCodeRestrictedHint: the gateway reads it as the
// account restricted, rests it and asks the group's next member, and the
// Routing page says it in the user's language.
const START_RESTRICTED = "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"
// START_EDGE is what a block page from ZCode's edge firewall (Aliyun's)
// means: this network's address, not the account. Word for word magpie's
// provider.BlockedHint.
const START_EDGE = "the provider's network firewall blocked requests from this IP; wait a while, or switch to another network or proxy"
const EDGE_PAGE = /errors\.aliyun\.com|<html/i
const START_REFUSED = /unusual activity|request has been blocked|"code"\s*:\s*"?3012\b/i
// startRefused says a Start Plan answer is that refusal, as the built-in's
// zcodeStartExplain read it: a 405, a block page or code 3012.
const startRefused = (status, text) => status >= 400 && (status === 405 || EDGE_BLOCKED.test(text) || START_REFUSED.test(text))
// startRefused says a Start Plan answer is a refusal: a 405, a block page
// or code 3012.
const startRefused = (status, text) => status >= 400 && (status === 405 || START_REFUSED.test(text))
// startBlocked is the refusal's answer as the built-in passed it on: what
// the vendor said (its status for a block page), then START_BLOCKED.
// startBlocked is the refusal's answer: what the vendor said (its status
// for a block page), then what it means. A block page is the network's;
// anything else, ZCode's JSON 3012 or a bare 405, the account's.
function startBlocked(res, text) {
const page = EDGE_PAGE.test(text)
let said = ""
if (!EDGE_BLOCKED.test(text)) {
if (!page) {
try {
const v = JSON.parse(text)
said = first(v?.error?.message, typeof v?.error === "string" ? v.error : "", v?.message, v?.msg)
const code = v?.code ?? v?.error?.code
if (said && code != null && !String(said).includes(String(code))) said = `${said} (${res.status}, code ${code})`
} catch {}
}
said ||= `${res.status} ${STATUS_TEXT[res.status] ?? res.statusText}`.trim()
const h = new Headers(res.headers)
h.set("content-type", "application/json")
const error = { type: "permission_error", message: `${said} — ${START_BLOCKED}` }
const error = { type: "permission_error", message: `${said} — ${page ? START_EDGE : START_RESTRICTED}` }
return new Response(JSON.stringify({ type: "error", error }), { status: res.status, statusText: res.statusText, headers: h })
}
@@ -1900,7 +1912,7 @@ export async function ZCodeAuthPlugin({ client }) {
}
let res = await fetch(url, { ...opts, headers: h })
// the Start Plan turning the request away says what to do about
// it, as the built-in's zcodeStartExplain did
// it: the account blocked, or the network
if (start && res.status >= 400) {
const text = await res.text()
if (startRefused(res.status, text)) return kept(startBlocked(res, text))
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-zcode-auth",
"version": "0.1.26",
"version": "0.1.27",
"description": "OpenCode provider plugin: signs in to Z.ai's or BigModel's (智谱) GLM Coding Plan as ZCode does, including team seats and ZCode's Start Plan",
"type": "module",
"main": "./index.mjs",
+22 -10
View File
@@ -386,10 +386,11 @@ test("a team seat's request goes as the agent sent it, ZCode's token or not", as
sentAsIs(await send(auth, agentText), "team.secret", "/api.z.ai/api/anthropic/v1/messages")
})
// magpie's provider.ZCodeStartBlockedHint, word for word
const START_BLOCKED = "ZCode's Start Plan still turned this request away, though magpie sends it as the ZCode app does; it can be a network block of this IP, or ZCode checking for something new. Use an account with a GLM Coding Plan, or add another provider to this group"
// magpie's provider.ZCodeRestrictedHint and provider.BlockedHint, word for word
const START_RESTRICTED = "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"
const START_EDGE = "the provider's network firewall blocked requests from this IP; wait a while, or switch to another network or proxy"
test("the Start Plan turning a request away says what to do about it, as the built-in's zcodeStartExplain did (#425)", async () => {
test("the Start Plan's 3012 says ZCode blocked the account, and a block page the network (plugins#348, #425)", async () => {
const ask = async (auth, url = "https://api.z.ai/api/anthropic/v1/messages") => {
routeToFake()
const hooks = await ZCodeAuthPlugin({ client: { auth: { set: async () => {} } } })
@@ -397,19 +398,30 @@ test("the Start Plan turning a request away says what to do about it, as the bui
const res = await opts.fetch(url, { method: "POST", headers: { "content-type": "application/json", "x-api-key": "zcode" }, body: agentText })
return { status: res.status, text: await res.text(), signIn: res.headers.get("x-magpie-sign-in") }
}
// the block page zcode.z.ai serves: its status, then the hint, and none
// of the page's words, which magpie would read as a firewall's
answer = () => new Response("<html>Sorry, your request has been blocked due to unusual activity.</html>", { status: 405, headers: { "content-type": "text/html" } })
// zcode.z.ai's answer as plugins#348 has it, byte for byte: ZCode's
// words with the code, then what they mean, never a network block
answer = () => new Response('{ "code": 3012, "msg": "request has been blocked due to unusual activity.", "logid": "202610241036161d8571a39683011267ff" }', { status: 405, headers: { "content-type": "application/json" } })
let r = await ask(start("zai"))
expect(r.status).toBe(405)
expect(JSON.parse(r.text)).toEqual({ type: "error", error: { type: "permission_error", message: "405 Method Not Allowed — " + START_BLOCKED } })
expect(r.text).not.toMatch(/request has been blocked/)
expect(JSON.parse(r.text)).toEqual({ type: "error", error: { type: "permission_error", message: "request has been blocked due to unusual activity. (405, code 3012) — " + START_RESTRICTED } })
expect(r.text).not.toMatch(/network|IP\b|sends it as/)
expect(r.signIn).toBe("kept")
// code 3012 in JSON: the vendor's own words, then the hint
// a bare 405 is the same block
answer = () => new Response("", { status: 405 })
r = await ask(start("zai"))
expect(JSON.parse(r.text).error.message).toBe("405 Method Not Allowed — " + START_RESTRICTED)
// code 3012 under another status: the vendor's own words, then the hint
answer = () => Response.json({ code: 3012, msg: "method not allowed" }, { status: 403 })
r = await ask(start("zai"))
expect(r.status).toBe(403)
expect(JSON.parse(r.text).error.message).toBe("method not allowed — " + START_BLOCKED)
expect(JSON.parse(r.text).error.message).toBe("method not allowed (403, code 3012) — " + START_RESTRICTED)
// the edge firewall's block page: its status, then the network's hint,
// and none of the page's words
answer = () => new Response("<html>Sorry, your request has been blocked due to unusual activity. errors.aliyun.com</html>", { status: 405, headers: { "content-type": "text/html" } })
r = await ask(start("zai"))
expect(r.status).toBe(405)
expect(JSON.parse(r.text)).toEqual({ type: "error", error: { type: "permission_error", message: "405 Method Not Allowed — " + START_EDGE } })
expect(r.text).not.toMatch(/request has been blocked/)
// any other refusal of the Start Plan goes on as it came
answer = () => Response.json({ type: "error", error: { type: "overloaded_error", message: "busy" } }, { status: 529 })
r = await ask(start("zai"))