@@ -985,18 +985,48 @@ export class Task extends EventEmitter<ClineEvents> {
985985 }
986986
987987 // Release any terminals associated with this task.
988- TerminalRegistry . releaseTerminalsForTask ( this . taskId )
989-
990- this . urlContentFetcher . closeBrowser ( )
991- this . browserSession . closeBrowser ( )
992- this . rooIgnoreController ?. dispose ( )
993- this . fileContextTracker . dispose ( )
994-
995- // If we're not streaming then `abortStream` (which reverts the diff
996- // view changes) won't be called, so we need to revert the changes here.
997- // This check should ideally be more robust or part of abortStream's logic.
998- if ( this . isStreaming && this . diffViewProvider . isEditing ) {
999- this . diffViewProvider . revertChanges ( ) . catch ( console . error )
988+ try {
989+ // Release any terminals associated with this task.
990+ TerminalRegistry . releaseTerminalsForTask ( this . taskId )
991+ } catch ( error ) {
992+ console . error ( "Error releasing terminals:" , error )
993+ }
994+
995+ try {
996+ this . urlContentFetcher . closeBrowser ( )
997+ } catch ( error ) {
998+ console . error ( "Error closing URL content fetcher browser:" , error )
999+ }
1000+
1001+ try {
1002+ this . browserSession . closeBrowser ( )
1003+ } catch ( error ) {
1004+ console . error ( "Error closing browser session:" , error )
1005+ }
1006+
1007+ try {
1008+ if ( this . rooIgnoreController ) {
1009+ this . rooIgnoreController . dispose ( )
1010+ this . rooIgnoreController = undefined
1011+ }
1012+ } catch ( error ) {
1013+ console . error ( "Error disposing RooIgnoreController:" , error )
1014+ // This is the critical one for the leak fix
1015+ }
1016+
1017+ try {
1018+ this . fileContextTracker . dispose ( )
1019+ } catch ( error ) {
1020+ console . error ( "Error disposing file context tracker:" , error )
1021+ }
1022+
1023+ try {
1024+ // If we're not streaming then `abortStream` won't be called
1025+ if ( this . isStreaming && this . diffViewProvider . isEditing ) {
1026+ this . diffViewProvider . revertChanges ( ) . catch ( console . error )
1027+ }
1028+ } catch ( error ) {
1029+ console . error ( "Error reverting diff changes:" , error )
10001030 }
10011031 }
10021032
@@ -1011,10 +1041,19 @@ export class Task extends EventEmitter<ClineEvents> {
10111041 this . abort = true
10121042 this . emit ( "taskAborted" )
10131043
1014- this . dispose ( ) // Call the centralized dispose method
1015-
1044+ try {
1045+ this . dispose ( ) // Call the centralized dispose method
1046+ } catch ( error ) {
1047+ console . error ( `Error during task ${ this . taskId } .${ this . instanceId } disposal:` , error )
1048+ // Don't rethrow - we want abort to always succeed
1049+ }
10161050 // Save the countdown message in the automatic retry or other content.
1017- await this . saveClineMessages ( )
1051+ try {
1052+ // Save the countdown message in the automatic retry or other content.
1053+ await this . saveClineMessages ( )
1054+ } catch ( error ) {
1055+ console . error ( `Error saving messages during abort for task ${ this . taskId } .${ this . instanceId } :` , error )
1056+ }
10181057 }
10191058
10201059 // Used when a sub-task is launched and the parent task is waiting for it to
0 commit comments