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
This commit is contained in:
Roo Code 2025-09-08 01:49:47 +00:00
parent 25717817a6
commit 713e8919ea

View file

@ -2528,11 +2528,15 @@ export class Task extends EventEmitter<TaskEvents> 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.