File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -2240,6 +2240,17 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
22402240 error ,
22412241 streamingFailedMessage ,
22422242 )
2243+
2244+ // Check if task was aborted during the backoff
2245+ if ( this . abort ) {
2246+ console . log (
2247+ `[Task#${ this . taskId } .${ this . instanceId } ] Task aborted during mid-stream retry backoff` ,
2248+ )
2249+ // Abort the entire task
2250+ this . abortReason = "user_cancelled"
2251+ await this . abortTask ( )
2252+ break
2253+ }
22432254 }
22442255
22452256 // Push the same content back onto the stack to retry, incrementing the retry attempt counter
@@ -2790,6 +2801,15 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
27902801 // Apply shared exponential backoff and countdown UX
27912802 await this . backoffAndAnnounce ( retryAttempt , error , errorMsg )
27922803
2804+ // CRITICAL: Check if task was aborted during the backoff countdown
2805+ // This prevents infinite loops when users cancel during auto-retry
2806+ // Without this check, the recursive call below would continue even after abort
2807+ if ( this . abort ) {
2808+ throw new Error (
2809+ `[Task#attemptApiRequest] task ${ this . taskId } .${ this . instanceId } aborted during retry` ,
2810+ )
2811+ }
2812+
27932813 // Delegate generator output from the recursive call with
27942814 // incremented retry count.
27952815 yield * this . attemptApiRequest ( retryAttempt + 1 )
You can’t perform that action at this time.
0 commit comments