From 7d26b8107524ffcb7d3236dce95ba0b93ac85b12 Mon Sep 17 00:00:00 2001 From: alfadb Date: Wed, 18 Mar 2026 14:31:57 +0800 Subject: [PATCH] fix: address review - add missing whitespace patterns and narrow error matching --- backend/internal/service/gateway_request.go | 6 +++++- backend/internal/service/gateway_service.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/internal/service/gateway_request.go b/backend/internal/service/gateway_request.go index 4581a3c4..29b6cfd6 100644 --- a/backend/internal/service/gateway_request.go +++ b/backend/internal/service/gateway_request.go @@ -32,6 +32,8 @@ var ( // Fast-path patterns for empty text blocks: {"type":"text","text":""} patternEmptyText = []byte(`"text":""`) patternEmptyTextSpaced = []byte(`"text": ""`) + patternEmptyTextSp1 = []byte(`"text" : ""`) + patternEmptyTextSp2 = []byte(`"text" :""`) ) // SessionContext 粘性会话上下文,用于区分不同来源的请求。 @@ -247,7 +249,9 @@ func FilterThinkingBlocksForRetry(body []byte) []byte { // Check for empty text blocks: {"type":"text","text":""} // These cause upstream 400: "text content blocks must be non-empty" hasEmptyTextBlock := bytes.Contains(body, patternEmptyText) || - bytes.Contains(body, patternEmptyTextSpaced) + bytes.Contains(body, patternEmptyTextSpaced) || + bytes.Contains(body, patternEmptyTextSp1) || + bytes.Contains(body, patternEmptyTextSp2) // Fast path: nothing to process if !hasThinkingContent && !hasEmptyContent && !hasEmptyTextBlock { diff --git a/backend/internal/service/gateway_service.go b/backend/internal/service/gateway_service.go index 6113f871..899d47ec 100644 --- a/backend/internal/service/gateway_service.go +++ b/backend/internal/service/gateway_service.go @@ -6071,7 +6071,7 @@ func (s *GatewayService) isThinkingBlockSignatureError(respBody []byte) bool { // 例如: "all messages must have non-empty content" // "messages: text content blocks must be non-empty" if strings.Contains(msg, "non-empty content") || strings.Contains(msg, "empty content") || - strings.Contains(msg, "must be non-empty") { + strings.Contains(msg, "content blocks must be non-empty") { logger.LegacyPrintf("service.gateway", "[SignatureCheck] Detected empty content error") return true }