Skip to content

Commit 9957d53

Browse files
committed
fix: check abort flag before calling abortTask to properly distinguish API failures
- Check if this.abort is true BEFORE calling abortTask() in the error handler - This allows proper distinction between user-initiated cancellations (where abort was already true) and actual API failures (where abort was false) - Fixes issue #5427 where all API failures were incorrectly reported as "API Request Cancelled"
1 parent 9fce90b commit 9957d53

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/core/task/Task.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,16 +1442,18 @@ export class Task extends EventEmitter<ClineEvents> {
14421442
// could be in (i.e. could have streamed some tools the user
14431443
// may have executed), so we just resort to replicating a
14441444
// cancel task.
1445-
this.abortTask()
14461445

1447-
// Check if this was a user-initiated cancellation
1448-
// If this.abort is true, it means the user clicked cancel, so we should
1446+
// Check if this was a user-initiated cancellation BEFORE calling abortTask
1447+
// If this.abort is already true, it means the user clicked cancel, so we should
14491448
// treat this as "user_cancelled" rather than "streaming_failed"
14501449
const cancelReason = this.abort ? "user_cancelled" : "streaming_failed"
14511450
const streamingFailedMessage = this.abort
14521451
? undefined
14531452
: (error.message ?? JSON.stringify(serializeError(error), null, 2))
14541453

1454+
// Now call abortTask after determining the cancel reason
1455+
this.abortTask()
1456+
14551457
await abortStream(cancelReason, streamingFailedMessage)
14561458

14571459
const history = await provider?.getTaskWithId(this.taskId)

0 commit comments

Comments
 (0)