Skip to content

Commit 713e891

Browse files
committed
fix: correct rate limiting calculation to prevent incorrect delay display
- Fixed rate limiting logic in Task.ts to properly handle undefined lastGlobalApiRequestTime - Added check for rateLimit > 0 before applying rate limiting - Simplified calculation to only apply delay when there's actually time remaining - This prevents the incorrect '15903 seconds' message reported in issue #7770
1 parent 2571781 commit 713e891

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/core/task/Task.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,11 +2528,15 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
25282528

25292529
// Use the shared timestamp so that subtasks respect the same rate-limit
25302530
// window as their parent tasks.
2531-
if (Task.lastGlobalApiRequestTime) {
2531+
const rateLimit = apiConfiguration?.rateLimitSeconds || 0
2532+
if (Task.lastGlobalApiRequestTime && rateLimit > 0) {
25322533
const now = Date.now()
25332534
const timeSinceLastRequest = now - Task.lastGlobalApiRequestTime
2534-
const rateLimit = apiConfiguration?.rateLimitSeconds || 0
2535-
rateLimitDelay = Math.ceil(Math.max(0, rateLimit * 1000 - timeSinceLastRequest) / 1000)
2535+
const remainingDelay = rateLimit * 1000 - timeSinceLastRequest
2536+
// Only apply rate limit if there's actually time remaining to wait
2537+
if (remainingDelay > 0) {
2538+
rateLimitDelay = Math.ceil(remainingDelay / 1000)
2539+
}
25362540
}
25372541

25382542
// Only show rate limiting message if we're not retrying. If retrying, we'll include the delay there.

0 commit comments

Comments
 (0)