fix(bot): re-exchange tokens on 401 instead of rotating refresh#108
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Stop the bot from rotating refresh tokens. On a 401 it now re-exchanges
telegramId+namefor a fresh token pair (one retry), instead of calling/auth/telegram/refresh. Adds a 20s fetch timeout;tokenStorenow persistsnamealongside the tokens. API unchanged.Why
Fixes the intermittent
Failed to load history/summaryflap. Access TTL is 15 min, so the bot refreshed often; the API's refresh does rotation + reuse-detection, and a Render free cold start (30–50s) sometimes lost the refresh response after the server already rotated. The bot kept the old refresh token, replayed it, the API read that as token theft and revoked the whole session family → 401 → flap until a re-exchange. The bot is a trusted service client (it holdstelegramId+ bot secret), so it can just mint fresh tokens via the already-battle-testedexchangeendpoint — removing refresh removes the entire failure class.Testing
Manual: spam
/history//summaryrepeatedly — no moreFailed to load. n/a automated (no test infra for the bot yet).