codexcat: every reasoning level in magpie-models.json says a description (#5024)

Codex fails the whole model_catalog_json on one supported_reasoning_levels
entry without a description ("missing field `description` at line 189"),
so Codex would not start. The entries magpie writes from a vendor's own
Codex entry (a sub2api's) kept the vendor's levels as written, the
description only where the vendor gave one, and levels made for an effort
of the user's the vendor doesn't list were {"effort": ...} alone. Every
level of such an entry now says a description: the vendor's own where it
gave one, else the effort's display name. Entries magpie makes itself
already wrote one.

Changed from the contributor's patch: the levels are read with a checked
type assertion. The patch's bare .([]any) panicked ("interface {} is nil,
not []interface {}") on a vendor entry with no levels for a model with no
efforts, which would have taken down the whole catalog write; the test has
that case now.

Run (mote): go test -tags nogui ./internal/codexcat/ (ok);
go test -tags nogui ./internal/provider/ ./internal/usage/ ./internal/catalog/;
go vet -tags nogui ./internal/codexcat/; gofmt -l (empty).
Broken by hand: with the old listedEntry, TestCodexListedLevelsSayDescription
fails ("level medium says description \"\", want \"Medium\"", and the
same for high, low, xhigh); with the patch's unchecked assertion it panics.
Real Codex (codex-cli 0.165.0, sandbox CODEX_HOME): a catalog whose levels
lack description fails "missing field `description`"; the same catalog with
descriptions loads and Codex starts.
Not tried: Windows (the reporter's OS); nothing here is OS-specific.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
This commit is contained in:
yetone
2026-11-06 10:06:51 +08:00
co-authored by ggbdpq
parent ce2a59daa9
commit b33633d593
2 changed files with 94 additions and 0 deletions
+29
View File
@@ -1135,6 +1135,22 @@ func listedEntry(m catalog.Model, priority int, work settings.Settings, autoRevi
}
}
}
// every level says its description: Codex 0.166 fails the whole
// catalog on one without the field (#5024), so a level the vendor
// listed without one — kept as it wrote it, or made for an effort of
// the user's the vendor doesn't — says the effort's display name
levels, _ := e["supported_reasoning_levels"].([]any)
for _, l := range levels {
o, _ := l.(map[string]any)
if o == nil {
continue
}
if _, ok := o["description"].(string); ok {
continue
}
ef, _ := o["effort"].(string)
o["description"] = effortLabel(ef)
}
// images, where the user's say (or magpie describing them) differs
if in, ok := e["input_modalities"].([]any); ok {
has := slices.Contains(in, any("image"))
@@ -1156,6 +1172,19 @@ func listedEntry(m catalog.Model, priority int, work settings.Settings, autoRevi
return e, true
}
// effortLabels are the reasoning efforts' display names, as the pickers say
// them (T3 Code's labels, internal/agent/t3code.go).
var effortLabels = map[string]string{"none": "None", "minimal": "Minimal", "low": "Low", "medium": "Medium", "high": "High", "xhigh": "Extra High", "max": "Max", "ultra": "Ultra"}
// effortLabel is the display name of an effort, the effort itself when it
// has none.
func effortLabel(ef string) string {
if l, ok := effortLabels[ef]; ok {
return l
}
return ef
}
// Window has one of Codex's own entries say a context window of n tokens
// (none: as it says), and most at the most it may be raised to (0: as it
// says). Only those two fields change. An entry whose max_context_window is
+65
View File
@@ -0,0 +1,65 @@
package codexcat
import (
"encoding/json"
"testing"
"github.com/yetone/magpie/internal/catalog"
)
// #5024: Codex 0.166 fails the whole model catalog on a
// supported_reasoning_levels entry without a description ("missing field
// `description`"), so every level of an entry magpie writes from a vendor's
// carries one: the vendor's own where it gave it, else the effort's display
// name. That is whether the user's efforts are the vendor's own, whose
// levels magpie keeps as it wrote them, or differ from them, whose missing
// ones magpie makes. A level of an entry magpie makes alone has said a
// description (an empty one) all along.
func TestCodexListedLevelsSayDescription(t *testing.T) {
v1Home(t, `{"etag":"W/\"a\"","models":[]}`)
same := json.RawMessage(`{"slug":"glm-5.3","display_name":"GLM-5.3","description":"x","base_instructions":"y",` +
`"supported_reasoning_levels":[{"effort":"low","description":"Fastest"},{"effort":"medium"},{"effort":"high"}],` +
`"shell_type":"shell_command","visibility":"list"}`)
// a vendor entry with no levels at all, for a model with no efforts
bare := json.RawMessage(`{"slug":"plain","display_name":"Plain","description":"x","base_instructions":"y",` +
`"shell_type":"shell_command","visibility":"list"}`)
short := json.RawMessage(`{"slug":"kimi","display_name":"Kimi","description":"x","base_instructions":"y",` +
`"supported_reasoning_levels":[{"effort":"low"}],` +
`"shell_type":"shell_command","visibility":"list"}`)
var got struct {
Models []struct {
Slug string `json:"slug"`
Levels []map[string]any `json:"supported_reasoning_levels"`
} `json:"models"`
}
if err := json.Unmarshal(Catalog([]catalog.Model{
{ID: "relay/glm-5.3", Name: "GLM-5.3", Efforts: []string{"low", "medium", "high"}, Codex: same},
{ID: "relay/kimi", Name: "Kimi", Efforts: []string{"low", "xhigh"}, Codex: short},
{ID: "or/deepseek-v4", Name: "DeepSeek V4", Efforts: []string{"low", "max"}},
{ID: "relay/plain", Name: "Plain", Codex: bare},
}), &got); err != nil || len(got.Models) != 4 {
t.Fatalf("%v %v", err, got)
}
want := map[string]map[string]string{
// the vendor's own kept where it gave one, the name where it didn't
"relay/glm-5.3": {"low": "Fastest", "medium": "Medium", "high": "High"},
// one the vendor doesn't list, made for an effort of the user's
"relay/kimi": {"low": "Low", "xhigh": "Extra High"},
// magpie's own entry: a description said all along
"or/deepseek-v4": {"low": "", "max": ""},
// none listed and none asked for: nothing to describe, no panic
"relay/plain": {},
}
for _, m := range got.Models {
if len(m.Levels) != len(want[m.Slug]) {
t.Fatalf("%s: levels %v", m.Slug, m.Levels)
}
for _, l := range m.Levels {
ef, _ := l["effort"].(string)
d, _ := l["description"].(string)
if d != want[m.Slug][ef] {
t.Errorf("%s: level %s says description %q, want %q", m.Slug, ef, d, want[m.Slug][ef])
}
}
}
}