Repository navigation
Description
Area
Core (codex-api / error mapping)
Steps to reproduce
- Use a ChatGPT-plan account that hits a usage limit on the codex backend (
chatgpt.com/backend-api/codex/responses). - Send a request that receives
429with these (real, captured) headers and body:
X-Codex-Active-Limit: premium
X-Codex-Plan-Type: plus
X-Codex-Primary-Used-Percent: 100
X-Codex-Primary-Reset-At: 1793390439
X-Codex-Primary-Window-Minutes: 300
X-Codex-Secondary-Used-Percent: 53
X-Codex-Secondary-Reset-At: 1793870576
X-Codex-Secondary-Window-Minutes: 10080
X-Codex-Credits-Balance: 0
{"error":{"type":"usage_limit_reached","message":"The usage limit has been reached","plan_type":"plus","resets_at":1793390439,"eligible_promo":null,"limit_window_minutes":300,"resets_in_seconds":4454}}
- Observe what
map_api_errorproduces for the rate-limit snapshot, and what downstream consumers (app-serveraccount/rateLimits/updatednotifications, TUI rate-limit banner) receive.
Expected behavior
The 429 carries a complete x-codex-* window family (primary 100% + reset timestamp, secondary 53% + reset). map_api_error should surface that snapshot on UsageLimitReachedError.rate_limits so core's update_rate_limits records the real windows and the app-server emits an account/rateLimits/updated notification with usable reset data.
Actual behavior
api_bridge.rs parses the snapshot from the ACTIVE limit family only: parse_rate_limit_for_limit(headers, limit_id) where limit_id comes from x-codex-active-limit: premium. That keys the header prefix to x-premium-*, which matches nothing, so the snapshot is RateLimitSnapshot { limit_id: "premium", primary: None, secondary: None, ... }. The complete codex-family window data on the same response is discarded.
Downstream effect: core calls update_rate_limits with the empty snapshot and clients receive an all-null premium update instead of real window state. Any client that tracks usage-window resets (e.g. to schedule resume-after-limit) only has data if earlier successful responses already primed its state; a client whose first request in a session 429s never learns the reset time, even though the error message itself says "try again at " (parsed from the body's resets_at).
Impact tier
Medium: no data loss or crash, but automated resume-after-limit and usage-window display silently break exactly when the limit is hit, which is when they matter.
Version or commit
rust-v0.165.0 (also present on current main; verified against codex-api/src/api_bridge.rs)
Environment
Linux x86_64 + aarch64, codex CLI driven through an OpenAI-compatible proxy; headers captured live from the codex backend's 429 on 2026-10-30.
Workaround
None client-side; a client can fall back to parsing resets_at out of the 429 body, but the structured snapshot path stays blind until a successful response re-primes it.
Activity
imluckii commentedon Oct 30, 2026
Reference implementation that fixes this locally (passes the full
codex-apilib suite, 193/193, including the two tests pinning metadata-only active families):with
use crate::rate_limits::parse_default_rate_limit;anduse codex_protocol::protocol::RateLimitSnapshot;added to the imports.Regression test (fails on main with
limit_id == "premium"/ no windows, passes with the patch):Design note: metadata-only active families (e.g.
codex_otherwith a limit name but no windows, and no default-family windows either) keep today's behavior exactly - the fallback only fires when the default family actually has windows to contribute.Authored with GLM (glm-5.3) through the Hermes agent.
imluckii commentedon Oct 30, 2026
Thanks - the matrix matches what the reference patch above already does, mapping each case:
active=premiumwith onlyx-codex-primary/secondary-*present: the fallback returns the default-family snapshot keyedcodexwith its own reset epochs, and never fabricatespremiumwindows (the active family's limit name/credits ride along as display metadata).x-premium-*windows:has_windows(active)is true, so the active snapshot is returned untouched in its own bucket.api_bridgestill returns the metadata-only snapshot (existing tests pin the limit-name/reached-type path), so the "don't publish an all-null update as measured state" half of this belongs on the consumer side - incore/src/session/turn.rsthe usage-limit branch could gateupdate_rate_limitson the same has-windows predicate rather than treatingSomeas quota data.error.resets_atis untouched by the patch; it stays error-level evidence feedingUsageLimitReachedError.resets_atand the retry message.Verified against the full
codex-apilib suite (193 passed) with a regression test for case 1; cases 2-4 are covered by the existingmap_api_error_*tests, which stay green.imluckii commentedon Nov 22, 2026
Closing from the reporter's side. We only needed this fixed in our two consumers, and both are done: t3 re-reads rate limits after a first-request 429 (pingdotgg/t3code#27791) and recovers the reset time from the error text on proxied routes (pingdotgg/t3code#32188), and our proxy no longer carries a header workaround now that the parser quirk is understood. The active-limit parsing behavior remains as described for anyone tracking it upstream.