codex: a relay's dated or renamed GPT id keeps its xhigh, max and Ultra levels

Found while looking into maomao_00001's report on Discord: the Windows
Codex app offered no xhigh or Ultra for a relay's model. Their relay
(vip.aipro.love, ids from its public /api/pricing) names its 31 models
plainly, and every one already got its full levels in
magpie-models.json before this change and gets the same after it, so
this is not their fix. Exact ids (gpt-6.1-sol, openai/gpt-6.1-sol)
were fine; two spellings other relays use were not:

- OpenAI's dated snapshot id (gpt-6.1-sol-2026-09-29) was unknown to
  the catalog, so it got the low/medium/high fallback. borrowedEfforts
  now drops a dated suffix and takes the base model's levels.
- A relay's rename (codex-gpt-6.1-sol, "[A] gpt-6.1-sol", an id the
  user marked the same as gpt-6.1-sol) got the levels up to max but no
  Ultra, because OffersUltra matched exact ids only. It now matches
  through catalog.IsOneOf, the lookup ContextOf and EffortsOf use.

Only known models change: a dated id whose base is unknown
(model-x-2026-01-01) keeps low/medium/high, a dated Luna gets its own
levels without Ultra, and glm-5.3-flash keeps [low high max].

Not changed: a dashed-date id's window and price are still unknown,
because catalog.SameModel doesn't strip that date form (#5643).

Run:
- TestCodexCatalogRelaysKnownModelsLevels red on the old code (the
  dated Sol and Luna at [low medium high], three renames without
  ultra), green with the fix.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... and builds on mote.
- go test -tags nogui ./internal/catalog ./internal/provider
  ./internal/agent ./internal/codexcat on mote: all ok.
- The relay's 31 ids put through codex's Set with the real
  models.dev file (a probe, not committed): the same levels on
  origin/main and with this change.
- Full suite: not finished. My probe runs reused the suite's copy
  on mote, so it was stopped; it runs again after the push.

