provider: a routing group keeps its thinking members' levels beside a member known not to think, so Codex shows its effort control (#2127, cnlove7777777-art)

#2127: with a routing group as its model, Codex showed an effort but no
control to change it, and new sessions and subagents ran at medium. A
group offers agents the levels its members have in common
(groupEntries), and a member magpie knows doesn't think (Entry.Quiet: its
vendor's list says no reasoning) counted as having none, so the
intersection came out empty. The group still reasons when one member
does, so Codex got its entry with reasoning but no
supported_reasoning_levels and no default_reasoning_level: no slider,
and Codex's own medium.

Since #950 the gateway sends such a member no reasoning ask at all
(withoutReasoningAsk, quiet.go), as it does a reasonless one (f074996d9)
and as it handles a member whose levels nothing knows (#597), so its
having no levels is no reason to take the others' away. groupEntries now
skips it like those two. The group's levels are those of its members
that think; Group.Levels and fixed-effort members are unchanged.

Tests: TestGroupQuietMemberKeepsCodexEffortControl builds the Codex
catalog (codexcat.Catalog(CodexListed())) for a group of a models.dev
reasoning:false model and one with levels, and wants the levels and
default (high, and max when config.toml asks max); TestGroupReasoningLevels
gains "quiet between". Both fail on the old group.go (levels [], default
""). TestGroupLevelsWithUnknownMember's "plain" group and
TestModelsListReasoning's group/auto-mixed encoded the old rule and now
want the thinking member's levels. docs/reference.md and
gateway-routing.md say the new rule.

Run (worktree on origin/main bda271999, private GOCACHE): gofmt -l clean;
go vet (darwin), GOOS=linux -tags nogui and GOOS=windows go vet of
internal/provider clean; go test -count=1 ./internal/provider
./internal/gateway ./internal/agent ./internal/codexcat ok.
Not tried: a real Codex session against the reporter's groups (their
config isn't known; a group with a non-thinking member is the case that
produces exactly what they describe).
This commit is contained in:
yetone
2026-10-14 18:14:17 +08:00
parent 778000326a
commit 8c5190a203
6 changed files with 103 additions and 26 deletions
+3 -3
View File
@@ -1618,9 +1618,9 @@ It exposes:
Each `/v1/models` entry includes `reasoning` and `supported_reasoning_levels`
(`[{"effort":"low"}, ...]`). A routing group is marked `reasoning` when any
member thinks, even where it offers no levels to pick from (a member known
to take none still leaves the group none); `supported_reasoning_levels`
lists only the levels every member supports, as before. A member magpie
member thinks; `supported_reasoning_levels` lists the levels the members
that think have in common. A member known not to think doesn't take them
away (#2127), nor does one whose levels nothing knows (#597). A member magpie
knows does not think is sent no reasoning ask when the group routes to it,
so the effort the group is asked for reaches the members that take it and
doesn't turn a vendor away as a 400; a member nothing speaks for is sent
+1
View File
@@ -130,6 +130,7 @@ recorded as a prediction failure (`noPrediction`).
- Structured output is carried across every translation (`Format`, [`format.go`](../../internal/gateway/format.go)). It is read from Responses' `text.format`, Chat's `response_format`, Anthropic's `output_config.format` and Gemini's `responseMimeType` with `responseJsonSchema`/`responseSchema`: `json_schema` with its name, description, schema and strict, or `json_object`. Each upstream is asked in its own field: `text.format` on Responses, `response_format` on Chat, `output_config.format` on Messages, and `generationConfig.responseMimeType`/`responseJsonSchema` on Gemini and Code Assist. An API with no name for it gets `response`. Messages and the Claude subscription's `--json-schema` take a schema only, so `json_object` is told in the system prompt there (`inSystem`). The bridges to a vendor's own API (Cursor, Devin, Kiro, Qoder, Command Code, Zed) are always told in the system prompt. A 400 or 422 that names the field (`refusesFormat`: DeepSeek's "This response_format type is unavailable now", a schema Anthropic can't hold) marks the provider and model (`formatRefused`), and the request is asked again with the format told in the system prompt, as are later requests to that provider and model. A relayed request keeps its format as sent. A Gemini client's format is also still told in its system prompt, as before.
- A tool's images reach the model on every translation (`toolOutput` in [`ir.go`](../../internal/gateway/ir.go) reads them from Anthropic's `tool_result`, Responses' `function_call_output`, such as Codex's `view_image` output `[{"type":"input_image","image_url":"data:…"}]`, and a Chat tool message). Anthropic's Messages keeps them in the `tool_result`. Chat, Qoder and Cursor (`cursorImage`) put them in a user message right after the results, and the result says they follow. Command Code puts them in the user's turn after the results, Gemini and Code Assist after the function's response, and Devin in its tool message. Kiro's results hold text alone, so Kiro (the built-in, and its plugin from 0.1.9 on) sends them with the message that answers the call, and only the latest images go again (#369, #1861). `TestCodexToolImageReachesAnthropicPlugin`, `TestCodexToolImageKiro`, `TestCodexToolImageCursor`, and the plugin's `tool-images.test.mjs`.
- Group members are `provider/model[:effort]`. A member with a fixed effort is asked for that effort, bounded by the group's levels (#671).
- A group offers agents the reasoning levels its members have in common (`groupEntries` in [`group.go`](../../internal/provider/group.go)), or the ones it names (`Group.Levels`, #295). A member that doesn't follow the agent's effort is left out of that: one fixed at an effort, one whose levels nothing knows (#597), one that thinks with no levels, one the user made reasonless, and one known not to think (`Entry.Quiet`), which the gateway sends no reasoning ask (`withoutReasoningAsk`, [`quiet.go`](../../internal/gateway/quiet.go)). A quiet member used to empty the group's levels, so Codex got its entry with no `supported_reasoning_levels`, showed no effort control and ran at its own medium (#2127, `TestGroupQuietMemberKeepsCodexEffortControl`).
- An agent whose config can't carry an effort has one picked in magpie (`provider.AgentEffort`, settings' `agentEfforts`; Cursor Private Inference's row, #1003). It is asked for on that agent's requests to a model that reasons (`Provider.Thinks`), in place of the level the request sent, fitted to the model's levels and bounded by the group's. Order: a member's fixed effort, then a model's `:effort` suffix, then the turn's pick (a routing rule's), then the agent's pick, then the request's own. A model that doesn't reason is sent as asked; the default (none picked) leaves every request as it came. The pick beats the request's own because Cursor sends its own default as often as a real choice. Picking Default hands the choice back to Cursor.
- In models.dev, entries from `deepseek`, `kimi-code-plan-cn` and `kimi-code-plan-global` gain `none` only when they have both a `toggle` and effort levels; the DeepSeek and Kimi APIs accepted that value in [#1098](https://github.com/yetone/magpie/issues/1098). Other providers keep their listed levels because their APIs may reject `none`; toggle-only entries remain level-less ([`mdModel.efforts`](../../internal/catalog/catalog.go)).
- Gemini's OpenAI-compatible API (AI Studio's, or a proxy in front of Gemini on this computer or the LAN: `geminiCompat`) is asked for the model's thoughts in `extra_body.google.thinking_config`. A 400 or 422 whose error names `extra_body`, `include_thoughts` or thinking at all (`refusesThinkingConfig`) marks the provider unfit for the field (`thinking_config`), and it is asked again with `reasoning_effort` alone. Gemini 3 can't stop thinking, so reasoning turned off goes at `minimal`, its least, or at the model's lowest level where it has no `minimal` (`geminiLevels`: those of the model's levels it hasn't turned away, or of Gemini 3's where its own aren't known or none is left). Gemini 3 turns away a level the model hasn't with a 400 that names the level (`geminiRefusedLevel`): AI Studio's "Thinking level MINIMAL is not supported for this model. Please retry with other thinking level." for gemini-3.8-flash, Vertex AI's "Thinking level is unsupported: THINKING_LEVEL_MINIMAL". It names thinking too, but isn't the field turned away. The level is marked refused for that model (`levelRefused`), and the model is asked again at the nearest level it has left, still for its thoughts, and at that level from then on. A level turned away again, with none left, is the client's 400. Passed through, a Chat client's own `none` or `minimal` that Gemini turns away this way is asked again at the model's lowest level (`onEffort`), and that level goes at the lowest from then on (`turnedAway`); the other still goes as sent, as AI Studio takes `none` from gemini-3.8-flash. A refusal that names the levels the model takes (`effortLevelsNamed`, Command Code's for Qoder's `none`) marks reasoning off as a whole (`offRefused`): both go at the lowest from then on; one that lists the other among the levels taken (`otherOffNamed`, quoted, OpenAI's for gpt-5.1's `minimal`) marks only the level turned away. Both routes read and write the same marks. Vertex AI's OpenAI-compatible API marks each streamed chunk of thoughts in the delta's `extra_content.google.thought`, and such a chunk is read as thinking.
+5 -3
View File
@@ -969,12 +969,14 @@ func TestModelsListReasoning(t *testing.T) {
}
want := map[string]string{
"a/sol": "low,medium,high,max", "b/sol": "medium,high", "group/auto-sol": "medium,high",
"a/mixed": "low,high", "b/mixed": "", "group/auto-mixed": "", "a/plain": "",
"a/mixed": "low,high", "b/mixed": "", "group/auto-mixed": "low,high", "a/plain": "",
}
// a group reasons when any member does: b/mixed has no levels and a
// list that says nothing of reasoning, but a/mixed does, so the group
// is told to reason — Levelless, with no levels to pick from (#756's
// rule for images, applied to reasoning)
// is told to reason (#756's rule for images, applied to reasoning),
// at a/mixed's levels: b/mixed is sent no reasoning ask (quiet.go), so
// it doesn't take them away (#2127: Codex showed no effort control for
// a group with none, and ran it at medium)
reasoning := map[string]bool{"group/auto-mixed": true}
for _, m := range response.Data {
expected, ok := want[m.ID]
+13 -6
View File
@@ -746,8 +746,9 @@ func membersOff(entries []Entry, all []Group, g Group, off func(pid, model strin
// levels the members have in common, as before, but for those fixed at
// an effort of their own, which take whatever the agent asks, and those
// whose levels nothing magpie reads knows (levelsUnknown), which are
// sent it as asked, and those that think with no levels to pick from,
// which are sent it as asked up to high (the gateway's fitFor). With
// sent it as asked, those that think with no levels to pick from,
// which are sent it as asked up to high (the gateway's fitFor), and those
// known not to think, which are sent no reasoning ask (Quiet). With
// every member fixed, the group offers the levels they are fixed at, so
// that an agent still asks it to reason. A group that names its own
// levels (Group.Levels) offers those, and so does a group in it for its
@@ -794,10 +795,8 @@ func groupEntries(entries []Entry) []Entry {
// to think is sent none of it, as a text-only member is sent
// no image (#756's rule for images, applied to reasoning).
// One that doesn't think is no reason to tell the agent the
// group can't. Which levels the group offers is left as it
// was: a member known to take none still leaves the group
// none (#597), and the group is then Levelless, a shape
// magpie serves
// group can't, nor does it take the others' levels away
// (below)
e.Reasoning = e.Reasoning || thinks
// the reply agents are told is the longest a member gives: the
// gateway asks each member for no more than its own
@@ -864,6 +863,14 @@ func groupEntries(entries []Entry) []Entry {
// Discord: routing group 在接入 harness 的时候,没有设置
// reasoning_efforts)
continue
} else if len(efforts) == 0 {
// it is known not to think (Quiet): the gateway sends it no
// reasoning ask (quiet.go, #950), so it doesn't take the
// others' levels away either. It left the group none, and a
// group that reasons with none to pick from is a model Codex
// offers no effort control for, at its own medium (#2127:
// a 高性能 group's sessions and subagents ran at medium)
continue
}
ultra = ultra || slices.Contains(efforts, "ultra")
if !levelled {
+75 -9
View File
@@ -1,10 +1,15 @@
package provider
import (
"cmp"
"encoding/json"
"os"
"path/filepath"
"slices"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/codexcat"
)
// A group reasons when a member does: a member that doesn't think is no
@@ -16,11 +21,6 @@ import (
// 不支持推理, and the agent turned thinking off for it: a routing group of
// deepseek-v4-flash-0731-max (a Trae plugin model magpie read as one that
// doesn't reason) with a DeepSeek that does lost reasoning for both.
//
// What the group offers as levels is not changed here: a member known to
// take none still leaves the group none (#597), and the group is then
// Levelless — magpie's shape for a model that thinks with no level to
// pick from — rather than 不支持推理.
func TestGroupReasoningFromAMemberThatThinks(t *testing.T) {
groupReasoningHome(t)
for name, in := range map[string][]Entry{
@@ -53,16 +53,19 @@ func TestGroupReasoningFromNoMember(t *testing.T) {
// A group that thinks offers the levels its members have in common, as
// before: a member that thinks with none of its own doesn't take the
// others' away (the #597 rule for a model whose levels nothing knows), and
// two that think share theirs.
// others' away (the #597 rule for a model whose levels nothing knows), nor
// does one known not to think, which the gateway sends no reasoning ask
// (#2127: the group had none, and Codex no effort control for it), and two
// that think share theirs.
func TestGroupReasoningLevels(t *testing.T) {
groupReasoningHome(t)
for name, c := range map[string]struct {
in []Entry
want []string
}{
"one thinks": {[]Entry{thinksMember(), quietMember()}, nil},
"quiet first": {[]Entry{quietMember(), thinksMember()}, nil},
"one thinks": {[]Entry{thinksMember(), quietMember()}, levels},
"quiet first": {[]Entry{quietMember(), thinksMember()}, levels},
"quiet between": {[]Entry{thinksMember(), quietMember(), thinks("b", []string{"low", "high", "medium"})}, []string{"low", "high"}},
"two think": {[]Entry{thinksMember(), thinks("b", []string{"low", "high", "medium"})}, []string{"low", "high"}},
"thinks no levels": {[]Entry{thinks("a", nil), thinks("b", []string{"low", "high"})}, []string{"low", "high"}},
} {
@@ -152,6 +155,69 @@ func TestGroupReasoningOfAPluginModelThatDoesNotThink(t *testing.T) {
}
}
// #2127: a routing group with a member known not to think, as Codex is
// handed it. The group's entry lists the levels of the member that thinks,
// so Codex shows its effort control and starts new sessions at the level
// set for them, not at its own medium with no control to change it.
func TestGroupQuietMemberKeepsCodexEffortControl(t *testing.T) {
isolate(t)
groupReasoningHome(t)
codex := t.TempDir()
t.Setenv("CODEX_HOME", codex)
// a vendor whose own list says its model doesn't think (models.dev's
// reasoning false): known quiet, not #597's unknown
if err := os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(catalog.CachePath(), []byte(`{"opencode-go": {"models": {"plain": {"id":"plain","reasoning":false}}}}`), 0o644); err != nil {
t.Fatal(err)
}
catalog.Reset()
t.Cleanup(catalog.Reset)
if err := Save(Provider{ID: "q", Name: "Q", Key: "k", Chat: "http://127.0.0.1:1/v1", Catalog: "opencode-go", Models: []string{"plain"}}); err != nil {
t.Fatal(err)
}
if e, ok := ServedEntryOf("q/plain"); !ok || !e.Quiet() {
t.Fatalf("q/plain isn't a member known not to think: %+v", e)
}
if err := SaveGroup(Group{Name: "high", Members: []string{"q/plain", "a/m"}}); err != nil {
t.Fatal(err)
}
for _, effort := range []string{"", "max"} {
if effort != "" {
if err := os.WriteFile(filepath.Join(codex, "config.toml"), []byte("model_reasoning_effort = \""+effort+"\"\n"), 0o600); err != nil {
t.Fatal(err)
}
}
type entry struct {
Slug string `json:"slug"`
Default string `json:"default_reasoning_level"`
Levels []struct {
Effort string `json:"effort"`
} `json:"supported_reasoning_levels"`
}
var out struct {
Models []entry `json:"models"`
}
if err := json.Unmarshal(codexcat.Catalog(CodexListed()), &out); err != nil {
t.Fatal(err)
}
i := slices.IndexFunc(out.Models, func(m entry) bool { return m.Slug == GroupPrefix+"high" })
if i < 0 {
t.Fatalf("no group/high in Codex's list: %+v", out.Models)
}
m := out.Models[i]
var got []string
for _, l := range m.Levels {
got = append(got, l.Effort)
}
want := cmp.Or(effort, "high") // DefaultEffort: medium, else high
if !slices.Equal(got, levels) || m.Default != want {
t.Errorf("new sessions at %q: levels %v, default %q; want %v, %q", effort, got, m.Default, levels, want)
}
}
}
// levels are the levels of the member that thinks in these tests.
var levels = []string{"low", "high", "max"}
@@ -15,8 +15,9 @@ import (
// without reasoning while magpie showed max. A model a provider serves that
// its vendor's list leaves out takes the levels the gateway fits an effort
// to (Provider.Efforts), and a member whose levels nothing knows takes
// whatever the agent asks rather than taking the others' away. A member
// known to have none still does.
// whatever the agent asks rather than taking the others' away. Nor does a
// member known to have none, which the gateway sends no reasoning ask
// (#2127).
func TestGroupLevelsWithUnknownMember(t *testing.T) {
t.Setenv("HOME", t.TempDir())
t.Setenv("USERPROFILE", t.TempDir())
@@ -73,9 +74,9 @@ func TestGroupLevelsWithUnknownMember(t *testing.T) {
if e := entry("group/ds"); !slices.Equal(e.Efforts, want) || !e.Reasoning {
t.Fatalf("ds: levels %v, reasoning %v", e.Efforts, e.Reasoning)
}
// a member listed without levels still takes them away, and a group
// of models nothing knows offers none
if e := entry("group/plain"); len(e.Efforts) != 0 {
// a member listed without levels doesn't take them away (#2127), and
// a group of models nothing knows offers none
if e := entry("group/plain"); !slices.Equal(e.Efforts, want) {
t.Fatalf("plain: levels %v", e.Efforts)
}
if e := entry("group/tp"); len(e.Efforts) != 0 {