Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

routing: the live view and Usage's Requested name a found group auto/<model>, not group/auto-<model> (未寒 on Discord)

yetone0eb5cbe81a91
diff --git a/internal/gateway/trace.go b/internal/gateway/trace.go
index c651dabe2..477703727 100644
--- a/internal/gateway/trace.go
+++ b/internal/gateway/trace.go
@@ -163,7 +163,10 @@ func (u RouteUsage) PricingRecord() usage.Record {
// GroupRef is the routing group a request asked for.
type GroupRef struct {
- ID string `json:"id"`
+ ID string `json:"id"`
+ // Ref: the id agents pick it by (provider.Group.Ref), auto/<model>
+ // for a group magpie found, which the Routing page names it by
+ Ref string `json:"ref,omitempty"`
Name string `json:"name"`
Routing string `json:"routing"`
Affinity string `json:"affinity"`
@@ -185,6 +188,7 @@ type GroupRef struct {
// SubGroup is a routing group in the group a request asked for.
type SubGroup struct {
ID string `json:"id"`
+ Ref string `json:"ref,omitempty"` // as GroupRef's
Name string `json:"name"`
Routing string `json:"routing"`
In string `json:"in"` // the group it is in
@@ -200,7 +204,7 @@ type NestedRule struct {
// groupRef is the trace's g, with its models ms.
func groupRef(g provider.Group, ms []provider.Member) *GroupRef {
- ref := &GroupRef{ID: g.ID, Name: g.Name, Routing: g.Routing, Affinity: g.Affinity, Auto: g.Auto, Sink: sinks(g.Sink, g.Routing)}
+ ref := &GroupRef{ID: g.ID, Ref: g.Ref(), Name: g.Name, Routing: g.Routing, Affinity: g.Affinity, Auto: g.Auto, Sink: sinks(g.Sink, g.Routing)}
seen := map[string]bool{}
for _, m := range ms {
ref.Members = append(ref.Members, provider.WithMemberEffort(m.Provider.ID+"/"+m.Model, m.Effort))
@@ -212,7 +216,7 @@ func groupRef(g provider.Group, ms []provider.Member) *GroupRef {
for _, v := range m.Via {
if !seen[v.ID] {
seen[v.ID] = true
- ref.Subs = append(ref.Subs, SubGroup{ID: v.ID, Name: v.Name, Routing: v.Routing, In: in, Rules: len(v.Rules)})
+ ref.Subs = append(ref.Subs, SubGroup{ID: v.ID, Ref: v.Ref(), Name: v.Name, Routing: v.Routing, In: in, Rules: len(v.Rules)})
}
in = v.ID
}
diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js
index 18ad29e5c..298149dee 100644
--- a/internal/gui/assets/plugins/routing/client.js
+++ b/internal/gui/assets/plugins/routing/client.js
@@ -760,7 +760,12 @@ function routingPage(part) {
return out + "]".repeat(open.length);
}
// useName is what a rule sends to: a model, or a group in the group
- const useName = (r, id) => id?.startsWith("group/") ? t("the group {name}", { name: r.group?.subs?.find((s) => "group/" + s.id === id)?.name || id.slice(6) }) : id;
+ // a group magpie found goes by the id agents pick it by (auto/<model>), not its internal group/auto-…
+ const useName = (r, id) => {
+ if (!id?.startsWith("group/")) return id;
+ const s = r.group?.subs?.find((s) => "group/" + s.id === id);
+ return t("the group {name}", { name: s?.name || (s?.ref && !s.ref.startsWith("group/") ? s.ref : id.slice(6)) });
+ };
// nestedWhy tells, for each group in the group down to the one that
// went first, what its own rules did — and which group it came through
function nestedWhy(r) {
diff --git a/internal/gui/context.go b/internal/gui/context.go
index 2ef6578bd..faa74fe7f 100644
--- a/internal/gui/context.go
+++ b/internal/gui/context.go
@@ -486,6 +486,11 @@ func contextRoutes(r *http.Request, days int) []gateway.Route {
}
}
}
+ // a group magpie found by the id agents pick it by (publicRoute)
+ pub := publicRefs()
+ for i := range out {
+ out[i].Model = pub(out[i].Model)
+ }
return out
}
diff --git a/internal/gui/trace.go b/internal/gui/trace.go
index 8ed061c60..22aaef905 100644
--- a/internal/gui/trace.go
+++ b/internal/gui/trace.go
@@ -5,12 +5,14 @@ import (
"net/http"
"net/url"
"regexp"
+ "slices"
"strconv"
"strings"
"sync"
"time"
"github.com/yetone/magpie/internal/gateway"
+ "github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/sessions"
"github.com/yetone/magpie/internal/usage"
)
@@ -94,7 +96,9 @@ func pricedRoutes(routes []gateway.Route) []routeJSON {
}
}
titles := sessions.CodexTitles(ids)
+ pub := publicRefs()
for _, r := range routes {
+ r = publicRoute(r, pub)
recs := make([]usage.Record, len(r.Usage))
for i, u := range r.Usage {
recs[i] = u.PricingRecord()
@@ -115,6 +119,58 @@ func pricedRoutes(routes []gateway.Route) []routeJSON {
return out
}
+// publicRefs is provider.PublicRef, each ref looked up once: a page of
+// routes names a few models many times over.
+func publicRefs() func(string) string {
+ seen := map[string]string{}
+ return func(ref string) string {
+ if ref == "" {
+ return ref
+ }
+ out, ok := seen[ref]
+ if !ok {
+ out = provider.PublicRef(ref)
+ seen[ref] = out
+ }
+ return out
+ }
+}
+
+// publicRoute is r as the Routing page names it: a group magpie found by
+// the id agents pick it by, auto/<model>, wherever r names one — the
+// model asked for, the request a search or an image was for, a subagent's
+// pick, the group and the groups in it (未寒 on Discord: the live view
+// still said group/auto-<model>). The gateway keeps group/auto-<slug> in
+// the trace and its history (provider.CanonicalRef); r's own pointers are
+// the trace's, so what changes is copied first.
+func publicRoute(r gateway.Route, pub func(string) string) gateway.Route {
+ r.Model = pub(r.Model)
+ if r.For != nil {
+ f := *r.For
+ f.Model = pub(f.Model)
+ r.For = &f
+ }
+ if r.Subagent != nil {
+ s := *r.Subagent
+ s.Asked, s.To = pub(s.Asked), pub(s.To)
+ r.Subagent = &s
+ }
+ if g := r.Group; g != nil {
+ c := *g
+ if c.Ref == "" { // history written before the trace kept it
+ c.Ref = pub(provider.GroupPrefix + c.ID)
+ }
+ c.Subs = slices.Clone(c.Subs)
+ for i, sub := range c.Subs {
+ if sub.Ref == "" {
+ c.Subs[i].Ref = pub(provider.GroupPrefix + sub.ID)
+ }
+ }
+ r.Group = &c
+ }
+ return r
+}
+
// mainView is the tab the window is asked to open on, as the page's view
// parameter: the Routing page on one request (req, its id) when the tray
// panel's Routing tab asks for it, or the Usage page's Requests on one
diff --git a/internal/gui/trace_publicref_test.go b/internal/gui/trace_publicref_test.go
new file mode 100644
index 000000000..fd2f250d2
--- /dev/null
+++ b/internal/gui/trace_publicref_test.go
@@ -0,0 +1,137 @@
+package gui
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "path/filepath"
+ "slices"
+ "testing"
+ "time"
+
+ "github.com/yetone/magpie/internal/catalog"
+ "github.com/yetone/magpie/internal/gateway"
+ "github.com/yetone/magpie/internal/provider"
+ "github.com/yetone/magpie/internal/usage"
+)
+
+// The Routing page names a group magpie found as agents pick it,
+// auto/<model>, wherever a route names one: the model the agent asked
+// for, the group and the groups in it, the request a search was for and a
+// subagent's pick (未寒 on Discord: the live view still said
+// group/auto-<model> after the rename). The gateway's trace and history
+// keep group/auto-<slug>; a group the user made stays group/<id>.
+func TestRoutesNameFoundGroupsByTheirPublicID(t *testing.T) {
+ sandboxHome(t)
+ old := served.Swap(nil)
+ t.Cleanup(func() { served.Store(old) })
+ if err := os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(catalog.CachePath(), []byte(`{"anthropic": {"models": {
+ "claude-opus-5.5": {"id":"claude-opus-5.5","name":"Claude Opus 5.5","limit":{"context":400000,"output":96000}}}}}`), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ catalog.Reset()
+ t.Cleanup(catalog.Reset)
+ for id, m := range map[string]string{"a": "claude-opus-5-5", "b": "claude-opus-5.5"} {
+ if err := provider.Save(provider.Provider{ID: id, Name: id, Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{m, "x"}}); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if err := provider.SaveGroup(provider.Group{Name: "Mine", Members: []string{"a/x", "b/x"}}); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.MkdirAll(gateway.HistoryDir(), 0o700); err != nil {
+ t.Fatal(err)
+ }
+ // as the gateway wrote them, before the trace kept a group's ref
+ lines := `{"id":1,"model":"group/auto-claude-opus-5-5:high","provider":"a","done":true,` +
+ `"group":{"id":"auto-claude-opus-5-5","name":"Claude Opus 5.5","routing":"","affinity":"","members":["a/claude-opus-5-5"]},` +
+ `"subagent":{"asked":"group/auto-claude-opus-5-5","to":"group/mine"}}` + "\n" +
+ `{"id":2,"model":"group/mine","provider":"a","done":true,"kind":"web_search","for":{"agent":"claude","model":"group/auto-claude-opus-5-5"},` +
+ `"group":{"id":"mine","name":"Mine","routing":"","affinity":"","members":["a/x"],"subs":[{"id":"auto-claude-opus-5-5","name":"Claude Opus 5.5","routing":"","in":"mine"}]}}` + "\n"
+ if err := os.WriteFile(filepath.Join(gateway.HistoryDir(), "2026-10-20.jsonl"), []byte(lines), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ mux := http.NewServeMux()
+ traceRoutes(mux)
+ w := httptest.NewRecorder()
+ mux.ServeHTTP(w, httptest.NewRequest("GET", "/api/gateway/history?day=2026-10-20", nil))
+ var got struct {
+ Routes []gateway.Route `json:"routes"`
+ }
+ if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil || len(got.Routes) != 2 {
+ t.Fatalf("history: %v %s", err, w.Body)
+ }
+ byID := map[int64]gateway.Route{}
+ for _, r := range got.Routes {
+ byID[r.ID] = r
+ }
+ one, two := byID[1], byID[2]
+ if one.Model != "auto/claude-opus-5.5:high" {
+ t.Errorf("the model asked for: %q", one.Model)
+ }
+ if one.Group == nil || one.Group.Ref != "auto/claude-opus-5.5" || one.Group.ID != "auto-claude-opus-5-5" {
+ t.Errorf("the group: %+v", one.Group)
+ }
+ if s := one.Subagent; s == nil || s.Asked != "auto/claude-opus-5.5" || s.To != "group/mine" {
+ t.Errorf("the subagent's pick: %+v", s)
+ }
+ if two.Model != "group/mine" || two.Group == nil || two.Group.Ref != "group/mine" {
+ t.Errorf("the user's group: %q %+v", two.Model, two.Group)
+ }
+ if two.For == nil || two.For.Model != "auto/claude-opus-5.5" {
+ t.Errorf("what the search was for: %+v", two.For)
+ }
+ if two.Group == nil || len(two.Group.Subs) != 1 || two.Group.Subs[0].Ref != "auto/claude-opus-5.5" {
+ t.Errorf("the group in the group: %+v", two.Group)
+ }
+
+ // the request's own route, as the panel's link opens it
+ w = httptest.NewRecorder()
+ mux.ServeHTTP(w, httptest.NewRequest("GET", "/api/gateway/route?id=1&day=2026-10-20", nil))
+ var r gateway.Route
+ if err := json.Unmarshal(w.Body.Bytes(), &r); err != nil || r.Model != "auto/claude-opus-5.5:high" {
+ t.Errorf("one route: %q %v", r.Model, err)
+ }
+
+ // the Context page's sessions and agents, of the same routes (today's)
+ h := filepath.Join(gateway.HistoryDir(), time.Now().Format("2006-01-02")+".jsonl")
+ if err := os.WriteFile(h, []byte(lines), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ found := false
+ for _, r := range contextRoutes(httptest.NewRequest("GET", "/api/context", nil), 1) {
+ if r.ID == 1 {
+ found = true
+ if r.Model != "auto/claude-opus-5.5:high" {
+ t.Errorf("the Context page's model: %q", r.Model)
+ }
+ }
+ }
+ if !found {
+ t.Error("the Context page has no route 1")
+ }
+
+ // Usage › Requests' Requested column, which the ledger keeps the same way
+ for _, req := range []string{"group/auto-claude-opus-5-5", "group/mine"} {
+ usage.Append(usage.Record{Time: time.Now(), Provider: "a", Model: "claude-opus-5-5", Requested: req, Status: 200, Input: 10})
+ }
+ usageRoutes(mux, folderOnly{})
+ w = httptest.NewRecorder()
+ mux.ServeHTTP(w, httptest.NewRequest("GET", "/api/usage/requests?period=all", nil))
+ var ledger ledgerJSON
+ if err := json.Unmarshal(w.Body.Bytes(), &ledger); err != nil {
+ t.Fatal(err, w.Body)
+ }
+ var asked []string
+ for _, row := range ledger.Rows {
+ asked = append(asked, row.Requested)
+ }
+ slices.Sort(asked)
+ if !slices.Equal(asked, []string{"auto/claude-opus-5.5", "group/mine"}) {
+ t.Errorf("the ledger's Requested: %q", asked)
+ }
+}
diff --git a/internal/usageapi/usageapi.go b/internal/usageapi/usageapi.go
index dcf0e5417..25f29c6d4 100644
--- a/internal/usageapi/usageapi.go
+++ b/internal/usageapi/usageapi.go
@@ -281,9 +281,18 @@ func LedgerPage(p usage.Period, f usage.Filter, offset, limit int) Ledger {
for _, g := range out.CallerKeys {
callerLabels[g.CallerKeyID] = g.Name
}
+ // a group magpie found is named as agents pick it, auto/<model>; the
+ // ledger keeps group/auto-<slug> (provider.CanonicalRef)
+ pub := map[string]string{}
for _, r := range page {
a := who(r.Agent)
lr := Row{Row: r, AgentName: a.Name, Icon: a.Icon, ProviderName: which(r.Provider).Name}
+ if req := r.Requested; strings.HasPrefix(req, provider.GroupPrefix) {
+ if _, ok := pub[req]; !ok {
+ pub[req] = provider.PublicRef(req)
+ }
+ lr.Requested = pub[req]
+ }
if r.Source != "log" && r.Source != usage.SourceReported {
lr.Access = access[r.Provider]
}