Skip to content

fix: prevent negative wait time in rate limit error message#28765

Merged
romitg2 merged 2 commits intocalcom:mainfrom
Akash504-ai:fix/rate-limit-negative-wait-time
Apr 7, 2026
Merged

fix: prevent negative wait time in rate limit error message#28765
romitg2 merged 2 commits intocalcom:mainfrom
Akash504-ai:fix/rate-limit-negative-wait-time

Conversation

@Akash504-ai
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #28764

This PR prevents negative wait times from being displayed in the rate limit error message.

Previously, if the reset timestamp was in the past, the computed wait time could become negative, leading to messages like:

"Rate limit exceeded. Try again in -5 seconds."

This PR clamps the value to a minimum of 0 to ensure correct and user-friendly output.


Visual Demo (For contributors especially)

N/A — this is a logic-level fix and does not require UI interaction.


Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code
  • I have updated the developer docs in /docs if required (N/A)
  • I confirm automated tests are in place that prove my fix is effective

How should this be tested?

  1. Mock a rate limiter response where:

    • success = false
    • reset < Date.now()
  2. Call:

    checkRateLimitAndThrowError(...)
  3. Verify:

  • Error message contains "0 seconds"
  • No negative values appear

@github-actions github-actions bot added the 🐛 bug Something isn't working label Apr 6, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f2a6a2f2-084f-49f6-9445-9e83707b17d1

📥 Commits

Reviewing files that changed from the base of the PR and between facc074 and 12d242c.

📒 Files selected for processing (2)
  • packages/lib/checkRateLimitAndThrowError.test.ts
  • packages/lib/checkRateLimitAndThrowError.ts

📝 Walkthrough

Walkthrough

The pull request modifies rate limit error handling logic and adds test coverage. The implementation adjusts how computed wait times are calculated when a rate limit check fails, ensuring the value doesn't become negative when the reset timestamp has already elapsed. A corresponding unit test case verifies this behavior by mocking a rate limiter with a past reset timestamp and confirming the error message reports a minimum of zero seconds.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the primary change: preventing negative wait times in rate limit error messages.
Description check ✅ Passed The description is well-related to the changeset, explaining the issue, the fix, testing approach, and referencing the linked issue #28764.
Linked Issues check ✅ Passed The PR fully addresses issue #28764 by clamping secondsToWait to minimum 0 via Math.max() and includes test validation matching the expected behavior.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the negative wait time issue: clamping logic in the main function and a corresponding test case, with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@romitg2 romitg2 added ready-for-e2e run-ci Approve CI to run for external contributors labels Apr 7, 2026
@romitg2 romitg2 enabled auto-merge (squash) April 7, 2026 18:16
@romitg2 romitg2 merged commit 3c52f57 into calcom:main Apr 7, 2026
60 of 64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working ready-for-e2e run-ci Approve CI to run for external contributors size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negative wait time displayed in rate limit error message

2 participants