Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jul 18, 2025

This PR fixes issue #5895 where provider connection/API failures were incorrectly triggering "API request cancelled" messages instead of proper error handling.

Problem

When API providers like Gemini experience connection issues or become unresponsive, the system incorrectly reports these as user cancellations instead of API failures. This leads to:

  • Misleading "API request cancelled" messages when the user did not cancel
  • Tasks being silently abandoned without proper error notification
  • No retry attempts for legitimate API failures

Root Cause

The issue was in the cancellation reason detection logic in Task.ts. The code was using the abort flag to determine if a cancellation was user-initiated, but this flag gets set to true for both user cancellations AND API failures, making it impossible to distinguish between the two.

Solution

  1. Added abortReason field to the Task class to explicitly track the source of cancellation (user | api_failure | null)
  2. Updated abortTask method to accept a reason parameter with default value of user
  3. Fixed cancellation logic to use abortReason instead of the ambiguous abort flag
  4. Updated all calls to abortTask() to specify the correct reason:
    • User-initiated cancellations: abortTask(false, "user")
    • API failure cancellations: abortTask(false, "api_failure")

Changes

  • src/core/task/Task.ts: Added abortReason field and updated cancellation logic
  • src/core/webview/ClineProvider.ts: Updated abortTask() calls to specify user cancellation reason

Testing

The fix ensures that:

  • API failures are correctly identified as streaming_failed with proper error messages
  • User cancellations are correctly identified as user_cancelled
  • Proper retry behavior is maintained for API failures
  • Error messages accurately reflect the actual cause of cancellation

Fixes #5895


Important

Fixes issue #5895 by distinguishing API failures from user cancellations using a new abortReason field in Task.ts.

  • Behavior:
    • Introduced abortReason field in Task class to distinguish between user cancellations and API failures.
    • Updated abortTask() method in Task.ts to accept a reason parameter (user or api_failure).
    • Modified logic in Task.ts to use abortReason for accurate error reporting and handling.
  • Code Changes:
    • Task.ts: Added abortReason field, updated abortTask() method, and adjusted cancellation logic.
    • ClineProvider.ts: Updated abortTask() calls to specify user as the cancellation reason.
  • Testing:
    • Ensures API failures are logged as streaming_failed and user cancellations as user_cancelled.
    • Maintains retry behavior for API failures and accurate error messages.

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

- Add abortReason field to Task class to track cancellation source
- Update abortTask method to accept reason parameter (user vs api_failure)
- Fix cancellation reason logic to use abortReason instead of abort flag
- Update ClineProvider calls to specify user cancellation reason
- Resolves issue where API failures were incorrectly reported as user cancellations

Fixes #5895
@roomote roomote bot requested review from cte, jr and mrubens as code owners July 18, 2025 15:32
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Jul 18, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 18, 2025
@daniel-lxs
Copy link
Member

The issue isn't with distinguishing, is that the error API request cancelled is happening all the time, this PR would be a bandaid fix

@daniel-lxs daniel-lxs closed this Jul 21, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 21, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jul 21, 2025
@daniel-lxs daniel-lxs deleted the fix/api-failure-cancellation-detection branch July 21, 2025 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Provider connection/API failures sometimes trigger "API request cancelled" even though I did not cancel it

4 participants