From 188d9026d8d344464676c7919c09730a5181adb6 Mon Sep 17 00:00:00 2001 From: tsumon <47944351+tsumon@users.noreply.github.com> Date: Thu, 8 Oct 2026 01:22:04 +0800 Subject: [PATCH] fix(models): honor OpenRouter native thinking for legacy defaults (#3807) --- internal/models/parity/parity_test.go | 22 ++++++++++++++++++++++ internal/models/runtime/legacy.go | 23 ++++++++++++++++++----- internal/models/runtime/resolve.go | 10 ++++++---- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/internal/models/parity/parity_test.go b/internal/models/parity/parity_test.go index 9c0de964..6b563bf6 100644 --- a/internal/models/parity/parity_test.go +++ b/internal/models/parity/parity_test.go @@ -315,6 +315,28 @@ func TestLegacyWireParity(t *testing.T) { opts: &api.Options{Thinking: ptrBool(true)}, want: map[string]any{"chat_template_kwargs": map[string]any{"enable_thinking": true}}, }, + { + name: "openrouter legacy default keeps the native reasoning format", + provider: "openrouter", model: "qwen/qwen3.7-flash", + extra: map[string]string{models.ExtraThinkingControl: "none"}, + opts: &api.Options{Thinking: ptrBool(false)}, + want: map[string]any{ + "reasoning": map[string]any{"enabled": false}, + "chat_template_kwargs": nil, + }, + divergence: "the pre-catalog editor persisted OpenRouter's default `none` on every remote row; " + + "that default must not suppress the provider's native reasoning switch.", + }, + { + name: "openrouter non-default legacy format remains an explicit override", + provider: "openrouter", model: "qwen/qwen3.7-flash", + extra: map[string]string{models.ExtraThinkingControl: "chat_template_kwargs"}, + opts: &api.Options{Thinking: ptrBool(false)}, + want: map[string]any{ + "reasoning": nil, + "chat_template_kwargs": map[string]any{"enable_thinking": false}, + }, + }, { name: "moonshot v1 pins temperature to 1 and drops other sampling", provider: "moonshot", model: "moonshot-v1-8k", diff --git a/internal/models/runtime/legacy.go b/internal/models/runtime/legacy.go index 5ecb00ae..2c1cb1d4 100644 --- a/internal/models/runtime/legacy.go +++ b/internal/models/runtime/legacy.go @@ -21,11 +21,23 @@ func inferAPIFromURL(baseURL string, current api.API) api.API { // applyLegacyThinkingControl maps the pre-catalog thinking_control value // onto the new settings. Unknown non-empty values keep the historical -// fallback (chat_template_kwargs). -func applyLegacyThinkingControl(s *api.OpenAICompletionsSettings, value string) { - switch strings.ToLower(strings.TrimSpace(value)) { - case "": - return +// fallback (chat_template_kwargs). It reports whether a stored value was +// applied, so the caller can still silence catalogued non-reasoning models +// when a legacy default is ignored. +func applyLegacyThinkingControl(s *api.OpenAICompletionsSettings, value string) bool { + normalized := strings.ToLower(strings.TrimSpace(value)) + if normalized == "" { + return false + } + // The pre-catalog editor persisted "none" as OpenRouter's default for + // every remote model row. It was not an explicit request to suppress the + // provider's newer native reasoning format, which is needed to honor the + // caller's thinking=false setting. Keep honoring every non-default legacy + // encoding as an explicit per-row override. + if normalized == "none" && s.ThinkingFormat == api.ThinkingFormatOpenRouter { + return false + } + switch normalized { case "none": s.ThinkingFormat = api.ThinkingFormatNone case "enable_thinking": @@ -35,4 +47,5 @@ func applyLegacyThinkingControl(s *api.OpenAICompletionsSettings, value string) default: s.ThinkingFormat = api.ThinkingFormatChatTemplateKwargs } + return true } diff --git a/internal/models/runtime/resolve.go b/internal/models/runtime/resolve.go index c6d45475..c2b95084 100644 --- a/internal/models/runtime/resolve.go +++ b/internal/models/runtime/resolve.go @@ -169,7 +169,9 @@ func resolveWithVendor(ref Ref, vendor *Provider) (*Resolved, error) { ); err != nil { return nil, err } - applyLegacyThinkingControl(&completions, ref.Extra[models.ExtraThinkingControl]) + legacyThinkingControlApplied := applyLegacyThinkingControl( + &completions, ref.Extra[models.ExtraThinkingControl], + ) out.OpenAICompletions = completions responses := api.DefaultOpenAIResponses() @@ -213,9 +215,9 @@ func resolveWithVendor(ref Ref, vendor *Provider) (*Resolved, error) { return nil, err } out.GoogleGenerativeAI = google - // An explicit legacy thinking_control is the operator saying "this row - // does think, send the switch this way", so it outranks the catalog. - if strings.TrimSpace(ref.Extra[models.ExtraThinkingControl]) == "" { + // A non-default legacy thinking_control is an explicit per-row override. + // An ignored provider default lets the catalog's reasoning metadata apply. + if !legacyThinkingControlApplied { out.silenceThinkingForNonReasoningModel() }