fix(ollama): abort streaming requests when task is cancelled (#7907)
Previously, clicking cancel would break out of the stream loop but leave the HTTP connection open. Ollama would continue generating in the background, keeping the GPU busy and blocking subsequent requests until completion. Now we call the Ollama SDK's abort() method to immediately close the connection. Fixes #7468
This commit is contained in:
1 parent
ee154826b6
commit
8e7b1c6884
4 files changed
+11
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"claude-dev": patch
|
||||
---
|
||||
|
||||
fix(ollama): abort streaming requests when task is cancelled
|
||||
@@ -51,6 +51,7 @@ export interface ApiHandler {
|
||||
createMessage(systemPrompt: string, messages: ClineStorageMessage[], tools?: ClineTool[], useResponseApi?: boolean): ApiStream
|
||||
getModel(): ApiHandlerModel
|
||||
getApiStreamUsage?(): Promise<ApiStreamUsageChunk | undefined>
|
||||
abort?(): void
|
||||
}
|
||||
|
||||
export interface ApiHandlerModel {
|
||||
|
||||
@@ -121,4 +121,8 @@ export class OllamaHandler implements ApiHandler {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
abort(): void {
|
||||
this.client?.abort()
|
||||
}
|
||||
}
|
||||
@@ -2907,6 +2907,7 @@ export class Task {
|
||||
)
|
||||
|
||||
if (this.taskState.abort) {
|
||||
this.api.abort?.()
|
||||
if (!this.taskState.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")
|
||||
|
||||
Reference in new issue
Block a user