From a299c7d1c42ba8bb361ed84a1881d8d84132f46a Mon Sep 17 00:00:00 2001 From: CJACK Date: Sun, 3 May 2026 06:59:20 +0800 Subject: [PATCH] refactor: remove thinking content from empty output validation logic to enforce stricter completion requirements --- internal/assistantturn/turn.go | 5 ----- internal/httpapi/openai/chat/empty_retry_runtime.go | 3 +-- internal/httpapi/openai/shared/upstream_empty.go | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/internal/assistantturn/turn.go b/internal/assistantturn/turn.go index 0bfadba..bc8bd19 100644 --- a/internal/assistantturn/turn.go +++ b/internal/assistantturn/turn.go @@ -206,11 +206,6 @@ func ValidateTurn(turn Turn, policy promptcompat.ToolChoicePolicy) *OutputError if strings.TrimSpace(turn.Text) != "" { return nil } - // Thinking-only with no visible text is not an immediate error; - // the caller should retry via ShouldRetryEmptyOutput first. - if strings.TrimSpace(turn.Thinking) != "" { - return nil - } status, message, code := UpstreamEmptyOutputDetail(turn.ContentFilter, turn.Text, turn.Thinking) return &OutputError{Status: status, Message: message, Code: code} } diff --git a/internal/httpapi/openai/chat/empty_retry_runtime.go b/internal/httpapi/openai/chat/empty_retry_runtime.go index 847bbe7..d3fca68 100644 --- a/internal/httpapi/openai/chat/empty_retry_runtime.go +++ b/internal/httpapi/openai/chat/empty_retry_runtime.go @@ -151,8 +151,7 @@ func shouldRetryChatNonStream(result chatNonStreamResult, attempts int) bool { attempts < emptyOutputRetryMaxAttempts() && !result.contentFilter && result.detectedCalls == 0 && - strings.TrimSpace(result.text) == "" && - strings.TrimSpace(result.thinking) == "" + strings.TrimSpace(result.text) == "" } func (h *Handler) handleStreamWithRetry(w http.ResponseWriter, r *http.Request, a *auth.RequestAuth, resp *http.Response, payload map[string]any, pow, completionID, model, finalPrompt string, refFileTokens int, thinkingEnabled, searchEnabled bool, toolNames []string, toolsRaw any, toolChoice promptcompat.ToolChoicePolicy, historySession *chatHistorySession) { diff --git a/internal/httpapi/openai/shared/upstream_empty.go b/internal/httpapi/openai/shared/upstream_empty.go index e180637..d2e396c 100644 --- a/internal/httpapi/openai/shared/upstream_empty.go +++ b/internal/httpapi/openai/shared/upstream_empty.go @@ -6,7 +6,7 @@ import ( ) func ShouldWriteUpstreamEmptyOutputError(text, thinking string) bool { - return strings.TrimSpace(text) == "" && strings.TrimSpace(thinking) == "" + return strings.TrimSpace(text) == "" } func UpstreamEmptyOutputDetail(contentFilter bool, text, thinking string) (int, string, string) {