Skip to content

Conversation

evan-onyx
Copy link
Contributor

@evan-onyx evan-onyx commented May 23, 2025

Description

Fixes https://linear.app/danswer/issue/DAN-2012/refresh-drive-creds-during-perm-sync
When drive perm sync runs for a while, we sometimes get the following difficult-to-explain exception:

google.auth.exceptions.RefreshError: ('unauthorized_client: Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested.', {'error': 'unauthorized_client', 'error_description': 'Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested.'})

This can happen several hours into permission syncing despite the fact that drive tokens auto-refresh roughly every hour. So, presumably 1 or 2 refreshes succeed, then one fails.

How Has This Been Tested?

n/a

Backporting (check the box to trigger backport action)

Note: You have to check that the action passes, otherwise resolve the conflicts manually and tag the patches.

  • This PR should be backported (make sure to check that the backport attempt succeeds)
  • [Optional] Override Linear Check

@evan-onyx evan-onyx requested a review from a team as a code owner May 23, 2025 21:25
Copy link

vercel bot commented May 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
internal-search ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 23, 2025 9:25pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR addresses a Google Drive token refresh issue during permission sync by introducing a RefreshableDriveObject wrapper and improved credential management.

  • Added RefreshableDriveObject in resources.py to handle token refresh failures and retries during Drive API calls
  • Modified get_permissions_by_ids in permission_retrieval.py to use RefreshableDriveObject instead of raw Resource
  • Added _creds_dict storage in GoogleDriveConnector to maintain credential state for refresh operations
  • Implemented _drive_connector_creds_getter in doc_sync.py to properly handle credential retrieval and refresh cycles
  • Added error logging for missing owner emails and improved type hints for credential objects

4 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

@Weves Weves enabled auto-merge May 23, 2025 21:41
@Weves Weves added this pull request to the merge queue May 23, 2025
Merged via the queue into main with commit dad99cb May 24, 2025
11 of 12 checks passed
@Weves Weves deleted the bugfix/refresh-drive-creds branch May 24, 2025 00:03
ferdinandl007 pushed a commit to ferdinandl007/onyx that referenced this pull request May 27, 2025
aronszanto pushed a commit to aronszanto/onyx that referenced this pull request May 27, 2025
ZhipengHe pushed a commit to ZhipengHe/onyx that referenced this pull request Jun 6, 2025
AnkitTukatek pushed a commit to TukaTek/onyx that referenced this pull request Sep 23, 2025
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.

2 participants