From fb711a097cdccd9ae62df2c742ce0c06892d8166 Mon Sep 17 00:00:00 2001 From: roomote Date: Mon, 30 Jun 2025 07:48:57 -0700 Subject: [PATCH] Fixes #4903: Consistent cancellation error messages for thinking vs streaming phases (#4904) Co-authored-by: Daniel <57051444+daniel-lxs@users.noreply.github.com> --- src/core/task/Task.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index ef5db499d2..bc7cd31f26 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -1425,10 +1425,15 @@ export class Task extends EventEmitter { // cancel task. this.abortTask() - await abortStream( - "streaming_failed", - error.message ?? JSON.stringify(serializeError(error), null, 2), - ) + // Check if this was a user-initiated cancellation + // If this.abort is true, it means the user clicked cancel, so we should + // treat this as "user_cancelled" rather than "streaming_failed" + const cancelReason = this.abort ? "user_cancelled" : "streaming_failed" + const streamingFailedMessage = this.abort + ? undefined + : (error.message ?? JSON.stringify(serializeError(error), null, 2)) + + await abortStream(cancelReason, streamingFailedMessage) const history = await provider?.getTaskWithId(this.taskId)