-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix file revert on abort #949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 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) { | ||||||
| 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}`) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using raw console.log for logging. Consider using a structured logging mechanism or an existing logger to ensure consistent and production-ready logs.
Suggested change
|
||||||
|
|
||||||
| 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 | ||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taken from Cline's current |
||||||
| 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 | ||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taken from Cline's current |
||||||
| } | ||||||
|
|
||||||
| // need to call here in case the stream was aborted | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the fix for file revert on abort, please add (or update) unit/integration tests covering this abort behavior to ensure regressions are caught.