Skip to content

Commit 2f4d085

Browse files
committed
fix: prevent infinite loop when canceling during auto-retry
- Add abort check after backoffAndAnnounce in first-chunk retry logic - Add abort check after backoffAndAnnounce in mid-stream retry logic - Properly handle task abortion to break retry loops Fixes #8901
1 parent f839d4c commit 2f4d085

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/core/task/Task.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff 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,13 @@ 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+
// Check if task was aborted during the backoff
2805+
if (this.abort) {
2806+
throw new Error(
2807+
`[Task#attemptApiRequest] task ${this.taskId}.${this.instanceId} aborted during retry`,
2808+
)
2809+
}
2810+
27932811
// Delegate generator output from the recursive call with
27942812
// incremented retry count.
27952813
yield* this.attemptApiRequest(retryAttempt + 1)

0 commit comments

Comments
 (0)