[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:

  1. 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.
  2. After an upstream 429 or 503 with Retry-After, a later request can be sent immediately because request-retry=0 only 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/503 with Retry-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 429 is a queue-timeout signal, not an upstream quota response.
  • Without cross-request Retry-After state, later requests can immediately repeat the upstream failure.

Expected behavior

  1. Direct and fixed-provider routes with one bound provider account share one account admission slot across client keys and model aliases.
  2. The slot remains held for the complete upstream lifecycle, including the full SSE stream, cancellation, timeout, and downstream disconnect cleanup.
  3. Waiting is bounded by accountConcurrencyWaitMs and an explicit queue cap; cancellation and timeout must not reach the upstream or leak a slot.
  4. An upstream 429 or 503 with a valid Retry-After is cached by (bound account, gateway, actual upstream model).
  5. Requests during that backoff receive a bounded 429 with the advertised Retry-After; the sidecar must not perform an automatic retry.
  6. The original upstream error body and diagnostic headers remain available for the first failure.
  7. 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=0 as the safe default.
  • Add focused Go tests for shared-account admission, full-stream slot lifetime, cancellation/timeout cleanup, Retry-After seconds 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).