-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: correct rate limiting calculation to prevent incorrect delay display #7771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…play - 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.
| // window as their parent tasks. | ||
| if (Task.lastGlobalApiRequestTime) { | ||
| const rateLimit = apiConfiguration?.rateLimitSeconds || 0 | ||
| if (Task.lastGlobalApiRequestTime && rateLimit > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional? While checking for rateLimit > 0 correctly handles the undefined/0 case, what happens if someone accidentally configures a negative rate limit? Should we add validation to ensure rateLimit >= 0 or use Math.max(0, rateLimit) to be defensive?
| 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we improve readability by combining these conditions? Something like:
| if (remainingDelay > 0) { | |
| if (Task.lastGlobalApiRequestTime && rateLimit > 0) { | |
| const now = Date.now() | |
| const timeSinceLastRequest = now - Task.lastGlobalApiRequestTime | |
| const remainingDelay = rateLimit * 1000 - timeSinceLastRequest | |
| rateLimitDelay = remainingDelay > 0 ? Math.ceil(remainingDelay / 1000) : 0 | |
| } |
This would eliminate the nested if statement while maintaining the same logic.
| // 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestion: Consider renaming this variable to rateLimitSeconds to match the configuration property name (apiConfiguration?.rateLimitSeconds). This would make the code more consistent and self-documenting.
Description
This PR fixes an issue where users were seeing an incorrect rate limiting message displaying "Rate limiting for 15903 seconds..." when using the DeepSeek API provider.
Problem
The rate limiting calculation in
Task.tswas not properly handling cases where:Task.lastGlobalApiRequestTimewas undefined (on first request)rateLimitSecondswas 0 or undefinedThis resulted in incorrect delay calculations that showed unrealistic wait times.
Solution
rateLimit > 0before applying rate limiting logicTesting
Related Issue
Fixes #7770
Changes Made
src/core/task/Task.ts(lines 2527-2540)Impact
This fix ensures that rate limiting messages are only displayed when:
Users will no longer see incorrect rate limiting messages when using DeepSeek or other providers without rate limiting configured.
Important
Fixes rate limiting calculation in
Task.tsto prevent incorrect delay messages by ensuring valid rate limits and adjusting delay logic.Task.tsto prevent incorrect delay messages.rateLimit > 0before applying rate limiting logic.This description was created by
for 713e891. You can customize this summary. It will automatically update as commits are pushed.