Repository navigation
Conversation
Implemented retry logic for HTTP 429 (rate limit) errors encountered during the streaming loop in AgentLoop.run. The fix ensures that streaming requests interrupted by rate limits are retried up to 5 times with a 15-second delay between attempts, reinitializing pending abort outputs and recreating the stream to maintain context.
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
Have you seen #176? |
I took a quick look. It doesn't address the issue that the stream consumption |
|
I've tried the various proposals to fix the rate-limit problem; this is the only one that seems to actually work. |
|
Really appreciate the fix, but there is a lot going on in the change and the logic looks quite convoluted, making it hard to follow and review. Would you be able to simplify things to the be more minimal, possibly extracting some of the logic and adding tests, also while removing some of the extra functionality that introduces complexity? Thanks working on making codex more stable when facing rate limits! |
#506) As requested by @tibo-openai at #357 (comment), this attempts a more minimal implementation of #357 that preserves as much as possible of the existing code's exponential backoff logic. Adds a small retry wrapper around the streaming for‑await loop so that HTTP 429s which occur *after* the stream has started no longer crash the CLI. Highlights • Re‑uses existing RATE_LIMIT_RETRY_WAIT_MS constant and 5‑attempt limit. • Exponential back‑off identical to initial request handling. This comment is probably more useful here in the PR: // The OpenAI SDK may raise a 429 (rate‑limit) *after* the stream has // started. Prior logic already retries the initial `responses.create` // call, but we need to add equivalent resilience for mid‑stream // failures. We keep the implementation minimal by wrapping the // existing `for‑await` loop in a small retry‑for‑loop that re‑creates // the stream with exponential back‑off.
|
Closing as we have merged #506 |
Fix for 429 rate limit CLI crash during streaming in AgentLoop
This Draft PR introduces retry logic to handle HTTP 429 (rate limit) errors encountered in the streaming loop of
AgentLoop.runin the Codex CLI. The fix prevents abrupt stream failures by wrapping stream consumption in a while loop, retrying up to 5 times with a 15-second delay.The code is likely not production-ready due to lack of testing and potential edge cases, and the suboptimal static 15 second wait between retries. However, it does fix the issue for me.
Changes:
src/utils/agent/agent-loop.ts:for awaitloop in awhileloop to retry on rate limit errors.setTimeout.MAX_STREAM_RETRIES = 5andstreamRetryAttemptto control retries.isRateLimitErrorfunction to detect 429 errors viacode: "rate_limit_exceeded".