@@ -146,6 +146,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
146146 readonly rootTaskId ?: string
147147 readonly parentTaskId ?: string
148148 childTaskId ?: string
149+ wasSubtaskCancelled ?: boolean
149150
150151 readonly instanceId : string
151152 readonly metadata : TaskMetadata
@@ -1649,32 +1650,55 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
16491650 } )
16501651 }
16511652
1652- public async completeSubtask ( lastMessage : string ) {
1653+ public async completeSubtask ( lastMessage : string , wasCancelled : boolean = false ) {
16531654 this . isPaused = false
16541655 this . childTaskId = undefined
1656+ this . wasSubtaskCancelled = wasCancelled
16551657
16561658 this . emit ( RooCodeEventName . TaskUnpaused , this . taskId )
16571659
1658- // Fake an answer from the subtask that it has completed running and
1659- // this is the result of what it has done add the message to the chat
1660- // history and to the webview ui.
1661- try {
1662- await this . say ( "subtask_result" , lastMessage )
1660+ // Only add the subtask result if it wasn't cancelled
1661+ if ( ! wasCancelled ) {
1662+ // Fake an answer from the subtask that it has completed running and
1663+ // this is the result of what it has done add the message to the chat
1664+ // history and to the webview ui.
1665+ try {
1666+ await this . say ( "subtask_result" , lastMessage )
16631667
1664- await this . addToApiConversationHistory ( {
1665- role : "user" ,
1666- content : [ { type : "text" , text : `[new_task completed] Result: ${ lastMessage } ` } ] ,
1667- } )
1668+ await this . addToApiConversationHistory ( {
1669+ role : "user" ,
1670+ content : [ { type : "text" , text : `[new_task completed] Result: ${ lastMessage } ` } ] ,
1671+ } )
16681672
1669- // Set skipPrevResponseIdOnce to ensure the next API call sends the full conversation
1670- // including the subtask result, not just from before the subtask was created
1671- this . skipPrevResponseIdOnce = true
1672- } catch ( error ) {
1673- this . providerRef
1674- . deref ( )
1675- ?. log ( `Error failed to add reply from subtask into conversation of parent task, error: ${ error } ` )
1673+ // Set skipPrevResponseIdOnce to ensure the next API call sends the full conversation
1674+ // including the subtask result, not just from before the subtask was created
1675+ this . skipPrevResponseIdOnce = true
1676+ } catch ( error ) {
1677+ this . providerRef
1678+ . deref ( )
1679+ ?. log ( `Error failed to add reply from subtask into conversation of parent task, error: ${ error } ` )
16761680
1677- throw error
1681+ throw error
1682+ }
1683+ } else {
1684+ // If the subtask was cancelled, add a message indicating that
1685+ try {
1686+ await this . say ( "subtask_result" , "Subtask was cancelled by user" )
1687+
1688+ await this . addToApiConversationHistory ( {
1689+ role : "user" ,
1690+ content : [ { type : "text" , text : `[new_task cancelled] The subtask was cancelled by the user.` } ] ,
1691+ } )
1692+
1693+ // Set skipPrevResponseIdOnce to ensure the next API call sends the full conversation
1694+ this . skipPrevResponseIdOnce = true
1695+ } catch ( error ) {
1696+ this . providerRef
1697+ . deref ( )
1698+ ?. log ( `Error failed to add cancellation message to parent task, error: ${ error } ` )
1699+
1700+ throw error
1701+ }
16781702 }
16791703 }
16801704
0 commit comments