@@ -487,6 +487,8 @@ export class DebuggingHandler implements IDebuggingHandler {
487487 private async waitForStateChange ( beforeState : DebugState ) : Promise < DebugState > {
488488 const timeoutMs = this . timeoutInSeconds * 1000 ;
489489 const subscriptions : vscode . Disposable [ ] = [ ] ;
490+ const operatingSession = this . executor . getActiveSession ( ) ;
491+ let operatingSessionTerminated = false ;
490492
491493 try {
492494 await new Promise < void > ( resolve => {
@@ -517,9 +519,12 @@ export class DebuggingHandler implements IDebuggingHandler {
517519 } )
518520 ) ;
519521 subscriptions . push (
520- vscode . debug . onDidTerminateDebugSession ( ( ) => {
522+ vscode . debug . onDidTerminateDebugSession ( session => {
521523 // continue/step that runs the program to completion.
522- if ( ! vscode . debug . activeDebugSession ) {
524+ if ( operatingSession && session . id === operatingSession . id ) {
525+ operatingSessionTerminated = true ;
526+ settle ( ) ;
527+ } else if ( ! vscode . debug . activeDebugSession ) {
523528 settle ( ) ;
524529 }
525530 } )
@@ -537,7 +542,14 @@ export class DebuggingHandler implements IDebuggingHandler {
537542 subscriptions . forEach ( d => d . dispose ( ) ) ;
538543 }
539544
540- return await this . executor . getCurrentDebugState ( this . numNextLines ) ;
545+ const afterState = await this . executor . getCurrentDebugState ( this . numNextLines ) ;
546+ // The operating session ended (program ran to completion). A lingering
547+ // parent session (e.g. the JS debug terminal) can leave a different
548+ // session reported as active, so reflect termination explicitly here.
549+ if ( operatingSessionTerminated ) {
550+ afterState . sessionActive = false ;
551+ }
552+ return afterState ;
541553 }
542554
543555 /**
0 commit comments