codex: the Codex app's picker puts a ChatGPT model its list lacks where the order put it (Wangalan167673 on X)

Wangalan167673's Order tab (Codex's list on the Agents page) had GPT-6.2
Sol and Astra third and fourth, and the Codex app's picker had them last,
"GPT-6.2 Astra · Codex", after every other provider's models.

The app's list (model_catalog_json, gateway.CodexDesktopCatalog) is the
ChatGPT backend's list asked for the app, then magpie's models. A model
of the account's own that the app's list lacks yet (GPT-6.2 beside a list
asked before it came, CodexListedBeside) is handed by magpie's id,
codex/<slug>, which is where the "· Codex" comes from. provider.CodexOrder
mapped an own model of the order only to its bare slug, as the backend
lists it, so the codex/ entry matched nothing in the order and went after
every model the order names. It now maps both the bare slug and the
entry id. Groups and other providers' models were already matched by id.

The Codex app reads the file at its start, so an order changed while it
runs reaches its picker after it is restarted.

TestCodexDesktopCatalogInUsersOrder (gateway) builds the reporter's list:
GPT-6.1 Terra and Sol in the backend's list for the app, GPT-6.2 Sol and
Astra only in the account's own list, three routing groups and four
models of an agy-cli provider, in the reporter's order. Red on the old
code: "got [gpt-6.1-terra gpt-6.1-sol group/code-daily ... agy-cli/
claude-sonnet-5.5 gpt-6.2-sol gpt-6.2-astra]"; green with the fix.

