codex: a model magpie has no word on is offered low, medium and high
ccdcn on X: in the Codex app, the models of a provider they added
(XJAI's model-code, model-work, model-test) had no reasoning effort to
pick, though the chip said 中. Nothing magpie reads knows those ids, so
their entries in magpie-models.json (and /v1/codex/models) had
supported_reasoning_levels [] and default_reasoning_level null. Codex
then hides the choice but still sends an effort (medium, or
model_reasoning_effort), and the gateway's fitEffort passes an effort on
as asked when a model's levels are unknown, so the effort went out and
couldn't be changed.
provider.CodexEfforts offers low, medium and high for a model whose
levels are wholly unknown. It is used by codexListed (GET
/v1/codex/models, the backend list, spawn models) and by
agent.magpieModels("codex") (the file Codex reads, and magpie's own
Codex effort control). A model known to have no levels keeps none: one
the vendor's catalog or models.dev lists (any provider, any spelling),
one the user marked as taking no reasoning ask, a vendor entry in
Codex's shape, and a routing group.
TestCodexDesktopEfforts' "user's own" now expects medium added to the
user's enabled-reasoning-efforts: its fixture's fake/m1 is such a model.
Run (on mote):
- go test -timeout 45m -count=1 ./internal/provider ./internal/agent
./internal/codexcat: ok
- go test -timeout 45m -count=1 ./internal/gateway ./internal/gui:
gateway ok (615s); gui red only in 10 real-window AppKit tests
(dock, panel, tray, main window), each killed at its deadline. Four of
them run alone on origin/main 024393fbb fail the same way on mote:
#4125 (mote's AppKit/launchd hang). Not run on another Mac.
- GOOS=linux / GOOS=windows go vet ./internal/provider ./internal/agent
./internal/gateway: ok; gofmt -l clean
The runs above were at base d99e213f5. Rebased on 024393fbb, which
changed internal/gateway only; at this head the new tests and every
TestCodex.*Effort test in provider, agent and gateway pass again.
Broken by hand: with codex_models.go and route.go stashed, the new
TestCodexOffersLevelsForUnknownModels and
TestCodexCatalogOffersUnknownModelsLevels fail (offered []).
TestCodexPickedEffortReachesUnknownModel checks each offered level
reaches the vendor as reasoning_effort.
Real Codex: codex-cli 0.165.0 app-server (sandbox CODEX_HOME), model/list
on the catalog codexcat writes for xjai/model-test: before,
supportedReasoningEfforts [] / default none; after, low, medium, high /
default medium.
Not tried: the Codex desktop app with a real XJAI vendor. Not changed:
other agents (OpenCode variants etc.), which send no effort for such a
model today, and groups whose members are all unknown.
This commit is contained in:
@@ -49,7 +49,9 @@ func TestCodexDesktopEfforts(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg := read()
|
||||
if !strings.Contains(cfg, "# the ones I use\nenabled-reasoning-efforts = [\"high\", \"low\", \"max\"] # mine\nother = 1\n") {
|
||||
// medium: codexHome's fake/m1, a model nothing knows, is offered
|
||||
// low, medium and high (provider.CodexEfforts)
|
||||
if !strings.Contains(cfg, "# the ones I use\nenabled-reasoning-efforts = [\"high\", \"low\", \"medium\", \"max\"] # mine\nother = 1\n") {
|
||||
t.Fatalf("config:\n%s", cfg)
|
||||
}
|
||||
// again: nothing missing, nothing written
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// ccdcn on X: in the Codex app, the models of a provider the user added
|
||||
// (XJAI's model-code, model-work, model-test), which nothing magpie reads
|
||||
// knows, had no reasoning effort to pick. magpie-models.json, which Codex
|
||||
// reads them from, now offers them low, medium and high, as GET
|
||||
// /v1/codex/models does (provider.CodexEfforts).
|
||||
func TestCodexCatalogOffersUnknownModelsLevels(t *testing.T) {
|
||||
home := syncHome(t)
|
||||
if err := provider.Save(provider.Provider{ID: "xjai", Name: "XJAI", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"model-code", "model-work", "model-test"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cx := codex(home)
|
||||
if err := cx.Fields[0].Set("xjai/model-test"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var got struct {
|
||||
Models []struct {
|
||||
Slug string `json:"slug"`
|
||||
Default *string `json:"default_reasoning_level"`
|
||||
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)
|
||||
}
|
||||
seen := 0
|
||||
for _, m := range got.Models {
|
||||
if m.Slug != "xjai/model-code" && m.Slug != "xjai/model-work" && m.Slug != "xjai/model-test" {
|
||||
continue
|
||||
}
|
||||
seen++
|
||||
var ls []string
|
||||
for _, l := range m.Levels {
|
||||
ls = append(ls, l.Effort)
|
||||
}
|
||||
if len(ls) != 3 || ls[0] != "low" || ls[1] != "medium" || ls[2] != "high" || m.Default == nil {
|
||||
t.Errorf("%s offers %v (default %v), want low, medium, high", m.Slug, ls, m.Default)
|
||||
}
|
||||
}
|
||||
if seen != 3 {
|
||||
t.Errorf("%d of XJAI's models in magpie-models.json: %s", seen, raw)
|
||||
}
|
||||
// and magpie's own effort control for Codex offers the same
|
||||
if opts := codexEfforts(magpieModels("codex"), "xjai/model-test"); len(opts) != 4 || opts[0].Value != "" {
|
||||
t.Errorf("effort control: %+v", opts)
|
||||
}
|
||||
}
|
||||
@@ -199,7 +199,13 @@ func magpieModels(agent string) []catalog.Model {
|
||||
return ms
|
||||
}
|
||||
for i, e := range shown {
|
||||
m := catalog.Model{ID: e.ID, Name: labels[i], Provider: firstOf(e.Provider.Catalogs()), Efforts: e.Efforts, Images: e.Images || seen, ImageInput: e.ImageInput, Context: e.Context, Output: e.Output, OutputSet: e.OutputSet, AgentsV2: e.AgentsV2, Reasoning: e.Thinks()}
|
||||
efforts := e.Efforts
|
||||
if agent == "codex" {
|
||||
// the levels Codex's picker offers, a model magpie has no
|
||||
// word on included (provider.CodexEfforts)
|
||||
efforts = provider.CodexEfforts(e)
|
||||
}
|
||||
m := catalog.Model{ID: e.ID, Name: labels[i], Provider: firstOf(e.Provider.Catalogs()), Efforts: efforts, Images: e.Images || seen, ImageInput: e.ImageInput, Context: e.Context, Output: e.Output, OutputSet: e.OutputSet, AgentsV2: e.AgentsV2, Reasoning: e.Thinks()}
|
||||
// where Codex and Claude Code compact it (#876): a threshold the
|
||||
// user set on the model or on its provider, else a window they
|
||||
// typed whole (#1809), else the one for every model, which codexcat
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// ccdcn on X: Codex now offers low, medium and high for a model magpie
|
||||
// has no word on (provider.CodexEfforts, XJAI's model-test). Each reaches
|
||||
// the vendor as Codex picked it, on its Responses: the levels offered are
|
||||
// ones the gateway sends, not a picker that changes nothing.
|
||||
func TestCodexPickedEffortReachesUnknownModel(t *testing.T) {
|
||||
f := &fake{t: t, reply: sse(
|
||||
`data: {"id":"c1","model":"model-test","choices":[{"delta":{"role":"assistant","content":"hi"}}]}`,
|
||||
`data: {"id":"c1","choices":[{"delta":{},"finish_reason":"stop"}]}`,
|
||||
`data: [DONE]`)}
|
||||
up := setup(t, provider.Chat, f)
|
||||
if err := provider.Save(provider.Provider{ID: "xjai", Name: "XJAI", Key: "k", Chat: up.URL + "/v1", Models: []string{"model-test"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
e, ok := provider.EntryOf("xjai/model-test")
|
||||
if !ok {
|
||||
t.Fatal("xjai/model-test not listed")
|
||||
}
|
||||
levels := provider.CodexEfforts(e)
|
||||
if len(levels) != 3 {
|
||||
t.Fatalf("Codex is offered %v for xjai/model-test", levels)
|
||||
}
|
||||
for _, effort := range levels {
|
||||
code, body := post(t, "/v1/responses", `{"model":"xjai/model-test","stream":true,"input":"hi","reasoning":{"effort":"`+effort+`","summary":"auto"}}`)
|
||||
if code != 200 {
|
||||
t.Fatalf("%s: status %d: %s", effort, code, body)
|
||||
}
|
||||
var got struct {
|
||||
Effort string `json:"reasoning_effort"`
|
||||
}
|
||||
json.Unmarshal(f.got, &got)
|
||||
if got.Effort != effort {
|
||||
t.Errorf("Codex picked %s; the vendor was sent %s", effort, f.got)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -757,7 +757,7 @@ func codexListed(shown []Entry, members func(id string) []Member, own bool) []ca
|
||||
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, Apart: apart[i]}
|
||||
m := catalog.Model{ID: e.ID, Name: labels[i], Efforts: CodexEfforts(e), 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)
|
||||
@@ -765,6 +765,46 @@ func codexListed(shown []Entry, members func(id string) []Member, own bool) []ca
|
||||
return ms
|
||||
}
|
||||
|
||||
// codexUnknownLevels are the levels Codex is offered on a model magpie
|
||||
// has no word on (CodexEfforts): the three every API that takes a
|
||||
// reasoning effort reads, OpenAI's Chat and Responses and the relays
|
||||
// copying them.
|
||||
var codexUnknownLevels = []string{"low", "medium", "high"}
|
||||
|
||||
// CodexEfforts are the levels Codex's picker offers for e: its own, or,
|
||||
// for a model nothing magpie reads says anything about — a custom
|
||||
// provider's model-code, a relay's alias — low, medium and high. Codex
|
||||
// sends such a model an effort whatever its entry lists (medium, or the
|
||||
// one config.toml starts sessions at), and the gateway passes an effort
|
||||
// on as asked where the model's levels aren't known (fitEffort), so with
|
||||
// no levels in its entry the effort was sent and couldn't be changed
|
||||
// (ccdcn on X: no effort choice for a custom provider's models). A model
|
||||
// known to have no levels keeps none: one its vendor's catalog or
|
||||
// models.dev lists without them, one the user said takes no reasoning
|
||||
// ask, and a routing group, whose levels are its members'.
|
||||
func CodexEfforts(e Entry) []string {
|
||||
if len(e.Efforts) > 0 || !e.levelsUnknown() {
|
||||
return e.Efforts
|
||||
}
|
||||
return slices.Clone(codexUnknownLevels)
|
||||
}
|
||||
|
||||
// levelsUnknown reports whether nothing magpie reads says which reasoning
|
||||
// levels e's model has, or that it has none: not its vendor's own list
|
||||
// (levels, or an entry in Codex's shape), not the vendor's catalog, not
|
||||
// models.dev under any provider, not the user.
|
||||
func (e Entry) levelsUnknown() bool {
|
||||
if e.Group != "" || len(e.Efforts) > 0 || e.Reasonless || len(e.Codex) > 0 || e.Model == "" {
|
||||
return false
|
||||
}
|
||||
if _, ok := catalog.ListedBy(e.Provider.Catalogs(), e.Model); ok {
|
||||
return false
|
||||
}
|
||||
// models.dev lists it (glm-4.5-air, with no reasoning) or knows it
|
||||
// under another spelling: what it says stands
|
||||
return !catalog.Lists(e.Model) && !catalog.Knows(e.Model)
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/codexcat"
|
||||
)
|
||||
|
||||
// ccdcn on X: the Codex app's picker offered no reasoning effort for the
|
||||
// models of a provider the user added (model-code, model-work and
|
||||
// model-test of their XJAI), which nothing magpie reads knows. Codex sent
|
||||
// them an effort anyway (its chip said 中) and the gateway passed it on,
|
||||
// but with supported_reasoning_levels [] it couldn't be changed. A model
|
||||
// nothing says anything about is offered low, medium and high; one known
|
||||
// to have no levels, one the user said takes no reasoning ask and a
|
||||
// routing group keep what they had.
|
||||
func TestCodexOffersLevelsForUnknownModels(t *testing.T) {
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
t.Setenv("USERPROFILE", t.TempDir())
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
cache := t.TempDir()
|
||||
t.Setenv("XDG_CACHE_HOME", cache)
|
||||
os.MkdirAll(filepath.Join(cache, "magpie"), 0o755)
|
||||
if err := os.WriteFile(catalog.CachePath(), []byte(`{
|
||||
"deepseek": {"models": {"deepseek-v4-pro": {"id":"deepseek-v4-pro","name":"DeepSeek V4 Pro","reasoning":true,
|
||||
"reasoning_options":[{"type":"toggle"},{"type":"effort","values":["low","high","max"]}],"limit":{"context":1000000}}}},
|
||||
"plaincat": {"models": {"plain-chat": {"id":"plain-chat","limit":{"context":128000}}}}
|
||||
}`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
catalog.Reset()
|
||||
t.Cleanup(catalog.Reset)
|
||||
if err := Save(Provider{ID: "xjai", Name: "XJAI", Key: "k", Chat: "http://127.0.0.1:1/v1",
|
||||
Models: []string{"model-code", "model-work", "model-test", "model-off", "plain-chat", "deepseek-v4-pro"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := SetModelReasonless("xjai/model-off", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
shown, _ := CatalogFor("codex")
|
||||
shown = append(shown, Entry{ID: "group/mix", Model: "group/mix", Name: "mix", Group: "mix", Provider: Provider{ID: "xjai"}})
|
||||
levels := map[string][]string{}
|
||||
for _, m := range CodexCatalog(shown) {
|
||||
levels[m.ID] = m.Efforts
|
||||
}
|
||||
want := map[string][]string{
|
||||
"xjai/model-code": {"low", "medium", "high"},
|
||||
"xjai/model-work": {"low", "medium", "high"},
|
||||
"xjai/model-test": {"low", "medium", "high"},
|
||||
"xjai/model-off": nil,
|
||||
"xjai/plain-chat": nil,
|
||||
"xjai/deepseek-v4-pro": {"low", "high", "max"},
|
||||
"group/mix": nil,
|
||||
}
|
||||
for id, w := range want {
|
||||
got, ok := levels[id]
|
||||
if !ok {
|
||||
t.Errorf("%s not in Codex's list: %v", id, levels)
|
||||
continue
|
||||
}
|
||||
if !slices.Equal(got, w) {
|
||||
t.Errorf("%s offered %v, want %v", id, got, w)
|
||||
}
|
||||
}
|
||||
|
||||
// and so the entry Codex reads: levels to pick from, a default among
|
||||
// them, and the effort sent (supports_reasoning_summaries, which
|
||||
// Codex before 0.145 sends it by)
|
||||
var entries []struct {
|
||||
Slug string `json:"slug"`
|
||||
Default *string `json:"default_reasoning_level"`
|
||||
Levels []struct {
|
||||
Effort string `json:"effort"`
|
||||
} `json:"supported_reasoning_levels"`
|
||||
Summaries bool `json:"supports_reasoning_summaries"`
|
||||
}
|
||||
b, _ := json.Marshal(codexcat.Entries(CodexCatalog(shown), 0))
|
||||
if err := json.Unmarshal(b, &entries); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, e := range entries {
|
||||
if e.Slug != "xjai/model-test" {
|
||||
continue
|
||||
}
|
||||
if len(e.Levels) != 3 || e.Default == nil || *e.Default != "medium" || !e.Summaries {
|
||||
t.Errorf("model-test's entry: %s", b)
|
||||
}
|
||||
return
|
||||
}
|
||||
t.Errorf("model-test has no entry: %s", b)
|
||||
}
|
||||
Reference in New Issue
Block a user