Refs: maomao_00001 (Discord)
This commit is contained in:
yetone
2026-11-08 02:37:42 +08:00
parent 0ec4e84ebd
commit 30b7a17326
4 changed files with 125 additions and 3 deletions
+89
View File
@@ -0,0 +1,89 @@
package agent
import (
"encoding/json"
"os"
"path/filepath"
"slices"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/settings"
)
// maomao_00001 on Discord: in the Codex app, a relay's GPT model offered
// low, medium and high alone, none of the levels above. A relay names a
// known model as OpenAI's own list does, by a dated snapshot
// (gpt-6.1-sol-2026-09-29), or renames it (codex-gpt-6.1-sol, a tag in
// brackets, one the user said is gpt-6.1-sol in magpie): each is offered
// that model's levels in magpie-models.json, Ultra on one Codex offers it
// on. A model nothing knows keeps low, medium and high, and another
// vendor's model and a model that stops at max keep their own.
func TestCodexCatalogRelaysKnownModelsLevels(t *testing.T) {
home := syncHome(t)
// models.dev's rows, as it listed them on 2026-11-07
os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755)
os.WriteFile(catalog.CachePath(), []byte(`{
"openai":{"id":"openai","name":"OpenAI","npm":"@ai-sdk/openai","models":{
"gpt-6.1-sol":{"id":"gpt-6.1-sol","name":"GPT-6.1 Sol","description":"Near-Astra performance for complex coding, computer use, and professional work at a lower cost.","family":"gpt-sol","attachment":true,"reasoning":true,"reasoning_options":[{"type":"effort","values":["low","medium","high","xhigh","max"]}],"tool_call":true,"structured_output":true,"temperature":false,"knowledge":"2026-04-30","release_date":"2026-09-29","last_updated":"2026-09-29","modalities":{"input":["text","image","pdf"],"output":["text"]},"open_weights":false,"limit":{"context":1050000,"input":922000,"output":128000},"experimental":{"modes":{"fast":{"cost":{"input":4,"output":20,"cache_read":0.2,"cache_write":5},"provider":{"body":{"service_tier":"priority"}}},"pro":{"provider":{"body":{"reasoning":{"mode":"pro"}}}},"ultrafast":{"cost":{"input":12,"output":60,"cache_read":0.6,"cache_write":15},"provider":{"body":{"service_tier":"ultrafast"}}}}},"cost":{"input":2,"output":10,"cache_read":0.1,"cache_write":2.5,"tiers":[{"input":4,"output":15,"cache_read":0.2,"cache_write":5,"tier":{"type":"context","size":272000}}],"context_over_200k":{"input":4,"output":15,"cache_read":0.2,"cache_write":5}},"canonical_model_id":"openai/gpt-6.1-sol"},
"gpt-6-luna":{"id":"gpt-6-luna","name":"GPT-6 Luna","description":"OpenAI's most efficient model for focused, high-volume tasks","family":"gpt-luna","attachment":true,"reasoning":true,"reasoning_options":[{"type":"effort","values":["none","low","medium","high","xhigh","max"]}],"tool_call":true,"structured_output":true,"temperature":false,"knowledge":"2026-05-18","release_date":"2026-09-22","last_updated":"2026-09-22","modalities":{"input":["text","image","pdf"],"output":["text"]},"open_weights":false,"limit":{"context":1050000,"input":922000,"output":128000},"experimental":{"modes":{"fast":{"cost":{"input":0.2,"output":1,"cache_read":0.02,"cache_write":0.25},"provider":{"body":{"service_tier":"priority"}}},"pro":{"provider":{"body":{"reasoning":{"mode":"pro"}}}}}},"cost":{"input":0.1,"output":0.5,"cache_read":0.01,"cache_write":0.125,"tiers":[{"input":0.2,"output":0.75,"cache_read":0.02,"cache_write":0.25,"tier":{"type":"context","size":272000}}],"context_over_200k":{"input":0.2,"output":0.75,"cache_read":0.02,"cache_write":0.25}},"canonical_model_id":"openai/gpt-6-luna"}}},
"zai":{"id":"zai","name":"Z.AI","models":{"glm-5.3-flash":{"id":"glm-5.3-flash","name":"GLM-5.3-Flash","description":"Native multimodal GLM model for efficient coding and long-horizon agent tasks","family":"glm-flash","attachment":true,"reasoning":true,"reasoning_options":[{"type":"effort","values":["low","high","max"]}],"tool_call":true,"interleaved":{"field":"reasoning_content"},"structured_output":true,"temperature":true,"release_date":"2026-08-26","last_updated":"2026-08-26","modalities":{"input":["text","image","video","pdf"],"output":["text"]},"open_weights":true,"limit":{"context":1000000,"output":131072},"cost":{"input":0.15,"output":0.5,"cache_read":0.03,"cache_write":0},"canonical_model_id":"zhipuai/glm-5.3-flash"}}}}`), 0o644)
catalog.Reset()
t.Cleanup(catalog.Reset)
s := settings.Load()
s.ModelSameAs = map[string]string{"relay/sol-of-mine": "gpt-6.1-sol"}
if err := settings.Save(s); err != nil {
t.Fatal(err)
}
ids := []string{"gpt-6.1-sol", "gpt-6.1-sol-2026-09-29", "codex-gpt-6.1-sol", "[A] gpt-6.1-sol", "sol-of-mine",
"gpt-6-luna-2026-09-22", "glm-5.3-flash", "model-x-2026-01-01"}
if err := provider.Save(provider.Provider{ID: "relay", Name: "Relay", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: ids}); err != nil {
t.Fatal(err)
}
if err := codex(home).Fields[0].Set("relay/gpt-6.1-sol-2026-09-29"); err != nil {
t.Fatal(err)
}
var got struct {
Models []struct {
Slug string `json:"slug"`
Levels []struct {
Effort string `json:"effort"`
} `json:"supported_reasoning_levels"`
} `json:"models"`
}
raw := readFile(filepath.Join(home, ".codex", "magpie-models.json"))
if err := json.Unmarshal([]byte(raw), &got); err != nil {
t.Fatalf("%v: %s", err, raw)
}
sol := []string{"low", "medium", "high", "xhigh", "max", "ultra"}
want := map[string][]string{
"relay/gpt-6.1-sol": sol,
"relay/gpt-6.1-sol-2026-09-29": sol,
"relay/codex-gpt-6.1-sol": sol,
"relay/[A] gpt-6.1-sol": sol,
"relay/sol-of-mine": sol,
// Codex's own catalog stops Luna at max
"relay/gpt-6-luna-2026-09-22": {"none", "low", "medium", "high", "xhigh", "max"},
"relay/glm-5.3-flash": {"low", "high", "max"},
"relay/model-x-2026-01-01": {"low", "medium", "high"},
}
seen := map[string]bool{}
for _, m := range got.Models {
w, ok := want[m.Slug]
if !ok {
continue
}
seen[m.Slug] = true
var ls []string
for _, l := range m.Levels {
ls = append(ls, l.Effort)
}
if !slices.Equal(ls, w) {
t.Errorf("%s offers %v, want %v", m.Slug, ls, w)
}
}
if len(seen) != len(want) {
t.Errorf("%d of %d of the relay's models in magpie-models.json: %s", len(seen), len(want), raw)
}
}
+12
View File
@@ -1334,6 +1334,18 @@ func Knows(id string) bool {
return ContextOf(id) > 0 || len(EffortsOf(id)) > 0 || Thinks(id)
}
// IsOneOf reports whether the model of this id is one of ids (bare,
// lowercase), matched as ContextOf and EffortsOf match it: by the id, a
// relay's rename (codex-gpt-6.1-sol, a tag in brackets), another spelling,
// or the model the user said it is the same as (UserSame). It is how a
// rule kept for some models by name reaches them on a relay that renames
// them.
func IsOneOf(id string, ids map[string]bool) bool {
load()
_, ok := lookup(id, ids)
return ok
}
// KnowsAsWritten is Knows without another spelling (normalFor): the
// usage report sends a model's id only when models.dev knows it as
// written, so an id a user typed that only folds into a known one
+7
View File
@@ -2133,6 +2133,13 @@ func borrowedEfforts(id string) []string {
if base, ok := catalog.Unsuffixed(id); ok {
return borrowedEfforts(base)
}
// a dated snapshot of a known model, as OpenAI's own list names them
// and a relay passing it on does (gpt-6.1-sol-2026-09-29): the model's
// levels. Codex offered it low, medium and high alone, no xhigh, max
// or Ultra (maomao_00001 on Discord)
if base := datedSuffix.ReplaceAllString(id, ""); base != id && base != "" {
return borrowedEfforts(base)
}
return nil
}
+17 -3
View File
@@ -4,6 +4,8 @@ import (
"regexp"
"slices"
"strings"
"github.com/yetone/magpie/internal/catalog"
)
// Codex's Ultra is not a level an API takes: Codex sends the model its max
@@ -17,24 +19,36 @@ import (
// carries it since #4909.
var ultraModels = []string{"gpt-6.1-sol", "gpt-6-sol", "gpt-6-astra", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-6.1-terra"}
// ultraSet is ultraModels as catalog.IsOneOf takes them.
var ultraSet = func() map[string]bool {
m := map[string]bool{}
for _, id := range ultraModels {
m[id] = true
}
return m
}()
// datedSuffix is a snapshot's date after a model's id (-2026-09-14, -20260914).
var datedSuffix = regexp.MustCompile(`-(\d{4}-\d{2}-\d{2}|\d{8})$`)
// OffersUltra reports whether Codex offers its Ultra on the model, by the id
// a vendor serves it under: openai/gpt-6.1-sol on a relay, a dated snapshot.
// a vendor serves it under: openai/gpt-6.1-sol on a relay, a dated snapshot,
// and a relay's rename the catalog reads as one of them (codex-gpt-6.1-sol,
// "[A]gpt-6.1-sol", one the user said is gpt-6.1-sol), whose levels are
// that model's already (provider.borrowedEfforts) and stopped at max.
func OffersUltra(model string) bool {
id := strings.ToLower(model)
if i := strings.LastIndex(id, "/"); i >= 0 {
id = id[i+1:]
}
id = datedSuffix.ReplaceAllString(id, "")
return slices.Contains(ultraModels, id)
return ultraSet[id] || id != "" && catalog.IsOneOf(id, ultraSet)
}
// withUltra adds Codex's ultra to the levels of a model that offers it and
// reaches max; the gateway sends max for it (fitEffort).
func withUltra(model string, efforts []string) []string {
if !OffersUltra(model) || !slices.Contains(efforts, "max") || slices.Contains(efforts, "ultra") {
if !slices.Contains(efforts, "max") || slices.Contains(efforts, "ultra") || !OffersUltra(model) {
return efforts
}
return append(slices.Clone(efforts), "ultra")