@@ -655,69 +655,81 @@ export class TaskManager implements vscode.Disposable {
655655 }
656656
657657 private onTaskStarted ( e : vscode . TaskStartEvent ) {
658- console . log ( `Task started: ${ e . execution . task . name } ` ) ;
658+ this . log ( `Task started: ${ e . execution . task . name } ` ) ;
659+ }
660+
661+ /**
662+ * Find execution ID for a task event.
663+ * VS Code may return different object references for the same execution,
664+ * so we fall back to matching by task name for running executions.
665+ */
666+ private findExecutionId ( execution : vscode . TaskExecution ) : string | undefined {
667+ // First try direct object lookup
668+ const directId = this . executionToId . get ( execution ) ;
669+ if ( directId ) {
670+ return directId ;
671+ }
672+ // Fall back to object identity check in activeExecutions
673+ for ( const [ id , exec ] of this . activeExecutions ) {
674+ if ( exec === execution ) {
675+ return id ;
676+ }
677+ }
678+ // Final fallback: match by task name for running interactive executions
679+ // This handles cases where VS Code returns different object references
680+ const taskName = execution . task . name ;
681+ for ( const [ id , info ] of this . executions ) {
682+ if ( info . taskName === taskName &&
683+ info . status === 'running' &&
684+ this . interactiveExecutionIds . has ( id ) ) {
685+ this . log ( `Matched task "${ taskName } " by name (object identity mismatch)` ) ;
686+ return id ;
687+ }
688+ }
689+ return undefined ;
659690 }
660691
661692 private onTaskEnded ( e : vscode . TaskEndEvent ) {
662693 const taskName = e . execution . task . name ;
663- const execId = this . executionToId . get ( e . execution ) ;
694+ this . log ( `onTaskEnded fired for "${ taskName } "` ) ;
695+ const execId = this . findExecutionId ( e . execution ) ;
664696 if ( execId ) {
697+ this . log ( `Found execution ID ${ execId } for ended task "${ taskName } "` ) ;
665698 this . activeExecutions . delete ( execId ) ;
666699 this . executionToId . delete ( e . execution ) ;
667700 this . interactiveExecutionIds . delete ( execId ) ;
668701 const info = this . executions . get ( execId ) ;
669702 if ( info && info . status === 'running' ) {
670703 info . status = 'completed' ;
671704 info . endTime = Date . now ( ) ;
705+ this . log ( `Updated status to 'completed' for execution ${ execId } ` ) ;
672706 }
673707 } else {
674- for ( const [ id , exec ] of this . activeExecutions ) {
675- if ( exec === e . execution ) {
676- this . activeExecutions . delete ( id ) ;
677- const info = this . executions . get ( id ) ;
678- if ( info && info . status === 'running' ) {
679- info . status = 'completed' ;
680- info . endTime = Date . now ( ) ;
681- }
682- break ;
683- }
684- }
708+ this . log ( `No execution ID found for ended task "${ taskName } " (may be external task)` ) ;
685709 }
686- console . log ( `Task ended: ${ taskName } ` ) ;
687710 }
688711
689712 private onTaskProcessEnded ( e : vscode . TaskProcessEndEvent ) {
690713 const taskName = e . execution . task . name ;
691- const execId = this . executionToId . get ( e . execution ) ;
714+ this . log ( `onTaskProcessEnded fired for "${ taskName } " with exit code ${ e . exitCode } ` ) ;
715+ const execId = this . findExecutionId ( e . execution ) ;
692716 if ( execId ) {
717+ this . log ( `Found execution ID ${ execId } for process-ended task "${ taskName } "` ) ;
693718 const info = this . executions . get ( execId ) ;
694719 if ( info ) {
695720 info . exitCode = e . exitCode ;
696721 if ( info . status === 'running' ) {
697722 info . status = e . exitCode === 0 ? 'completed' : 'failed' ;
698723 info . endTime = Date . now ( ) ;
724+ this . log ( `Updated status to '${ info . status } ' with exit code ${ e . exitCode } for execution ${ execId } ` ) ;
699725 }
700726 }
701727 this . activeExecutions . delete ( execId ) ;
702728 this . executionToId . delete ( e . execution ) ;
703729 this . interactiveExecutionIds . delete ( execId ) ;
704730 } else {
705- for ( const [ id , exec ] of this . activeExecutions ) {
706- if ( exec === e . execution ) {
707- const info = this . executions . get ( id ) ;
708- if ( info ) {
709- info . exitCode = e . exitCode ;
710- if ( info . status === 'running' ) {
711- info . status = e . exitCode === 0 ? 'completed' : 'failed' ;
712- info . endTime = Date . now ( ) ;
713- }
714- }
715- this . activeExecutions . delete ( id ) ;
716- break ;
717- }
718- }
731+ this . log ( `No execution ID found for process-ended task "${ taskName } " (may be external task)` ) ;
719732 }
720- console . log ( `Task process ended: ${ taskName } with exit code ${ e . exitCode } ` ) ;
721733 }
722734
723735 private generateExecutionId ( ) : string {
0 commit comments