From 169ec91651948f7b0039ddc8c7c373256fa2f6f1 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 12 Nov 2026 15:50:10 +0800 Subject: [PATCH] =?UTF-8?q?gateway:=20a=20relay's=20Chinese=20"=E6=9C=AA?= =?UTF-8?q?=E7=9F=A5=E8=AF=B7=E6=B1=82=E5=AD=97=E6=AE=B5=EF=BC=9Aprompt=5F?= =?UTF-8?q?cache=5Fretention"=20is=20read=20as=20a=20refusal=20of=20that?= =?UTF-8?q?=20field,=20and=20the=20request=20is=20asked=20again=20without?= =?UTF-8?q?=20it=20(ldl123292=20on=20X)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 基元律动's OpenAI-compatible relay answers a field it doesn't take as "未知请求字段:". refusedOptional only knew the English wordings, so the retry without prompt_cache_retention (and the other optionalFields) never happened and the error went to the client. magpie itself adds none of these fields to a custom provider's request: prompt_cache_retention is the client's own, and optionalFields already drops it on a refusal and remembers the provider. Added the Chinese wordings (未知/未识别/不支持/ 不允许/无效 + 请求 + 字段/参数/属性) to unsupportedOptionalField. Run: gofmt clean; go test -run 'Optional|Refus' ./internal/gateway ok on mote; go vet gateway darwin/windows/linux. chinese-unknown-field and chinese-unsupported-quoted in TestRefusedOptionalNamesOnlyUnsupportedFields fail on the old gateway.go (checked by hand). Not run: full suite before the tag (started after), the relay itself (no account). --- internal/gateway/gateway.go | 10 ++++++++++ internal/gateway/optional_fields_test.go | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index 052d51508..df1c0c532 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -8713,6 +8713,11 @@ func refusedOptional(status int, msg, body []byte) []string { var unknownOptionalField = lazyre.New("(?i)\\b(?:unknown (?:name|field|parameter)|unsupported (?:parameter|field|property|argument)|unrecognized (?:request )?(?:argument|parameter)(?: supplied)?):?\\s*['\"\\x60]([a-z_]+)['\"\\x60]") var unquotedUnsupportedOptionalField = lazyre.New("(?i)\\bunsupported (?:parameter|field|property|argument):\\s*([a-z_]+)\\b") + +// chineseRefusedOptionalField is a relay refusing a field in Chinese: +// 基元律动's "未知请求字段:prompt_cache_retention" (ldl123292 on X). +var chineseRefusedOptionalField = lazyre.New("(?:未知|未识别|不支持|不允许|无效)(?:的)?(?:请求)?(?:字段|参数|属性)\\s*[::]?\\s*['\"\\x60「“]?([a-z_]+)") + var rejectedOptionalField = lazyre.New("(?i)(?:^|\\b(?:parameter|field|property|argument)\\s+)['\"\\x60]([a-z_]+)['\"\\x60]\\s+(?:is\\s+)?(?:unsupported|not supported)\\b") // leadingRejectedOptionalField is a message that starts with the field's @@ -8771,6 +8776,11 @@ func unsupportedOptionalField(fault any, field string) bool { return true } } + for _, match := range chineseRefusedOptionalField.FindAllStringSubmatch(v, -1) { + if match[1] == field { + return true + } + } for _, match := range rejectedOptionalField.FindAllStringSubmatch(v, -1) { if match[1] == field { return true diff --git a/internal/gateway/optional_fields_test.go b/internal/gateway/optional_fields_test.go index 10cb13e6b..6241f2a4e 100644 --- a/internal/gateway/optional_fields_test.go +++ b/internal/gateway/optional_fields_test.go @@ -181,6 +181,10 @@ func TestRefusedOptionalNamesOnlyUnsupportedFields(t *testing.T) { {"codex-unquoted-unsupported-parameter", `{"code":null,"message":"Codex: Unsupported parameter: prompt_cache_retention","param":null,"type":"invalid_request_error"}`, 400, []string{"prompt_cache_retention"}}, // the ChatGPT backend's, as it gave it on 2026-10-14 (#2154) {"openai-bare-name", `{"error":{"message":"prompt_cache_options is not supported on this model","type":"invalid_request_error","param":"prompt_cache_options","code":"invalid_parameter"}}`, 400, []string{"prompt_cache_options"}}, + // a relay's Chinese refusal (基元律动, ldl123292 on X) + {"chinese-unknown-field", `{"error":{"message":"未知请求字段:prompt_cache_retention","type":"invalid_request_error"}}`, 400, []string{"prompt_cache_retention"}}, + {"chinese-unsupported-quoted", `{"error":{"message":"不支持的参数: 'prompt_cache_retention'"}}`, 400, []string{"prompt_cache_retention"}}, + {"chinese-other-field", `{"error":{"message":"未知请求字段:foo_bar"}}`, 400, nil}, {"bare-name-not-leading", `{"error":{"message":"The input said metadata is not supported here"}}`, 400, nil}, {"bare-name-other-field", `{"error":{"message":"reasoning is not supported on this model"}}`, 400, nil}, {"plain-error", `Unknown name "store": Cannot find field.`, 400, []string{"store"}},