@@ -261,11 +261,11 @@ interface PendingCommand {
261261 resolve ( result : TerminalRunResult ) : void
262262}
263263
264- /** How long a new shell gets to reach its first prompt, each measured from its spawn . */
264+ /** How long a new shell gets to reach its first prompt. */
265265export interface ShellStartupBounds {
266- /** To begin the startup files we generated; a shell that has not by then never will. */
266+ /** From spawn, to begin the startup files we generated; a shell that has not by then never will. */
267267 unstartedMs : number
268- /** For startup files that did begin to reach a prompt. */
268+ /** From the moment they began, for those startup files to reach a prompt. */
269269 startingMs : number
270270}
271271
@@ -329,7 +329,8 @@ export class TerminalSession {
329329 private lines : number
330330 private shellIntegration = false
331331 /** The shell has begun the startup files we generated, so its integration is on the way. */
332- private startupBegun = false
332+ /** When the shell began the startup files we generated, or null while it has not. */
333+ private startupBegunAt : number | null = null
333334 private readonly spawnedAt = Date . now ( )
334335 private altScreen = false
335336 private foregroundCommand : string | null = null
@@ -516,7 +517,7 @@ export class TerminalSession {
516517 /**
517518 * Resolves once the shell reaches its first prompt with integration live, or once it is clear
518519 * it will not: it never began our startup files within `bounds.unstartedMs` of spawning, it is
519- * still running them `bounds.startingMs` after spawning , it exited, or `signal` stopped the
520+ * still running them `bounds.startingMs` after they began , it exited, or `signal` stopped the
520521 * wait. A shell's startup files take a while, and longer on a busy machine, so a command issued
521522 * soon after spawn would otherwise be refused when the shell is merely early.
522523 */
@@ -531,8 +532,11 @@ export class TerminalSession {
531532 timer = null
532533 const readiness = signal ?. aborted ? 'stopped' : this . readiness ( bounds )
533534 if ( readiness === null ) {
534- const limit = this . startupBegun ? bounds . startingMs : bounds . unstartedMs
535- timer = setTimeout ( check , Math . max ( 0 , this . spawnedAt + limit - Date . now ( ) ) )
535+ const deadline =
536+ this . startupBegunAt === null
537+ ? this . spawnedAt + bounds . unstartedMs
538+ : this . startupBegunAt + bounds . startingMs
539+ timer = setTimeout ( check , Math . max ( 0 , deadline - Date . now ( ) ) )
536540 return
537541 }
538542 this . readinessWaiters . delete ( check )
@@ -549,11 +553,13 @@ export class TerminalSession {
549553 private readiness ( bounds : ShellStartupBounds ) : ShellReadiness | null {
550554 if ( this . shellIntegration ) return 'ready'
551555 if ( this . disposed ) return 'exited'
552- const elapsed = Date . now ( ) - this . spawnedAt
553- if ( ! this . startupBegun ) {
554- return ! this . instrumented || elapsed >= bounds . unstartedMs ? 'not-instrumented' : null
556+ const now = Date . now ( )
557+ if ( this . startupBegunAt === null ) {
558+ return ! this . instrumented || now - this . spawnedAt >= bounds . unstartedMs
559+ ? 'not-instrumented'
560+ : null
555561 }
556- return elapsed >= bounds . startingMs ? 'starting' : null
562+ return now - this . startupBegunAt >= bounds . startingMs ? 'starting' : null
557563 }
558564
559565 private notifyReadinessWaiters ( ) : void {
@@ -849,8 +855,8 @@ export class TerminalSession {
849855 ) : void {
850856 switch ( marker . kind ) {
851857 case 'startup' :
852- if ( ! this . startupBegun ) {
853- this . startupBegun = true
858+ if ( this . startupBegunAt === null ) {
859+ this . startupBegunAt = Date . now ( )
854860 this . notifyReadinessWaiters ( )
855861 }
856862 break
0 commit comments