Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Oct 29, 2025

Summary

This PR fixes an infinite loop issue that occurs when users cancel a task during automatic retry with auto-approval enabled.

Fixes #8901

Problem

When autoApprovalEnabled and alwaysApproveResubmit are both true, if an API request fails on the first chunk, the system automatically retries with exponential backoff. However, if the user cancels the task or starts a new one during the backoff countdown, the recursive retry continues without checking if the task was aborted, causing an infinite loop.

Root Cause

The attemptApiRequest method was missing abort checks after the backoffAndAnnounce method completed. This meant that even after the task was aborted, the code would continue to make recursive calls to retry the API request.

Solution

Added critical abort checks in two locations:

  1. First-chunk retry logic (line ~2804): Check if task was aborted after backoff before making recursive retry call
  2. Mid-stream retry logic (line ~2247): Check if task was aborted after backoff before pushing retry onto stack

These checks ensure that when a user cancels during the backoff countdown, the retry loop is properly terminated.

Testing

  • ✅ All existing tests pass
  • ✅ Type checking passes
  • ✅ Linting passes
  • ✅ Manual testing confirmed the infinite loop no longer occurs when canceling during retry

Changes Made

  • Added abort check after backoffAndAnnounce in first-chunk retry logic
  • Added abort check after backoffAndAnnounce in mid-stream retry logic
  • Added documentation comments explaining the importance of these checks

Impact

This fix prevents the application from getting stuck in an infinite loop when users cancel tasks during automatic retries, improving user experience and preventing resource waste.


Important

Fixes infinite loop in Task.ts by adding abort checks during auto-retry cancellation.

  • Behavior:
    • Fixes infinite loop when canceling during auto-retry in Task class in Task.ts.
    • Adds abort check after backoffAndAnnounce in first-chunk retry logic (~line 2804).
    • Adds abort check after backoffAndAnnounce in mid-stream retry logic (~line 2247).
  • Testing:
    • All existing tests pass.
    • Type checking and linting pass.
    • Manual testing confirms fix.

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

- Add abort check after backoffAndAnnounce in first-chunk retry logic
- Add abort check after backoffAndAnnounce in mid-stream retry logic
- Properly handle task abortion to break retry loops

Fixes #8901
- Document the importance of abort checks after backoff
- Explain how these checks prevent infinite loops
- Add context for future maintainability
@roomote roomote bot requested review from cte, jr and mrubens as code owners October 29, 2025 04:32
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Oct 29, 2025
@dosubot dosubot bot added the bug Something isn't working label Oct 29, 2025
@roomote
Copy link
Contributor Author

roomote bot commented Oct 29, 2025

Review Complete

No issues found

The PR correctly implements abort checks after backoffAndAnnounce to prevent infinite loops when users cancel during auto-retry.

Changes verified:

  • ✅ First-chunk retry logic (line ~2807): Abort check before recursive attemptApiRequest call
  • ✅ Mid-stream retry logic (line ~2245): Abort check before pushing retry onto stack
  • ✅ Documentation comments explaining the importance of these checks

Implementation analysis:

  • The backoffAndAnnounce method checks this.abort during its countdown but catches errors internally, so callers must re-check abort state after it returns
  • Both new checks properly throw errors when abort is detected, breaking the retry loop
  • The fix addresses the root cause described in issue [BUG] The program is stuck in a loop. #8901

Follow Along on Roo Code Cloud

Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

No issues found.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 29, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Oct 29, 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 Oct 29, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Oct 30, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 30, 2025
@mrubens mrubens merged commit b284edd into main Oct 30, 2025
26 checks passed
@mrubens mrubens deleted the fix/issue-8901-infinite-loop-auto-retry branch October 30, 2025 23:12
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Oct 30, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Oct 30, 2025
mini2s added a commit to zgsm-ai/costrict that referenced this pull request Oct 31, 2025
* fix(i18n):  spelling mistake in zh-CN chat.json

