From 713e8919eab533207df834589f08c254389bd017 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Mon, 8 Sep 2025 01:49:47 +0000 Subject: [PATCH] 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 --- src/core/task/Task.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/task/Task.ts b/src/core/task/Task.ts index c5be865731..38d4d8412a 100644 --- a/src/core/task/Task.ts +++ b/src/core/task/Task.ts @@ -2528,11 +2528,15 @@ export class Task extends EventEmitter implements TaskLike { // Use the shared timestamp so that subtasks respect the same rate-limit // window as their parent tasks. - if (Task.lastGlobalApiRequestTime) { + const rateLimit = apiConfiguration?.rateLimitSeconds || 0 + if (Task.lastGlobalApiRequestTime && rateLimit > 0) { const now = Date.now() const timeSinceLastRequest = now - Task.lastGlobalApiRequestTime - const rateLimit = apiConfiguration?.rateLimitSeconds || 0 - rateLimitDelay = Math.ceil(Math.max(0, rateLimit * 1000 - timeSinceLastRequest) / 1000) + const remainingDelay = rateLimit * 1000 - timeSinceLastRequest + // Only apply rate limit if there's actually time remaining to wait + if (remainingDelay > 0) { + rateLimitDelay = Math.ceil(remainingDelay / 1000) + } } // Only show rate limiting message if we're not retrying. If retrying, we'll include the delay there.