gateway: MiniMax's and Volcengine Ark's refusals of thinking turned off are asked again with it left to the model (#1141)

thinkingOffUnlessAsked turns thinking off on a Messages request for a
non-Claude model that doesn't mention it (Claude Desktop's model_validation
probe, its health probe, title generation). MiniMax-M3.1-Flash-Preview and
Ark's glm-5.3 / glm-5.3-flash refuse that with 400, in wordings neither
alwaysThinks, mandatoryReasoning nor thinkingOffRefused matched, so the 400
went back to the client and Desktop wouldn't switch to the model.

alwaysThinks now matches the reporters' literal messages, narrowly:
- MiniMax: `requires adaptive thinking; thinking.type="disabled" (including
  reasoning.effort=none) is not allowed (2013)`
- Ark: "thinking.type `disabled` is not supported by this model"
Both retry sites use it: the relayed Messages path (withoutThinkingOff,
gateway.go) and the translated Chat/Responses path (thinkingBackOn).

Tests: TestAnthropicPassthroughMiniMaxArkThinkingOffRefused (each vendor's
body: omitted thinking succeeds after one retry without thinking; adaptive
goes once, as sent; another 400 of MiniMax's own 2013 and a near Ark
wording "top_k is not supported by this model" are not retried), and
TestTranslatedThinkingOffRefused now runs the GLM, MiniMax and Ark wordings.
With the regex change reverted both fail (400 handed back). The JSON
envelopes around the reporters' messages are assumed (Anthropic's error
shape); not tried against the live MiniMax or Ark endpoints.

