lichess-org / lila

♞ lichess.org: the forever free, adless and open source chess server ♞
https://lichess.org
GNU Affero General Public License v3.0
15.63k stars 2.28k forks source link

Bot cannot abort or resign after another bot challenged it and left #15318

Closed greg-finley closed 5 months ago

greg-finley commented 5 months ago

Exact URL of where the bug happened

https://lichess.org/DJbIIQtieK1K

Steps to reproduce the bug

Another bot challenged mine and went offline.

What did you expect to happen?

Either the game aborts automatically, or I can manually abort it.

Using the bot's API key:

curl --location --request POST 'https://lichess.org/api/bot/game/DJbIIQti/abort'

{
    "error": "This game can no longer be aborted"
}

curl --location --request POST 'https://lichess.org/api/bot/game/DJbIIQti/resign'

{
    "error": "This game cannot be resigned"
}

What happened instead?

Now the game is hanging and using up a thread.

Operating system

n/a

Browser and version (or alternate access method)

bot API

Additional information

No response

kelseyde commented 5 months ago

The same is happening for my bot, against the same opponent: https://lichess.org/jOFDwY6j

The lichess-bot say 400 Bad Request when trying to abort the game: https://lichess.org/api/bot/game/jOFDwY6j/abort

If I log in to my bot's Lichess account and try to resign the game via the UI, the orange 'resign' flag is unresponsive.

greg-finley commented 5 months ago

Looks like the offending bot has 25 such open games

tors42 commented 5 months ago

It is possible to set rules for the game when sending the challenge, https://lichess.org/api#tag/Challenges/operation/challengeCreate

If the challenge contains the rule noAbort, that would currently lead to this behaviour...

So one way to avoid the problem, is to decline / not accept the challenge if it contains the rule noAbort

And possibly it doesn't make sense for BOTs to play games with the rule noAbort, so maybe that rule could be disabled for BOT challenges in some future update...

Example of incoming challenge with noAbort rule ```json { "type": "challenge", "challenge": { "id": "CmcSdfd6", "url": "http://localhost:8080/CmcSdfd6", "status": "created", "challenger": { "id": "ana", "name": "Ana", "rating": 1739, "title": null, "online": true, "lag": 4 }, "destUser": { "id": "bot0", "name": "Bot0", "rating": 1500, "title": "BOT", "provisional": true, "online": true }, "variant": { "key": "standard", "name": "Standard", "short": "Std" }, "rated": false, "speed": "rapid", "timeControl": { "type": "clock", "limit": 600, "increment": 5, "show": "10+5" }, "color": "random", "finalColor": "white", "perf": { "icon": "", "name": "Rapid" }, "rules": [ "noAbort" ] }, "compat": { "bot": true, "board": true } } ```
greg-finley commented 5 months ago

Thanks @tors42 I thought about this as well. I saw that the main wrapper to make Lichess bots doesn't seem to pass noAbort, but who knows what the person who made this bot used. It seems unlikely they would have known to toggle on that option if they wrote the code on their own.

Also it would be interesting to retrieve the game rules via the API for these stuck games, but I don't think there's a way?

kelseyde commented 5 months ago

Cheers @tors42, I will look into that option in the future.

Do you have an idea if there's any way to terminate this ongoing game? My bot is stuck now in a loop of trying to abort, and can't start any new games.

Thanks, Dan

tors42 commented 5 months ago

Do you have an idea if there's any way to terminate this ongoing game?

I don't know of any ways to terminate the game...

My bot is stuck now in a loop of trying to abort, and can't start any new games.

If you have implemented the Lichess client yourself, you could add some mechanism to ignore this specific game id or user, I.e not try to abort it and not try to connect to it to play it.

If you are using some library, you could check if the library has support to ignore games by id or by user, or some other mechanism.

It is allowed to have multiple ongoing games.

skycloudd commented 5 months ago

This also happened to my bot. https://lichess.org/xrTxLW8i/black

It would be extremely helpful if these games could somehow be aborted anyway. I think it's clear that this is harmful behaviour from the bot in question by starting many games like this and never playing a move.

Torom commented 5 months ago

I think the best first step would be to ban https://lichess.org/@/HaBaGuBot. He's obviously doing it on purpose. Ideally, his games would be cancelled when he's banned.

kelseyde commented 5 months ago

Agreed, they have 80+ active games now, all of which are abandoned...

greg-finley commented 5 months ago

Hmm now my original link is 404'ing and I have a thread back available, so I guess it takes care of itself after a while? Or someone intervened?

kelseyde commented 5 months ago

I got a notification saying someone I reported was banned, so it seems someone at Lichess intervened!

greg-finley commented 5 months ago

Nice, though I still see the bot having many games hanging still (though not with my bot). 🤷