fix: resume parent task when subtask gets interrupted

- Add handleInterruptedSubtask method to properly handle interrupted subtasks
- Check and unpause parent tasks in resumeTaskFromHistory when they were waiting for an interrupted subtask
- Add proper logging and conversation history updates when subtask is interrupted

Fixes #7780
This commit is contained in:
Roo Code 2025-09-08 10:56:07 +00:00
parent 25717817a6
commit b6005bf614

View file

@ -1228,6 +1228,12 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
}
}
// Check if this task was paused waiting for a subtask that got interrupted
// If so, handle the interrupted subtask properly
if (this.isPaused && this.childTaskId) {
await this.handleInterruptedSubtask()
}
const modifiedClineMessages = await this.getSavedClineMessages()
// Check for any stored GPT-5 response IDs in the message history.
@ -1657,6 +1663,55 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
}
}
/**
* Handle the case when a subtask was interrupted (e.g., due to 5-hour limit)
* and the parent task needs to be resumed without the subtask result.
*/
public async handleInterruptedSubtask() {
if (!this.isPaused || !this.childTaskId) {
return // Not waiting for a subtask
}
const provider = this.providerRef.deref()
provider?.log(
`[handleInterruptedSubtask] Handling interrupted subtask ${this.childTaskId} for parent task ${this.taskId}`,
)
// Clear the paused state
this.isPaused = false
const interruptedChildId = this.childTaskId
this.childTaskId = undefined
// Clear any pause interval
if (this.pauseInterval) {
clearInterval(this.pauseInterval)
this.pauseInterval = undefined
}
// Emit event to update UI
this.emit(RooCodeEventName.TaskUnpaused, this.taskId)
// Add a message to the conversation history indicating the subtask was interrupted
try {
await this.say("subtask_result", `[Subtask ${interruptedChildId} was interrupted and could not complete]`)
await this.addToApiConversationHistory({
role: "user",
content: [
{
type: "text",
text: `[new_task interrupted] The subtask was interrupted before completion. Please continue with the main task.`,
},
],
})
// Set skipPrevResponseIdOnce to ensure continuity
this.skipPrevResponseIdOnce = true
} catch (error) {
provider?.log(`Error handling interrupted subtask: ${error}`)
}
}
// Task Loop
private async initiateTaskLoop(userContent: Anthropic.Messages.ContentBlockParam[]): Promise<void> {