Skip to content

Commit b284edd

Browse files
fix: prevent infinite loop when canceling during auto-retry (#8902)
* 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 * docs: add critical comments explaining abort checks - Document the importance of abort checks after backoff - Explain how these checks prevent infinite loops - Add context for future maintainability --------- Co-authored-by: Roo Code <[email protected]>
1 parent f583be3 commit b284edd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/core/task/Task.ts

Lines changed: 20 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,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)

0 commit comments

Comments
 (0)