Skip to content

fix: respect challenge rate limits#1211

Merged
AttackingOrDefending merged 1 commit into
lichess-bot-devs:masterfrom
ilAYAli:fix/challenge-rate-limit
Jun 4, 2026
Merged

fix: respect challenge rate limits#1211
AttackingOrDefending merged 1 commit into
lichess-bot-devs:masterfrom
ilAYAli:fix/challenge-rate-limit

Conversation

@ilAYAli

@ilAYAli ilAYAli commented May 26, 2026

Copy link
Copy Markdown
Contributor

Treat generic 429 responses from the challenge endpoint as bot rate limits, honoring Retry-After when present and otherwise using bounded exponential backoff. Also prevent expired outgoing challenges from bypassing the local challenge rate-limit timer.

Validation:

  • python3 -m py_compile lib/lichess.py lib/matchmaking.py test_bot/test_lichess.py test_bot/test_matchmaking.py
  • python -m ruff check lib/lichess.py lib/matchmaking.py test_bot/test_lichess.py test_bot/test_matchmaking.py
  • python -m pytest test_bot/test_lichess.py::test_challenge_429_without_ratelimit_body_sets_bot_rate_limit test_bot/test_lichess.py::test_challenge_429_without_retry_after_uses_exponential_backoff test_bot/test_matchmaking.py::test_should_create_challenge_respects_rate_limit_when_previous_challenge_expired

Type of pull request:

  • Bug fix
  • Feature
  • Other

Description:

Treat generic 429 responses from the challenge endpoint as bot rate limits, honoring Retry-After when
present and otherwise using bounded exponential backoff. Also prevent expired outgoing challenges from
bypassing the local challenge rate-limit timer.

This treats generic challenge 429s as bot rate limits, honors Retry-After when present, falls back to
bounded exponential backoff, and prevents expired outgoing challenges from bypassing the local rate-
limit timer.

Validation:

  • python3 -m py_compile lib/lichess.py lib/matchmaking.py test_bot/test_lichess.py test_bot/ test_matchmaking.py
  • python -m ruff check lib/lichess.py lib/matchmaking.py test_bot/test_lichess.py test_bot/ test_matchmaking.py
  • python -m pytest test_bot/ test_lichess.py::test_challenge_429_without_ratelimit_body_sets_bot_rate_limit test_bot/ test_lichess.py::test_challenge_429_without_retry_after_uses_exponential_backoff test_bot/ test_matchmaking.py::test_should_create_challenge_respects_rate_limit_when_previous_challenge_expired

Related Issues:

[Reference any related issues that this pull request addresses or closes. Use the syntax Closes #issue_number to automatically close the linked issue upon merging.]

Checklist:

  • I have read and followed the contribution guidelines.
  • I have added necessary documentation (if applicable).
  • The changes pass all existing tests.

Screenshots/logs (if applicable):

Comment thread lib/lichess.py Outdated
@ilAYAli ilAYAli force-pushed the fix/challenge-rate-limit branch 3 times, most recently from 50dcb88 to a1c0576 Compare May 31, 2026 07:02
@ilAYAli

ilAYAli commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

@MarkZH updated the test assertions to use seconds() instead of raw floats

@ilAYAli ilAYAli force-pushed the fix/challenge-rate-limit branch from a1c0576 to bd91a33 Compare May 31, 2026 08:06
Comment thread lib/matchmaking.py Outdated
Treat generic 429 responses from the challenge endpoint as bot rate limits, honoring Retry-After when present and otherwise using bounded exponential backoff. Also prevent expired outgoing challenges from bypassing the local challenge rate-limit timer.

Validation:
- python3 -m py_compile lib/lichess.py lib/matchmaking.py test_bot/test_lichess.py test_bot/test_matchmaking.py
- python -m ruff check lib/lichess.py lib/matchmaking.py test_bot/test_lichess.py test_bot/test_matchmaking.py
- python -m pytest test_bot/test_lichess.py::test_challenge_429_without_ratelimit_body_sets_bot_rate_limit test_bot/test_lichess.py::test_challenge_429_without_retry_after_uses_exponential_backoff test_bot/test_matchmaking.py::test_should_create_challenge_respects_rate_limit_when_previous_challenge_expired
@ilAYAli ilAYAli force-pushed the fix/challenge-rate-limit branch from bd91a33 to e396724 Compare June 1, 2026 10:31
@AttackingOrDefending AttackingOrDefending merged commit 38d3446 into lichess-bot-devs:master Jun 4, 2026
23 checks passed
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.

3 participants