From c45ece36a0e591e1a69cbb6306458e9fe69a4ec7 Mon Sep 17 00:00:00 2001 From: wei Date: Wed, 7 Oct 2026 00:19:51 -0700 Subject: [PATCH] gateway: Code Assist sends the auto mode classifier's reasoning off at low, not high, on a Gemini 3 Flash that lists minimal fitAutoModeClassifier asks a model to think at its least level (#250). On a Gemini 3 Flash whose models.dev levels include minimal (gemini-3.5-flash, 3.1-flash-lite, 3-flash-preview), that level is minimal. thinkingConfig sends minimal only to an Antigravity variant whose id says minimal, and everything else fell through to high. So the classifier, asked to think least, went at the most, with 2112 tokens to think and answer in. Sending minimal instead isn't safe. Gemini CLI's 3.5 Flash goes out as 3.8 Flash where that is rolled out (geminiFlags.wire), and 3.8 Flash has no minimal: AI Studio answers it with a 400. Reasoning off (minimal or none) with no variant level now goes at low, which every Gemini 3 text model lists. An image model may have no low (3.1 Flash Image has minimal and high), so it still goes at high, as before. Every other case is unchanged: a variant's own level, low, medium, high, no effort, and Gemini 2.5's budgets. The comment saying Flash takes minimal, low, medium and high is corrected. Factory's Gemini route (buildGemini) builds its request with the same code, and gets the same change. TestCodeAssistReasoningOffAtLow sends Claude Code's classifier request (autoModeAsk) to Gemini CLI's gemini-3.5-flash and to Antigravity's gemini-3.1-flash-lite, with models.dev's levels. Both go at low. It also asks an image model at low, which fits to minimal; that goes at high. * With the parent's codeassist.go it fails with: the classifier on gemini's gemini-3.5-flash: "minimal" at "high", want minimal at low. Antigravity's 3.1-flash-lite fails the same way. * Without the image check it fails with: gemini-3.1-flash-image asked low: at "low", want high. Verified with the commit before. Not tried live. --- internal/gateway/codeassist.go | 12 +++++- internal/gateway/codeassist_test.go | 60 +++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/internal/gateway/codeassist.go b/internal/gateway/codeassist.go index 42df556a5..a937d17b5 100644 --- a/internal/gateway/codeassist.go +++ b/internal/gateway/codeassist.go @@ -367,8 +367,14 @@ func buildCodeAssistSent(r *Request, sent, agent string) []byte { // stop thinking once the request has tools, and give none of it back // (#636); Antigravity's own tiered ids, sent a level, don't. // -// Gemini 3's levels: Flash takes minimal, low, medium and high, so medium -// goes as medium; Pro takes low and high only, so medium goes up to high. +// Gemini 3's levels: medium goes as medium to Flash, and up to high to +// Pro, which took low and high only (3 Pro). Minimal goes only to a Flash +// variant at minimal: 3.7 and 3.8 Flash have none (AI Studio answers 3.8's +// with a 400), and the id here doesn't say which Flash serves it (Gemini +// CLI's 3.5 Flash goes out as 3.8 Flash where that is rolled out). +// Reasoning off otherwise (the auto mode classifier's least level) goes at +// low, which every Gemini 3 text model takes; an image model may have no +// low (3.1 Flash Image: minimal and high), and goes at high. func thinkingConfig(r *Request, model string, claude bool, at string) map[string]any { m := strings.ToLower(model) if strings.HasPrefix(m, "gpt-oss") || claude && !strings.Contains(m, "thinking") { @@ -393,6 +399,8 @@ func thinkingConfig(r *Request, model string, claude bool, at string) map[string level = "low" case effort == "minimal" && at != "": level = "minimal" + case offEffort(effort) && !catalog.DrawsID(m): + level = "low" case effort == "medium" && strings.Contains(m, "flash"): level = "medium" } diff --git a/internal/gateway/codeassist_test.go b/internal/gateway/codeassist_test.go index 3d8d3a081..4e8c84927 100644 --- a/internal/gateway/codeassist_test.go +++ b/internal/gateway/codeassist_test.go @@ -2,11 +2,14 @@ package gateway import ( "encoding/json" + "os" + "path/filepath" "reflect" "strings" "testing" "github.com/yetone/magpie/internal/catalog" + "github.com/yetone/magpie/internal/provider" ) func codeAssistRequest(t *testing.T) *Request { @@ -195,6 +198,63 @@ func TestCodeAssistAntigravityLevels(t *testing.T) { } } +// Claude Code's auto mode classifier turns thinking off and is asked at the +// least level the model has (fitAutoModeClassifier, #250): minimal, on a +// Gemini 3 Flash models.dev gives minimal. Code Assist sends minimal only +// to a variant at minimal, as the id doesn't say which Flash serves it and +// 3.8 Flash has none, and sent the rest at high, the most: they go at low. +// An image model asked low, which fits to minimal (3.1 Flash Image has +// minimal and high), still goes at high. +func TestCodeAssistReasoningOffAtLow(t *testing.T) { + t.Setenv("XDG_CACHE_HOME", t.TempDir()) + os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o755) + if err := os.WriteFile(catalog.CachePath(), []byte(`{"google":{"models":{ + "gemini-3.5-flash":{"id":"gemini-3.5-flash","reasoning":true,"reasoning_options":[{"type":"effort","values":["minimal","low","medium","high"]}]}, + "gemini-3.1-flash-lite":{"id":"gemini-3.1-flash-lite","reasoning":true,"reasoning_options":[{"type":"effort","values":["minimal","low","medium","high"]}]}, + "gemini-3.1-flash-image":{"id":"gemini-3.1-flash-image","reasoning":true,"reasoning_options":[{"type":"effort","values":["minimal","high"]}]}}}}`), 0o644); err != nil { + t.Fatal(err) + } + catalog.Reset() + t.Cleanup(catalog.Reset) + // the level the request goes at, its effort fitted as forwardTranslated + // fits it + level := func(p provider.Provider, model string, r *Request) string { + if r.Effort != "" { + r.Effort = fitFor(p, model, r.Effort) + } + var env struct { + Request struct { + GenerationConfig struct { + ThinkingConfig struct { + ThinkingLevel string `json:"thinkingLevel"` + } `json:"thinkingConfig"` + } `json:"generationConfig"` + } `json:"request"` + } + json.Unmarshal(codeAssistBody(p, r, model, nil), &env) + return env.Request.GenerationConfig.ThinkingConfig.ThinkingLevel + } + for _, c := range []struct{ agent, model string }{{"gemini", "gemini-3.5-flash"}, {"antigravity", "gemini-3.1-flash-lite"}} { + p := provider.Provider{ID: c.agent, Account: &provider.Account{Agent: c.agent, User: "u"}} + r, err := parseAnthropic([]byte(autoModeAsk(c.model))) + if err != nil { + t.Fatal(err) + } + fitAutoModeClassifier(p, c.model, r) + if got := level(p, c.model, r); r.Effort != "minimal" || got != "low" { + t.Errorf("the classifier on %s's %s: %q at %q, want minimal at low", c.agent, c.model, r.Effort, got) + } + } + p := provider.Provider{ID: "antigravity", Account: &provider.Account{Agent: "antigravity", User: "u"}} + r, err := parseChat([]byte(`{"model":"gemini-3.1-flash-image","stream":true,"reasoning_effort":"low","messages":[{"role":"user","content":"draw a cat"}]}`)) + if err != nil { + t.Fatal(err) + } + if got := level(p, "gemini-3.1-flash-image", r); got != "high" { + t.Errorf("gemini-3.1-flash-image asked low: at %q, want high", got) + } +} + // A call Antigravity's model writes out in its reply's text, // call:default_api:{...}, is the call it meant, however the stream // cuts it up, and a call named with Gemini's namespace is the client's