gateway: ZCode 405 (code 3012, failRestricted) aborts at tries=1 without failing over because retryable() omits failRestricted / 405
Environment
- magpie version:
0.1.4777(Windows 11 amd64) - Where: Gateway (
group/agentcompass,orderrouting) - Provider / Model:
zcode/GLM-5.4(ZCode plugin)
What happened
When zcode/GLM-5.4 returned 405 (code 3012 — Start Plan account suspended), Magpie did not fail over to any of the other providers in the routing group (TRIES: 1), and returned the 405 directly to Codex.
This happened repeatedly in routing/2026-11-25.jsonl (e.g. 08:47:42, 09:47:15, 10:47:37, ..., 18:16:38):
{
"time": "2026-11-25T18:16:38.4822686-08:00",
"status": 405,
"model": "group/agentcompass",
"tries": [
{
"model": "GLM-5.4",
"status": 405,
"error": "ZCode: Your account has been suspended for misusing the Start Plan, such as proxying it to non-ZCode clients. Please contact support if you believe this is a mistake. (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"
}
]
}
Notice the error message itself says "it rests, and the group's other providers are used", yet tries has length 1 and no other provider in group/pool-code / group/agentcompass was tried.
Root Cause in Source
internal/gateway/routing.go:599-600(failure) classifiesrestrictedSaid(405, body)(matchingprovider.ZCodeRestrictedHint) asfailRestricted, so ZCode rests forrestrictedRest(2 * time.Hour,routing.go:283).- However,
retryable(status int, body []byte)ininternal/gateway/fallback.go:2162-2205:- Lists
401, 402, 403, 404, 408, 429, >= 500,modelRetired,provider.EdgeBlocked,failCredit,claudeOffWords,refusedWords— but omits405and omitsrestrictedSaid/failRestricted! - As a result,
retryable(405, body)returnsfalse, immediately aborting the fallback loop atTRIES: 1instead of trying the next provider in the group.
- Lists
- Additionally, for a permanent/account-suspension
3012(account has been suspended), a flat 2-hourrestrictedRestcauses it to wake up and fail with405(TRIES: 1) again every 2 hours.
Expected Behavior
retryable(status, body)ininternal/gateway/fallback.goshould returntruewhenrestrictedSaid(status, body)(orfailure(status, raw) == failRestricted) is true (so405from ZCode 3012 / WorkBuddy 11140 actually fails over to the group's other providers as the error text promises).- Consider a longer or escalating rest (like
creditLadder) forfailRestrictedwhen the vendor explicitly reports account suspension (code 3012).
Fix branch: https://github.com/qq01-hub/magpie/tree/fix/restricted-4xx-failover (dec5bb5d3)
Root cause: ZCode's newer 405 (code 3012) suspension message no longer contains "request has been blocked", so provider.EdgeBlocked returns false, and retryable() did not check restrictedSaid(). That caused holdWriter.failed() to return false (aborting routing groups at tries=1) and decideFailed() to skip resting.
Changes:
- Add
case restrictedSaid(status, body): return trueininternal/gateway/fallback.go(retryable), keepingriskRefused()skipping sibling accounts of the restricted provider and keeping plain 405 / 200 non-retryable. - Decode
bodywithwordsOf()inrestrictedRefused()(internal/gateway/routing.go) so JSON-escaped hints match consistently withfailure()andretryable(). - Add
TestRestricted4xxFailsOverininternal/gateway/zcode_blocked_test.go.
Verification (Windows 11 amd64, Go 1.26.8):
- Before fix:
TestRestricted4xxFailsOverfailed (retryable(405, ZCodeRestrictedHint) = false). - After fix: targeted suite (
TestRestricted4xxFailsOver|TestZCodeStartPlanBlockRestsRestricted|TestZCodeRiskControlNotToldAsFirewall|TestRiskRefusal|TestWorkBuddyRestricted|TestOnlyWorkBuddyRestricted|TestRestrictedLoneAccount|TestSuspendedAccounts|TestDecide) passed-count=5;go vetpassed on Windows/Linux/macOS (-racenot run, no cgo compiler locally).
Fixed in v0.1.4840. A group now fails over when ZCode answers 405 with code 3012.
ZCode's newer suspension text ("Your account has been suspended for misusing the Start Plan…") no longer says "request has been blocked", so retryable() didn't treat the 405 as one another provider could take. Now any 4xx that carries magpie's restricted-account hint is retryable:
- the ZCode account rests as restricted;
- the group's next member answers;
- ZCode's other accounts are still skipped for that request, since the vendor's risk control reads the request too.
A plain 405 still goes back to the agent.
Thank you @qq01-hub for the fix and the root cause. Your commit (36b76f775) landed as you wrote it, under your name. A follow-up (da02781fa) adds a test of this exact case through the ZCode plugin, with your trace's words. That test fails on the old code, and it also fails with the new retryable case removed by hand.
Not changed: your third point, a longer rest for a suspended account. It still rests 2 hours, so every 2 hours one request tries it once and then fails over.
@ArmedHelicopter, I'll leave this open until it works for you on group/agentcompass. After updating, the routing log should show two tries for these requests, not one.