Repository navigation
agent-loop: minimal mid-stream #429 retry loop using existing back-off - #506
Merged
Merged
Conversation
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. • No new helpers or config; ~35 LOC diff. • Keeps existing error paths untouched and ESLint‑clean. All tests, lint, build and type‑check pass.
This was referenced Apr 22, 2025
|
Tested and works for me. No more 429 on long sessions on a Tier 1 account. |
Collaborator
|
We'll want to simplify all of this in a follow-up as the whole implementation here is starting to have more complexity than desired, however the core logic contributed here looks sound and I've tried it locally without hiccup. I will merge this as this resolves a large stability issues currently affecting users and we should push on making agent-loop.ts easier to maintain going forward. One thing I would like to see happen in particular is for all the error pattern matching and some helpers to be extracted to agent-error.ts. |
Collaborator
|
Thank you @scottleibrand for the great contribution, no doubt many users will benefit from this! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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‑awaitloop in a small retry‑for‑loop that re‑creates// the stream with exponential back‑off.