Files
magpie/docs
yetone 0746140772 gateway: the Qwen Token Plan's concurrency 429 is asked again on the same account (pelikanade on X)
pelikanade on X: under many requests at once the Qwen Token Plan answers
"HTTP 429: Qwen Token Plan: Allocated quota exceeded, please increase
your quota limit" with plenty of quota left, and a retry by hand works.

Cause: d83f887a7 made DashScope's "Allocated quota exceeded" a rate
limit for the rest (dashScopeRate, in failureOf), but passing and busy,
which decide whether the same one is asked again and whether patience
waits, read the body through failure(), which knows no vendor and reads
"quota" as out of quota. So a lone Qwen Token Plan provider gave the
agent the 429 after one try. A group moved on at once and rested the
member a minute.

Fix (qwen_plan_busy.go, gateway.go):
- qwenPlanBusy: a 429 from the qwen-token-plan preset or a provider at
  token-plan.maas.qianwenaiapi.com, in dashScopeRate's words (not its
  free allowance, nor a Coding Plan's hour/week/month).
- passingFor/busyFor replace passing/busy at the try loop's last-one
  and patience sites: that 429 is asked again on the same account up to
  rateRetries (3) times, with jittered pauses of about 1, 2 and 4s (half
  to one and a half of each, so one burst's requests don't come back
  together), or after the vendor's Retry-After, then within the
  provider's patience, as any rate limit is. The error is held, so
  nothing reaches the agent before then.
- A group member that isn't last is asked again in place as often
  (planAgain) before the group moves on. Only then does it rest, as a
  rate limit (failRate, a minute), never as out of quota.
- Other vendors are unchanged. DashScope pay-as-you-go (same words, a
  real per-minute limit), the Bailian and Alibaba Cloud Token Plans and
  any other provider still get one try. Bailian and Alibaba Cloud are
  the same plan on other hosts, but nobody has reported the concurrency
  429 there: #6950.
- docs/subsystems/gateway-routing.md: a bullet after the minute-limit one.

Tests (fixtures are the reporter's words, in OpenAI's and DashScope's
error shapes, and Anthropic's for /apps/anthropic):
TestQwenPlanConcurrencyIsAskedAgain (lone: 429, 429, 200 is served on
the 3rd try with no rest; one that never clears is tried 1+3+12 times,
like any rate limit), TestQwenPlanConcurrencyInAGroup (served in place,
or after 4 tries the next member is asked and the member rests as
rate), TestQwenPlanConcurrencyOnAnthropic,
TestOtherVendorsAllocatedQuotaUnchanged (qwen-cn, bailian-token-plan
and a plain relay: one try alone, next member at once in a group),
TestQwenPlanBusyScope.

Run:
- Red on the old code (gateway.go from origin/main, the new tests kept):
  IsAskedAgain gave "429 after 1 tries" with the reporter's exact text
  ("Qwen Token Plan: Allocated quota exceeded, please increase your
  quota limit"), and InAGroup gave qwen 1, b 1.
- Broken by hand, the scope widened to every DashScope provider:
  TestOtherVendorsAllocatedQuotaUnchanged went red for qwen-cn and
  bailian-token-plan (alone 200 after 3 tries; in a group a 3, b 0), and
  TestQwenPlanBusyScope went red for dashscope.aliyuncs.com and
  token-plan.cn-beijing.
- mica: go test ./... -count=1 -timeout 45m at 9fa2a63c0 (this change
  on 167101d57): 102 ok, internal/gateway FAIL on my own test only.
  IsAskedAgain checked Again > 0, but a jittered 1ms test pause can
  round to 0ms. It now checks Fail == rate. The "close of closed
  channel" in the log is a recovered http panic in continuation_test's
  doneHold fake, and the package's verdict didn't depend on it.
- mica: the new tests -count=20 ok after the fix.
- At the pushed tree (rebased on cd89ccdb4): go vet, GOOS=linux go vet
  -tags nogui and GOOS=windows go vet of ./internal/gateway, and go test
  ./internal/gateway -count=1 -timeout 45m: vet ok on all three, ok (957s). gofmt -l empty.
- Rebased again on 64ad53f6c (claude_subscription.go and sessions_mcp.go
  changed in the gateway, not gateway.go): go vet ./internal/gateway and
  go test ./internal/gateway -run 'QwenPlan|OtherVendorsAllocatedQuota|
  DashScope|ClaudeSubscription': ok.

Not tried: a real Qwen Token Plan key under concurrency (there is none
here), so the real host's wait before it serves again is not measured.
2026-11-17 17:40:23 +08:00
..