Skip to content

fix(api): add configurable request retries#3302

Open
jayy-77 wants to merge 1 commit intosimstudioai:mainfrom
jayy-77:fix/api-block-retries-3225
Open

fix(api): add configurable request retries#3302
jayy-77 wants to merge 1 commit intosimstudioai:mainfrom
jayy-77:fix/api-block-retries-3225

Conversation

@jayy-77
Copy link
Contributor

@jayy-77 jayy-77 commented Feb 22, 2026

Summary

  • Add tool-level HTTP retry support with exponential backoff (including Retry-After) for timeouts/network failures, 429s, and 5xx responses.
  • Expose retry controls in the API block (Advanced) and the http_request tool.
  • Update API block docs so the retries section matches behavior and configuration.

Test plan

  • DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres bun run test tools/index.test.ts
  • DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres bun run test tools/http/request.test.ts

Fixes #3225

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
@vercel
Copy link

vercel bot commented Feb 22, 2026

@jayy-77 is attempting to deploy a commit to the Sim Team on Vercel.

A member of the Team first needs to authorize it.

@waleedlatif1 waleedlatif1 marked this pull request as ready for review February 24, 2026 17:44
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 24, 2026

Greptile Summary

Added configurable HTTP retry support with exponential backoff for the API block and http_request tool. The implementation includes intelligent defaults (2 retries for idempotent methods like GET/PUT/DELETE/HEAD, 0 for non-idempotent methods like POST/PATCH), respects Retry-After headers, and retries on timeouts, network failures, 429s, and 5xx responses.

  • Exposed retry configuration in API block Advanced settings: retries, retry delay, max retry delay, and option to enable retries for non-idempotent methods
  • Implemented robust retry logic with exponential backoff and jitter in tools/index.ts
  • Added comprehensive test coverage for various retry scenarios
  • Updated documentation to accurately reflect the new retry capabilities

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

  • This PR is safe to merge with minor review of the retry loop logic
  • The implementation is well-tested and comprehensive, with proper error handling and intelligent defaults. Score is 4 rather than 5 due to the complexity of the retry loop in executeToolRequest which warrants careful review to ensure all edge cases are handled correctly, particularly around response body consumption and cleanup.
  • Pay close attention to apps/sim/tools/index.ts - the retry loop is complex and handles both errors and HTTP status retries

Important Files Changed

Filename Overview
apps/sim/blocks/blocks/api.ts Added retry configuration UI fields (retries, retryDelayMs, retryMaxDelayMs, retryNonIdempotent)
apps/sim/tools/http/request.ts Added retry configuration with intelligent defaults for idempotent vs non-idempotent methods
apps/sim/tools/index.ts Implemented core retry logic with exponential backoff, Retry-After support, proper error classification, and configurable parameters
apps/sim/tools/index.test.ts Added comprehensive test coverage for retry behavior (5xx, 429, 4xx, timeout, idempotent vs non-idempotent)

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
Loading

Last reviewed commit: 543ddfb

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] doc on API Block | Retries howto achive that block tries more than once

1 participant