* web: Opengraph image (RooCodeInc#8285)

Co-authored-by: Matt Rubens <[email protected]>

* Set port 3446 for web-evals in production mode (RooCodeInc#8288)

* Show cloud switcher and option to add a team when logged in (RooCodeInc#8291)

* fix: include initial ask in condense summarization (RooCodeInc#8293) (RooCodeInc#8298)

* fix: include initial ask in condense summarization (RooCodeInc#8293)

---------

Co-authored-by: Matt Rubens <[email protected]>

* Fix frequent "No tool used" errors by clarifying tool-use rules (RooCodeInc#8292)

* Add a couple more free models to the Roo provider (RooCodeInc#8304)

* Release v3.28.8 (RooCodeInc#8305)

* Changeset version bump (RooCodeInc#8306)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* feat: log out from cloud when resetting extension state (RooCodeInc#8312)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Matt Rubens <[email protected]>

* Merge remote-tracking branch 'upstream/main' into roo-to-main

* feat: Add telemetry tracking to DismissibleUpsell component (RooCodeInc#8309)

* feat: add telemetry tracking to DismissibleUpsell component

- Added UPSELL_DISMISSED and UPSELL_CLICKED events to TelemetryEventName enum
- Updated DismissibleUpsell component to track clicks and dismissals with telemetry
- Added telemetry tests to DismissibleUpsell test suite
- Events include upsellId in the payload for tracking specific upsells

* refactor(webview): make handleDismiss synchronous in DismissibleUpsell

test(webview): add scenario where dismissOnClick=true without onClick tracks only UPSELL_DISMISSED; update tests; all tests passing locally

---------

Co-authored-by: Roo Code <[email protected]>

* Correct tool use suggestion to improve model adherence to suggestion (RooCodeInc#8315)

* Correct tool use suggestion to improve model adherence to suggestion

* tweak

* removing user hint when refreshing models (RooCodeInc#7710)

* feat(zgsm): add quota info display and periodic updates

* Show the Roo provider on the welcome screen (RooCodeInc#8317)

* wip: Website Improvements (RooCodeInc#8303)

Co-authored-by: Matt Rubens <[email protected]>

* refactor: remove pr-reviewer mode (RooCodeInc#8222)

* feat: add animated quota display with staggered transitions

* Merge remote-tracking branch 'upstream/main' into roo-to-main

* web: More website copy tweaks (RooCodeInc#8326)

Co-authored-by: Matt Rubens <[email protected]>

* fix: remove <thinking> tags from prompts for cleaner output and fewer tokens (RooCodeInc#8319)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Hannes Rudolph <[email protected]>

* Upgrade Supernova (RooCodeInc#8330)

* chore: add changeset for v3.28.9 (RooCodeInc#8336)

* Changeset version bump (RooCodeInc#8337)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* Track when telemetry settings change (RooCodeInc#8339)

* fix: use max_completion_tokens for GPT-5 models in LiteLLM provider (RooCodeInc#6980)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>

* Make chat icons shrink-0 (RooCodeInc#8343)

* web: Testimonials (RooCodeInc#8360)

* Adds lots of testimonials, 5-stars from marketplace

* Fits more testimonials in one page

* Testimonial heading tweak

* ci: refresh contrib.rocks cache workflow (RooCodeInc#8083)

* feat: add Claude 4.5 Sonnet model across all providers (RooCodeInc#8368)

* chore: add changeset for v3.28.10 (RooCodeInc#8369)

* Changeset version bump (RooCodeInc#8370)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* fix: correct AWS Bedrock Claude Sonnet 4.5 model identifier (RooCodeInc#8372)

Fixes RooCodeInc#8371 - Updates the model ID from anthropic.claude-4.5-sonnet-v1:0
to anthropic.claude-sonnet-4-5-20250929-v1:0 to match AWS Bedrock naming convention

Co-authored-by: Roo Code <[email protected]>

* fix: correct Claude Sonnet 4.5 model ID format (RooCodeInc#8373)

* chore: add changeset for v3.28.11 (RooCodeInc#8374)

* Changeset version bump (RooCodeInc#8375)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* fix: Anthropic Sonnet 4.5 model id + Bedrock 1M context checkbox (RooCodeInc#8384)

fix(anthropic): use claude-sonnet-4-5 id
fix(bedrock): enable 1M context checkbox for Sonnet 4.5 via shared list
closes RooCodeInc#8379
closes RooCodeInc#8381

* chore: add changeset for v3.28.12 (RooCodeInc#8385)

* Changeset version bump (RooCodeInc#8376)

* changeset version bump

* Revise changelog for version 3.28.12

Updated version number and consolidated patch notes.

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* Fix Vertex Sonnet 4.5 (RooCodeInc#8391)

* fix: remove topP parameter from Bedrock inference config (RooCodeInc#8388)

Co-authored-by: Matt Rubens <[email protected]>

* chore: add changeset for v3.28.13 (RooCodeInc#8393)

* Changeset version bump (RooCodeInc#8394)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* feat: add GLM-4.6 model support for z.ai provider (RooCodeInc#8408)

Co-authored-by: Roo Code <[email protected]>

* chore: add changeset for v3.28.14 (RooCodeInc#8413)

* Changeset version bump (RooCodeInc#8414)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* A couple more sonnet 4.5 fixes (RooCodeInc#8421)

* chore: Remove unsupported Gemini 2.5 Flash Image Preview free model (RooCodeInc#8359)

* Include reasoning messages in cloud tasks (RooCodeInc#8401)

* fix: show send button when only images are selected in chat textarea (RooCodeInc#8423)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Matt Rubens <[email protected]>

* Add structured data to the homepage (RooCodeInc#8427)

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>

* fix(ui): disable send button when no input content and update tests

* fix: Addresses overeager 'there are unsaved changes' dialog in settings (RooCodeInc#8410)

Fixes overeager 'there are unsaved changes' dialog in settings

* feat: add UsageStats schema and type (RooCodeInc#8441)

feat: add UsageStats schema and type to cloud.ts

Co-authored-by: Roo Code <[email protected]>

* Release: v1.80.0 (RooCodeInc#8442)

chore: bump version to v1.80.0

* feat: add new DeepSeek and GLM models with detailed descriptions to the Chutes provider (RooCodeInc#8467)

* Deprecate free grok 4 fast (RooCodeInc#8481)

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

* fix: improve save button activation in prompts settings (RooCodeInc#5780) (RooCodeInc#8267)

Co-authored-by: MuriloFP <[email protected]>
Co-authored-by: Roo Code <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>

* fix: properly reset cost limit tracking when user clicks "Reset and Continue" (RooCodeInc#6890)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>

* chore(deps): update dependency vite to v6.3.6 [security] (RooCodeInc#7838)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update dependency glob to v11.0.3 (RooCodeInc#7767)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore: add changeset for v3.28.15 (RooCodeInc#8491)

* Changeset version bump (RooCodeInc#8492)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* Clamp GPT-5 max output tokens to 20% of context window (RooCodeInc#8495)

* fix: add ollama and lmstudio to MODELS_BY_PROVIDER (