Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
gateway: Claude Desktop's model check goes to the session's model again
yetone02a328d86a88
diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.mdindex 073737f60..60d613082 100644--- a/docs/subsystems/gateway-routing.md+++ b/docs/subsystems/gateway-routing.md@@ -271,7 +271,7 @@ recorded as a prediction failure (`noPrediction`).- Locally, Claude Code's classifier is a request of its own on the session's model: no tools, a system prompt asking for `<block>yes</block>` or `<block>no</block>`, the transcript in `<transcript>`, a small `max_tokens`, and no stream; Claude Code 2.1.310 waits 60 seconds an attempt for it. To a model that isn't Claude it goes with `classifierRoom` (2048) added to a limit below it and asked to reason least (`fitAutoModeClassifier`): none, or the lowest of the model's known levels. A model whose levels magpie doesn't know (a relay's own name, gpt6.1-sol) is asked for none too, as magpie's own ask (`Request.OwnEffort`): left to the vendor, a reasoning model reasoned at its default past the 60 seconds and every classifier request ended 499 (CyberCaius on Discord). Its 400 to that effort (`ownEffortRefused`) is asked again at low when it named the level, and without the effort when it named the field ("Unrecognized request argument supplied: reasoning_effort"), remembered in `unfit` until magpie restarts (`TestAutoModeClassifierReasonsLeastOnAnUnknownModel`, `TestAutoModeClassifierEffortRefusedGoesWithout`).- Claude Code's billing line (`x-anthropic-billing-header: cc_version=…; cc_entrypoint=…; cch=…;`, its own first system block, `cch` changing every turn) goes on only to a Claude model asked on Anthropic's Messages API (`keepsBillingLine` in [`billing_line.go`](../../internal/gateway/billing_line.go): Anthropic's, a relay's, Bedrock's), as Claude Code sent it. Anywhere else it is left out, the rest of the system as sent (`withoutBillingLine`): a vendor's model relayed on Messages (`passthrough`), every translation to Chat, Responses or Gemini (`forwardTranslated`, Claude models too). Kept, a vendor read it as the prompt's first words and its prefix cache missed from byte 0 every turn (#1600, justrun1983: 4% read from DeepSeek's cache behind Command Code's plan). The Claude subscription's run sends its own (`withoutBillingHeader`), another magpie decides for the provider it picks, and Code Assist (Antigravity, Gemini CLI) is sent it as before, which `antigravityTurnsAway` reads (#666). Once Antigravity has turned such a request away, for `agForeseeing` (6 hours) after, a candidate loop with someone left after an Antigravity account skips it for a request that carries the line, without asking it (`antigravityForeseen`, #2156: each Claude Desktop turn waited about a second on the same refusal before the next member). The skip goes in `Fallback` with the hint, nothing rests, and the agent is told the refusal if nobody after it answers but with a quota. The last one left is still asked, and an old refusal foresees nothing, so a block Google lifts is noticed (`TestAntigravityTurnedAwayIsForeseen`). Codex's own identity line for its GPT-5 models ("You are Codex, an agent based on GPT-5", "…a coding agent based on GPT-5", any case) is turned away the same way (`antigravityTurnsCodexAway`): Codex sends its model's prompt as the thread's first developer message, which goes in as the system instruction, and a thread begun on a GPT model keeps it after `/model`, `resume -m` or a fork as an agent's thread, so such a thread on an Antigravity model 429'd until Codex's retry limit while dsh on the same account answered (Jodiezzzzzz on X, 10-27). It gets its own hint (`antigravityCodexHint`: start a new chat on the model, which is sent magpie's own Codex prompt "You are Codex, based on GPT-5.", which Antigravity answers), chosen by `antigravityHint`. Codex sends its `web_search` tool every turn, so an Antigravity model's Codex turn goes through magpie's own search (`searchReply`); its rounds are wrapped in `antigravityRound`, which tells the 429 (or the reply's error event) the same way and marks the attempt, where before the search path returned the bare 429 that Codex retried to its limit.- A request translated to a Chat or Responses upstream that carries no `prompt_cache_key` of the client's (every Anthropic client's) gets one for its conversation when the provider is OpenAI's API with a key or one the user added by its address (`ownCacheKey`, `cacheKeyOf` in [`gateway.go`](../../internal/gateway/gateway.go)): a hash, in a UUID's shape, of the session the client names, else of its first user message, so every turn of it has the same key and nothing in it names the client or magpie. A relay can turn a request away without one ("prompt_cache_key is required", CyberCaius's AnyRouter). A vendor's preset, a signed-in account, a plugin, Bedrock and Vertex get none, nor does a provider whose extraBody names `prompt_cache_key` (the user's value is sent). An upstream whose 400 names the field is asked again without it and not sent it again; another 400 is not asked again for it, so an unrelated refusal is tried as often as before.-- Claude Desktop's check that a gateway model answers (`{"max_tokens":1,"messages":[{"role":"user","content":"."}]}`, sent as it starts and by its settings' Test on the first haiku it is listed, else sonnet, else opus) goes to the model it names (`desktopProbe` in [`desktop.go`](../../internal/gateway/desktop.go)), not to the session's model as a title does: sent there, a failure of the session's model was shown as the haiku rejected (CyberCaius on Discord).+- Claude Desktop's check that a gateway model answers (`{"max_tokens":1,"messages":[{"role":"user","content":"."}]}`, sent as it starts and by its settings' Test on the first haiku it is listed, else sonnet, else opus) is routed as a title is (`desktopTurn` in [`desktop.go`](../../internal/gateway/desktop.go)): to the session's model, never to another provider's Claude model whose quota it would spend (CyberCaius on Discord, after v0.1.1819 sent it to the haiku it names). A relay's floor on max_tokens is met by asking again (`tokenFloor`), and a relay that needs `prompt_cache_key` gets one (above), so the check is answered there.- Antigravity answers a system instruction holding one of a few lines with a 429 "Resource has been exhausted" whatever quota is left, on every model (`agTurnedAway` in [`codeassist.go`](../../internal/gateway/codeassist.go)): Claude Code's billing line, the Claude Agent SDK's identity line, Codex's identity lines for its GPT-5 models (which a Codex thread begun on a GPT model keeps after a switch), and Hermes Agent's earlier default persona. An Antigravity account's system instruction goes with a zero-width space after each such line's first letter (`antigravityCloak`, in `codeAssistBody`), which Google lets through and the model reads the same; every other provider, Gemini CLI's sign-in on the same envelope included, is sent the prompt as written. `magpie provider set antigravity prompt=as-written` (`Provider.PromptAsWritten`) turns it off. The refusal is still told against the system prompt as the agent wrote it (`antigravityTurnedAway`): a 400 with the hint for that prompt, the account not rested, and a group skipping Antigravity for that prompt for 6 hours after a refusal (`antigravityForeseen`).- Claude Code's advisor (`/advisor`, `--advisor`) is Anthropic's server tool `advisor_20260301`, its `model` named as Claude Code names its own: on magpie, by magpie's id (the tier an alias like `opus` is on), which no vendor knows, so the request was turned away whole (JackChou on Discord). Relayed on Messages (`passthrough`), the advisor's model goes as the upstream's own name for it when it is the same provider's Claude model, or a Claude id naming no provider (`advisorTools` in [`advisor.go`](../../internal/gateway/advisor.go)); one it can't run there (another provider's, a group, not Claude's) is left out, as is every advisor when the request's own model isn't a Claude model (a vendor's Messages API knows no such tool), and the turn is answered without one. A translation drops it with every other server tool. Claude Code (2.1.300) also puts the advisor in the conversation: a `{role: "system"}` message whose text ends in its instructions ("# Advisor Tool … call advisor BEFORE substantive work") and a `tool_addition` naming it. Where the advisor is left out, that `tool_addition` goes too (and a message it leaves empty), and the instructions become Claude Code's own "The advisor tool is no longer available; disregard the earlier advisor instructions." (`withoutAdvisor` on Messages, `advisorGoneIn` in `parseAnthropic` for a translation): left there, the model called `advisor()` as one of the agent's tools and Claude Code answered "No such tool available: advisor" (JackChou on Discord). The Claude subscription's run declares only magpie's tools, so it never has one. `TestAdvisorModelAsTheUpstreamNamesIt`, `TestAdvisorLeftOutOnTranslation`.- Kiro is told where to cache the prompt (plugins#110: a Kiro subscription read 0 from its cache). Its API takes Bedrock's `cachePoint: {"type":"default"}` on a `userInputMessage`, an `assistantResponseMessage` or as a tool entry. The built-in (`buildKiro` in [`kiro.go`](../../internal/gateway/kiro.go)) marks the first message when there is a system prompt, which it folds into that message, and the current message, as `buildAnthropic` marks Anthropic's. A moved Kiro's plugin (opencode-kiro-auth 0.1.10, the mover's `min`) turns each `cache_control` in the Anthropic body it is handed into one, at most 4, the last kept.diff --git a/internal/gateway/desktop.go b/internal/gateway/desktop.goindex 4e5c0aee0..463863b83 100644--- a/internal/gateway/desktop.go+++ b/internal/gateway/desktop.go@@ -483,10 +483,6 @@ func desktopTurn(asked string, body []byte, byClaudeCode, bySubagent bool) strinif m := desktopTierTurn(asked); m != "" {return m}- if desktopProbe(body) && !unserved(asked) {- // Desktop's check that the model works: asked of it alone- return asked- }tools := hasTools(body)desktopPicked.Lock()defer desktopPicked.Unlock()@@ -593,32 +589,6 @@ func desktopDefault(asked string) string {return shown[0].ID}-// desktopProbe: the request is Claude Desktop's check that a gateway model-// answers, which it runs as it starts and from its gateway settings' Test:-// {"model":<it>,"max_tokens":1,"messages":[{"role":"user","content":"."}]}-// (lWt with JUt in its app.asar, 2.7032), on the shortest id with haiku-// in it, else sonnet, else opus (YT). It is small and tool-less like a-// title, but it asks whether that model answers: sent to the session's-// model instead, a failure there was shown as the haiku model rejected-// ("Gateway rejected model …haiku…", CyberCaius on Discord, whose session-// was on a relay's GPT model that turned the request away).-func desktopProbe(body []byte) bool {- var v struct {- MaxTokens int `json:"max_tokens"`- System json.RawMessage `json:"system"`- Tools json.RawMessage `json:"tools"`- Messages []json.RawMessage `json:"messages"`- }- if json.Unmarshal(body, &v) != nil || v.MaxTokens != 1 || len(v.System) > 0 || len(v.Tools) > 0 || len(v.Messages) != 1 {- return false- }- var m struct {- Role string `json:"role"`- Content string `json:"content"`- }- return json.Unmarshal(v.Messages[0], &m) == nil && m.Role == "user" && m.Content == "."-}-// desktopTitlePrompt is how the system prompt Claude Desktop asks a// session's title and branch name with starts (dcr in its app.asar), sent// by its own client or, when that fails, as Claude Code's --system-prompt.diff --git a/internal/gateway/desktop_probe_test.go b/internal/gateway/desktop_probe_test.goindex e20a7b12c..3440b3a94 100644--- a/internal/gateway/desktop_probe_test.go+++ b/internal/gateway/desktop_probe_test.go@@ -1,7 +1,6 @@package gatewayimport (- "bytes""encoding/json""net/http/httptest""strings"@@ -22,16 +21,26 @@ func relayNeedsCacheKey(body []byte) (int, string) {// Claude Desktop checks a gateway model as it starts with// {"max_tokens":1,"messages":[{"role":"user","content":"."}]} on the first-// haiku it is listed. With a session on a relay's GPT model, magpie took-// that check for a title and sent it to the relay, which turned it away,-// and Desktop said the haiku model was rejected (CyberCaius on Discord).-// The check goes to the model it names; a title still goes to the-// session's model, and reaches the relay with a cache key it needs.-func TestClaudeDesktopProbeAsked(t *testing.T) {+// haiku it is listed. It goes, as a title does, to the session's model:+// the one the user picked, never another provider's Claude model, whose+// quota it would spend (CyberCaius on Discord, after v0.1.1819 sent it to+// leee's haiku). On a relay's GPT model it once failed for the cache key+// the relay needs (shown as the haiku rejected); with the key, and the+// relay's floor on max_tokens met by asking again, it is answered.+func TestClaudeDesktopProbeToSessionModel(t *testing.T) {claude := &fake{t: t, reply: sse(`event: message_start`+"\n"+`data: {"type":"message_start","message":{"id":"m","type":"message","role":"assistant","model":"claude-haiku-5-5","content":[],"usage":{"input_tokens":1,"output_tokens":0}}}`,`event: message_stop`+"\n"+`data: {"type":"message_stop"}`)}- relay := &fake{t: t, reply: deepseekReply, refuse: relayNeedsCacheKey}+ relay := &fake{t: t, reply: deepseekReply, refuse: func(body []byte) (int, string) {+ if c, m := relayNeedsCacheKey(body); c != 0 {+ return c, m+ }+ // as OpenAI's models answer a reply of fewer than 16 tokens+ if n := max(gjson.GetBytes(body, "max_tokens").Int(), gjson.GetBytes(body, "max_completion_tokens").Int()); n > 0 && n < 16 {+ return 400, `{"error":{"message":"Invalid 'max_tokens': integer below minimum value. Expected a value >= 16, but got 1 instead.","type":"invalid_request_error"}}`+ }+ return 0, ""+ }}up := setup(t, provider.Anthropic, claude)_ = upru := httptest.NewServer(relay)@@ -68,15 +77,18 @@ func TestClaudeDesktopProbeAsked(t *testing.T) {// Desktop's check of its haiku, by the id it was listedhaiku := "magpie-" + aliasNumber("leee/claude-haiku-5-5") + ".anthropic.claude-haiku-5-5[1m]"- relay.calls, claude.got = 0, nil+ relay.calls, relay.got, claude.got = 0, nil, nilif code, body := send(`{"model":"` + haiku + `","max_tokens":1,"messages":[{"role":"user","content":"."}]}`); code != 200 {t.Fatalf("probe: %d %s", code, body)}- if relay.calls != 0 || !bytes.Contains(claude.got, []byte(`"claude-haiku-5-5"`)) {- t.Fatalf("probe went to the relay (%d calls); leee got %s", relay.calls, claude.got)+ if claude.got != nil || modelOf(relay.got) != "gpt-6.1-sol" {+ t.Fatalf("probe went to leee (%s), not the session's model (relay got %s)", claude.got, relay.got)+ }+ if relay.calls != 2 {+ t.Fatalf("relay asked %d times, want 2 (the floor met once)", relay.calls)}- // a title still goes to the session's model, and the relay takes it+ // so does a titlerelay.got = nilif code, body := send(`{"model":"` + haiku + `","max_tokens":200,"stream":true,"system":"You write short session titles.","messages":[{"role":"user","content":"hi"}]}`); code != 200 {t.Fatalf("title: %d %s", code, body)@@ -93,21 +105,6 @@ func TestClaudeDesktopProbeAsked(t *testing.T) {}}-// desktopProbe knows Desktop's check alone, not a title or a turn.-func TestDesktopProbe(t *testing.T) {- for body, want := range map[string]bool{- `{"model":"x","max_tokens":1,"messages":[{"role":"user","content":"."}]}`: true,- `{"model":"x","max_tokens":200,"messages":[{"role":"user","content":"."}]}`: false,- `{"model":"x","max_tokens":1,"system":"You write short session titles.","messages":[{"role":"user","content":"."}]}`: false,- `{"model":"x","max_tokens":1,"messages":[{"role":"user","content":"hi"}]}`: false,- `{"model":"x","max_tokens":1,"tools":[{"name":"a"}],"messages":[{"role":"user","content":"."}]}`: false,- } {- if desktopProbe([]byte(body)) != want {- t.Errorf("desktopProbe(%s) = %v", body, !want)- }- }-}-// magpie's own cache key goes only to OpenAI's API and a provider the user// added by its address; a vendor's preset, a signed-in account and a// plugin get none. A relay that turns the field away is asked again