Files
magpie/docs/subsystems
yetone ee6f8866f3 gateway: Claude Desktop's connection check goes to its default model
CyberCaius on Discord, v0.1.1838, after restarting Claude Desktop: as it
starts and from Test connection (Configure third-party inference ->
Gateway), Desktop said "Gateway rejected model
magpie-0958175816.anthropic.claude-haiku-5-5[1m] (HTTP 400)", the body
"AnyRouter: bad response status code 400". His default model in Desktop
is his routing group 天翼云; Routing showed leee/claude-haiku-5-5 sent to
AnyRouter gpt-6.1-sol.

Why 02a328d86 (v0.1.1821) didn't cover it: it routed the check as a
title is, to desktopPicked, the model the last session's tool turn ran
on, kept on disk across restarts. At start and in Desktop's settings no
session is running, so that was a days-old AnyRouter session's model,
not the model he chose. Desktop names the check's model itself (YT in
its app.asar 2.7032: the shortest /v1/models id with haiku in it, here
leee's haiku), and its own settings call the first listed model the
default ("the default model (the first listed model)",
resolveDefaultSessionModel). And AnyRouter 400'd the check because a
max_tokens of 1 reaches the GPT model below OpenAI's floor of 16; the
relay passes on no floor, so tokenFloor had nothing to ask again at
(02a328d86's test faked OpenAI's own wording, which a relay hides).

Now desktopProbe (Desktop's exact body: max_tokens 1, one user message
".", no system or tools) goes to desktopDefault, the first model listed
to Desktop (its order on the Agents page), so his 天翼云 group gets it
with zero config. The check is asked for 16 tokens upstream
(desktopProbeTokens); Desktop reads only whether it is answered. Titles
still go to the session's model.

Tests: TestClaudeDesktopProbeToSessionModel becomes
TestClaudeDesktopProbeToDefaultModel, with the literal id
magpie-0958175816.anthropic.claude-haiku-5-5[1m] (leee/claude-haiku-5-5's
alias), a session turn on anyrouter/gpt-6.1-sol first, 天翼云 as a group
listed first, and a relay that answers fewer than 16 tokens with
AnyRouter's opaque 400. The check reaches 天翼云 (leee and the relay get
nothing); with the relay's model listed first it is answered there in
one call. TestDesktopProbe is back.

Run (mote, at this tree):
- go test -tags nogui ./internal/gateway/ -run 'Desktop|Title|CacheKey|
  TooFew|TokenFloor|Alias|Science': ok
- Not run to the end: the whole internal/gateway package (started on
  mote, still running when this was pushed as asked) and the full suite.
- go vet ./internal/gateway/ (darwin, GOOS=linux, GOOS=windows), go
  build ./...: ok; gofmt -l: clean

Broken by hand: the probe branch taken out of desktopTurn -> red "probe
went to leee () or the relay (1 calls), not Desktop's default 天翼云";
the 16-token room turned off -> red with his exact error, 400 "AnyRouter:
bad response status code 400".

No GUI file is reached. Not tried: a real AnyRouter account or a real
Claude Desktop (read from its 2.7032 app.asar). A user whose first
listed model is not the one they mean by default gets the check there:
it is Desktop's own definition.
2026-10-28 15:32:20 +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
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.