sub2api icon indicating copy to clipboard operation
sub2api copied to clipboard

OpenAI 503 overload cooldown is hardcoded to 600s and not configurable (v0.2.5)

Open hellpup opened this issue 2 months ago • 5 comments

Summary

On v0.2.5, OpenAI OAuth (Codex) accounts are cooled down for exactly 600 seconds whenever the upstream returns 503 Our servers are currently overloaded. None of the three available configuration switches has any effect on this — the admin UI accepts the change and reads it back correctly, but the runtime behaviour never changes.

The 600s cooldown is also far longer than the actual recovery time we measured (median 17 seconds), so healthy accounts are removed from the pool for ~35x longer than necessary. During peak hours this shrinks the schedulable pool enough to cause cascading local rejections.

Environment

  • sub2api v0.2.5 (confirmed via GET /api/v1/admin/system/version)
  • OpenAI OAuth (Codex) accounts, /v1/responses
  • ~11 accounts in one group, steady ~60 req/min, peaks ~100 req/min

What we observed

Upstream returns 503 with Our servers are currently overloaded. Please try again later. → the account gets overload_until = now + 600s.

Measured repeatedly, always exactly 600.000s:

account last 503 overload_until window
A 11:12:31 11:22:02 572s*
B 18:07:55 18:18:08 613s*
C 11:02:03 11:12:03 600.000s

* measured from last-503 rather than from the marking instant; C was measured from the marking instant.

Configuration switches that have no effect

Each was changed and the service restarted, then re-verified against real markings:

# Switch Result
1 PUT /api/v1/admin/settings/overload-cooldown → {"cooldown_minutes": 1} ❌ still 600s
2 PUT /api/v1/admin/settings/overload-cooldown → {"enabled": false} ❌ accounts still marked
3 config.yaml → rate_limit.overload_cooldown_minutes: 1 ❌ still 600s

For #2 the very next marking appeared 38 seconds after the restart, with a 600s window.

The API reads the new value back correctly in every case, which makes this hard to notice — we were misled twice before verifying against observed behaviour instead of the API response.

Reading the code, rate_limit.overload_cooldown_minutes and SetOverloadCooldownSettings appear to be scoped to Anthropic 529 only:

  • config.example.yaml: "Cooldown time (in minutes) when upstream returns 529 (overloaded)"
  • setting_features.go: // SetOverloadCooldownSettings 设置529过载冷却配置
  • ratelimit_service.go: handle529() is the only caller of SetOverloaded(), reached only from case 529:

If that is the intended scope, then the OpenAI capacity-shed cooldown is a separate, undocumented and unconfigurable mechanism — and the admin UI presents the 529-scoped setting as a generic "overload cooldown", giving OpenAI users no indication that it does not apply to them.

Trigger rule (reverse-engineered)

Marking consistently fires on the 2nd 503 within roughly a 4-minute window, and successes do not reset the counter:

account gap between the two 503s marked?
A 20s ✅
B 58s ✅
C 1m36s ✅
D 3m29s ✅
E 12m24s ❌
F 14m31s ❌
G 17m14s ❌

The "successes do not reset" part is the most damaging: one account served 30+ successful requests between its two 503s and was still frozen for 600s. A standard consecutive-failure counter reset by success would not have tripped at all here.

Why 600s is disproportionate

Excluding samples taken while the account was already in cooldown (which would be circular), recovery after a 503 is essentially immediate:

503 at successes before next 503 time to next success
20:45:36 65 1s
21:31:17 120 0s
23:45:23 98 274s
01:08:21 244 9s
09:08:17 7 18s
10:02:21 3 0s

Median recovery ≈ 17 seconds; accounts routinely serve 65–244 consecutive successes between two 503s. A 600s cooldown costs roughly 35x more capacity than the problem it mitigates.

Impact at peak

503 Our servers are currently overloaded is strongly time-of-day dependent. Normalised over 30 days / ~610k successful requests, the 503 rate per 1000 successes varies ~14x across the day and peaks in a narrow window (worst hour 4.32‰, best hours 0.00‰) — independent of our own load: two hours with nearly identical traffic (61.4k vs 62.2k successes) differ 3x in 503 rate.

In that peak window the 503s hit many accounts at once, so the per-account cooldown removes a large fraction of the pool simultaneously. In one 14-minute stretch we had 5 of 11 accounts (45%) frozen at the same time. With a low per-account concurrency limit this tipped the remaining pool into queue overflow, producing 149 local Too many pending requests rejections in a single hour — i.e. the cooldown converted an upstream blip into a self-inflicted local outage.

