Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
groups: a model unchecked in its provider's list is not a member to route to (#3911)
yetonef561cc5d9ba1
diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.mdindex 5c0be0d2e..3e78531ba 100644--- a/docs/subsystems/gateway-routing.md+++ b/docs/subsystems/gateway-routing.md@@ -256,6 +256,7 @@ recorded as a prediction failure (`noPrediction`).- A tool's images reach the model on every translation (`toolOutput` in [`ir.go`](../../internal/gateway/ir.go) reads them from Anthropic's `tool_result`, Responses' `function_call_output`, such as Codex's `view_image` output `[{"type":"input_image","image_url":"data:…"}]`, and a Chat tool message). Anthropic's Messages keeps them in the `tool_result`. Chat puts them in a user message right after the results, and the result says they follow; Gemini and Code Assist after the function's response. Kiro's results hold text alone, so Kiro's plugin (from 0.1.9 on) sends them with the message that answers the call, and only the latest images go again (#369, #1861). `TestCodexToolImageReachesAnthropicPlugin` and the Kiro plugin's `tool-images.test.mjs`.- An image's `detail` (`Part.Detail`, read from a Responses `input_image` and a Chat `image_url`, in a message or a tool's output) is carried on a translation to Chat and Responses (`chatImage`, `chatDetail`, `responsesDetail` in [`chat.go`](../../internal/gateway/chat.go)). Chat takes `low`, `high` and `auto` as they came, and Responses' `original`, which Chat lacks, as `high`; an image without one goes without. Responses takes the four as they came, and anything else, none included, as `auto` (#1474). Messages and Gemini have no such field, so it isn't sent there (mysterious_dove on Discord, Codex: `high` and `original` were dropped on the way to Chat; `TestResponsesImageDetailReachesChat`, `TestChatImageDetailReachesResponses`).- Group members are `provider/model[:effort]`. A member with a fixed effort is asked for that effort, bounded by the group's levels (#671).+- A member the user unchecked in its provider's model list is skipped (`unpicked` in [`group.go`](../../internal/provider/group.go), in `membersOff`; #3911, timonwong): the provider has picks and its served models lack it, as the Routing page strikes it, and the Routing card says it is not ready (`provider.ResolveRoute`). A provider with no picks still routes a model its list lacks (#2642), a decision model is still a decision group's, and a request naming the model itself still reaches it (`resolveIn` takes any `provider/model` of a provider that is on). `group_model_pick_test.go`.- A group offers agents the reasoning levels its members have in common (`groupEntries` in [`group.go`](../../internal/provider/group.go)), or the ones it names (`Group.Levels`, #295). A member that doesn't follow the agent's effort is left out of that: one fixed at an effort, one whose levels nothing knows (#597), one that thinks with no levels, one the user made reasonless, and one known not to think (`Entry.Quiet`), which the gateway sends no reasoning ask (`withoutReasoningAsk`, [`quiet.go`](../../internal/gateway/quiet.go)). A quiet member used to empty the group's levels, so Codex got its entry with no `supported_reasoning_levels`, showed no effort control and ran at its own medium (#2127, `TestGroupQuietMemberKeepsCodexEffortControl`).- An agent whose config can't carry an effort has one picked in magpie (`provider.AgentEffort`, settings' `agentEfforts`; Cursor Private Inference's row, #1003). It is asked for on that agent's requests to a model that reasons (`Provider.Thinks`), in place of the level the request sent, fitted to the model's levels and bounded by the group's. Order: a member's fixed effort, then the effort the rule that put the member first sets (`Rule.UseEffort`), then a model's `:effort` suffix, then the turn's pick (a routing rule's), then the agent's pick, then the request's own. A model that doesn't reason is sent as asked; the default (none picked) leaves every request as it came. The pick beats the request's own because Cursor sends its own default as often as a real choice. Picking Default hands the choice back to Cursor.- In models.dev, entries from `deepseek`, `kimi-code-plan-cn` and `kimi-code-plan-global` gain `none` only when they have both a `toggle` and effort levels; the DeepSeek and Kimi APIs accepted that value in [#1098](https://github.com/yetone/magpie/issues/1098). Other providers keep their listed levels because their APIs may reject `none`; toggle-only entries remain level-less ([`mdModel.efforts`](../../internal/catalog/catalog.go)).diff --git a/internal/gateway/group_model_pick_test.go b/internal/gateway/group_model_pick_test.gonew file mode 100644index 000000000..9bcc728c6--- /dev/null+++ b/internal/gateway/group_model_pick_test.go@@ -0,0 +1,117 @@+package gateway++import (+ "strings"+ "testing"++ "github.com/yetone/magpie/internal/provider"+)++// unpickAX is #3911's case (timonwong): providers a (x, y) and b (x),+// and the group made of them, then x unchecked in a's model list.+func unpickAX(t *testing.T, g provider.Group) (a, b *keyed) {+ t.Helper()+ fresh(t)+ a, b = &keyed{}, &keyed{}+ serveOn(t, "a", "ka", []string{"x", "y"}, a)+ serveOn(t, "b", "kb", []string{"x"}, b)+ if err := provider.SaveGroup(g); err != nil {+ t.Fatal(err)+ }+ if err := provider.SetModels("a", []string{"y"}); err != nil {+ t.Fatal(err)+ }+ return a, b+}++// A model unchecked in its provider's list is no longer a group's to+// route to (#3911): the Routing page strikes it, and no request goes to+// it, whatever the group's routing.+func TestGroupSkipsModelRemovedFromProviderPicks(t *testing.T) {+ for _, routing := range []string{provider.Ordered, provider.Weighted, provider.Rotate} {+ t.Run(routing, func(t *testing.T) {+ g := provider.Group{ID: "mine", Name: "Mine", Members: []string{"a/x", "b/x"}, Routing: routing}+ if routing == provider.Weighted {+ g.Weights = map[string]int{"a/x": 1000} // a/x would take nearly every request+ }+ a, b := unpickAX(t, g)+ for range 4 {+ code, body := postAs(t, New(), "", `{"model":"group/mine","messages":[{"role":"user","content":"hi"}]}`)+ if code != 200 || !strings.Contains(body, "from kb") {+ t.Fatalf("group/mine after a/x was unchecked: %d %s", code, body)+ }+ }+ if len(a.tried) != 0 || len(b.tried) != 4 {+ t.Fatalf("a tried %v, b tried %v", a.tried, b.tried)+ }+ })+ }+}++// A group in a group whose only model was unchecked has none left, and+// the outer group goes on to its next.+func TestNestedGroupSkipsModelRemovedFromProviderPicks(t *testing.T) {+ fresh(t)+ a, b := &keyed{}, &keyed{}+ serveOn(t, "a", "ka", []string{"x", "y"}, a)+ serveOn(t, "b", "kb", []string{"x"}, b)+ if err := provider.SaveGroup(provider.Group{ID: "inner", Name: "Inner", Members: []string{"a/x"}, Routing: provider.Ordered}); err != nil {+ t.Fatal(err)+ }+ if err := provider.SaveGroup(provider.Group{ID: "outer", Name: "Outer", Members: []string{"group/inner", "b/x"}, Routing: provider.Ordered}); err != nil {+ t.Fatal(err)+ }+ if err := provider.SetModels("a", []string{"y"}); err != nil {+ t.Fatal(err)+ }+ code, body := postAs(t, New(), "", `{"model":"group/outer","messages":[{"role":"user","content":"hi"}]}`)+ if code != 200 || !strings.Contains(body, "from kb") || len(a.tried) != 0 {+ t.Fatalf("group/outer after a/x was unchecked: %d %s, a tried %v, b tried %v", code, body, a.tried, b.tried)+ }+ if _, ms, ok := provider.FindGroup("group/inner"); !ok || len(ms) != 0 {+ t.Fatalf("inner's members: %v %v", ok, ms)+ }+}++// A request naming the unchecked model itself still reaches it: a+// "provider/model" id goes to a provider that is on whether or not its+// list has the model (resolveIn), and #3911 changed only groups.+func TestUncheckedModelNamedDirectlyStillServed(t *testing.T) {+ a, b := unpickAX(t, provider.Group{ID: "mine", Name: "Mine", Members: []string{"a/x", "b/x"}, Routing: provider.Ordered})+ code, body := postAs(t, New(), "", `{"model":"a/x","messages":[{"role":"user","content":"hi"}]}`)+ if code != 200 || !strings.Contains(body, "from ka") || len(a.tried) != 1 || len(b.tried) != 0 {+ t.Fatalf("a/x named: %d %s, a tried %v, b tried %v", code, body, a.tried, b.tried)+ }+}++// Checked again, the model is the group's again, where it was.+func TestGroupTakesModelCheckedAgain(t *testing.T) {+ a, b := unpickAX(t, provider.Group{ID: "mine", Name: "Mine", Members: []string{"a/x", "b/x"}, Routing: provider.Ordered})+ if err := provider.SetModels("a", []string{"x", "y"}); err != nil {+ t.Fatal(err)+ }+ code, body := postAs(t, New(), "", `{"model":"group/mine","messages":[{"role":"user","content":"hi"}]}`)+ if code != 200 || !strings.Contains(body, "from ka") || len(b.tried) != 0 {+ t.Fatalf("group/mine with a/x checked again: %d %s, a tried %v, b tried %v", code, body, a.tried, b.tried)+ }+}++// A decision model is never in the catalog, picked or not: a decision+// group keeps one whose provider has picks (#3911's check passes it by).+func TestDecisionGroupKeepsAPickedDecider(t *testing.T) {+ fresh(t)+ for _, p := range []provider.Provider{+ {ID: "ja", Name: "JA", Key: "ka", Decide: "http://127.0.0.1:1/v1", Models: []string{"jev-latest"}},+ {ID: "jb", Name: "JB", Key: "kb", Decide: "http://127.0.0.1:1/v1"},+ } {+ if err := provider.Save(p); err != nil {+ t.Fatal(err)+ }+ }+ if err := provider.SaveGroup(provider.Group{ID: "jevs", Name: "Jevs", Members: []string{"ja/jev-latest", "jb/jev-latest"}}); err != nil {+ t.Fatal(err)+ }+ if _, ms, ok := provider.FindGroup("group/jevs"); !ok || len(ms) != 2 {+ t.Fatalf("jevs' members: %v %v", ok, ms)+ }+}diff --git a/internal/gui/group_member_unpicked_test.go b/internal/gui/group_member_unpicked_test.gonew file mode 100644index 000000000..37ccb3910--- /dev/null+++ b/internal/gui/group_member_unpicked_test.go@@ -0,0 +1,51 @@+package gui++import (+ "os"+ "testing"++ "github.com/yetone/magpie/internal/provider"+)++// A group's member the user unchecked in its provider's model list is+// not ready on the Routing page (#3911), as the gateway skips it: a+// manual group's card struck nothing while the editor struck it.+func TestGroupMemberUncheckedInItsProvider(t *testing.T) {+ t.Setenv("HOME", t.TempDir())+ t.Setenv("USERPROFILE", os.Getenv("HOME"))+ t.Setenv("XDG_CONFIG_HOME", t.TempDir())+ t.Setenv("XDG_CACHE_HOME", t.TempDir())+ if err := provider.Save(provider.Provider{ID: "a", Name: "A", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"x", "y"}}); err != nil {+ t.Fatal(err)+ }+ if err := provider.Save(provider.Provider{ID: "b", Name: "B", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"x"}}); err != nil {+ t.Fatal(err)+ }+ if err := provider.SaveGroup(provider.Group{ID: "mine", Name: "Mine", Members: []string{"a/x", "b/x"}, Routing: provider.Manual, Pick: "a/x"}); err != nil {+ t.Fatal(err)+ }+ ready := func() map[string]bool {+ out := map[string]bool{}+ for _, g := range groupsState().Groups {+ if g.ID == "mine" {+ out["group"] = g.Ready+ for _, m := range g.Info {+ out[m.ID] = m.Ready+ }+ }+ }+ return out+ }+ if r := ready(); !r["a/x"] || !r["b/x"] || !r["group"] {+ t.Fatalf("before: %v", r)+ }+ if err := provider.SetModels("a", []string{"y"}); err != nil {+ t.Fatal(err)+ }+ if r := ready(); r["a/x"] || !r["b/x"] || r["group"] {+ t.Fatalf("a/x unchecked: %v", r)+ }+ if _, _, ok := provider.Resolve("a/x"); !ok {+ t.Fatal("a/x named directly no longer resolves")+ }+}diff --git a/internal/gui/groups.go b/internal/gui/groups.goindex cb2e6f9b5..46f6dde69 100644--- a/internal/gui/groups.go+++ b/internal/gui/groups.go@@ -320,7 +320,7 @@ func groupsState() groupsJSON {}of, effort := provider.MemberEffort(id)m.Of, m.Effort = of, effort- if p, model, ok := provider.Resolve(of); ok {+ if p, model, ok := provider.ResolveRoute(of); ok {_, who := onOf(p)m.Ready, m.Provider, m.Name, m.Icon, m.Model, m.On = true, p.ID, p.Name, p.Icon, model, max(len(who), 1)m.CanFast = provider.CanFast(p, model)diff --git a/internal/provider/group.go b/internal/provider/group.goindex 24dbd5acd..eed12d9f4 100644--- a/internal/provider/group.go+++ b/internal/provider/group.go@@ -890,6 +890,7 @@ func membersOff(entries []Entry, all []Group, g Group, off func(pid, model strinvar out []Memberseen := map[string]int{} // where in outat := 0+ find := entriesBy(entries)var walk func(g Group, path []string, via []Group, in []string)walk = func(g Group, path []string, via []Group, in []string) {for _, id := range g.routes() {@@ -906,8 +907,8 @@ func membersOff(entries []Entry, all []Group, g Group, off func(pid, model strinmodel, effort := memberEffortIn(entries, id)p, m, ok := resolveIn(entries, model)key := WithMemberEffort(p.ID+"/"+m, effort)- if !ok {- continue+ if !ok || unpicked(find, p, m) {+ continue // none serves it, or the user unchecked it (#3911)}mem := Member{ID: here[0], Path: here, Via: via, Provider: p, Model: m, Effort: effort, Fast: g.IsFast(id), At: at}at++@@ -928,6 +929,41 @@ func membersOff(entries []Entry, all []Group, g Group, off func(pid, model strinreturn out}+// unpicked reports whether p's model m is one the user unchecked in p's+// model list since a group took it (timonwong, #3911): p has picks and+// its served models (entries, as find has them) lack m. resolveIn takes+// any "provider/model" of a provider that is on, so that a request can+// name a model its list lacks; a group's member is the user's pick of a+// model they now said not to serve, and the Routing page strikes it.+// A provider with no picks still routes a model its list lacks (#2642),+// and a decision model, never in the catalog, is still a decision+// group's.+func unpicked(find entryOf, p Provider, m string) bool {+ return len(p.Models) > 0 && find(p.ID, m) < 0 && !p.DecidesModel(m)+}++// ResolveRoute is Resolve for a model a route names, as a routing+// group's member, as the group reaches it: not one the user unchecked+// (unpicked).+func ResolveRoute(id string) (Provider, string, bool) {+ entries := providerEntries()+ p, m, ok := resolveIn(entries, strings.TrimSuffix(strings.TrimSpace(id), "[1m]"))+ // one pass for the one model, not a map of every entry (entriesBy):+ // a request asks it for each fallback it may go to+ find := func(pid, model string) int {+ for i := range entries {+ if entries[i].Provider.ID == pid && entries[i].Model == model {+ return i+ }+ }+ return -1+ }+ if !ok || unpicked(find, p, m) {+ return Provider{}, "", false+ }+ return p, m, true+}+// groupEntries are the catalog's groups: each with a member ready, named// as the user named it, answering for its first member when an agent asks// what the model can do, and reasoning when any member does — a member