From 60561129f8e95c414620122f246a200d333aa9b7 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 28 Oct 2026 20:50:05 +0800 Subject: [PATCH] codexcat: two entries Codex's picker would name the same are told apart by their provider's id (nb5p on Discord) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nb5p had GPT-6.1-Sol from two providers both called Codex, and Codex's model picker showed two identical entries, the hover text identical too. Now, only when two listed entries would have the same display_name, each gets its provider's id after it ("GPT-6.1-Sol · Codex · codex-b"), or its own model id where the provider's doesn't tell them apart (a routing group, two of one provider). Every other entry is unchanged. Only display_name changes. The description and catalog Model.Name are as on main. Codex puts each of the first five catalog models' description into spawn_agent's "Available model overrides" (codex-rs multi_agents_spec.rs spawn_agent_models_description, and context/world_state/model_catalog.rs with model_catalog_in_context), which goes upstream on every request; the real Codex 0.162.1 bytes in internal/redact/testdata/codex-0.162.1-request.json show "- `fake/m1`: m1 · fake via magpie". magpie's own spawnChoices sends Name. So the first try (provider/account in the description) was dropped: it would have sent the account's email upstream. display_name: read in codex-rs at 5d5e5c5 (cloned on mote), core builds no prompt or tool text from a model's display_name (model_catalog.rs and spawn_agent_models_description use slug + description + efforts + tiers only); in the captured Codex requests the name appears only inside the description. The id is in the slug already, which is sent anyway. Apart is in the Model's JSON, so it is in the list's tag and Codex asks for the list again when it changes. Run (mote, at the rebased head): - TestCodexPickerNamesSameNamesApart (internal/provider) and TestCodexApartInDisplayNameOnly (internal/codexcat): pass. - Broken by hand: codexApart never marking a pair, and shownName ignoring Apart (the old behaviour): both tests FAIL, e.g. codex-b/gpt-6.1-sol shown as "GPT-6.1-Sol · Codex", want "GPT-6.1-Sol · Codex · codex-b". - gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: all ok (at base 7e58591dc + this change) - go test -tags nogui -timeout 45m internal/codexcat internal/catalog internal/provider internal/agent internal/gateway: all ok (provider 111s, agent 177s, gateway 559s) Not tried: a real Codex picker with two same-named providers (no second Codex-named provider in a sandbox here); the full ./... suite. --- internal/catalog/catalog.go | 8 ++++ internal/codexcat/apart_test.go | 49 +++++++++++++++++++++++ internal/codexcat/codexcat.go | 17 ++++++-- internal/provider/codex_apart_test.go | 57 +++++++++++++++++++++++++++ internal/provider/codex_models.go | 40 ++++++++++++++++++- 5 files changed, 166 insertions(+), 5 deletions(-) create mode 100644 internal/codexcat/apart_test.go create mode 100644 internal/provider/codex_apart_test.go diff --git a/internal/catalog/catalog.go b/internal/catalog/catalog.go index 17070c7ff..2a991255b 100644 --- a/internal/catalog/catalog.go +++ b/internal/catalog/catalog.go @@ -77,6 +77,14 @@ type Model struct { // provider after it (magpie_label): the name Provider in model names // Off has here (ARNO on Discord). Plain string `json:",omitempty"` + // Apart, in a list magpie hands Codex, is what tells the model from + // another entry Codex's picker would call the same (two providers + // named Codex each serving GPT-6.1-Sol, nb5p on Discord): its + // provider's id. Said in the entry's display_name alone + // (codexcat.Entries), which stays in Codex's picker; never in its + // description or Name, which go upstream in spawn_agent's list of + // models. Kept in the list's tag, so a change has Codex ask again. + Apart string `json:",omitempty"` // Fast is set on a model Codex may ask for priority processing (its // Fast mode): one a ChatGPT account serves. Fast bool `json:",omitempty"` diff --git a/internal/codexcat/apart_test.go b/internal/codexcat/apart_test.go new file mode 100644 index 000000000..e4fac0a8b --- /dev/null +++ b/internal/codexcat/apart_test.go @@ -0,0 +1,49 @@ +package codexcat + +import ( + "encoding/json" + "os" + "path/filepath" + "testing" + + "github.com/yetone/magpie/internal/catalog" +) + +// An entry with something that tells it apart (catalog.Model.Apart) says +// it in its display_name alone, whether magpie makes the entry, its vendor +// lists it, or it is Codex's own: the description, which Codex puts in +// spawn_agent's list of models upstream, is as it was. +func TestCodexApartInDisplayNameOnly(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + os.MkdirAll(filepath.Join(home, ".codex"), 0o755) + os.WriteFile(filepath.Join(home, ".codex", "models_cache.json"), []byte(`{"models":[ + {"slug":"gpt-6.1-sol","display_name":"GPT-6.1-Sol","description":"Frontier agentic coding model.","priority":3,"visibility":"list"}]}`), 0o644) + listed := json.RawMessage(`{"slug":"gpt-6.1-sol","display_name":"GPT-6.1-Sol","description":"Frontier agentic coding model.","base_instructions":"x","supported_reasoning_levels":[],"shell_type":"shell_command","visibility":"list"}`) + var got struct { + Models []struct { + Name string `json:"display_name"` + Desc string `json:"description"` + } `json:"models"` + } + if err := json.Unmarshal(Catalog([]catalog.Model{ + {ID: "codex/gpt-6.1-sol", Name: "GPT-6.1-Sol · Codex", Apart: "codex"}, + {ID: "codex-b/gpt-6.1-sol", Name: "GPT-6.1-Sol · Codex", Apart: "codex-b", Images: true}, + {ID: "relay/gpt-6.1-sol", Name: "GPT-6.1-Sol · Relay", Apart: "relay", Codex: listed}, + {ID: "or/glm-5.3", Name: "GLM-5.3 · OpenRouter", Images: true}, + }), &got); err != nil || len(got.Models) != 4 { + t.Fatalf("%v %v", err, got) + } + want := [][2]string{ + {"GPT-6.1-Sol · Codex · codex", "Frontier agentic coding model."}, + {"GPT-6.1-Sol · Codex · codex-b", "GPT-6.1-Sol · Codex via magpie"}, + {"GPT-6.1-Sol · Relay · relay", "Frontier agentic coding model. via magpie"}, + {"GLM-5.3 · OpenRouter", "GLM-5.3 · OpenRouter via magpie"}, + } + for i, m := range got.Models { + if [2]string{m.Name, m.Desc} != want[i] { + t.Errorf("entry %d: %q, %q; want %q", i, m.Name, m.Desc, want[i]) + } + } +} diff --git a/internal/codexcat/codexcat.go b/internal/codexcat/codexcat.go index 3cb55d1b0..bef0e7c52 100644 --- a/internal/codexcat/codexcat.go +++ b/internal/codexcat/codexcat.go @@ -205,7 +205,7 @@ func entriesAt(ms []catalog.Model, after int, effort string) []any { var entries []any for i, m := range ms { if raw, ok := own[strings.TrimPrefix(m.ID, "codex/")]; ok && strings.HasPrefix(m.ID, "codex/") { - e := ownEntry(raw, m.ID, m.Name, after+i+1) + e := ownEntry(raw, m.ID, shownName(m), after+i+1) // the window as magpie resolves it — the one the user set, // else the account's list's — not the cache's, which is what // magpie last handed Codex (#674) @@ -222,7 +222,7 @@ func entriesAt(ms []catalog.Model, after int, effort string) []any { continue } e := model{ - Slug: m.ID, DisplayName: m.Name, Description: m.Name + " via magpie", + Slug: m.ID, DisplayName: shownName(m), Description: m.Name + " via magpie", Instructions: Prompt, Efforts: []level{}, Shell: "unified_exec", Visibility: "list", InAPI: true, Priority: after + i + 1, ApplyPatch: "freeform", Tools: []string{}, Modalities: []string{"text"}, @@ -832,6 +832,17 @@ func ownEntry(raw map[string]any, id, name string, priority int) map[string]any return e } +// shownName is the name Codex's picker shows m by: its Name, with what +// tells it from another entry of that name after it (catalog.Model.Apart). +// The picker alone shows it: the description, and the names magpie adds +// to spawn_agent, which go upstream, keep Name. +func shownName(m catalog.Model) string { + if m.Apart == "" { + return m.Name + } + return m.Name + " · " + m.Apart +} + // listedEntry is the entry m's vendor lists it under in Codex's own shape // (catalog.Model.Codex, a sub2api's), under magpie's id: as the vendor // gave it — its instructions, tools, truncation, tiers and the rest, which @@ -847,7 +858,7 @@ func listedEntry(m catalog.Model, priority int, work settings.Settings, autoRevi if len(m.Codex) == 0 || json.Unmarshal(m.Codex, &raw) != nil || raw == nil { return nil, false } - e := ownEntry(raw, m.ID, m.Name, priority) + e := ownEntry(raw, m.ID, shownName(m), priority) desc, _ := e["description"].(string) e["description"] = cmp.Or(strings.TrimSpace(desc), m.Name) + " via magpie" if c := m.Context; c > 0 { diff --git a/internal/provider/codex_apart_test.go b/internal/provider/codex_apart_test.go new file mode 100644 index 000000000..8f89cc16b --- /dev/null +++ b/internal/provider/codex_apart_test.go @@ -0,0 +1,57 @@ +package provider + +import ( + "encoding/json" + "strings" + "testing" + + "github.com/yetone/magpie/internal/codexcat" +) + +// Two providers both called Codex, each serving GPT-6.1-Sol (nb5p on +// Discord), are named apart in Codex's picker by their provider's id, and +// two of one provider by their own id. Only display_name says it: the +// description and Name, which go upstream in spawn_agent's list of models, +// stay as they were, and an entry no other shares a name with is shown as +// before. +func TestCodexPickerNamesSameNamesApart(t *testing.T) { + a := Provider{ID: "codex", Name: "Codex", Account: &Account{Agent: "codex", User: "a@example.com"}} + b := Provider{ID: "codex-b", Name: "Codex", Account: &Account{Agent: "codex", User: "b@example.com"}} + r := Provider{ID: "relay", Name: "Relay"} + ms := codexListed([]Entry{ + {ID: "codex/gpt-6.1-sol", Model: "gpt-6.1-sol", Name: "GPT-6.1-Sol", Provider: a}, + {ID: "codex-b/gpt-6.1-sol", Model: "gpt-6.1-sol", Name: "GPT-6.1-Sol", Provider: b}, + {ID: "relay/glm-5.3", Model: "glm-5.3", Name: "GLM-5.3", Provider: r}, + {ID: "relay/glm-5.3-old", Model: "glm-5.3-old", Name: "GLM-5.3", Provider: r}, + {ID: "relay/kimi-k3", Model: "kimi-k3", Name: "Kimi K3", Provider: r}, + }, func(string) []Member { return nil }, true) + type shown struct{ name, desc string } + want := []shown{ + {"GPT-6.1-Sol · Codex · codex", "GPT-6.1-Sol · Codex via magpie"}, + {"GPT-6.1-Sol · Codex · codex-b", "GPT-6.1-Sol · Codex via magpie"}, + {"GLM-5.3 · Relay · relay/glm-5.3", "GLM-5.3 · Relay via magpie"}, + {"GLM-5.3 · Relay · relay/glm-5.3-old", "GLM-5.3 · Relay via magpie"}, + {"Kimi K3 · Relay", "Kimi K3 · Relay via magpie"}, + } + es := codexcat.Entries(ms, 0) + if len(es) != len(want) { + t.Fatalf("%d entries, want %d", len(es), len(want)) + } + for i, e := range es { + b, _ := json.Marshal(e) + var got struct { + Name string `json:"display_name"` + Desc string `json:"description"` + } + json.Unmarshal(b, &got) + // the text-only note is beside the point here + got.Desc = strings.Replace(got.Desc, " (text only: Accepts images is in its provider's Names & levels in magpie)", "", 1) + if (shown{got.Name, got.Desc}) != want[i] { + t.Errorf("%s: shown as %q, %q; want %q, %q", ms[i].ID, got.Name, got.Desc, want[i].name, want[i].desc) + } + // what goes upstream in spawn_agent's list (spawnChoices) is Name + if ms[i].Name != strings.TrimSuffix(want[i].desc, " via magpie") { + t.Errorf("%s: Name %q changed", ms[i].ID, ms[i].Name) + } + } +} diff --git a/internal/provider/codex_models.go b/internal/provider/codex_models.go index 03f85d23b..c02b20e88 100644 --- a/internal/provider/codex_models.go +++ b/internal/provider/codex_models.go @@ -684,11 +684,13 @@ func codexListed(shown []Entry, members func(id string) []Member, own bool) []ca seen := described() s := settings.Load() find := func(id string) (Group, []Member, bool) { return Group{}, members(id), true } + listed := func(e Entry) bool { return own || !CodexOwn(e) } + apart := codexApart(shown, labels, listed) for i, e := range shown { - if CodexOwn(e) && !own { + if !listed(e) { continue } - m := catalog.Model{ID: e.ID, Name: labels[i], Efforts: e.Efforts, Images: e.Images || seen, Context: e.Context, AgentsV2: e.AgentsV2, Codex: e.Codex} + m := catalog.Model{ID: e.ID, Name: labels[i], Efforts: e.Efforts, Images: e.Images || seen, Context: e.Context, AgentsV2: e.AgentsV2, Codex: e.Codex, Apart: apart[i]} m.Compact = CompactFor(s, e, find) CodexTiers(&m, e, members) ms = append(ms, m) @@ -696,6 +698,40 @@ func codexListed(shown []Entry, members func(id string) []Member, own bool) []ca return ms } +// codexApart is, for each of shown that is listed, what tells it from +// another listed entry its label (labels) would call the same in Codex's +// picker (catalog.Model.Apart): its provider's id, or its own id where +// that doesn't tell them apart (a routing group, or two of one provider). +// "" for every other entry, whose picker name stays as it was. +func codexApart(shown []Entry, labels []string, listed func(Entry) bool) []string { + out := make([]string, len(shown)) + same := map[string][]int{} + for i, e := range shown { + if listed(e) { + k := strings.ToLower(labels[i]) + same[k] = append(same[k], i) + } + } + for _, is := range same { + if len(is) < 2 { + continue + } + ids := map[string]int{} + for _, i := range is { + ids[strings.ToLower(shown[i].Provider.ID)]++ + } + for _, i := range is { + e := shown[i] + if e.Group == "" && e.Provider.ID != "" && ids[strings.ToLower(e.Provider.ID)] == 1 { + out[i] = e.Provider.ID + } else { + out[i] = e.ID + } + } + } + return out +} + // CodexTiers sets on m what Codex is offered on e's service tiers // (codexcat.Entries turns them into the entry's service_tiers): one source // for every list Codex is handed, the gateway's and the models.json file