Run (sandbox HOME, private GOCACHE, worktree at origin/main 97dfed0f3):
gofmt -l; go vet ./... (darwin), GOOS=linux -tags nogui, GOOS=windows;
go build for all three; go test -tags nogui ./internal/gateway
./internal/provider ./internal/catalog ./internal/codexcat: all ok.
This commit is contained in:
yetone
2026-10-13 05:05:23 +08:00
parent 0d39515b14
commit dc2e1cc124
3 changed files with 61 additions and 3 deletions
+6 -2
View File
@@ -350,8 +350,12 @@ var anthropicModel = regexp.MustCompile(`(?i)(?:^|[/.:-])claude-`)
// GLM-5.3 answers 1210, "…always engages in thinking…", or, in Chinese
// (ZCode's GLM-5.3-Flash), "该模型始终支持思考,不可关闭" (#699); DashScope's
// own glm-5.3 answers "The value of the enable_thinking parameter is
// restricted to True."
var alwaysThinks = regexp.MustCompile(`(?i)always engages in thinking|thinking (?:can ?not|can't) be (?:disabled|turned off)|enable_thinking[^"]{0,60}restricted to true|始终(?:支持|开启|启用)?思考|思考[^"]{0,20}(?:不可|无法|不能)关闭`)
// restricted to True." MiniMax's MiniMax-M3.1-Flash-Preview answers
// "…requires adaptive thinking; thinking.type="disabled" (including
// reasoning.effort=none) is not allowed (2013)", and Volcengine Ark's
// glm-5.3 "thinking.type `disabled` is not supported by this model"
// (#1141).
var alwaysThinks = regexp.MustCompile(`(?i)always engages in thinking|thinking (?:can ?not|can't) be (?:disabled|turned off)|enable_thinking[^"]{0,60}restricted to true|始终(?:支持|开启|启用)?思考|思考[^"]{0,20}(?:不可|无法|不能)关闭|requires adaptive thinking\W+thinking\.type\W+disabled\W+\(including reasoning\.effort=none\) is not allowed|thinking\.type \x60disabled\x60 is not supported by this model`)
// ThinksOnlyWhenAsked is a model that takes thinking turned off on the
// Messages API whatever its levels: one of Anthropic's own (anthropicModel,
+42
View File
@@ -669,6 +669,48 @@ func TestAnthropicPassthroughAlwaysThinksInChinese(t *testing.T) {
}
}
// #1141: MiniMax and Volcengine Ark refuse thinking turned off in their
// own words, the reporters' literal messages. The request magpie turned it
// off for (Claude Desktop's model_validation probe, its health probe and
// titles send none) is asked again with thinking left to the model, once;
// thinking the caller asked for goes as it came, and another 400 on the
// same request, or a near wording, is the caller's to see.
func TestAnthropicPassthroughMiniMaxArkThinkingOffRefused(t *testing.T) {
for _, c := range []struct{ vendor, refusal string }{
{"MiniMax", `{"type":"error","error":{"type":"invalid_request_error","message":"invalid params, model \"MiniMax-M3.1-Flash-Preview\" requires adaptive thinking; thinking.type=\"disabled\" (including reasoning.effort=none) is not allowed (2013)"}}`},
{"Ark", `{"type":"error","error":{"type":"invalid_request_error","message":"thinking.type ` + "`disabled`" + ` is not supported by this model Request id: 021760000000000000000000000000000000000000000000000000"}}`},
} {
t.Run(c.vendor, func(t *testing.T) {
f := &fake{t: t, ctype: "application/json", reply: `{"id":"msg","type":"message","content":[]}`}
f.refuse = func(b []byte) (int, string) {
if bytes.Contains(b, []byte(`"disabled"`)) {
return 400, c.refusal
}
return 0, ""
}
setup(t, provider.Anthropic, f)
code, body := post(t, "/v1/messages", `{"model":"m1","max_tokens":1,"messages":[{"role":"user","content":[{"type":"text","text":"Hi","cache_control":{"type":"ephemeral"}}]}]}`)
if code != 200 || f.calls != 2 || bytes.Contains(f.got, []byte("thinking")) || !bytes.Contains(f.got, []byte(`"Hi"`)) {
t.Fatalf("omitted: %d %s after %d calls, last sent %s", code, body, f.calls, f.got)
}
f.calls = 0
if code, body := post(t, "/v1/messages", `{"model":"m1","max_tokens":1,"thinking":{"type":"adaptive"},"messages":[{"role":"user","content":"."}]}`); code != 200 || f.calls != 1 || !bytes.Contains(f.got, []byte(`"thinking":{"type":"adaptive"}`)) {
t.Errorf("adaptive: %d %s after %d calls, sent %s", code, body, f.calls, f.got)
}
for _, other := range []string{
`{"type":"error","error":{"type":"invalid_request_error","message":"invalid params, max_tokens must be less than 8192 (2013)"}}`,
`{"type":"error","error":{"type":"invalid_request_error","message":"top_k is not supported by this model Request id: 0217"}}`,
} {
f.calls = 0
f.refuse = func([]byte) (int, string) { return 400, other }
if code, _ := post(t, "/v1/messages", `{"model":"m1","max_tokens":1,"messages":[{"role":"user","content":"."}]}`); code != 400 || f.calls != 1 {
t.Errorf("%s: %d after %d calls", other, code, f.calls)
}
}
})
}
}
func TestOpenRouterMandatoryReasoningRetries(t *testing.T) {
const refusal = `{"error":{"message":"OpenRouter: Reasoning is mandatory for this endpoint and cannot be disabled.","type":"invalid_request_error"},"type":"error"}`
for _, tc := range []struct {
+13 -1
View File
@@ -2,6 +2,7 @@ package gateway
import (
"encoding/json"
"fmt"
"net/http/httptest"
"strings"
"testing"
@@ -92,6 +93,17 @@ func TestTranslatedEffortLoggedAsSent(t *testing.T) {
// (#1636): asked again thinking at its least, as before, and from then on
// asked so at once.
func TestTranslatedThinkingOffRefused(t *testing.T) {
for i, refusal := range []string{
`GLM-5.3 always engages in thinking and cannot be disabled`,
// MiniMax's and Volcengine Ark's wordings (#1141)
`invalid params, model \"MiniMax-M3.1-Flash-Preview\" requires adaptive thinking; thinking.type=\"disabled\" (including reasoning.effort=none) is not allowed (2013)`,
"thinking.type `disabled` is not supported by this model Request id: 0217",
} {
t.Run(fmt.Sprint(i), func(t *testing.T) { translatedThinkingOffRefused(t, refusal) })
}
}
func translatedThinkingOffRefused(t *testing.T, refusal string) {
var sent []string
f := &fake{t: t, reply: anthropicHi}
f.refuse = func(b []byte) (int, string) {
@@ -103,7 +115,7 @@ func TestTranslatedThinkingOffRefused(t *testing.T) {
json.Unmarshal(b, &v)
sent = append(sent, v.Thinking.Type)
if v.Thinking.Type == "disabled" {
return 400, `{"type":"error","error":{"type":"invalid_request_error","message":"GLM-5.3 always engages in thinking and cannot be disabled"}}`
return 400, `{"type":"error","error":{"type":"invalid_request_error","message":"` + refusal + `"}}`
}
return 0, ""
}