Skip to content

Conversation

justin-tahara
Copy link
Contributor

@justin-tahara justin-tahara commented Sep 26, 2025

Description

[Provide a brief description of the changes in this PR]
Fixing the gmail connector to skip over the emails that do not have gmail enabled. This happens since Flex hit this issue where once of their accounts doesn't have gmail enabled and thus it prevents the entire workflow from working.

This PR aims to skip over the emails that are not enabled with the mail service

How Has This Been Tested?

[Describe the tests you ran to verify your changes]

Additional Options

  • [Optional] Override Linear Check

Summary by cubic

Skip Gmail sync for accounts where the mailbox is disabled so one bad account no longer breaks the workflow. Detects the Gmail “Mail service not enabled” error and continues syncing other users.

  • Bug Fixes
    • Added _is_mail_service_disabled_error to detect 400 failedPrecondition/"Mail service not enabled".
    • Wrapped thread list/get calls with try/except; on match, log a warning and skip the user, otherwise re-raise.
    • Applied to both full thread fetch and slim thread fetch paths.

@justin-tahara justin-tahara requested a review from a team as a code owner September 26, 2025 02:01
Copy link

vercel bot commented Sep 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
internal-search Ready Ready Preview Comment Sep 26, 2025 2:03am

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.

Greptile Overview

Summary

This PR improves the Gmail connector's robustness by adding error handling for users who don't have Gmail enabled on their accounts. Previously, when the connector encountered an account without Gmail service, it would fail the entire sync operation. Now it gracefully skips those users and continues processing other accounts.

The changes include:

  • New _is_mail_service_disabled_error() function to detect Gmail service disabled errors
  • Try-catch blocks in both _fetch_threads() and _fetch_slim_threads() methods
  • Appropriate warning logs when skipping disabled accounts
  • Continued processing of remaining users instead of complete failure

This fix ensures that multi-user Gmail syncing continues to work even when some accounts in the organization don't have Gmail enabled, which is particularly important for enterprise environments with mixed user configurations.

Confidence Score: 4/5

  • This PR is safe to merge with low risk - it only adds error handling without changing core functionality
  • Score reflects solid defensive programming with proper error detection and graceful degradation. The change is well-scoped and maintains backward compatibility while fixing a real production issue.
  • No files require special attention - the error handling implementation is straightforward and well-contained

Important Files Changed

File Analysis

Filename        Score        Overview
backend/onyx/connectors/gmail/connector.py 4/5 Added error handling for disabled Gmail services to gracefully skip users without Gmail enabled instead of failing the entire sync operation

Sequence Diagram

sequenceDiagram
    participant GC as GmailConnector
    participant GS as Gmail Service
    participant API as Gmail API
    participant LOG as Logger

    GC->>GC: _get_all_user_emails()
    loop For each user email
        GC->>GS: get_gmail_service(creds, user_email)
        GS-->>GC: gmail_service
        
        alt User has Gmail enabled
            GC->>API: execute_paginated_retrieval(threads.list)
            API-->>GC: thread list
            loop For each thread
                GC->>API: execute_single_retrieval(threads.get)
                API-->>GC: full thread data
                GC->>GC: thread_to_document(full_thread, user_email)
                GC->>GC: Add to doc_batch
            end
        else User has Gmail disabled
            GC->>API: execute_paginated_retrieval(threads.list)
            API-->>GC: HttpError (Mail service not enabled)
            GC->>GC: _is_mail_service_disabled_error(error)
            GC->>LOG: Warning: Skipping Gmail sync for user
            GC->>GC: continue to next user
        end
    end
    
    GC->>GC: yield doc_batch
Loading

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@Weves Weves merged commit 60f83dd into main Sep 26, 2025
57 of 61 checks passed
@Weves Weves deleted the jtahara/fix-gmail-connector branch September 26, 2025 02:57
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