@@ -165,6 +165,7 @@ export class Task {
165165 checkpointTrackerErrorMessage ?: string
166166 conversationHistoryDeletedRange ?: [ number , number ]
167167 isInitialized = false
168+ private initTaskPromise ?: Promise < void >
168169 isAwaitingPlanResponse = false
169170 didRespondToPlanAskBySwitchingMode = false
170171
@@ -296,9 +297,9 @@ export class Task {
296297
297298 // Continue with task initialization
298299 if ( historyItem ) {
299- this . resumeTaskFromHistory ( )
300+ this . initTaskPromise = this . resumeTaskFromHistory ( )
300301 } else if ( task || images || files ) {
301- this . startTask ( task , images , files )
302+ this . initTaskPromise = this . startTask ( task , images , files )
302303 }
303304
304305 // initialize telemetry
@@ -387,6 +388,10 @@ export class Task {
387388 }
388389
389390 async restoreCheckpoint ( messageTs : number , restoreType : ClineCheckpointRestore , offset ?: number ) {
391+ if ( this . initTaskPromise && ! this . isInitialized ) {
392+ await this . initTaskPromise
393+ }
394+
390395 const messageIndex = this . clineMessages . findIndex ( ( m ) => m . ts === messageTs ) - ( offset || 0 )
391396 // Find the last message before messageIndex that has a lastCheckpointHash
392397 const lastHashIndex = findLastIndex ( this . clineMessages . slice ( 0 , messageIndex ) , ( m ) => m . lastCheckpointHash !== undefined )
@@ -521,6 +526,10 @@ export class Task {
521526 }
522527
523528 async presentMultifileDiff ( messageTs : number , seeNewChangesSinceLastTaskCompletion : boolean ) {
529+ if ( this . initTaskPromise && ! this . isInitialized ) {
530+ await this . initTaskPromise
531+ }
532+
524533 const relinquishButton = ( ) => {
525534 this . postMessageToWebview ( { type : "relinquishControl" } )
526535 }
@@ -650,6 +659,10 @@ export class Task {
650659 }
651660
652661 async doesLatestTaskCompletionHaveNewChanges ( ) {
662+ if ( this . initTaskPromise && ! this . isInitialized ) {
663+ await this . initTaskPromise
664+ }
665+
653666 if ( ! this . enableCheckpoints ) {
654667 return false
655668 }
@@ -1200,6 +1213,10 @@ export class Task {
12001213 // Checkpoints
12011214
12021215 async saveCheckpoint ( isAttemptCompletionMessage : boolean = false ) {
1216+ if ( this . initTaskPromise && ! this . isInitialized ) {
1217+ await this . initTaskPromise
1218+ }
1219+
12031220 if ( ! this . enableCheckpoints ) {
12041221 // If checkpoints are disabled, do nothing.
12051222 return
0 commit comments