Skip to content

Handle new error message when challenging bots#1137

Merged
AttackingOrDefending merged 9 commits into
lichess-bot-devs:masterfrom
MarkZH:implement-new-rate-limits
Oct 1, 2025
Merged

Handle new error message when challenging bots#1137
AttackingOrDefending merged 9 commits into
lichess-bot-devs:masterfrom
MarkZH:implement-new-rate-limits

Conversation

@MarkZH
Copy link
Copy Markdown
Collaborator

@MarkZH MarkZH commented Sep 26, 2025

Detect when the rate limiting status code (429) is due to issuing a challenge after playing more than 100 games in a day. Use the message in the response to delay issuing another challenge.

Type of pull request:

  • Bug fix
  • Feature
  • Other

Description:

The biggest change is setting the time delay according to the ["ratelimit"]["seconds"] field in the response.

Related Issues:

Closes #1135

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):

Reference issue: lichess-bot-devs#1135

Detect when the rate limiting status code (429) is due to issuing more
than 100 challenges in a day. The change to matchmaking prevents adding
other bots to the block list in case the error is due to this rate
limit.
@MarkZH
Copy link
Copy Markdown
Collaborator Author

MarkZH commented Sep 26, 2025

I'm submitting this as a draft since I have more changes planned. Plus, I want to make sure that I'm on the right track in implementing the change to the bot API.

My next change is probably getting rid of Matchmaking.min_wait_time and the increasing delay calculations in Matchmaking. update_daily_challenge_record(). If the user wants to use all of their daily challenges in a short time, they should be able to since the new error message is very explicit.

The purpose of tracking daily challenges was to slow down the issuing of
challenges when the rate limit of 400/day was being approached. However,
now that the number of games is limited to 100/day (whether the bot
issues or receives the challenge), this tracking is redundant.

The rate at which challenges are issued is now entirely controlled by
the matchmaking: challenge_timeout configuration, which specifies how
long after a game ends to issue a new challenge.
Now that challenge times aren't recorded, there's no need for backdated
Timers or the recording of when a Timer was created.
@MarkZH
Copy link
Copy Markdown
Collaborator Author

MarkZH commented Sep 26, 2025

Next: add a message for short matchmaking: challenge_timeout configurations to warn users that they will run out of daily games quickly.

I don't think players will care if their 100 games/day limit is used up quickly or not.

@MarkZH
Copy link
Copy Markdown
Collaborator Author

MarkZH commented Sep 26, 2025

Since the daily game limit also counts games where the bot is challenged, should we include a configuration for a timeout between games? This way, a bot won't accept every challenge and can spread out the 100 games over the whole day.

The matchmaking:challenge_timeout already does this.

Put the rate-limit timeout into the RateLimitedError exception so other parts of the program can use it.

Add a rate-limit Timer to the Matchmaking class so that the user's logs aren't fill with rate-limited messages. Also, change the format of the "Next challenge will be created after" message to include the date since the delay may last into the next day.
This serves as a general rate limit on challenges and is still useful.
Create a function to handle the daily game limit. Update types to
accomodate the response error message.
@MarkZH MarkZH marked this pull request as ready for review September 28, 2025 05:33
@AttackingOrDefending AttackingOrDefending merged commit 5f78477 into lichess-bot-devs:master Oct 1, 2025
23 checks passed
@MarkZH MarkZH deleted the implement-new-rate-limits branch October 1, 2025 23:27
@ornicar
Copy link
Copy Markdown
Collaborator

ornicar commented Oct 2, 2025

I don't think players will care if their 100 games/day limit is used up quickly or not.

Maybe they could care. Imagine you just made a tweak to your bot, and want to see it in action, but all 100 games were played because lichess-bot rushes them asap

r0950336 pushed a commit to r0950336/lichess-bot that referenced this pull request Dec 31, 2025
* Handle new error message when challenging bots

Reference issue: lichess-bot-devs#1135

Detect when the rate limiting status code (429) is due to issuing more
than 100 challenges in a day. The change to matchmaking prevents adding
other bots to the block list in case the error is due to this rate
limit.

* Remove tracking of daily challenges

The purpose of tracking daily challenges was to slow down the issuing of
challenges when the rate limit of 400/day was being approached. However,
now that the number of games is limited to 100/day (whether the bot
issues or receives the challenge), this tracking is redundant.

The rate at which challenges are issued is now entirely controlled by
the matchmaking: challenge_timeout configuration, which specifies how
long after a game ends to issue a new challenge.

* Remove unneeded Timer attributes

Now that challenge times aren't recorded, there's no need for backdated
Timers or the recording of when a Timer was created.

* Delete unused type

* Put daily game limit info in user messages

Put the rate-limit timeout into the RateLimitedError exception so other parts of the program can use it.

Add a rate-limit Timer to the Matchmaking class so that the user's logs aren't fill with rate-limited messages. Also, change the format of the "Next challenge will be created after" message to include the date since the delay may last into the next day.

* Put back Matchmaking.min_wait_time

This serves as a general rate limit on challenges and is still useful.

* Undo unneeded parenthesis move

* Handle daily game limit on first failed challenge

Create a function to handle the daily game limit. Update types to
accomodate the response error message.

* Update wiki regarding daily bot game limits
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.

New lichess ratelimit applies

3 participants