Skip to content

[Bug] Anthropic pool quota exhaustion is returned as retryable rate_limit_exceeded, so Codex retries and shows 'exceeded retry limit, 429' instead of a usage-limit message #6991

Closed

Description

@vibewriter-hand

Client or integration

Codex App

Area

Authentication and account pool

Summary

When every Anthropic OAuth account in the pool is out of its five-hour or weekly quota, OpenCodex answers Codex with HTTP 429 rate_limit_error / rate_limit_exceeded. Codex treats that class as transient, keeps retrying ("reconnecting 1/5 ... 5/5") and ends with exceeded retry limit, last status: 429 Too Many Requests. The user sees a long "thinking" state and never learns that the quota is spent or when it resets.

I expected the same terminal class that OpenAI returns for a spent plan: usage_limit_reached with resets_at. Codex renders that class as "Usage limit reached ... try again at " and stops at once.

This is the Anthropic-pool form of #6000, which was closed automatically for the issue template and not fixed.

Reproduction

  1. Configure an Anthropic OAuth account pool and let every account reach its five-hour (or weekly) limit.
  2. Send a Codex turn with anthropic/claude-opus-5-5.
  3. Observe: the pool logs no eligible replacement; returning 429, and every later turn is refused locally in 2-9 ms with rate_limit_exceeded. Codex retries each turn (one conversation logged 16 refused requests) and shows only the retry-limit message.

Version

2.83.0

Operating system

macOS (Bun 1.4.2), Codex 0.162.1

Provider and model

anthropic / claude-opus-5-5 (any Anthropic OAuth pool model)

Logs or error output

[anthropic-pool] 429 on <account-a>; failing over to <account-b>
[anthropic-pool] no eligible replacement; returning 429
usage.jsonl: provider=anthropic status=429 errorCode=rate_limit_exceeded failureCause=rate-limit durationMs=2..9 (78 rows)
Codex: exceeded retry limit, last status: 429 Too Many Requests

Source-level analysis (v2.83.0)

  • src/oauth/anthropic-routing.ts:75-80: AnthropicAccountCooldownError ("All Anthropic OAuth accounts are temporarily rate-limited"). The pool already knows each cooldown source (retry-after, reset-derived, default, lines 84-100), so it knows when a cooldown is a drained quota window and when it resets.
  • src/server/responses/adapter-dispatch.ts:518-520 and src/server/responses/passthrough-dispatch.ts:951-953 turn that error into formatErrorResponse(429, "rate_limit_error", ...) with Retry-After. src/lib/errors.ts:448-458 maps every 429 to rate_limit_exceeded. The quota information is lost here.
  • The comment at adapter-dispatch.ts:521-524 says "the Codex client ... does not retry a 429", but Codex 0.162.1 does retry rate_limit_exceeded and ends with the retry-limit message.

Proposed change

  • When AnthropicAccountCooldownError fires and every blocking cooldown is reset-derived (quota window), return HTTP 429 with error.type = "usage_limit_reached", resets_at = earliest reset (epoch seconds), and a message that names the provider and the reset time. Keep rate_limit_exceeded for short retry-after throttles.
  • Apply the same rule to the Codex-account cooldown path (src/codex/auth-context.ts:946).
  • Test: a reset-derived cooldown yields usage_limit_reached + resets_at; a retry-after cooldown yields rate_limit_exceeded + Retry-After.

Related: #6989 (Retry-After-sourced cooldowns not recovering).

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    account-poolbug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions