fix(api): add configurable request retries#3302
Open
jayy-77 wants to merge 1 commit intosimstudioai:mainfrom
Open
fix(api): add configurable request retries#3302jayy-77 wants to merge 1 commit intosimstudioai:mainfrom
jayy-77 wants to merge 1 commit intosimstudioai:mainfrom
Conversation
The API block docs described automatic retries, but the block didn't expose any retry controls and requests were executed only once. This adds tool-level retry support with exponential backoff (including Retry-After support) for timeouts, 429s, and 5xx responses, exposes retry settings in the API block and http_request tool, and updates the docs to match. Fixes simstudioai#3225
|
@jayy-77 is attempting to deploy a commit to the Sim Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Greptile SummaryAdded configurable HTTP retry support with exponential backoff for the API block and
The implementation is well-structured with proper error classification (avoiding retries on non-retryable errors like body size limits or blocked IPs) and configurable limits (max 10 retries). Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
Start[Start Request] --> Config[Resolve Retry Config]
Config --> CheckMethod{Method Retryable?}
CheckMethod -->|GET/PUT/DELETE/HEAD| DefaultRetries[Default: 2 retries]
CheckMethod -->|POST/PATCH| CheckOverride{retryNonIdempotent?}
CheckOverride -->|true| UserRetries[Use user retries]
CheckOverride -->|false| NoRetries[0 retries]
DefaultRetries --> Loop[Start Attempt Loop]
UserRetries --> Loop
NoRetries --> Loop
Loop --> Attempt[Make HTTP Request]
Attempt --> Success{Success?}
Success -->|Response OK| Done[Return Response]
Success -->|Error Thrown| ErrorCheck{Retryable Error?}
Success -->|HTTP Error Status| StatusCheck{Retryable Status?}
ErrorCheck -->|Timeout/Network| CheckLast1{Last Attempt?}
ErrorCheck -->|Body Size/Blocked IP| Fail[Throw Error]
ErrorCheck -->|Other Error| Fail
StatusCheck -->|429 or 5xx| CheckLast2{Last Attempt?}
StatusCheck -->|4xx| Fail
CheckLast1 -->|Yes| Fail
CheckLast1 -->|No| Backoff1[Calculate Backoff Delay]
CheckLast2 -->|Yes| Fail
CheckLast2 -->|No| CheckRetryAfter{Retry-After Header?}
CheckRetryAfter -->|Yes| UseMax[Use max of backoff and Retry-After]
CheckRetryAfter -->|No| Backoff2[Calculate Backoff Delay]
Backoff1 --> Sleep1[Sleep with Delay]
UseMax --> Sleep2[Sleep with Delay]
Backoff2 --> Sleep2
Sleep1 --> Loop
Sleep2 --> Loop
Last reviewed commit: 543ddfb |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Retry-After) for timeouts/network failures, 429s, and 5xx responses.http_requesttool.Test plan
DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres bun run test tools/index.test.tsDATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres bun run test tools/http/request.test.tsFixes #3225