Skip to content

Commit e1604a8

Browse files
committed
fix: rehydrate parent task when subtask completes after interruption
- Modified finishSubTask() to check for parentTaskId and rehydrate parent from history if not on stack - Enhanced clearTask handler to support parentTaskId-based subtask detection - Added comprehensive unit tests for subtask rehydration scenarios Fixes #8081
1 parent c837025 commit e1604a8

File tree

3 files changed

+618
-4
lines changed

3 files changed

+618
-4
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,32 @@ export class ClineProvider
451451
// This is used when a subtask is finished and the parent task needs to be
452452
// resumed.
453453
async finishSubTask(lastMessage: string) {
454+
// Store the parent task ID before removing the child
455+
const parentTaskId = this.getCurrentTask()?.parentTaskId
456+
454457
// Remove the last cline instance from the stack (this is the finished
455458
// subtask).
456459
await this.removeClineFromStack()
457-
// Resume the last cline instance in the stack (if it exists - this is
458-
// the 'parent' calling task).
459-
await this.getCurrentTask()?.completeSubtask(lastMessage)
460+
461+
// Try to get the parent task from the stack
462+
let parentTask = this.getCurrentTask()
463+
464+
// If parent is not on the stack but we have a parentTaskId, rehydrate it
465+
if (!parentTask && parentTaskId) {
466+
try {
467+
const { historyItem } = await this.getTaskWithId(parentTaskId)
468+
// Create the parent task from history
469+
parentTask = await this.createTaskWithHistoryItem(historyItem)
470+
this.log(`[finishSubTask] Rehydrated parent task ${parentTaskId} from history`)
471+
} catch (error) {
472+
this.log(`[finishSubTask] Failed to rehydrate parent task ${parentTaskId}: ${error}`)
473+
// If we can't rehydrate the parent, at least log the error
474+
// The UI will remain in a state where the user can start a new task
475+
}
476+
}
477+
478+
// Resume the parent task (if it exists)
479+
await parentTask?.completeSubtask(lastMessage)
460480
}
461481
// Pending Edit Operations Management
462482

0 commit comments

Comments
 (0)