Skip to content

fix(trigger): handle Drive rate limits, 410 page token expiry, and clean up comments#4112

Merged
waleedlatif1 merged 3 commits intostagingfrom
fix/google-drive-polling
Apr 11, 2026
Merged

fix(trigger): handle Drive rate limits, 410 page token expiry, and clean up comments#4112
waleedlatif1 merged 3 commits intostagingfrom
fix/google-drive-polling

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Add explicit 403/429 rate limit handling in `fetchChanges` and `getStartPageToken` with clear error messages, consistent with the Calendar and Sheets handlers
  • Handle HTTP 410 (invalid page token) in `fetchChanges` — previously this caused the webhook to enter a permanent failure loop; now it clears the stored token so the next poll re-seeds from the current Drive state via `getStartPageToken`
  • Remove dead `eslint-disable-next-line no-constant-condition` comment (project uses Biome, not ESLint)
  • Remove verbose multi-line comments from the pagination resume token logic and state update block

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 11, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 11, 2026 9:40pm

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 11, 2026

PR Summary

Medium Risk
Changes polling error handling and state updates for Google Drive webhooks; mistakes could cause missed/duplicate events or delayed processing under rate limits, but scope is limited to this provider handler.

Overview
Improves Google Drive polling resilience by treating HTTP 410 page-token expiry and 429/403 quota errors as recoverable: 410 clears the stored pageToken so the next cycle re-seeds, and rate limits are logged and skipped without marking the webhook failed.

Adds explicit Drive rate-limit detection for 403s (rateLimitExceeded/userRateLimitExceeded), preserves existing knownFileIds when re-seeding, and streamlines pagination/state-update commentary while keeping resume-token behavior intact.

Reviewed by Cursor Bugbot for commit ccbc151. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 11, 2026

Greptile Summary

This PR hardens the Google Drive polling handler against two failure modes: HTTP 410 responses (stale page token) are now caught as DrivePageTokenInvalidError, which clears the stored token so the next poll re-seeds cleanly, and HTTP 429/rate-limit 403s are caught as DriveRateLimitError and routed to markWebhookSuccess rather than markWebhookFailed to prevent transient quota exhaustion from eroding the failure budget. An additional correctness fix preserves existing knownFileIds across the re-seed path (config.knownFileIds ?? [] instead of []) so previously-seen files aren't misclassified as "created" after a 410 recovery.

Confidence Score: 5/5

Safe to merge — fixes a genuine retry loop bug and a failure-budget erosion bug with no regressions introduced.

All three new code paths (410, rate-limit, re-seed with preserved knownFileIds) are logically correct. The updateWebhookProviderConfig utility spreads undefined values that JSON.stringify drops, so pageToken is reliably removed from the stored config on 410. No P0/P1 findings remain.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/lib/webhooks/polling/google-drive.ts Adds 410 page-token expiry handling (clears token, re-seeds on next poll), upgrades rate-limit errors to named types caught with markWebhookSuccess, preserves knownFileIds on re-seed, and removes obsolete comments.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[pollWebhook called] --> B{config.pageToken set?}
    B -- No --> C[getStartPageToken]
    C --> D{Rate limit 429/403?}
    D -- Yes --> E[throw DriveRateLimitError]
    D -- No --> F[Seed pageToken + preserve knownFileIds]
    F --> G[markWebhookSuccess → return success]

    B -- Yes --> H[fetchChanges]
    H --> I{HTTP error?}
    I -- 410 --> J[throw DrivePageTokenInvalidError]
    I -- 429/403 RL --> K[throw DriveRateLimitError]
    I -- Other --> L[throw generic Error]
    I -- OK --> M{changes found?}

    M -- None --> N[update pageToken, markWebhookSuccess]
    M -- Some --> O[filterChanges → processChanges → update state]
    O --> P[markWebhookSuccess/Failed]

    E --> Q[catch: DriveRateLimitError]
    K --> Q
    Q --> R[markWebhookSuccess → return success]

    J --> S[catch: DrivePageTokenInvalidError]
    S --> T[clear pageToken via updateWebhookProviderConfig]
    T --> U[markWebhookSuccess → return success]
    U --> V[Next poll re-seeds via getStartPageToken]

    L --> W[catch: generic]
    W --> X[markWebhookFailed → return failure]
Loading

Reviews (3): Last reviewed commit: "fix(trigger): distinguish Drive 403 rate..." | Re-trigger Greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit ccbc151. Configure here.

@waleedlatif1 waleedlatif1 merged commit 6a4f5f2 into staging Apr 11, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/google-drive-polling branch April 11, 2026 22:04
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.

1 participant