Run on mica at 230feb5b2 (base 1bfa8d5a1): go vet of provider and
gateway for darwin, GOOS=linux -tags nogui and GOOS=windows; go test
-count=1 -timeout 45m ./internal/provider ./internal/gateway
./internal/codexcat, ok. After the rebase onto bfddc9cfb (71b8ab46c
changed gateway): go test -count=1 -run Codex of the three packages, ok;
gofmt -l clean.
Not run before the push: the full suite. mote and mica each had another
session's full suite running; it is queued on mote behind that one and
its result is reported with the release.
Not tried: a real Codex app with this build. No GUI change.
This commit is contained in:
yetone
2026-11-18 18:23:25 +08:00
parent bfddc9cfba
commit e199eb9c79
2 changed files with 131 additions and 6 deletions
+117
View File
@@ -0,0 +1,117 @@
package gateway
import (
"context"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"slices"
"strings"
"sync/atomic"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// The Codex app's picker follows the order dragged on the Agents page
// (Codex's list, Order), for every kind of entry in it: the account's own
// models the backend lists, the account's own the backend's list for the
// app lacks yet (handed by magpie's id, codex/<slug>, "· Codex"), routing
// groups and another provider's models (Wangalan167673 on X: GPT-6.2 Astra
// and Sol last, Gemini 4 Hydrogen before Argon, the groups after GPT-6.1
// Sol).
func TestCodexDesktopCatalogInUsersOrder(t *testing.T) {
codexSignedIn(t)
codexDeskReset(t)
full := `{"models":[` +
`{"slug":"gpt-6.1-sol","priority":1,"visibility":"list","base_instructions":"You are Codex."},` +
`{"slug":"gpt-6.1-terra","priority":2,"visibility":"list","base_instructions":"You are Codex."},` +
`{"slug":"gpt-6.2-astra","priority":3,"visibility":"list","base_instructions":"You are Codex."},` +
`{"slug":"gpt-6.2-sol","priority":4,"visibility":"list","base_instructions":"You are Codex."}]}`
short := `{"models":[` +
`{"slug":"gpt-6.1-sol","priority":1,"visibility":"list","base_instructions":"You are Codex."},` +
`{"slug":"gpt-6.1-terra","priority":2,"visibility":"list","base_instructions":"You are Codex."}]}`
var list atomic.Value
list.Store(full)
up := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, list.Load().(string))
}))
defer up.Close()
was := provider.CodexBase
provider.CodexBase = up.URL + "/backend-api/codex"
defer func() { provider.CodexBase = was }()
// the account's own list has GPT-6.2; the one asked for the app not yet
p, err := provider.Find("codex")
if err != nil {
t.Fatal(err)
}
if _, err := p.Fetch(context.Background()); err != nil {
t.Fatal(err)
}
list.Store(short)
if err := provider.Save(provider.Provider{ID: "agy-cli", Name: "agy-cli", Key: "k", Anthropic: "http://127.0.0.1:1",
Models: []string{"gemini-4-hydrogen", "gemini-4-argon", "claude-opus-5.5", "claude-sonnet-5.5"}}); err != nil {
t.Fatal(err)
}
for _, g := range []string{"free-workers", "code-review", "code-daily"} {
if err := provider.SaveGroup(provider.Group{ID: g, Name: g, Members: []string{"agy-cli/gemini-4-argon"}}); err != nil {
t.Fatal(err)
}
}
// the order as the Agents page saves it: by entry id
byModel := map[string]string{}
for _, e := range provider.CatalogOf("codex") {
key := e.ID
if provider.CodexOwn(e) {
key = e.Model
}
byModel[key] = e.ID
}
var order, want []string
for _, k := range []string{"gpt-6.1-terra", "gpt-6.1-sol", "gpt-6.2-sol", "gpt-6.2-astra",
"group/code-daily", "group/code-review", "group/free-workers",
"agy-cli/gemini-4-argon", "agy-cli/gemini-4-hydrogen", "agy-cli/claude-opus-5.5", "agy-cli/claude-sonnet-5.5"} {
id, ok := byModel[k]
if !ok {
t.Fatalf("no catalog entry for %s: %v", k, byModel)
}
order = append(order, id)
want = append(want, k)
}
if err := provider.SetModelOrder("codex", order); err != nil {
t.Fatal(err)
}
CodexDesktopCatalog()
codexDeskAsked(t)
b, ok := CodexDesktopCatalog()
if !ok {
t.Fatal("not known after the backend answered")
}
var got struct {
Models []map[string]any `json:"models"`
}
if err := json.Unmarshal(b, &got); err != nil {
t.Fatal(err)
}
// as the app lists them: by priority
slices.SortStableFunc(got.Models, func(a, b map[string]any) int {
return int(a["priority"].(float64) - b["priority"].(float64))
})
var shown []string
for _, m := range got.Models {
if v, _ := m["visibility"].(string); v == "hide" {
continue
}
slug := m["slug"].(string)
// the account's own the app's list lacks goes by magpie's id
slug = strings.TrimPrefix(slug, "codex/")
shown = append(shown, slug)
}
if !slices.Equal(shown, want) {
t.Errorf("the Codex app's list\n got %v\nwant %v", shown, want)
}
}
+14 -6
View File
@@ -776,7 +776,8 @@ func CodexOwnLeftOut(keep string) func(slug string) bool {
// CodexOrder is where each model of Codex's list goes when the user put
// them in an order of their own on the Agents page (#855), by the slug
// Codex knows it by — a ChatGPT account's own by its bare one, as the
// backend lists it — and whether they did. A model it doesn't name keeps
// backend lists it, and by magpie's id, as magpie lists one the backend's
// list lacks — and whether they did. A model it doesn't name keeps
// its place after them.
func CodexOrder() (map[string]int, bool) {
order := ModelOrder("codex")
@@ -793,12 +794,19 @@ func CodexOrder() (map[string]int, bool) {
if !ok {
continue
}
slug := e.ID
if CodexOwn(e) {
slug = e.Model
put := func(slug string) {
if cur, seen := out[slug]; !seen || i < cur {
out[slug] = i
}
}
if cur, seen := out[slug]; !seen || i < cur {
out[slug] = i
put(e.ID)
// the account's own goes by its bare slug where the backend's list
// has it, and by magpie's id where that list lacks it
// (CodexListedBeside): GPT-6.2, beside a list asked for before it
// came, went last in the Codex app's picker wherever it was put
// (Wangalan167673 on X)
if CodexOwn(e) {
put(e.Model)
}
}
return out, true