Skip to content

Commit d264bef

Browse files
authored
Merge pull request RooCodeInc#949 from RooVetGit/cte/fix-diff-editor-revert-on-abort
Fix file revert on abort
2 parents e39b006 + 6119cb1 commit d264bef

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/core/Cline.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,18 @@ export class Cline {
732732
}
733733

734734
async abortTask() {
735-
this.abort = true // Will stop any autonomously running promises.
735+
// Will stop any autonomously running promises.
736+
this.abort = true
737+
736738
this.terminalManager.disposeAll()
737739
this.urlContentFetcher.closeBrowser()
738740
this.browserSession.closeBrowser()
739-
// Need to await for when we want to make sure directories/files are
740-
// reverted before re-starting the task from a checkpoint.
741-
await this.diffViewProvider.revertChanges()
741+
742+
// If we're not streaming then `abortStream` (which reverts the diff
743+
// view changes) won't be called, so we need to revert the changes here.
744+
if (this.isStreaming && this.diffViewProvider.isEditing) {
745+
await this.diffViewProvider.revertChanges()
746+
}
742747
}
743748

744749
// Tools
@@ -2817,6 +2822,8 @@ export class Cline {
28172822
}
28182823

28192824
const abortStream = async (cancelReason: ClineApiReqCancelReason, streamingFailedMessage?: string) => {
2825+
console.log(`[Cline#abortStream] cancelReason = ${cancelReason}`)
2826+
28202827
if (this.diffViewProvider.isEditing) {
28212828
await this.diffViewProvider.revertChanges() // closes diff view
28222829
}
@@ -2871,6 +2878,7 @@ export class Cline {
28712878
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)
28722879
let assistantMessage = ""
28732880
let reasoningMessage = ""
2881+
this.isStreaming = true
28742882
try {
28752883
for await (const chunk of stream) {
28762884
if (!chunk) {
@@ -2903,11 +2911,13 @@ export class Cline {
29032911
}
29042912

29052913
if (this.abort) {
2906-
console.log("aborting stream...")
2914+
console.log(`aborting stream, this.abandoned = ${this.abandoned}`)
2915+
29072916
if (!this.abandoned) {
29082917
// 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)
29092918
await abortStream("user_cancelled")
29102919
}
2920+
29112921
break // aborts the stream
29122922
}
29132923

@@ -2940,6 +2950,8 @@ export class Cline {
29402950
// await this.providerRef.deref()?.postStateToWebview()
29412951
}
29422952
}
2953+
} finally {
2954+
this.isStreaming = false
29432955
}
29442956

29452957
// need to call here in case the stream was aborted

0 commit comments

Comments
 (0)