Skip to content

Negative wait time displayed in rate limit error message #28764

@Akash504-ai

Description

@Akash504-ai

Issue Summary

The checkRateLimitAndThrowError function can generate a negative wait time in its error message when the reset timestamp is in the past. This results in incorrect and confusing user-facing messages.


Steps to Reproduce

  1. Call checkRateLimitAndThrowError with a mocked rate limiter response where:
    • success = false
    • reset < Date.now()
  2. Observe the generated error message.

Example scenario:

reset = Date.now() - 5000;

Actual Results

The error message may display a negative wait time: Rate limit exceeded. Try again in -5 seconds.

Expected Results

The wait time should never be negative. It should be clamped to 0 or a minimum valid value: Rate limit exceeded. Try again in 0 seconds.

Technical details

  • Node.js version: N/A (logic-level issue)
  • Environment: Any
  • This issue is reproducible via code without requiring UI interaction

Relevant code:

const secondsToWait = Math.floor((reset - Date.now()) / 1000);

Evidence

This is a deterministic logic issue:

If:

reset < Date.now()

Then:

secondsToWait < 0

This leads to invalid negative values in the error message.

Suggested fix

Clamp the computed value to a minimum of 0:

const secondsToWait = Math.max(0, Math.floor((reset - Date.now()) / 1000));

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions