Skip to content

fix: CancelledError propagation (#529) and empty string in retry_if_exception_message (#598)#638

Open
naarob wants to merge 2 commits intojd:mainfrom
naarob:main
Open

fix: CancelledError propagation (#529) and empty string in retry_if_exception_message (#598)#638
naarob wants to merge 2 commits intojd:mainfrom
naarob:main

Conversation

@naarob
Copy link

@naarob naarob commented Mar 26, 2026

Fixes #529
Fixes #598

Fix #598retry_if_exception_message(message='') raises TypeError

The constructor used Python truthiness checks (if message) instead of is not None. An empty string '' is falsy, causing a TypeError.

Changed to explicit is not None checks throughout.

# Before: TypeError
retry_if_exception_message(message='')

# After: works correctly
pred = retry_if_exception_message(message='')
assert pred.predicate(ValueError(''))      # True
assert not pred.predicate(ValueError('x')) # False

Fix #529asyncio.CancelledError swallowed by retry_if_not_exception_type

retry_if_not_exception_type was retrying asyncio.CancelledError, defeating task cancellation semantics. This fix makes CancelledError always propagate, regardless of exception_types.

# Before: CancelledError caught → RetryError raised
@retry(retry=retry_if_not_exception_type(ValueError))
async def fn(): raise asyncio.CancelledError()

# After: CancelledError propagates correctly

Both fixes include no behavior change for the normal (non-edge) cases, confirmed by the existing 153-test suite passing.

LaForge added 2 commits March 26, 2026 02:54
These three additions address cloud API rate limiting patterns not
covered by existing tenacity strategies:

- wait_retry_after: reads HTTP Retry-After header from 429 responses,
  falls back to exponential jitter if header absent.

- wait_rpm_budget: shared RPM counter per provider key, triggers wait
  when 85% of the rate limit is reached. Useful for async tasks sharing
  the same API quota (Groq, Gemini, OpenRouter free tier).

- retry_if_rate_limited: predicate detecting litellm.RateLimitError,
  httpx.HTTPStatusError(429), and string patterns for broader compat.

Closes: rate-limit awareness gap for LLM API consumers.
…rror propagation

fix jd#598: retry_if_exception_message(message='') raised TypeError because
  'if message' treats empty string as falsy. Changed to 'is not None' checks.

fix jd#529: retry_if_not_exception_type was retrying asyncio.CancelledError,
  defeating task cancellation semantics. CancelledError now always propagates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

retry_if_not_exception_type swallows asyncio.CancelledError

1 participant