-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: rehydrate parent task when resuming subtask after interruption #8090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -451,12 +451,32 @@ export class ClineProvider | |
| // This is used when a subtask is finished and the parent task needs to be | ||
| // resumed. | ||
| async finishSubTask(lastMessage: string) { | ||
| // Store the parent task ID before removing the child | ||
| const parentTaskId = this.getCurrentTask()?.parentTaskId | ||
|
|
||
| // Remove the last cline instance from the stack (this is the finished | ||
| // subtask). | ||
| await this.removeClineFromStack() | ||
| // Resume the last cline instance in the stack (if it exists - this is | ||
| // the 'parent' calling task). | ||
| await this.getCurrentTask()?.completeSubtask(lastMessage) | ||
|
|
||
| // Try to get the parent task from the stack | ||
| let parentTask = this.getCurrentTask() | ||
|
|
||
| // If parent is not on the stack but we have a parentTaskId, rehydrate it | ||
| if (!parentTask && parentTaskId) { | ||
| try { | ||
| const { historyItem } = await this.getTaskWithId(parentTaskId) | ||
| // Create the parent task from history | ||
| parentTask = await this.createTaskWithHistoryItem(historyItem) | ||
| this.log(`[finishSubTask] Rehydrated parent task ${parentTaskId} from history`) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider extracting the '[finishSubTask]' prefix to a constant since it's used multiple times in the logging statements. This would ensure consistency and make future changes easier: Rehydrated parent task from history |
||
| } catch (error) { | ||
| this.log(`[finishSubTask] Failed to rehydrate parent task ${parentTaskId}: ${error}`) | ||
| // If we can't rehydrate the parent, at least log the error | ||
| // The UI will remain in a state where the user can start a new task | ||
| } | ||
| } | ||
|
|
||
| // Resume the parent task (if it exists) | ||
| await parentTask?.completeSubtask(lastMessage) | ||
| } | ||
| // Pending Edit Operations Management | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great implementation of the minimal fix! The rehydration logic is clean and handles the edge cases well. Consider adding JSDoc comments to document this new behavior for future maintainers: