From 0ff094b87f9b20b965ba45542eae302b4006e23f Mon Sep 17 00:00:00 2001 From: Ben Vargas Date: Wed, 19 Nov 2025 13:14:40 -0700 Subject: [PATCH] fix(executor): prevent streaming on failed response when no fallback Fix critical bug where ExecuteStream would create a streaming channel from a failed (non-2xx) response after exhausting all retries with no fallback models available. When retries were exhausted on the last model, the code would break from the inner loop but fall through to streaming channel creation (line 401), immediately returning at line 461. This made the error handling code at lines 464-471 unreachable, causing clients to receive an empty/closed stream instead of a proper error response. Solution: Check if httpResp is non-2xx before creating the streaming channel. If failed, continue the outer loop to reach error handling. Identified by: codex-bot review Ref: https://github.com/router-for-me/CLIProxyAPI/pull/280#pullrequestreview-3484560423 --- internal/runtime/executor/gemini_cli_executor.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/runtime/executor/gemini_cli_executor.go b/internal/runtime/executor/gemini_cli_executor.go index 294761c8..2f48871b 100644 --- a/internal/runtime/executor/gemini_cli_executor.go +++ b/internal/runtime/executor/gemini_cli_executor.go @@ -392,6 +392,12 @@ func (e *GeminiCLIExecutor) ExecuteStream(ctx context.Context, auth *cliproxyaut continue } + // If we have a failed response (non-2xx), don't attempt streaming + // Continue outer loop to try next model or return error + if httpResp == nil || httpResp.StatusCode < 200 || httpResp.StatusCode >= 300 { + continue + } + out := make(chan cliproxyexecutor.StreamChunk) stream = out go func(resp *http.Response, reqBody []byte, attempt string) {