Suggested fixes

  1. Make the OpenAI capacity-shed cooldown configurable (window / threshold / cooldown), the way #6347 did for the OpenAI 403 path. #6987 appears to have aimed at this before being abandoned.
  2. Reset the failure counter on success. A success between two 503s is strong evidence the account is healthy.
  3. Lower the default, or scale it to observed recovery time. 60s matches both our measurements and the common circuit-breaker default; 600s does not.
  4. Add a half-open probe so a cooled account is validated with one cheap request instead of being returned to full traffic blindly.
  5. Short term: label the setting in the admin UI as applying to Anthropic 529 only, so OpenAI users are not misled into thinking they have changed something.

Related: #6631, #7174, #2258 (same class of bug on the 429 path), #1917.

Current workaround

An external daemon polls every 5s and caps the window:

UPDATE accounts SET overload_until = now() + interval '60 seconds'
WHERE overload_until > now() + interval '60 seconds';

Writing overload_until directly takes effect immediately with no cache issues. Since deploying it, local rejections dropped to zero through the peak window, and the longest observed cooldown is 57s instead of 600s. Happy to test a proper fix.

hellpup avatar Sep 16 '26 07:09 hellpup

你是发现了啥, 可以避开过载吗?

cyn-zn avatar Sep 16 '26 07:09 cyn-zn

目前sub2api过载冷却的设置都是硬编码,导致配置无效,在目前的情况暂时没更好办法,只能先取消或者设置更短的过载冷却

hellpup avatar Sep 16 '26 07:09 hellpup

Adding a back-to-back A/B measurement that supports this report.

Same account pool (4 schedulable ChatGPT Pro OAuth accounts), same production traffic, two consecutive 15-minute windows, only the image tag differs. No config changes between the two windows.

Client-visible status codes

v0.2.5 v0.2.4
200 181 214
502 55 (19.0%) 12 (5.2%)
503 26 (9.0%) 2 (0.9%)
499 (client cancel) 23 5
total 5xx share 27.9% 6.0%

Upstream status codes, same windows

v0.2.5 v0.2.4
503 479 101
502 270 99
429 145 0

The 429 column is what convinced me this is self-inflicted rather than an upstream capacity problem. Identical traffic, identical accounts, 145 upstream 429s on v0.2.5 and zero on v0.2.4. Quota was never the constraint — the 5h window was at 0% and the 7d window at 33–63% on every account throughout both runs.

This matches the cascading-rejection mechanism described in the issue: a 503 that upstream recovers from in ~17s removes the account for 600s, the remaining pool absorbs the redirected load, gets rate limited, and those accounts are then cooled down too.

On v0.2.4 the pool stayed at 4 schedulable accounts for the whole window.

For context on the upstream side during these runs: direct requests to /backend-api/codex/responses with each account's own token and proxy returned 200 consistently, so the accounts and network paths themselves were healthy.

Environment: 5 OpenAI OAuth accounts (Pro), WS mode off on all of them, PostgreSQL 18, single instance.

zhouxichao-auroramob avatar Sep 16 '26 07:09 zhouxichao-auroramob

目前

怎么改呢, 怎么让他不是429 之类的呢

cyn-zn avatar Sep 16 '26 09:09 cyn-zn

Correction — this was my own local automation, not sub2api

Closing this as invalid. The 600s cooldown I reported does not come from sub2api.

Root cause on my side: a locally-written PostgreSQL script (sub2api_openai_overload_breaker.sql, run by a systemd timer every 30s) that writes accounts.overload_until directly:

interval '5 minutes'  AS lookback,
interval '10 minutes' AS cooldown,
2::bigint             AS min_overloads,
p.observed_at + p.cooldown AS block_until

That accounts for every observation in the original report:

  • the exactly-600s window → cooldown = 10 minutes
  • the "2 × 503 within ~4 minutes" trigger → lookback = 5 minutes, min_overloads = 2
  • successes not resetting the counter → it uses a rate threshold, not consecutive failures
  • multiple accounts sharing an overload_until value identical to the microsecond → a single UPDATE writing one observed_at + cooldown to every matching row

And it explains why none of the settings appeared to work: rate_limit.overload_cooldown_minutes and the admin overload-cooldown setting are scoped to Anthropic 529 (handle529), which is correct and documented — my traffic was OpenAI 503, so that path was never reached. SetOverloaded() is only called from handle529, i.e. sub2api never set overload_until for my 503s at all.

So there is no bug here. Apologies for the noise, and thanks to anyone who spent time reading it.

One small doc suggestion, take it or leave it: the admin UI labels the setting simply as overload cooldown, with no indication that it only applies to Anthropic 529. Noting the scope in the UI (as config.example.yaml already does in its comment) would have made my misdiagnosis much less likely.

The underlying question I was actually chasing — sustained Our servers are currently overloaded on specific OpenAI accounts — is unrelated to this issue and still open on my side. If it turns out to be something sub2api can help with, I'll open a separate, properly diagnosed issue.

hellpup avatar Sep 16 '26 13:09 hellpup