Skip to content

Raise OAuthRefreshException on refresh failure and remove dead retry flow#109

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/remove-retry-logic-and-exceptions
Open

Raise OAuthRefreshException on refresh failure and remove dead retry flow#109
Copilot wants to merge 3 commits into
mainfrom
copilot/remove-retry-logic-and-exceptions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 1, 2026

OAuth refresh failures regressed to silent behavior: OAuthRefreshException existed but was never raised. Since refresh retries are effectively disabled (MAX_RETRIES = 1), the retry guard/error-logging branch added complexity without behavior value.

  • Refresh failure semantics

    • TokenAuth.refresh_token() now raises OAuthRefreshException directly when oauth/token refresh calls fail (OAuthException / BadRequestException) instead of logging and returning.
    • Failure path marks token state invalid before propagating the exception.
  • Retry path cleanup

    • Removed single-attempt retry bookkeeping (MAX_RETRIES gate + refresh_attempts state/checks).
    • Deleted duplicate refresh-error extraction/logging logic in api.py; exception payload parsing remains encapsulated in OAuthRefreshException.
  • Refresh state safety

    • validate_token() now resets TOKEN_UNDER_REFRESH in a finally block so failed refresh attempts cannot leave refresh state stuck.
  • Regression coverage

    • Added API-level test to assert expired-token refresh failure raises OAuthRefreshException with expected error / error_description, and confirms refresh state/token validity flags are updated correctly.
try:
    response = self.client.post('oauth/token', data)
except (OAuthException, BadRequestException) as e:
    self.OAUTH_TOKEN_VALID = False
    raise OAuthRefreshException(response=e.response) from e

Copilot AI changed the title Raise OAuthRefreshException and remove retry bookkeeping Raise OAuthRefreshException on refresh failure and remove dead retry flow Jun 1, 2026
Copilot finished work on behalf of glensc June 1, 2026 11:11
Copilot AI requested a review from glensc June 1, 2026 11:11
glensc and others added 3 commits June 1, 2026 15:22
- Ensure TOKEN_UNDER_REFRESH is cleared on failures
- Avoid leaving token auth stuck in refresh state

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: OpenCode (gpt-5.4) <noreply@openai.com>
- Replace inline refresh logging with OAuthRefreshException
- Remove retry bookkeeping tied to the old failure path

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: OpenCode (gpt-5.4) <noreply@openai.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: OpenCode (gpt-5.4) <noreply@openai.com>
@glensc glensc force-pushed the copilot/remove-retry-logic-and-exceptions branch from 4370ed0 to 3b53f18 Compare June 1, 2026 12:23
@glensc glensc marked this pull request as ready for review June 1, 2026 12:23
@glensc glensc requested a review from Copilot June 1, 2026 12:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restores explicit failure semantics for OAuth token refresh by raising OAuthRefreshException when refresh requests fail, while simplifying the refresh flow by removing effectively-dead retry bookkeeping and ensuring refresh state is always reset.

Changes:

  • Raise OAuthRefreshException on refresh failures (instead of logging and returning) and mark token validity as false.
  • Remove unused retry state/guards around refresh attempts.
  • Ensure TOKEN_UNDER_REFRESH is reset via a finally block; add a regression test for refresh-failure behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
trakt/api.py Raises OAuthRefreshException on refresh failure, removes dead retry logic, and guarantees refresh-state reset.
tests/test_oauth.py Adds regression coverage for expired-token refresh failure raising OAuthRefreshException and updating state flags.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread trakt/api.py
Comment thread tests/test_oauth.py
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.

3 participants