From a8baa494508d440f644ababc36715e35ad9aa531 Mon Sep 17 00:00:00 2001 From: waleed Date: Thu, 9 Apr 2026 16:33:39 -0700 Subject: [PATCH] fix(polling): don't advance state when all events fail across sheets, calendar, drive handlers --- apps/sim/lib/webhooks/polling/google-calendar.ts | 6 ++++-- apps/sim/lib/webhooks/polling/google-drive.ts | 6 +++++- apps/sim/lib/webhooks/polling/google-sheets.ts | 8 +------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/sim/lib/webhooks/polling/google-calendar.ts b/apps/sim/lib/webhooks/polling/google-calendar.ts index abb06c8243..b57400d109 100644 --- a/apps/sim/lib/webhooks/polling/google-calendar.ts +++ b/apps/sim/lib/webhooks/polling/google-calendar.ts @@ -140,8 +140,10 @@ export const googleCalendarPollingHandler: PollingProviderHandler = { logger ) - // Use the latest `updated` value from response to avoid clock skew - const newTimestamp = latestUpdated || now.toISOString() + const newTimestamp = + processedCount === 0 && failedCount > 0 + ? config.lastCheckedTimestamp + : latestUpdated || now.toISOString() await updateWebhookProviderConfig(webhookId, { lastCheckedTimestamp: newTimestamp }, logger) if (failedCount > 0 && processedCount === 0) { diff --git a/apps/sim/lib/webhooks/polling/google-drive.ts b/apps/sim/lib/webhooks/polling/google-drive.ts index 2ea50a4274..5e2be5b4b9 100644 --- a/apps/sim/lib/webhooks/polling/google-drive.ts +++ b/apps/sim/lib/webhooks/polling/google-drive.ts @@ -151,9 +151,13 @@ export const googleDrivePollingHandler: PollingProviderHandler = { MAX_KNOWN_FILE_IDS ) + const allFailed = processedCount === 0 && failedCount > 0 await updateWebhookProviderConfig( webhookId, - { pageToken: newStartPageToken, knownFileIds: mergedKnownIds }, + { + pageToken: allFailed ? config.pageToken : newStartPageToken, + knownFileIds: allFailed ? existingKnownIds : mergedKnownIds, + }, logger ) diff --git a/apps/sim/lib/webhooks/polling/google-sheets.ts b/apps/sim/lib/webhooks/polling/google-sheets.ts index 636a4d0654..8a51615e86 100644 --- a/apps/sim/lib/webhooks/polling/google-sheets.ts +++ b/apps/sim/lib/webhooks/polling/google-sheets.ts @@ -182,14 +182,8 @@ export const googleSheetsPollingHandler: PollingProviderHandler = { logger ) - // Advance row count only by successfully processed rows so failed rows - // can be retried on the next poll cycle. Idempotency deduplicates the - // already-processed rows when they are re-fetched. - const rowsAdvanced = failedCount > 0 ? processedCount : rowsToFetch + const rowsAdvanced = failedCount > 0 ? 0 : rowsToFetch const newLastKnownRowCount = config.lastKnownRowCount + rowsAdvanced - // When batching (more rows than maxRowsPerPoll) or retrying failed rows, - // keep the old lastModifiedTime so the Drive pre-check doesn't skip - // remaining/retried rows on the next poll. const hasRemainingOrFailed = rowsAdvanced < newRowCount await updateWebhookProviderConfig( webhookId,