Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Codex limit errors lose reset time when the cached quota is still at 99% #28284

Closedtensorcopy(GitHub profile, opens in a new tab) opened this issue 3 comments

Before submitting

  • I searched existing issues. Related: #27773 (an empty snapshot when the first request is limited) and #14169 (missing reset information).
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

Observed on an official nightly during an active Codex run. A deterministic adapter replay can reproduce the protocol sequence without consuming quota:

  1. Emit account/rateLimits/updated for limitId: "codex" with a primary window at 99% used and a valid future resetsAt.
  2. Emit a separate premium update with null primary and secondary windows.
  3. Complete the turn as failed with codexErrorInfo: "usageLimitExceeded".
  4. Inspect the terminal failure's resetAt.

Expected behavior

The adapter should attempt a fresh account/rateLimits/read when its cached snapshot cannot identify an exhausted window. If that read identifies exhausted windows with known resets, attach the latest required reset to the failure so recovery controls can use it. Preserve an unknown reset if the read fails or does not establish the blocking windows.

Actual behavior

The adapter only consults the rolling snapshot. codexUsageLimitResetAt() filters for usedPercent >= 100, so the 99% window is ignored and the failure stores resetAt: null, despite the timestamp already present in the snapshot and the provider's error text.

Sanitized evidence from October 31, 2026 (UTC):

16:12:18.948 account/rateLimits/updated:
  limitId=codex
  primary: usedPercent=99, windowDurationMins=300, resetsAt=1793474421
  secondary: usedPercent=60, windowDurationMins=10080, resetsAt=1793799932
16:12:21.161 account/rateLimits/updated:
  limitId=premium, primary=null, secondary=null
16:12:21.165 error:
  codexErrorInfo=usageLimitExceeded
  message ends with "try again at 12:20 PM."
16:12:21.192 persisted failure:
  class=usage_limit, code=usageLimitExceeded, resetAt=null

The primary timestamp is 2026-10-31 12:20:21 America/Los_Angeles, matching the error text. An earlier limit stop had a cached 100% window and correctly persisted its reset. The non-codex update is correctly ignored; it does not erase the main snapshot.

This extends #27773 with a mid-run stale-snapshot trigger: successful requests and a known reset do not prevent the failure if the last update remains below 100%. No fresh account read was captured during this production incident, so whether that read would have reported 100% at that instant is unverified.

Impact

Minor bug or occasional failure. Reset scheduling is unavailable on affected limit stops, requiring a manual retry.

Version or commit

T3 Code 0.1.6-nightly.20261031.3956; Codex CLI 0.166.0.

Environment

macOS arm64, desktop app, local Codex app-server, ChatGPT Plus subscription.

Workaround

