[Bug][Codex] Bound Direct Provider Gateway by account and honor Retry-After
Author: sciman-topCreated Oct 1, 2026Updated Oct 1, 2026
Summary
The current main branch exposes maxAccountConcurrency and accountConcurrencyWaitMs, and #2677 preserves those fields when a Provider Gateway collection is regenerated. However, the Direct/fixed Provider Gateway request path still does not enforce the configured bound at the provider-account level, and it does not remember an upstream Retry-After for subsequent requests.
This leaves two related failure modes:
- Multiple client API keys or model aliases bound to the same upstream account can bypass one shared account limit and create a burst against the same provider account.
- After an upstream
429or503withRetry-After, a later request can be sent immediately becauserequest-retry=0only disables same-request retries; it does not provide cross-request backoff.
Reproduction shape
- One Provider Gateway account is shared by at least two client keys or model routes.
- The first request is a slow streaming Responses request, or the upstream returns
429/503withRetry-After. - A second request is sent through the Direct or fixed-provider route.
Observed behavior in a downstream deployment:
- Without an account-level gate, the second request reaches the upstream while the first SSE stream is still active.
- With a single-flight gate, slow streams can occupy the only slot until the configured wait budget expires; the resulting local
429is a queue-timeout signal, not an upstream quota response. - Without cross-request
Retry-Afterstate, later requests can immediately repeat the upstream failure.
Expected behavior
- Direct and fixed-provider routes with one bound provider account share one account admission slot across client keys and model aliases.
- The slot remains held for the complete upstream lifecycle, including the full SSE stream, cancellation, timeout, and downstream disconnect cleanup.
- Waiting is bounded by
accountConcurrencyWaitMsand an explicit queue cap; cancellation and timeout must not reach the upstream or leak a slot. - An upstream
429or503with a validRetry-Afteris cached by(bound account, gateway, actual upstream model). - Requests during that backoff receive a bounded
429with the advertisedRetry-After; the sidecar must not perform an automatic retry. - The original upstream error body and diagnostic headers remain available for the first failure.
- Automatic routing and unbound provider routes retain their existing behavior unless they can prove a single bound account.
Safety constraints
- Do not add an unbounded or default retry for
server_is_overloaded. - Do not increase provider quota, rotate credentials, or change model mappings as part of this fix.
- Keep
request-retry=0as the safe default. - Add focused Go tests for shared-account admission, full-stream slot lifetime, cancellation/timeout cleanup,
Retry-Afterseconds and HTTP-date parsing, longer-deadline preservation, and isolation by account/gateway/model.
Related: #2677 (Provider Gateway template concurrency persistence), #2659 (Responses SSE Flush), #2639 (capacity retry proposal).
Source: jlcodes99/cockpit-tools