Skip to content

Conversation

@MuriloFP
Copy link
Contributor

@MuriloFP MuriloFP commented Jun 27, 2025

Related GitHub Issue

Closes: #2724

Description

fix: cap API retry exponential backoff at 10 minutes maximum

Files affected:

  • src/core/task/Task.ts

Issue:
Auto-retry feature with exponential backoff was causing excessive delays
that could reach multiple hours (e.g., 7168 seconds ≈ 2 hours) when API
requests repeatedly failed. This particularly affected users working with
frequently overloaded models like Gemini 2.0 Thinking that return 503
"model overloaded" errors.

Root cause:
The retry logic used unbounded exponential backoff with formula:
baseDelay * 2^retryAttempt. With a 7-second base delay, this resulted
in delays growing as: 7s → 14s → 28s → 56s → ... → 7168s after 11 failures.

Solution:
Added Math.min() cap of 600 seconds (10 minutes) to the exponential delay
calculation. This preserves the benefits of exponential backoff for
transient errors while preventing excessive delays that could abandon
long-running tasks.

Impact:

  • Maintains exponential backoff benefits for short-term outages
  • Prevents "all night prompts" from getting stuck for hours
  • Only affects auto-retry with alwaysApproveResubmit enabled
  • Does not impact 429 rate-limit handling or manual retry flows

Test Procedure

  • Set a AI profile config with an invalid URL (can be something random like "aisdaujdshfjgsd.com")
  • Set auto-approve retry
  • Check if the retry time goes to at most 10 minutes. The logic that was implemented before doubled the time after every retry, I set a hard cap to at most 10 minutes.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Documentation Updates

Additional Notes

Should I set a configuration for the max delay time? Or change the limit for something other than 10 minutes?

Get in Touch


Important

Caps API retry exponential backoff at 10 minutes in Task.ts to prevent excessive delays.

  • Behavior:
    • Caps exponential backoff for API retries at 600 seconds (10 minutes) in Task.ts.
    • Affects auto-retry logic with alwaysApproveResubmit enabled.
  • Logic:
    • Uses Math.min() to limit delay calculation in attemptApiRequest().
    • Does not affect 429 rate-limit handling or manual retries.

This description was created by Ellipsis for 3c1a46f. You can customize this summary. It will automatically update as commits are pushed.

Prevents excessive retry delays when auto-retry is enabled. Previously,
the exponential backoff could grow to hours (e.g., 7168s after 11 retries
with 7s base delay), causing "all night prompts" to get stuck waiting.
Now capped at 600 seconds (10 minutes) maximum.

Fixes RooCodeInc#2724
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jun 27, 2025
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Jun 27, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jun 27, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jun 27, 2025
- Replaced magic number 600 with named constant for better maintainability
- Constant clearly indicates the 10-minute cap for exponential backoff
- Addresses review feedback from PR RooCodeInc#5171
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Jun 27, 2025
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Thank you @MuriloFP!

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 27, 2025
@mrubens mrubens merged commit b9626a7 into RooCodeInc:main Jun 30, 2025
17 checks passed
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jun 30, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 30, 2025
hannesrudolph pushed a commit that referenced this pull request Jul 3, 2025
utarn pushed a commit to modelharbor/ModelHarbor-Agent that referenced this pull request Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer PR - Needs Review size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Auto Retry Timer can become Excessive.

4 participants