From 901adc580fab1f6acd9882ab12ccfdf115814178 Mon Sep 17 00:00:00 2001 From: cte Date: Tue, 11 Feb 2025 12:44:32 -0800 Subject: [PATCH 1/2] Fix file revert on abort --- src/core/Cline.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index bacade3f74..f9a179736b 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -732,13 +732,18 @@ export class Cline { } async abortTask() { - this.abort = true // Will stop any autonomously running promises. + // Will stop any autonomously running promises. + this.abort = true + this.terminalManager.disposeAll() this.urlContentFetcher.closeBrowser() this.browserSession.closeBrowser() - // Need to await for when we want to make sure directories/files are - // reverted before re-starting the task from a checkpoint. - await this.diffViewProvider.revertChanges() + + if (this.isStreaming && this.diffViewProvider.isEditing) { + // Need to await for when we want to make sure directories/files are + // reverted before re-starting the task from a checkpoint. + await this.diffViewProvider.revertChanges() + } } // Tools @@ -2817,6 +2822,8 @@ export class Cline { } const abortStream = async (cancelReason: ClineApiReqCancelReason, streamingFailedMessage?: string) => { + console.log(`[Cline#abortStream] cancelReason = ${cancelReason}`) + if (this.diffViewProvider.isEditing) { await this.diffViewProvider.revertChanges() // closes diff view } @@ -2871,6 +2878,7 @@ export class Cline { const stream = this.attemptApiRequest(previousApiReqIndex) // yields only if the first chunk is successful, otherwise will allow the user to retry the request (most likely due to rate limit error, which gets thrown on the first chunk) let assistantMessage = "" let reasoningMessage = "" + this.isStreaming = true try { for await (const chunk of stream) { if (!chunk) { @@ -2903,11 +2911,13 @@ export class Cline { } if (this.abort) { - console.log("aborting stream...") + console.log(`aborting stream, this.abandoned = ${this.abandoned}`) + if (!this.abandoned) { // only need to gracefully abort if this instance isn't abandoned (sometimes openrouter stream hangs, in which case this would affect future instances of cline) await abortStream("user_cancelled") } + break // aborts the stream } @@ -2940,6 +2950,8 @@ export class Cline { // await this.providerRef.deref()?.postStateToWebview() } } + } finally { + this.isStreaming = false } // need to call here in case the stream was aborted From 6119cb1aaf8cb01a11834e2429cf0c0c9e4c0d33 Mon Sep 17 00:00:00 2001 From: cte Date: Tue, 11 Feb 2025 12:48:19 -0800 Subject: [PATCH 2/2] Update comment --- src/core/Cline.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index f9a179736b..33865601aa 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -739,9 +739,9 @@ export class Cline { this.urlContentFetcher.closeBrowser() this.browserSession.closeBrowser() + // If we're not streaming then `abortStream` (which reverts the diff + // view changes) won't be called, so we need to revert the changes here. if (this.isStreaming && this.diffViewProvider.isEditing) { - // Need to await for when we want to make sure directories/files are - // reverted before re-starting the task from a checkpoint. await this.diffViewProvider.revertChanges() } }