Commit Graph
2 Commits
Author SHA1 Message Date
yetone 51f66fe8bb gateway: Claude Desktop's haiku calls stay on the chat's provider, not another provider's Claude haiku (cybercaius on Discord)
cybercaius picked AgentRouter's gpt-6.1-sol in Claude Desktop, and the
Routing page showed Claude Code's background calls in the same chat
(3-9k tokens) going to leee/claude-haiku-5-5: "为什么Claude Desktop中模型
选择的是AgentRouter · gpt-6.1-sol,但在对话过程中还是会去请求leee供应商的
模型呢?"

Cause: magpie's own default, not a pick of theirs. desktopModels tagged
every Claude model magpie serves with its own tier in the /v1/models it
gives Desktop (anthropic_family_tier, f55747ce8) whenever that tier had
no pick. Desktop's Code tab hands a tagged model to Claude Code as
ANTHROPIC_DEFAULT_HAIKU_MODEL, its small, fast model, so every haiku
call (summaries, bash prefix checks and the like) asked for Leee's haiku
by its catalog id and was served there, whatever the chat was on.

Now:
- Only a model the user picked for a tier (claude-desktop.tiers.json,
  the Agents page's opus/sonnet/haiku/fable) is tagged. Untagged, Claude
  Code asks for its own id of the tier (claude-haiku-4-5-…).
- desktopTurn: a background call (no tools) or a subagent's turn for a
  Claude model by Claude's own id that is no catalog id (claudeOwnID)
  stays on the chat's provider (desktopPicked) even when another
  provider serves a model of that name; before, only an unserved one
  did. A lead's turn and a tier pick (a catalog id) go as asked.
- servedBeside: the chat's provider's model of that name (also one
  listed by the bare name), else its newest model of the same tier,
  beside the chat's model first, else "" and the call goes to the chat's
  model. A chat on GPT gets its haiku calls on that GPT; a chat on a
  provider with haikus keeps them on a haiku there.
- The tier picker's "Not set" note says so in en/zh/zh-TW/ja/de ("the
  chat's provider's model of the tier, else the chat's model").
- gateway-routing.md describes the rule.

A value the user set is untouched: a tier pick stays tagged and served
as picked (asserted in the new test).

Tests: TestClaudeDesktopBackgroundStaysOnChatProvider (new): AgentRouter
gpt-6.1-sol + Leee claude-haiku-5-5 + a third provider with two haikus;
asserts nothing tagged unpicked, Claude Code's haiku calls (bare
claude-haiku-5-5 served elsewhere, an unserved dated haiku, a subagent)
go to agentrouter/gpt-6.1-sol, a chat on the third provider gets its
haikus, and a picked haiku is tagged and kept. Red on 5143bf593 (old
code, test file only): "auto/claude-haiku-5-5 tagged "haiku" with
nothing picked". TestClaudeDesktopTiers expects no tag unpicked;
TestClaudeDesktopClassifierOnRemoteMagpie's unserved claude-haiku-4-5
now goes to the remote's claude-haiku-5-5 (same provider, same tier),
and an unserved fable still to the session's opus.

Broken by hand (mote, new test):
- elsewhere forced false: FAIL "chat on AgentRouter, claude-haiku-5-5
  (subagent false) sent to "claude-haiku-5-5"" (and the subagent and
  Claudeish cases).
- servedBeside's tier stand-in skipped: FAIL "chat on Claudeish,
  claude-haiku-4-5-20251001 sent to "claudeish/claude-opus-5-5"".
Restored, it passes. The first run of this change also turned the old
remote test's expectation red ("unserved: sent
"work/claude-haiku-5-5""), the tier stand-in at work; changed on
purpose, see above.

Run (mote, this change on 5143bf593): go test ./internal/gateway
./internal/agent/... -count=1 -timeout 45m: gateway ok (889s), agent ok
(469s). Rebased onto origin/main after the run; the commits since touch
no file here.
GUI (wsl-run, magpie-desktop): desktop-tiers.test.cjs chromium+webkit,
en+zh, 4/4 ok; i18n-keys.test.cjs 8/8 ok. gofmt -l clean.

Not tried: a real Claude Desktop. Desktop reads /v1/models at start-up,
so the change reaches it after Desktop is restarted.
2026-10-29 17:28:07 +08:00
yetone 429698f969 gateway: Claude Desktop's sonnet classifier on a Remote magpie's Claude session goes to that magpie's sonnet, not the session's opus (#2187, SuInk)
A Claude Desktop session on another magpie's Claude model
(office/claude/claude-opus-5-5) sent Claude Code's own background
requests for claude-sonnet-5 (auto mode's safety and notification
classifiers) to the session's opus. The remote lists the model as
office/claude/claude-sonnet-5 with the model claude/claude-sonnet-5, so no
entry had "claude-sonnet-5" as its id or model, unserved() said magpie
didn't serve it, and desktopTurn fell back to the session's pick. The
reporter's 9 such calls wrote 480K tokens of 1-hour cache on opus.

desktopTurn now asks servedBeside first for such a request: the entry of
the session's own provider whose model is "<prefix>/<asked>", preferring
the one beside the session's model (same subscription on that magpie).
Only the picked model's provider is looked at, so a same-named model of
another provider doesn't take it, and Desktop's title (and a title Claude
Code asks for on Desktop's behalf) still follows the session. A Claude
model the session's provider doesn't serve still goes to the session's.
unserved() itself is unchanged, so terminal Claude Code's stand-in and
DesktopTiers keep their meaning; Resolve couldn't serve a bare id of a
nested model anyway, which is why the answer is a catalog id here.

Test: TestClaudeDesktopClassifierOnRemoteMagpie (desktop_remote_classifier_test.go):
the gateway serves as the other magpie's model list over httptest, the
local "work" provider is then removed so only the remote serves Claude; the
session turn goes by the alias Desktop was shown (DesktopID), then two
classifier bodies (Claude Code 2.1.295/2.1.296 bytes from #1539), a
Desktop title, and claude-haiku-4-5 the remote doesn't list.

Broken by hand:
- servedBeside skipped (if false &&): FAIL "classifier: the other magpie
  was asked for "work/claude-opus-5-5", want work/claude-sonnet-5".
- applied to titles too (title rule dropped): FAIL "title: sent
  "work/claude-sonnet-5"".
Restored, it passes.

Run at d692b2548: gofmt -l (clean); go vet ./..., GOOS=linux go vet -tags
nogui ./..., GOOS=windows go vet ./... (clean); go test -tags nogui
-timeout 40m ./... under a sandbox HOME with pinned caches: 50 packages ok; internal/gui's
TestProviderListReadsSettingsOnce failed (23s against its 2s bar, load
~260), which is #2185, filed and being fixed apart; internal/agent and
internal/gateway hit the 40m package timeout at load ~260 with a test
that had just started (no hang in the stacks), and rerun alone with
-timeout 100m both pass (1304s, 1355s). go test -run
'TestClaudeTier|Desktop|Remote' ./internal/gateway passes.
Not tried: the reporter's real Claude Desktop against a real remote
magpie with a Claude subscription (no second machine with one here).
2026-10-14 22:36:15 +08:00