Codex CLI exits abruptly on `rate_limit_exceeded`; should back-off & retry instead of closing
Resolved 💬 9 comments Opened Apr 27, 2025 by lucasrod Closed Aug 7, 2025
💡 Likely answer: A maintainer (tibo-openai, collaborator)
responded on this thread — see the highlighted reply below.
What version of Codex is running?
v0.1.2504161551
Which model were you using?
o4-mini
What platform is your computer?
Darwin 24.4.0 arm64 arm
What steps can reproduce the bug?
- Run a long Codex CLI command that streams a large prompt + completion (≈70 k tokens).
``bash``
codex 'explain this huge code base' --files src/**/*.py
- Wait until total tokens in the last minute exceed 200 000 TPM.
What is the expected behavior?
CLI should:
- Detect the
rate_limit_exceedederror. - Wait for the retry-after window (OpenAI returns 2.515 s in this case) with exponential back-off.
- Resume the same request or transparently re-send it, keeping the stream open.
- Exit with a non-zero code only after exhausting configured retries.
What do you see instead?
The CLI throws an uncaught exception and terminates:
e [Error]: Rate limit reached for o4-mini … Limit 200000, Used 136502, Requested 71884 …
at file:///opt/homebrew/lib/node_modules/@openai/codex/dist/cli.js:445:1514
Node.js v23.11.0
All partial output is lost; the user must re-run the command manually.
Additional information
- Running latest CLI via
npm i -g @openai/codex. - No custom flags (
--max-retriesdefaults to 0). - It would be safer to set a default retry policy (e.g., 3 attempts, exponential 2 → 4 → 8 s).
- See full stack trace in the console log attached above.
9 Comments
It is sad that this is still an issue. Should be priority one to fix the crashes since you loose all context and wasted tokens.
https://github.com/openai/codex/issues/137
https://github.com/openai/codex/issues/157
The version number above indicates that you are running an old version. This was fixed a while ago, please ensure that you are running the latest version here: https://github.com/openai/codex/blob/main/CHANGELOG.md#012504251709
You should see
I am still getting this issue in version
0.1.2504221401which supposedly includes the commit (https://github.com/openai/codex/pull/506) that was to fix these issues.For example:
When I look into the logs I see it was because I exceeded quota with the offending request.
This is really bad UX as it blows away context and costs the user money without giving value.
I am kinda shocked by the state of this tool. It feels very broken.
This relates to pretty much any "failed" api request, they all crash out.
Error 400 / 500 / etc should all be handled similarly to rate limiting, retry with backoff.
IMO The only one that should likely be fail fast is an invalid key (as opposed to a rate limited key)
Many other API error responses are fleeting, either their server needs you to retry because they're flooded, or the LLM needs to retry with slightly different request/response to come up with a working message.
Still there in:
Still crashing (v0.1.2505140839):
Still rate_limits_exceeded on version 0.1.2505172129 with model gpt-4.1.
Temporary fix I found for this that works is that you can ask codex or make yourself a simple script that saves user and codex assistant prompts and responses to log files, and when it crashes and you have to start a new session give the log file to codex so it knows where you left off.
I requested to run it every time I send a prompt and every time codex gave me an answer.
This is the script codex made for my project:
How is this issue still open and not fixed?
Thank you for the feedback! Please try again on the latest version of Codex CLI. If the issue persists, we'd be happy to take a look at a PR to the
codex-rs/implementation. For more details, see our update: https://github.com/openai/codex/discussions/1174.