Files
magpie/docs/subsystems
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
..
2026-11-10 03:25:44 +08:00

Subsystem design references

These pages describe current responsibilities, runtime paths, state, and contracts. Start with the subsystem relevant to your task, then follow its source links to verify the implementation you change.

Subsystem Reference
Built-in subscriptions moving to plugins Provider and plugin ownership
Built-in plugins: registry, lifecycle, plugins.yml, presets, settings schemas, the window's kernel (slots, error boundary, kit) Plugin runtime
Plugins that run on the gateway's requests and replies Gateway middleware
Tools that plugins give, offered to every agent as an MCP server Plugin tools
Plugins that await context recall and observe completed replies Asynchronous gateway request hooks
Claude subscription turns across Claude Code runs Claude subscription bridge
How the gateway picks a provider, key or account, and falls back Gateway routing and fallback
Gateway Session Aggregation Gateway Session Aggregation
Connecting an agent's config to the gateway, drift, disconnect, WSL twins Agent wiring
Providers, keys, subscription accounts, refresh and allowance Providers and accounts
Instructions, MCP servers, skills and RTK written into agents Library
One MCP server, magpie, given to every agent in place of the Library's servers MCP router
Memory shared by every agent: the memory MCP server, the digest in instructions, the Memory tab Memory
One skill, magpie-skills, listing the Library's skills in place of each agent's own Skill router
Tray, panel, window, magpie web and the page's JSON API GUI app shell
Encrypted backups and setup synchronization over WebDAV, S3 or GitHub Sync and backup

A subsystem can span several packages or repositories. Its reference describes the behavior those parts provide together; it does not need to list every function.

Maintain a reference

Update the owning reference in the same PR when a change alters a documented responsibility, interface, state transition, runtime path, compatibility rule, or failure behavior. An internal refactor that preserves these contracts does not require a prose change.

Keep each fact in one reference and link to it from agent instructions or other pages. Link to source files and named symbols rather than copying implementation details that change frequently. Explain field meanings and constraints that signatures alone do not express.

For a new reference, include the responsibilities and boundaries, source of truth, main runtime paths, state transitions, important constraints, and existing verification commands. Include failure and compatibility behavior where relevant. Document current behavior separately from proposed changes; the proposal belongs in its issue or PR.

Describe a PR's semantic changes

For each affected subsystem, explain the observable change with its trigger and before/after behavior. Include changes to interfaces, state, compatibility, and failure behavior when relevant. Link the affected reference, implementation, and verification evidence. State when a refactor preserves the documented behavior.

For example, a change to plugin adoption should explain which migration state and account condition trigger it, which implementation handles requests before and after adoption, and which test exercises that transition.

This is an author-provided explanation that a reviewer verifies against the diff and surrounding code. It is not an automatically proven compatibility verdict.

Review a change

  1. Identify the affected subsystem and the actual runtime path, including plugin or built-in ownership.
  2. Compare the claimed before/after behavior with the base and head implementation. Trace relevant callers and state transitions beyond the changed lines.
  3. Check that changed contracts appear in the owning reference and that source links still resolve.
  4. Check that the cited tests or runtime evidence exercise the claimed behavior. Report checks that were not run.

A documentation update alone does not prove the implementation. Existing tests and runtime evidence remain necessary for behavior changes.