Skip to content

feat: Telegram-based OAuth recovery flow#10

Open
alf239 wants to merge 2 commits into
atemerev:mainfrom
alf239:feature/telegram-oauth-recovery
Open

feat: Telegram-based OAuth recovery flow#10
alf239 wants to merge 2 commits into
atemerev:mainfrom
alf239:feature/telegram-oauth-recovery

Conversation

@alf239
Copy link
Copy Markdown
Contributor

@alf239 alf239 commented Mar 1, 2026

Summary

When Anthropic returns invalid_grant during token refresh (e.g., token rotated server-side, CLI used elsewhere), instead of dying and requiring manual SSH intervention, this PR enables self-healing via Telegram.

What it does

  1. Detects auth codes in messages — When you paste an OAuth code back, it's recognized and routed to the OAuth layer
  2. OAuth recovery flow — On invalid_grant, sends you a Telegram message with OAuth URL, waits for the code, exchanges it for fresh tokens
  3. Resumes operation — No restart required, no SSH needed

Changes

  • lethe/telegram/init.py: Import and integrate auth code detection
  • lethe/telegram/auth_detection.py: New module to detect OAuth codes in messages
  • lethe/memory/anthropic_oauth.py: Already had recovery flow, now properly wired

Testing

Next time you see invalid_grant, I'll send you a link instead of dying. Click it, paste the code back, and we continue.

- Add hot-reload check at start of ensure_access()
- Detect invalid_grant errors and give clear re-auth instructions
- No more restart needed after oauth-login
- Add oauth_tokens.json to .gitignore
When OAuth refresh fails with invalid_grant, instead of dying:
1. Generate PKCE challenge and OAuth URL
2. Send URL to user via Telegram
3. Wait for user to paste auth code back
4. Exchange code for fresh tokens and resume

This makes the system self-healing - no SSH required to re-auth.
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