stop infinite retry loop on rejected Lichess tokens
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 12s
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 12s
A gamer's periodic check would get permanently stuck if their stored token was revoked/expired: our stats API collapsed both "Lichess rejected the token" (401/403, permanent) and genuine transient errors into the same 502 response, so the bot treated an invalid token exactly like a network blip — retrying the same window forever at a capped 300s backoff, never advancing the checkpoint (observed in prod: Dor1zz stuck for 100+ consecutive errors over 8+ hours, admin alerts firing every 25 failures). Preserve the distinction that already existed one layer down (lichess_client.py already tells 401/403 apart from other failures) instead of collapsing it in stats_service.py: add PuzzleOfPeriodResponse.auth_failed, have main.py return 401 specifically for that case, and have the bot raise a distinct InvalidTokenError instead of returning None. On InvalidTokenError, the bot now clears the token for that pair, notifies the user to reconnect via /addtoken, and continues tracking games normally instead of stalling forever.
This commit is contained in:
parent
8080921141
commit
619c00aa06
7 changed files with 70 additions and 16 deletions
|
|
@ -335,6 +335,16 @@ class Database:
|
|||
)
|
||||
conn.commit()
|
||||
|
||||
def clear_user_gamer_token(self, user_id: int, gamer_id: int):
|
||||
"""Clear a rejected/expired token so periodic checks stop sending it (games-only monitoring continues)."""
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"UPDATE user_gamers SET token = NULL WHERE user_id = ? AND gamer_id = ?",
|
||||
(user_id, gamer_id)
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
def get_period_checkpoint(self, user_id: int, gamer_id: int) -> Optional[int]:
|
||||
"""Get persisted period checkpoint timestamp (seconds since epoch)."""
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue