fix(backend): detect stale/revoked GitHub tokens and prompt re-auth - #105
Open
faizahmad-khan wants to merge 2 commits into
Open
fix(backend): detect stale/revoked GitHub tokens and prompt re-auth#105faizahmad-khan wants to merge 2 commits into
faizahmad-khan wants to merge 2 commits into
Conversation
- github_service.py: catch GithubException 401 in commit_files and
return {error: 'invalid_token'} instead of falling through to unknown
- supabase_service.py: add clear_github_token() to wipe dead credentials
- bot.py: handle invalid_token in commit_confirm and force_commit callbacks
— clear the token from DB and send a targeted /auth re-prompt
- routes/staged_files.py: return HTTP 401 (not 500) on invalid_token
from /commit-direct so VS Code extension can show a clear error
Fixes #YOUR_ISSUE_NUMBER
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…ithub_username functions
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.
📋 Pull Request Description
When a user's GitHub token is revoked or expires,
commit_filesingithub_service.pyhad no401handler — theGithubException(401)fell straight through to the bareexcept Exceptionblock, returning a generic"Unknown error". Both the Telegram bot and VS Code/commit-directendpoint would silently swallow this error with no recovery guidance, leaving users permanently stuck with staged files that could never be committed.This PR implements full stale-token detection and recovery across 4 files:
github_service.py: Added a401check incommit_files' outerGithubExceptionhandler — returns{"error": "invalid_token"}instead of falling through to unknown.supabase_service.py: Addedclear_github_token(telegram_id)to wipe the dead credential from the database, mirroring the existingupdate_github_tokenpattern.bot.py: Bothcommit_confirm_callbackandcommit_force_callbacknow handleinvalid_token— clearing the stale token from DB and sending the user an actionable re-auth message: "🔑 Your GitHub token has expired or been revoked. Please run /auth to reconnect."routes/staged_files.py:POST /commit-directnow returnsHTTP 401with a descriptive message instead of the previous genericHTTP 500, so the VS Code extension can surface a clear error to the user.🔗 Related Issue
Closes #
🏷️ PR Type
✅ Checklist
mainECSoC26label to this PRruff check backend/locally and it passesnpx tsc --noEmitlocally and it passes.envfiles, secrets, or tokens🧪 How to Test
/auth/files→ select file → enter commit message → confirm/filesagain — the bot should prompt re-authenticationCommit Allwith a revoked token → extension should receiveHTTP 401with a descriptive message📸 Screenshots (if UI changes)
N/A — backend fix only.