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
This commit is contained in:
Ben Vargas
2025-11-19 13:14:40 -07:00
parent ed23472d94
commit 0ff094b87f

View File

@@ -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) {