fix: address rate limit detection false positives and reset-time cap

- Narrow `\boverloaded\b` regex to require server/api/system context,
  preventing false positives when Claude discusses method/operator
  overloading in OOP code (C++, Java, C#, etc.)
- Restore 24-hour cap for absolute reset-time delays instead of 1-hour
  clamp, avoiding unnecessary retry loops when rate limits reset hours
  in the future
- Add test for Retry-After: 0 returning 0 (regression lock for the
  `is not None` fix)
- Add false positive tests for "overloaded" in programming context

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Auto
2026-02-01 10:39:07 +02:00
parent e7aeea6b77
commit c4d0c6c9b2
3 changed files with 18 additions and 2 deletions

View File

@@ -43,6 +43,11 @@ class TestParseRetryAfter(unittest.TestCase):
assert parse_retry_after("60 seconds left") == 60
assert parse_retry_after("120 seconds until reset") == 120
def test_retry_after_zero(self):
"""Test 'Retry-After: 0' returns 0 (not None)."""
assert parse_retry_after("Retry-After: 0") == 0
assert parse_retry_after("retry after 0 seconds") == 0
def test_no_match(self):
"""Test messages that don't contain retry-after info."""
assert parse_retry_after("no match here") is None
@@ -141,6 +146,17 @@ class TestFalsePositives(unittest.TestCase):
assert is_rate_limit_error("File size limit reached") is False
assert is_rate_limit_error("Memory limit reached, consider optimization") is False
def test_overloaded_in_programming_context(self):
"""Method/operator overloading discussions should not trigger."""
assert is_rate_limit_error("I will create an overloaded constructor") is False
assert is_rate_limit_error("The + operator is overloaded") is False
assert is_rate_limit_error("Here is the overloaded version of the function") is False
assert is_rate_limit_error("The method is overloaded to accept different types") is False
# But actual API overload messages should still match
assert is_rate_limit_error("Server is overloaded") is True
assert is_rate_limit_error("API overloaded") is True
assert is_rate_limit_error("system is overloaded") is True
class TestBackoffFunctions(unittest.TestCase):
"""Test backoff calculation functions from rate_limit_utils."""