From 9f8fe81aa26481fc39f6e86d2ca3d66aebd63817 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 15 Oct 2026 18:39:52 +0800 Subject: [PATCH] models: a model that thinks with no levels magpie knows is marked reasoning for Pi and Command Code, as /v1/models says it (#2380) Trae CN's kimi-k3 / kimi-k3-max / kimi-k3-auto think, and /v1/models said reasoning: true, but Pi's models.json was written reasoning: false: piModelJSON read the levels alone. Pi then offered off alone and `magpie pi effort high` was clamped to off. provider.Entry.Thinks() (Reasoning or levels) is now the one judgement: /v1/models' modelObject and magpieModels, which every agent export reads, both take it. Pi writes reasoning from it, with no thinkingLevelMap when the levels aren't known, so Pi offers its own off to high (getSupportedThinkingLevels, read in Pi's bundle) and the gateway fits them (fitFor caps a switch-only model at high, #214). Command Code is told reasoning alone for such a model, which its BYOK reference takes for low/medium/high. OpenCode, Alma and Zed already judged it so. Left as they are: omp (pi-catalog's getSupportedEfforts gives a reasoning model without thinking.efforts no levels, so the flag alone buys nothing), jcode (how it reads reasoning with no effort not verified), Crush (can_reason without levels sends no effort on its openai type), cline/workbuddy/zcode (they write level lists only). TestOpenCodeNoResellerLevelsForSwitchModel pinned Xiaomi's mimo-v2.6-flash (a thinking switch alone) as reasoning: false in Pi; it is now reasoning: true with no map, so Pi still offers no xhigh or max. Run (worktree, sandbox HOME, -tags nogui -p 1): - new TestThinkingWithoutLevelsReachesTheExports (trae-cn/kimi-k3-max): green; red with Pi's old line ("Pi offers [off]") and red with Command Code's case removed - internal/agent -run 'Pi|CommandCode|CC|Cc|Thinking|Reason|OpenCode| Alma|Zed|Omp|JCode|Jcode|Crush|Route|MagpieModels': ok (382s) - internal/gateway -run 'Model|Reason|Thinks': ok - internal/provider -run 'Entry|Reason|Thinks|Catalog': ok - gofmt -l clean; go vet -tags nogui darwin/linux/windows on agent, provider, gateway: clean Not tried: a real Pi against a real Trae CN account; whether Xiaomi takes Pi's "minimal" for mimo-v2.6-flash (the gateway passes a level it has no list for as asked). Full suite: SUITE_LINE --- internal/agent/agents.go | 8 +++- internal/agent/commandcode.go | 9 +++- internal/agent/opencode_variants_test.go | 6 ++- internal/agent/route.go | 2 +- internal/agent/thinks_export_test.go | 57 ++++++++++++++++++++++++ internal/gateway/gateway.go | 2 +- internal/provider/modelprefs.go | 8 ++++ 7 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 internal/agent/thinks_export_test.go diff --git a/internal/agent/agents.go b/internal/agent/agents.go index 8297e166e..f955f847b 100644 --- a/internal/agent/agents.go +++ b/internal/agent/agents.go @@ -453,8 +453,12 @@ func piBlockKept(path string, value func() any) func() any { // api and baseUrl); without it the model is left on the provider's // openai-completions (Pencil, pencil.go). func piModelJSON(m catalog.Model, gw string, native bool) map[string]any { - // reasoning lets Pi offer its thinking levels for the model - e := map[string]any{"id": m.ID, "name": m.Name, "reasoning": len(m.Efforts) > 0} + // reasoning lets Pi offer its thinking levels for the model: as + // /v1/models says it (provider.Entry.Thinks), so one that thinks with + // no levels magpie knows (Trae CN's kimi-k3-max, #2380) is offered + // Pi's own off to high, which the gateway fits to the model, where + // it had off alone + e := map[string]any{"id": m.ID, "name": m.Name, "reasoning": m.Reasoning || len(m.Efforts) > 0} // each model is asked on the API its provider speaks natively, // so the gateway relays what Pi sent as it is instead of // translating Chat. One served on OpenAI's Responses API alone, diff --git a/internal/agent/commandcode.go b/internal/agent/commandcode.go index f258f85d5..e521ac8b5 100644 --- a/internal/agent/commandcode.go +++ b/internal/agent/commandcode.go @@ -157,9 +157,16 @@ func ccProviderJSONAt(v1 string) any { efforts = append(efforts, x) } } - if len(efforts) > 0 { + // a model that thinks with no levels magpie knows (Trae CN's + // kimi-k3-max, #2380) is marked reasoning alone, which Command + // Code takes for low, medium and high (its BYOK reference); the + // gateway fits them to the model + switch { + case len(efforts) > 0: e["reasoning"] = true e["reasoningEfforts"] = efforts + case len(m.Efforts) == 0 && m.Reasoning: + e["reasoning"] = true } ms[m.ID] = e } diff --git a/internal/agent/opencode_variants_test.go b/internal/agent/opencode_variants_test.go index 8ffaf4ffb..590a4b6a0 100644 --- a/internal/agent/opencode_variants_test.go +++ b/internal/agent/opencode_variants_test.go @@ -215,7 +215,9 @@ func TestOpenCodeWritesVariants(t *testing.T) { // thinking switch alone, gets no variants in opencode.json — under Xiaomi's // preset or a relay of the user's alike — and no thinking levels in Pi: // OpenCode offered it the resellers' levels up to max, which Xiaomi turns -// away with a 400 (#214). A model no maker lists keeps the resellers'. +// away with a 400 (#214). A model no maker lists keeps the resellers'. Pi is +// told it reasons, as /v1/models says (#2380), with no map, so Pi offers +// its own off to high and never xhigh or max. func TestOpenCodeNoResellerLevelsForSwitchModel(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) @@ -284,7 +286,7 @@ func TestOpenCodeNoResellerLevelsForSwitchModel(t *testing.T) { switch m.ID { case "xiaomi/mimo-v2.6-flash", "relay/mimo-v2.6-flash": seen++ - if m.Reasoning || m.Levels != nil { + if !m.Reasoning || m.Levels != nil { t.Errorf("pi %s: reasoning %v, levels %v", m.ID, m.Reasoning, m.Levels) } case "relay/open-model": diff --git a/internal/agent/route.go b/internal/agent/route.go index fa91b9d67..d62d9b3b5 100644 --- a/internal/agent/route.go +++ b/internal/agent/route.go @@ -150,7 +150,7 @@ 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.Reasoning} + 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()} // 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 diff --git a/internal/agent/thinks_export_test.go b/internal/agent/thinks_export_test.go new file mode 100644 index 000000000..afac4059f --- /dev/null +++ b/internal/agent/thinks_export_test.go @@ -0,0 +1,57 @@ +package agent + +import ( + "os" + "reflect" + "testing" + + "github.com/yetone/magpie/internal/catalog" + "github.com/yetone/magpie/internal/provider" +) + +// #2380: Trae CN's kimi-k3-max thinks with no levels magpie knows, and +// /v1/models said reasoning: true for it, but Pi's models.json was written +// reasoning: false (the export read the levels alone), so Pi offered off +// alone and `magpie pi effort high` was clamped to off. Every export that +// writes a reasoning flag says what /v1/models says. +func TestThinkingWithoutLevelsReachesTheExports(t *testing.T) { + syncHome(t) + if err := os.WriteFile(catalog.CachePath(), []byte(`{ + "moonshotai": {"models": {"kimi-k3-max": {"id":"kimi-k3-max","name":"Kimi-K3-Max","reasoning":true,"limit":{"context":262144}}}} + }`), 0o644); err != nil { + t.Fatal(err) + } + catalog.Reset() + if err := provider.Save(provider.Provider{ID: "trae-cn", Name: "Trae CN", Key: "k", Chat: "http://127.0.0.1:1/v1", + Catalog: "moonshotai", Models: []string{"kimi-k3-max"}}); err != nil { + t.Fatal(err) + } + const id = "trae-cn/kimi-k3-max" + + shown, _ := provider.CatalogFor("pi") + var entry *provider.Entry + for i := range shown { + if shown[i].ID == id { + entry = &shown[i] + } + } + if entry == nil || !entry.Thinks() || len(entry.Efforts) != 0 { + t.Fatalf("the fixture is a model that thinks with no levels, as /v1/models says it: %+v", entry) + } + + if got := piOffered("pi", "magpie/"+id); !reflect.DeepEqual(got, []string{"off", "minimal", "low", "medium", "high"}) { + t.Fatalf("Pi offers %v for %s, want its own off to high", got, id) + } + if got := piClamp("high", piOffered("pi", "magpie/"+id)); got != "high" { + t.Fatalf("magpie pi effort high runs at %q", got) + } + + ms := ccProviderJSONAt("http://127.0.0.1:1/v1").(map[string]any)["models"].(map[string]any) + cc, _ := ms[id].(map[string]any) + if cc["reasoning"] != true { + t.Fatalf("Command Code's entry: %v", cc) + } + if _, set := cc["reasoningEfforts"]; set { + t.Fatalf("Command Code was told levels magpie doesn't know: %v", cc) + } +} diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index ee458f23e..a5b2f78bf 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -818,7 +818,7 @@ func modelObject(e provider.Entry) map[string]any { levels = append(levels, reasoningLevel{Effort: effort}) } m := map[string]any{"id": e.ID, "object": "model", "type": "model", "created": 0, "created_at": "2025-01-01T00:00:00Z", - "owned_by": e.Provider.ID, "display_name": e.PlainName(), "reasoning": e.Reasoning || len(levels) > 0, "supported_reasoning_levels": levels} + "owned_by": e.Provider.ID, "display_name": e.PlainName(), "reasoning": e.Thinks(), "supported_reasoning_levels": levels} // the window, as the names clients read it by: a group's context // (magpie group set … context=) included if e.Context > 0 { diff --git a/internal/provider/modelprefs.go b/internal/provider/modelprefs.go index f77097500..7145ff945 100644 --- a/internal/provider/modelprefs.go +++ b/internal/provider/modelprefs.go @@ -733,6 +733,14 @@ func Labels(es []Entry) []string { // Discord: "· Relay A" and "· routing group" stayed under Off). func (e Entry) PlainName() string { return cmp.Or(e.Plain, e.Name) } +// Thinks is whether the model thinks, as /v1/models says it and every +// agent's list is told it: a model with levels, or one marked Reasoning +// with a thinking switch alone. An export that read the levels alone +// marked Trae CN's kimi-k3-max, which always thinks and has no levels +// magpie knows, not reasoning for Pi, and `magpie pi effort high` was +// clamped to off (#2380). +func (e Entry) Thinks() bool { return e.Reasoning || len(e.Efforts) > 0 } + // The ways the agents' lists name models (SuffixMode): every name with its // provider's after it, as by default; all but the names the user gave // models (#92); or none (#335).