← Back to Pull requests

fix(google_drive): sync a file shared between users only once #4902

Open
unknown opened this pull request with 487 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 03, 2026 13:15 UTC
Author

Relates to: no issue

This is a bug I found while reading the Google Drive connector.

With domain-wide delegation enabled, get_docs and get_docs_incrementally list the My Drive of every user in the workspace (list_files_from_my_drive, corpora="user"). A file shared with several users is in each of their listings. To process it only once, both methods create a seen_ids set and pass it to prepare_files, which drops files that are already in it:

# Keep track of seen file ids. If a file is shared directly
# with google workspace users it can be discovered multiple times.
# This is an optimization to process unique files only once.
seen_ids = set()

# Filter out files that have been already processed
new_files = [file for file in files if file.get("id") not in seen_ids]

But nothing ever adds an id to seen_ids (it has been like this since domain-wide delegation was added in #1602), so the filter never removes anything. A file shared with N users is prepared and yielded N times in the same sync:

  • with DLS enabled, its permissions are fetched N times;

  • the sink has already popped its _id from the existing ids after the first copy, so the other copies are queued as new documents and, with content extraction enabled, the file is downloaded and extracted again each time;

  • the sync job's document counts include the duplicates.
  • The fix adds the ids of the files prepared from each page to seen_ids, so a file is synced from the first listing it is found in.

    The personal drives used to be listed with no path lookup (paths={}), and the folder paths were resolved only afterwards for the shared drives listing (list_files, corpora="allDrives"), which also returns files of the shared drives account's own My Drive and files shared with it. Such a file used to be yielded again from that listing with its path, so keeping only the first copy would lose the path. The folder paths are therefore now resolved before the personal drives are listed and used there too, so the copy that is kept gets the same path that the shared drives listing would have given it. (Shared drive files themselves are not in the My Drive listings, includeItemsFromAllDrives=False.)

    Checklists

    Pre-Review Checklist


  • this PR does NOT contain credentials of any kind, such as API keys or username/passwords (double check config.yml.example)

  • this PR has a meaningful title

  • this PR links to all relevant github issues that it fixes or partially addresses

  • this PR has a thorough description

  • Covered the changes with automated tests

  • Tested the changes locally

  • Added a label for each target release version (example: v7.13.2, v7.14.0, v8.0.0)

  • Considered corresponding documentation changes

  • Contributed any configuration settings changes to the configuration reference

  • if you added or changed Rich Configurable Fields for a Native Connector, you made a corresponding PR in Kibana
  • Tests

    In tests/sources/test_google_drive.py:

  • test_get_docs_with_domain_wide_delegation_yields_shared_file_once: two users, the first with a shared file and a file of their own, the second with the same shared file. The test checks that get_docs yields shared_id and own_id once each.
  • The new test fails on main (['shared_id', 'own_id', 'shared_id']) and passes with the fix. The rest of test_google_drive.py has the same results before and after the change (on my Windows machine, test_get_content fails on main too because of the local base64 command). ruff check and ruff format --check are clean, apart from the repo-wide CPY001 notice.

    🤖 Generated with Claude Code

    Diff: 487 lines (+365 / -122) across 6 files Reviewer: ShivamSharma43 Review duration: 27806m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.47) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 487 lines diff across 6 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.370
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #4902"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.4% (MEDIUM) · Higher = larger blast radius
    47.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.2% · Safe to merge
    25.2%