catch TorngitRefreshTokenFailedError without retrying#783
catch TorngitRefreshTokenFailedError without retrying#783drazisil-codecov wants to merge 1 commit intomainfrom
Conversation
Token refresh failures (e.g. 400 from GitLab) are not retryable — retrying the same refresh token triggers reuse detection and permanently revokes the token family. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Why no retry? GitLab implements refresh token reuse detection via Doorkeeper: once a refresh token is consumed, it's immediately invalidated. If the same token is submitted again (e.g. by a retry), GitLab revokes the entire token family and all subsequent attempts return 400 permanently. Without this fix, the retry loop doesn't just fail — it actively destroys the token, turning a potentially recoverable situation into a permanent one requiring manual re-authorization. Reference: GitLab Token Unable To Refresh Due To Race Condition – HashiCorp Support |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #783 +/- ##
=======================================
Coverage 92.25% 92.25%
=======================================
Files 1305 1305
Lines 47981 47985 +4
Branches 1636 1636
=======================================
+ Hits 44263 44267 +4
Misses 3407 3407
Partials 311 311
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
TorngitRefreshTokenFailedErrorwas not caught inBaseCodecovTask.get_repo_provider_service, causing Celery to retry the task indefinitely on token refresh failures (e.g. 400 Bad Request from GitLab OAuth)TorngitClientErrorpatternRoot cause
TorngitRefreshTokenFailedErrorinherits fromTorngitError, notTorngitClientError, so it bypassed the existing clean-exit handler.TorngitCantRefreshTokenError(the "no refresh token present" case) was already handled correctly viaTorngitClientError.Test plan
test_get_repo_provider_service_refresh_token_failed— verifies exception is caught, returnsNone, breadcrumb task called withGIT_CLIENT_ERROR, no retry raisedTestBaseCodecovTaskclass passes (22 tests)🤖 Generated with Claude Code
Note
Low Risk
Low risk, targeted change to worker error handling that prevents infinite Celery retries on git-provider token refresh failures while keeping existing breadcrumb/error reporting behavior.
Overview
BaseCodecovTask.get_repo_provider_servicenow explicitly catchesTorngitRefreshTokenFailedErrorand exits cleanly (returningNone) instead of letting the task fail and be retried indefinitely.On refresh-token failure it records a
GIT_CLIENT_ERRORbreadcrumb and logs a warning with stack trace, and a new unit test asserts this behavior.Written by Cursor Bugbot for commit 1eba83f. This will update automatically on new commits. Configure here.