AIStudio2API icon indicating copy to clipboard operation
AIStudio2API copied to clipboard

[Bug] retryableGenerateAccountError does not retry Camoufox XHR NetworkError or interrupted non-200 error body reads

Open photobrand opened this issue 1 week ago • 0 comments

发生了什么 / What happened

Summary

Under WAA_BACKEND=camoufox, if Firefox's XHR fails with NetworkError when attempting to fetch resource. while receiving an error response (validateRPCResponse reading response.Body) or before headers arrive (readResponseHead), retryableGenerateAccountError returns false, immediately failing the request with 502 instead of switching to another account.

Observed Log Evidence (sanitized)

{"time":"2026-11-20T23:39:41.733+03:00","level":"INFO","msg":"请求开始","source":"request","request":{"id":"req_1038","model":"gemini-4-neon"}}
{"time":"2026-11-20T23:42:50.311+03:00","level":"ERROR","msg":"请求失败","source":"account_a","request":{"id":"req_1038","model":"gemini-4-neon","status":502,"error":"读取 AI Studio GenerateContent 错误响应: Error: NetworkError when attempting to fetch resource."}}

The request aborted on the very first account (account_a) with 502 without attempting any other account in the pool.

Root Cause Pointers

internal/camoufoxnative/protected.go (protectedSend, readResponseHead, protectedResponseBody.Read) and internal/camoufoxnative/generate.go: xhr.onerror emits a plain errors.New("NetworkError when attempting to fetch resource.") (not *url.Error). internal/aistudio/client.go (validateRPCResponse): When response.StatusCode != http.StatusOK and io.ReadAll(response.Body) fails, it returns fmt.Errorf("读取 AI Studio %s 错误响应: %w", method, readErr) (unlike 200 OK streams, which DecodeGenerateStream wraps in *aistudio.StreamInterruptedError). internal/app/proxy_pool.go (proxyNetworkError) explicitly checks strings.Contains(err.Error(), "NetworkError when attempting to fetch resource") to detect network failures—yet internal/app/runtime.go (retryableGenerateAccountError) only checks *aistudio.StreamInterruptedError, *url.Error, and *aistudio.RPCError, returning false for both plain NetworkError and interrupted validateRPCResponse reads.

Suggested Fix

Wrap non-context io.ReadAll(response.Body) failures in validateRPCResponse (or Camoufox XHR NetworkError errors) with a retryable transport/interrupted error type (e.g., *StreamInterruptedError or a shared browser network error) so retryableGenerateAccountError retries/switches accounts consistently across Go HTTP and Camoufox backends.

版本 / Version

No response

photobrand avatar Nov 21 '26 11:11 photobrand