Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Jun 19, 2025

Description

Fixes #4602

This PR resolves an issue where canceling a task during API retry would incorrectly display "Subtask Results" and create a checkpoint initialization loop, even though no subtask was actually created.

Changes Made

  • Modified the clearTask handler in webviewMessageHandler.ts to check for the existence of a parentTask property instead of relying on stack size
  • This ensures that only actual subtasks (tasks with a parent) trigger the finishSubTask() method
  • Single tasks without parents now correctly use clearTask() instead

Testing

  • All existing tests pass
  • Added comprehensive test coverage in ClineProvider.spec.ts:
  • Manual testing completed:
    • Started a task that triggers API retry
    • Canceled during the retry period
    • Verified no phantom "Subtask Results" appears
    • Verified no checkpoint initialization loop occurs

Verification of Acceptance Criteria

  • When canceling during API retry, no "Subtask Results" display appears
  • No checkpoint initialization loop is triggered
  • The fix correctly distinguishes between actual subtasks and single tasks
  • All tests pass and the implementation is properly tested

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Comments added for complex logic
  • Documentation updated (if needed)
  • No breaking changes
  • Tests added for the fix

Technical Details

The root cause was that the previous implementation checked provider.getClineStackSize() > 1 to determine if a task was a subtask. However, during API retry scenarios, the stack could have multiple entries even for a single task, leading to incorrect behavior.

The fix now properly checks for the existence of a parentTask property on the current task, which is the definitive way to determine if a task is actually a subtask.


Important

Fixes phantom subtask display issue by checking parentTask property in webviewMessageHandler.ts during task cancellation.

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

- Fixed clearTask handler to check for actual parent task existence
- Changed condition from getClineStackSize() > 1 to checking currentTask.parentTask
- Prevents finishSubTask() from being called on tasks without parents
- Added comprehensive test coverage for clearTask message handler
- Resolves infinite checkpoint initialization loop issue
- Modified clearTask handler to check for parentTask property instead of stack size
- This prevents single tasks from being incorrectly treated as subtasks
- Added comprehensive test coverage for the fix
- Fixes issue where canceling during API retry would show phantom 'Subtask Results' and create checkpoint initialization loop
Copilot AI review requested due to automatic review settings June 19, 2025 18:12
@hannesrudolph hannesrudolph requested review from cte, jr and mrubens as code owners June 19, 2025 18:12
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jun 19, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fixes an issue where canceling during an API retry incorrectly treated single tasks as subtasks.

  • Replace getClineStackSize() check with explicit parentTask existence in the clearTask handler
  • Introduce a new clearTask() method on ClineProvider for non-subtask cancellations
  • Add comprehensive tests for both subtask and single-task cancellation flows

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/core/webview/webviewMessageHandler.ts Updated clearTask case to branch on currentTask.parentTask and call finishSubTask or clearTask
src/core/webview/ClineProvider.ts Added clearTask() helper to remove the current task without subtask logic
src/core/webview/tests/ClineProvider.spec.ts Added tests covering the new clearTask logic, including the fix for issue #4602
Comments suppressed due to low confidence (2)

src/core/webview/tests/ClineProvider.spec.ts:675

  • This test does not mock or assert postStateToWebview; consider spying on provider.postStateToWebview to both avoid unintended side effects and verify that state is posted in this scenario.
			await messageHandler({ type: "clearTask" })

src/core/webview/webviewMessageHandler.ts:207

  • The translation function t is used here but not imported in this module. Add the appropriate import (e.g. import { t } from 'i18n';) to prevent a runtime error.
				await provider.finishSubTask(t("common:tasks.canceled"))

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jun 19, 2025
@hannesrudolph hannesrudolph moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jun 19, 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 19, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Jun 19, 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.

LGMT

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 19, 2025
@hannesrudolph hannesrudolph merged commit 9e96fca into main Jun 19, 2025
23 of 24 checks passed
@hannesrudolph hannesrudolph deleted the fix/issue-4602-phantom-subtask-results branch June 19, 2025 19:41
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 19, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Jun 19, 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:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Canceling API Retry Creates Phantom Subtask and Checkpoint Initialization Loop

4 participants