Issue
Videos were incorrectly archived when YouTube OAuth tokens expired or were revoked, despite these being recoverable authentication issues. The system defaulted to treating such errors as generic server errors, which followed a strict 3-retry policy (30 seconds, 2 minutes, and 5 minutes) before permanently archiving the videos. This required manual intervention to recover videos from archive folders and lost upload progress.
The key error pattern was an OAuth authentication failure:
invalid_grant: Token has been expired or revoked
Culprit
The root cause was a lack of specific handling for authentication failures in the error classification logic. All exceptions, including OAuth-specific errors like token expiration, were defaulted to a generic SERVER_ERROR type. This led to:
- The system calling
credentials.refresh()to attempt token recovery. - The OAuth refresh failing with an
invalid_grantexception. - A generic exception handler classifying the error as
SERVER_ERROR. - The retry logic for server errors allowing only 3 attempts before triggering archival.
- No special handling for authentication error strings such as
invalid_grantortoken has been expired.
Solution
1. Added AUTH_ERROR Classification
An additional error type, AUTH_ERROR, was introduced to explicitly handle OAuth token expiration or revocation cases that require manual re-authentication.
2. Enhanced Error Detection
The system now checks for OAuth-specific error strings, such as:
invalid_granttoken has been expiredtoken has been revokedinvalid_clientunauthorizedaccess_deniedinvalid_tokenexpired_token
If any of these indicators are found, the error is classified as AUTH_ERROR.
3. Infinite Retry Configuration
For authentication errors:
- Retry delays were extended to 5 minutes and then 30 minutes, repeating indefinitely.
- The maximum retry count was set to a practical infinity (999,999 attempts).
- Clear logging instructions were added to guide users on re-authentication.
4. User Guidance
Users are now provided with actionable steps in the logs, such as:
🔐 Horizontal upload failed (auth_error) - retrying in 300 seconds (attempt 1 of ∞). To resolve: Delete stored credentials and restart to re-authenticate.
Result: Videos remain in the upload queue indefinitely with extended retry delays until manual re-authentication occurs, preserving upload progress and eliminating the need for manual recovery.