Reconnect game stream when it drops mid-game - #1237
Conversation
|
Some initial suggestions:
This is a very complex change, but it looks plausible. |
|
Thanks for the review — addressed in e09b1f2:
Locally: |
|
What do you think about doing if stopped and game_is_active(li, game.id):
raisewhich would simplify this PR? I think it should accomplish everything this does apart from reusing the same engine instance, but I think it is probably better, as it keeps the code simpler and the rest of the code doesn't use same engine reconnect. |
StopIteration previously always left play_game, so a dropped mid-game stream looked like a local game over and the bot could flag with clock remaining. Re-raise so the existing backoff decorator retries play_game (new stream, new engine) while Lichess still lists the game as ongoing.
e09b1f2 to
b870003
Compare
|
Agreed — that's a better fit for this codebase.
Pushed in b870003. The only extra is a warning log so this path is visible at the default log level ( What we give up vs the previous approach, which I think is the right tradeoff here:
|
Type of pull request:
Description:
When the per-game HTTP stream (
/api/bot/game/stream/{id}) ends withStopIterationbut Lichess still lists the game as ongoing, re-raise so the existing@backoff.on_exceptionwrapper retriesplay_game(new stream, new engine) instead of treating it as a local game over.Previously:
So any stream EOF exited the game, even with time on the clock. A dropped mid-game stream then looks like a clean “Game over” locally while Lichess keeps the game alive until the bot flags.
We hit this in production: bot played a move with ~30s remaining, the game stream died, no further search was started, and the game was lost on time.
Retrying
play_gameis enough: the new stream’s initial full game info is injected withprior_game is None, so a search starts immediately if it is our turn.Related Issues:
Checklist:
Screenshots/logs (if applicable):