codex crashes on rate limit error instead of retrying
What version of Codex is running?
0.1.2504161510
Which model were you using?
o4-mini
What platform is your computer?
Linux 6.8.0-1026-gcp x86_64 x86_64
What steps can reproduce the bug?
Run a complex command that generates a high token load, e.g.
codex --approval-mode full-auto "perform this complicated task"
Wait until a rate limit is reached (e.g. due to high usage of o4-mini model)
What is the expected behavior?
Codex should wait the suggested time (e.g., 6.379 seconds), then retry the request gracefully
What do you see instead?
Codex crashes with an unhandled rate_limit_exceeded error. No retry is attempted.
Here’s the error message:
[Error]: Rate limit reached for o4-mini in organization [REDACTED_ORG_ID] on tokens per min (TPM): Limit 200000, Used 158833, Requested 62431. Please try again in 6.379s.
at e.a [as iterator] (dist/cli.js:449:1514)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async T0.run (dist/cli.js:466:2933) {
status: undefined,
headers: undefined,
request_id: undefined,
error: {
type: 'tokens',
code: 'rate_limit_exceeded',
message: 'Rate limit reached for o4-mini in organization [REDACTED_ORG_ID] on tokens per min (TPM): Limit 200000, Used 158833, Requested 62431. Please try again in 6.379s.',
param: null
},
code: 'rate_limit_exceeded',
param: null,
type: 'tokens'
}
Node.js v22.14.0
Additional information
_No response_
12 Comments
Dupe of https://github.com/openai/codex/issues/157
You can try to build from source and run the cli, there is something merged in but unreleased which may fix this
@jonchurch
Thanks for the reply, I built from source a couple hours ago - I can confirm I have the regex update that they made, but the issue persists.
Aww heck, ty for trying the new fix! I haven't been able to reproduce this reliably (the token limit)
If you are able to repro it and want to tackle it, maybe throw some console logs in there to verify it is actually hitting the maxRetry count. Would be curious to know if it just dies before it exhausts retries somehow.
Did it end up sitting for a while? it should eventually wait like a full minute cumulatively for the retries to exhaust
To add another datapoint, I'm having the same issue, making codex mostly unusable for me. For testing I added a console.log to the beginning of the loop like so:
And then within the codex codebase itself I prompted it with
I want you to analyze 15 files of the codebase and explain them to me. Just choose a few that are vaguely related.just to try and exceed the limit. This did make it exceed the limit (Rate limit reached for o4-mini in [REDACTED] on tokens per min (TPM): Limit 200000, Used 171023, Requested 38760. Please try again in 2.934s. Visit https://platform.openai.com/account/rate-limits to learn more.). The logged attempt count never grew past 1 on any request, so it doesn't seem like it was retrying at all in this case.It is failing pretty quickly for me. I believe the issue is, the stream consumption
for await (const event of stream)is outside the retry logic, only checking for abort errors. If it gets a 429 error during streaming, it throws a rate limit error with no retry handling. Line 794throw err;is what I tracked it down to.Also: https://github.com/openai/codex/issues/311
+1. The most annoying part is that after restarting it loses the context.
+1 was just about to come here and add the same issue. I'll look at the code later, but seems like it should be pretty easy to wait a few seconds and retry (the response even tells you how long to wait.) We're definitely spamming the API in terms of tokens, this behavior isn't surprising.
+1
OK, I figured out a fix: https://github.com/pascudder/codex
is it just me but I cant see the fix ? Sorry to be a pain.. Or are you changing code and we update? How do we update ? Thanks again !
replace this file
https://github.com/pascudder/codex/blob/main/codex-cli/src/utils/agent/agent-loop.ts