What was wrong: AutoVision (the model that describes images for models
that can't see) and autoSearcher (the model that searches for models
that can't) pick a provider and model before routing runs. They never
looked at routing's allowance state. That state covers accounts barred
at a usage cap, rests for quota or credit, and full key or subscription
windows. Routing then had one candidate and tried it all the same. Each
image or search was sent to the account that had run out and got the
same 429 again, while another provider with allowance sat unused.
What changed:
- fallback.go: spentModel(p, model, from, now). A model is spent when
every candidate routing would try for it (perKeyBarred) is capped,
resting for quota or credit, or has a full window (candidate.full,
model-aware for pools). It also says when the first one is back. A
rate rest doesn't count.
- search.go: smallModel goes through smallReady, which prefers models
that aren't spent (pickSmall keeps the old choice among them).
autoSearcher ranks a searcher with allowance before searchRank.
modelSearch doesn't ask a spent searcher that magpie picked
(searcherSpent), tries the others with allowance first, and adds why
it skipped to its error. A searcher named in Settings is asked as
before.
- vision.go: AutoVision ranks ready first, then tier and cost. When
every describer is out it still names one, so seer and Described
(which tell agents every model takes images) don't flip with a
window. askVisionWith (gateway and MCP) answers an auto describer
that is spent with the reason and when it is back, and doesn't call
upstream. A describer named in Settings is asked as before.
- Image and video generation (AutoDrawer, AutoVideomaker) are left
as they were.
- docs/subsystems/gateway-routing.md: new section, tests added to
Verification.
What was run:
- New tests in side_spent_test.go: TestAutoVisionPassesOverOneOut,
TestAutoVisionTierAmongThoseWithAllowance,
TestSpentModelAcrossAccounts, TestVisionDoesNotAskSpentDescriber and
TestSearcherPassesOverOneOut.
- Broken by hand three ways:
- spentModel returning false: all five go red.
- Only autoSpent's check in askVisionWith removed:
TestVisionDoesNotAskSpentDescriber goes red (200 from upstream).
- Only modelSearch's skip removed: TestSearcherPassesOverOneOut goes
red.
- go test ./internal/gateway -run 'Search|WorkBuddy|Kimi|Vision|Spent|PassesOver'
- gofmt -l, go vet ./... (darwin), GOOS=linux go vet -tags nogui ./...,
and GOOS=windows go vet ./... are all clean.
- Full go test -timeout 40m ./... in a sandbox HOME at load 66-100:
47 packages ok. internal/gateway and internal/agent hit the 40m
package timeout. Gateway also had failures, each filed:
- TestOTelWaterfall* (#1794, fixed on main since).
- TestCodexHeardWithinItsIdleTimeout (#1800).
- TestIntentClassifierGroup (3.17s against a 3s bound, filed as
#1813).
All of them pass alone, and go test ./internal/gateway on its own is
ok (982s).
Not verified: not tried with a real account that has run out. Windows
was only vetted.
What: beside /mcp/magpie/web-search, the gateway serves the model that
describes images (Settings › Models › Image recognition, else magpie's
automatic pick) as a Streamable HTTP MCP server. analyze_image takes an
image (absolute file path, http(s) URL or data:image URL) and an optional
prompt: without one it is described as a model's image is (same cache and
system text), with one the prompt is asked beside it. The JSON-RPC serving,
guard and Origin check are shared with the web search server (serveMCP).
A file path is read only for a local, unproxied caller, up to 20 MB, and
only when its bytes are an image; another computer sends a URL or data
URL with a gateway key. Each call holds the key's limit (budget.Reserve)
and reads in Routing as the agent's analyze_image call. Settings › Models
shows the address under Image generation (#visionMcpRow), in every
language.
Run:
- go test -tags nogui ./... (no failures); gofmt -l clean; GOOS=linux and
GOOS=windows go vet ./internal/gateway.
- New TestVisionMCPAnalyzesImage / WithNoSeer / Guarded / HeldToKeyLimit.
Broke the local() guard by hand: TestVisionMCPGuarded went red on the
other computer's file path being read.
- GUI (chromium + webkit, en/zh/zh-TW/ja/de, 1100 and 520px):
vision-mcp, search-mcp, public-url-default, images-missing,
settings-sections, i18n-keys, routing-vision-why: 95 pass. The row was
first put between the two pickers and images-missing went red (it finds
them by position), so it sits last.
- Real use: this build under a sandbox HOME holding only the owner's
OpenRouter provider, Image recognition set to openai/gpt-6-luna.
initialize, then tools/call with docs/screenshots/font-settings.png as a
file path and a prompt: the model listed every settings row and its
value correctly.
Not tried: a real agent (Claude Code, Cursor) mounting it; its MCP
exchange is the same as the web search server's.
On a provider with a long list, AutoVision and the searcher picked their
small model from everything the vendor lists (Available), not from what
the user enabled. A Trae CN user's text-only model had its image sent to
OpenRouter's anthropic/claude-haiku-5.5, which they never enabled and
which OpenRouter refused for their region (403).
smallModel, and so AutoVision, searcherModel and the searcher's
first-model fallback, now chooses from Exposed: the user's picks, else
what agents are offered. With no enabled model that sees, a request
turned away says so ("none of the models enabled in magpie can see
images ... enable one that can, or pick one in Settings → Models → Image
recognition"); Vision off says it is off; a describer magpie picked
itself that fails is named as magpie's pick.
Not done: no fallback to another describer on a refusal. With the pick
limited to enabled models, a refusal is of a model the user chose, and
the error now names it and where to change it. Image generation's
AutoDrawer still picks from image models a provider lists: image models
aren't in the chat pickers, so limiting it to picks would turn drawing
off for nearly everyone.
Run: the two new tests fail on the old code (AutoVision =
router/google/gemini-3-flash, searcherModel = google/gemini-3-flash) and
pass now; go test ./... green except internal/gui's
TestDockJoinLeadsCommandTab, which reads the live desktop's Command-Tab
order and passes run alone; gofmt; GOOS=linux and windows go vet
./internal/gateway.
Before, if the picked model didn't resolve (its provider removed or turned off, or the model gone), seer() and drawer() quietly fell back to AutoVision/AutoDrawer. Settings still showed the gone id as the pick, and Routing showed only the automatic model. The turn still goes ahead with the automatic model, so nothing the user sends breaks. What changed is that magpie now says so:
- VisionMissing and DrawerMissing (pickedMissing) name the pick that doesn't resolve. /api/settings carries them as visionMissing and imageGenMissing.
- CallFor.Missing is set on every description (withDescribeFor). This covers the single-model and group paths and every protocol. routing.js tells that story first.
- With no automatic describer either, the 400 and 502 a turn is refused with name the missing pick and where to change it. So does a draw request that names no model.
- renderImages and renderImageGen show "<id> · missing" in the picker and a red line under the row. The line names what stands in, or says nothing does, and asks the user to pick another model.
- zh, zh-TW, ja and de are translated.
Verified:
- New internal/gateway/vision_missing_test.go. I took out the behaviour (Missing on the row, the notes, the draw message) but kept the helpers so it compiles. Both tests then FAIL:
vision_missing_test.go:80: probe/text anthropic: the description's row is for {Agent:other Model:probe/text Unknown:false Missing:}, want it to name the missing gone/bigeye
(the same on responses, codex and chat, and for group/mixed)
vision_missing_test.go:116: probe/text with no describer: 400 ... "model \"probe/text\" does not support image input"
vision_missing_test.go:135: no drawer: 400 ... "no model to draw with: pick one in magpie's Settings → Images → Image generation, or name one"
- New internal/gui/tests/images-missing.test.cjs checks Settings › Models in en and zh at 1000px and 360px: the picker text, the line inside its row, and no page overflow. A pick that is found shows as before. routing-vision-why.test.cjs gains the missing row. With app.js and routing.js from before this change (Chromium): pass 2, fail 7.
- node --test images-missing, routing-vision-why, routing-side-calls, settings-sections, gui-ja, gui-de, gui-zh-tw and i18n-keys in Chromium and WebKit: 42 pass, 0 fail.
- go vet -tags nogui ./internal/gateway ./internal/gui passes on darwin, GOOS=linux and GOOS=windows. go build -tags nogui ./... passes.
- HOME=<tmp> go test -tags nogui ./internal/gateway ./internal/gui: ok (208.5s, 36.9s).
Not verified: no real magpie instance with a provider actually removed. The gateway was exercised through Handler with fake upstreams, and the GUI with a faked /api/settings. Drawing's own Routing row still doesn't say its model fell back: drawing calls have no story in kindWhy. Only the Settings row and the refusal say it.
The reporter set Codex to deepseek-v4.1-flash and saw a row "codex/gpt-6.1-sol · 图片描述" in Routing. The model was counted as unable to see images. With no Image recognition model set, magpie had a Codex account's model describe the image (AutoVision). The row said only "which can't see images", so it gave no reason and no way to change it.
CallFor gains Unknown. It is set when blindTo counted the model as text-only only because nothing says it sees (the request has no imageInput of its own). This holds on both the single-model path and the group candidate path. routing.js's kindWhy gives each case its own story. zh, zh-TW, ja and de are translated.
Verified:
- New TestDescriptionSaysWhyTheModelCantSee sends an image on the responses, codex, chat and anthropic routes. It covers an unknown model, a model whose list says text only, and a group of each. Without the gateway change it FAILs, e.g.
vision_unknown_test.go:182: probe/text responses: the description's row is for {Agent:other Model:probe/text Unknown:false}, want unknown true
with the same failure on codex, chat, anthropic and group/unknown.
- internal/gui/tests/routing-vision-why.test.cjs checks the vision row's tag and story in en and zh, in Chromium and WebKit. With routing.js from before this change it gives pass 0, fail 2.
- node --test routing-vision-why, routing-side-calls, gui-ja, gui-de, gui-zh-tw and i18n-keys: 18 pass, 0 fail.
- go vet -tags nogui ./internal/gateway ./internal/gui passes on darwin, GOOS=linux and GOOS=windows.
- HOME=<tmp> go test -tags nogui ./...: all ok except the root package and internal/plugin (TestHostRunsAsMagpieBun context deadline). Those fail only in the full run under load. Run alone, both pass (34.9s, 122.7s).
Not verified: the reporter's real provider. A throwaway test against the real models.dev data found no preset where deepseek-v4.1-flash counts as unable to see. So their case is one of: their provider's list says text only, a model setting, a stale models.dev cache, or a plugin. That is asked on the issue.
Distinguish decision-only providers from gateways that also serve conversations. Only Jev models use the decision API; ordinary models remain in the catalog, automatic groups and conversation routes. Keep the full model cache when probing a mixed provider’s decision endpoint, and allow conversation model tests in its editor.
Verified with go vet -tags gtk3 ./..., go test -tags gtk3 ./..., node --check internal/gui/assets/app.js, and an isolated browser fixture.
Amp-Thread-ID: https://ampcode.com/threads/T-01a0fe05-afd7-70df-97cf-fdb69c4f4680
Co-authored-by: Amp <amp@ampcode.com>