Skip to content

fix(bot): re-exchange tokens on 401 instead of rotating refresh#108

Merged
dzhhem merged 1 commit into
masterfrom
fix/bot-token-reexchange
Jun 29, 2026
Merged

fix(bot): re-exchange tokens on 401 instead of rotating refresh#108
dzhhem merged 1 commit into
masterfrom
fix/bot-token-reexchange

Conversation

@dzhhem

@dzhhem dzhhem commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

What

Stop the bot from rotating refresh tokens. On a 401 it now re-exchanges telegramId + name for a fresh token pair (one retry), instead of calling /auth/telegram/refresh. Adds a 20s fetch timeout; tokenStore now persists name alongside the tokens. API unchanged.

Why

Fixes the intermittent Failed to load history/summary flap. 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 holds telegramId + bot secret), so it can just mint fresh tokens via the already-battle-tested exchange endpoint — removing refresh removes the entire failure class.

Testing

Manual: spam /history / /summary repeatedly — no more Failed to load. n/a automated (no test infra for the bot yet).

@dzhhem dzhhem self-assigned this Jun 29, 2026
@dzhhem dzhhem merged commit 0cbcd87 into master Jun 29, 2026
12 checks passed
@dzhhem dzhhem deleted the fix/bot-token-reexchange branch June 29, 2026 12:44
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.

1 participant