Read the retry time in the provider error and retry manually after that time.

  1. Same failure on a live nightly, and the trigger is sharper than a stale snapshot: the cached window flipped 100% → 99% between two consecutive retries of the same thread, so the failure that stuck lost a reset time T3 had already resolved seconds earlier.

    Environment

    • T3 Code 0.1.7-nightly.20261101.4016, desktop app on macOS arm64, local server, autoResumeLimitedThreads: true
    • Codex app-server provider, codex-cli 0.164.0, ChatGPT team workspace

    Observed (UTC, 2026-11-01, one thread, three consecutive runs):

    16:10:12.225  account/rateLimits/updated limitId=codex
                  primary usedPercent=99, windowDurationMins=300, resetsAt=1793556820
    16:10:18.169  error codexErrorInfo=usageLimitExceeded
                  "Your workspace is out of credits. Ask your workspace owner to refill in order to continue."
    16:10:18.179  run A failure: resetAt=null
    
    16:10:23.053  account/rateLimits/updated limitId=codex
                  primary usedPercent=100, resetsAt=1793556820
    16:10:28.288  error usageLimitExceeded (same message)
    16:10:28.295  account/rateLimits/updated limitId=codex
                  primary usedPercent=99  (same resetsAt)
    16:10:28.297  run B failure: resetAt=2026-11-01T18:13:40Z
                  (resolved from the 100% snapshot before the 99% update landed)
    
    16:10:31.463  error usageLimitExceeded (same message)
    16:10:31.471  run C failure: resetAt=null   <-- latest run, the one on screen

    Each 429 is preceded by a premium update with primary=null, secondary=null, rateLimitReachedType=workspace_member_credits_depleted, correctly ignored by mergeCodexRateLimits. All runs share one adapter session (provider-instance:codex:shared).

    Effect: run C is the thread's latest run, so UsageLimitRecoveryWorker sees !thread.usageLimitResetAt and arms nothing. The composer banner renders "Reset time unavailable; retry manually" while Usage → Limits shows the 5h window resetting at 18:13:40Z. Auto-resume was enabled and could never run.

    Source: confirmed at 0.1.7-nightly.20261101.4016, and still on main and v0.1.7-nightly.20261101.4035: codexUsageLimitResetAt() in apps/server/src/provider/codexUsageLimits.ts filters usedPercent >= 100, so any 99% snapshot discards the resetsAt carried by the same snapshot.

    What this adds: the outcome depends on which notification lands last, not just on the snapshot being stale. Codex reports 99% and 100% for the same window seconds apart. A fresh account/rateLimits/read (as in #28291) covers the stale case, but the open question is what that read returns when the account itself reports 99% at that instant; if it also returns 99% for the exhausted window, the failure stays reset-less. Worth treating "99% + a future resetsAt + usageLimitExceeded in the same turn" as exhausted, or making the 429 error text's own reset a fallback.

    Also seen on this build: the v2 codex adapter relays the provider sentence "Your workspace is out of credits…" verbatim as the failure message. The v1 adapter rewrote this to name the limit and its reset (#10473); the v2 path does not, so the card reads like a billing problem while the exhausted 5h window is the cause.

    Workaround: wait out the reset shown in Usage → Limits and retry manually.

    Collected in a T3 Code triage session; diagnosing agent DeepSeek V4.1 Flash via the OpenCode harness.

  2. budres(GitHub profile, opens in a new tab)commented

    Posted by Claude Code (Opus 5.5, claude-opus-5-5) on behalf of budres, after checking this against their local state and provider logs.

    Another trigger for the below-100% case: concurrent threads on one shared Codex session. Readings from different threads arrive out of order, so a stale lower value replaces a 100% reading, and the gap is not limited to 99%.

    Environment: T3 Code 0.1.7-nightly.20261102.4093 (local server, Linux), codex-cli 0.166.0, ChatGPT Plus, gpt-6.1-sol. About 19 Codex threads (review coordinators and their delegated reviewers) were running at once. All of them used providerSessionId: provider-session:provider-instance:codex:shared, so they share one adapter rateLimitSnapshot.

    Decoded protocol log (UTC, 2026-11-02), main codex bucket primary window only:

    21:34:39.535  rateLimits/updated  codex primary=98
    21:34:40.082  rateLimits/updated  codex primary=99
    21:34:40.832  rateLimits/updated  codex primary=98
    21:34:41.461  error usageLimitExceeded "... try again at Nov 3rd, 2026 3:28 AM."   -> resetAt null
    21:34:42.544  rateLimits/updated  codex primary=98
    21:34:42.920  rateLimits/updated  codex primary=83
    21:34:42.960 .. 21:34:44.045  4 more usageLimitExceeded errors                     -> resetAt null
    21:34:44.121  rateLimits/updated  codex primary=100   (the only 100% reading in the log)
    21:34:44.438, 21:34:44.483  2 usageLimitExceeded errors                           -> resetAt 2026-11-03T02:28:43Z
    21:34:44.770  rateLimits/updated  codex primary=97
    21:34:45.569 .. 21:34:48.089  usageLimitExceeded errors continue                  -> resetAt null
    21:34:51.686  rateLimits/updated  codex primary=74

    Every error is preceded by a limitId: "premium" update with null windows, which is correctly ignored. All main readings carry the same resetsAt: 1793672923 (2026-11-03T02:28:43Z, which matches the error text).

    The persisted failures agree: 35 Codex usageLimitExceeded root failures in this burst and the retries after it, and only the 2 that landed in the 650 ms between the 100% reading and the following 97% reading have a resetAt. After a server restart, the next session got only premium updates, so every later failure also stored resetAt: null. That second part is the #27773 / #29277 case.

    What this means for the fixes:

    • A rule that accepts 99% (as in #18721) would not cover this burst: the last reading before most of the failures was between 83% and 98%. Readings are not monotonic across concurrent threads, so neither a threshold nor latest-wins merging gives the current state.

    • A fresh account/rateLimits/read when the reset is unknown (the approach in #28291 and the expected behavior in this issue) covers most of this case. #28291 discards the read if a main-allowance notification changes the snapshot while the read is pending, and with concurrent threads those arrived every 0.3 to 1.2 s around the refusals. To size that, I replayed #28291's rule against this log's timeline, using this machine's measured account/rateLimits/read latency (44 samples from the server trace: p50 569 ms, p90 721 ms, max 1052 ms):

      Read latencyusageLimitExceeded errors in the logCached 100% alreadyRead keptRead discarded by a main update
      570 ms392334
      1050 ms392325

      So about 1 in 10 failures in this burst would still store resetAt: null, and a later backfill does not reach them because ingestion stops at the failed terminal. This replays the rule against recorded timestamps; it does not run #28291's code, and it assumes the read reports the exhausted window at 100% (as in #29277).

    Workaround used: the reset time from the error text, with a scheduled manual "continue" after 02:28 UTC.

  3. tanstack-source added labelsbug

  4. This is the same problem as #27773, so I'm closing it in favour of that one. If it is different, say how and it will be reopened.

  5. juliusmarminge closed this

Sign in to join this conversation.