AIStudio2API icon indicating copy to clipboard operation
AIStudio2API copied to clipboard

[Bug] Consecutive 503 (code 14 "high demand") across pool exhausts MAX_ACCOUNT_SWITCHES in seconds and lacks brief backoff

Open photobrand opened this issue 1 week ago • 0 comments

发生了什么 / What happened

Summary

During temporary Google AI Studio traffic spikes, GenerateContent returns HTTP 503, protocol code 14: This model is currently experiencing high demand. Spikes in demand are usually temporary. Please try again later.

Because 503 is treated as a generic failure in settleAttempt:

  1. It immediately increments retry.failures++ against MAX_ACCOUNT_SWITCHES without any backoff or short cooldown.
  2. In a pool of 10+ accounts, a request cycles through 5 accounts in ~15 seconds, burns MAX_ACCOUNT_SWITCHES=5, and immediately returns 503 to the client—even though subsequent accounts in the pool were healthy.
  3. Subsequent requests immediately hit the same accounts and fail again.

Observed Log Evidence (sanitized)

In our logs over 5 hours, gemini-4-hydrogen recorded 117 account switches due to 503 code 14, evenly distributed across all 7 enabled accounts (17–21 times each).

Example timeline (13:17:54 to 13:18:17):

  • 13:17:59 account_1 -> 503 code 14
  • 13:18:02 account_2 -> 503 code 14
  • 13:18:06 account_3 -> 503 code 14
  • 13:18:10 account_4 -> 503 code 14
  • 13:18:14 account_5 -> 503 code 14
  • 13:18:17 account_6 -> 503 code 14 (failures = 6 > MAX_ACCOUNT_SWITCHES=5 -> request aborts with 503). The very next request at 13:18:48 cycled through the exact same accounts and failed again.

Root Cause Pointer

In internal/app/runtime.go (settleAttempt):

  • 503 sets quotaFailure = false.
  • Unlike 429 (which applies a cooldown and doesn't count against retry.failures), 503 increments retry.failures++.
  • No temporary model-level pause or jittered backoff exists for 503 code 14.

Suggested Improvement

  1. For HTTP 503 with protocol code 14 (high demand), don't burn MAX_ACCOUNT_SWITCHES immediately on every switch (or treat 503 spike switches similarly to quota switches bounded by len(EnabledAccounts())).
  2. Apply a brief transient cool-off (e.g. 15–30 seconds) on that specific model for that account, or add a short delay (200–500ms) before trying the next account so transient cluster spikes settle without failing the user request.

版本 / Version

v0.3.13

photobrand avatar Nov 21 '26 18:11 photobrand