Skip to content

fix(trigger): fix polling trigger config defaults, row count, clock-skew, and stale config clearing#4101

Merged
waleedlatif1 merged 3 commits intostagingfrom
waleedlatif1/fix-sheets-trigger-header-mapping
Apr 11, 2026
Merged

fix(trigger): fix polling trigger config defaults, row count, clock-skew, and stale config clearing#4101
waleedlatif1 merged 3 commits intostagingfrom
waleedlatif1/fix-sheets-trigger-header-mapping

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Fix `getConfigValue` and `useTriggerConfigAggregation` applying `defaultValue` only to required fields — now applies to all fields so optional defaults aren't silently dropped
  • Clear stale `providerConfig` entries in `buildProviderConfig` when a field has no value, preventing old deployment values from persisting as false positives
  • Remove `includeHeaders` toggle from Google Sheets trigger — headers are always fetched and rows always mapped to key-value objects
  • Fix `getDataRowCount` to fetch `A:Z` with `majorDimension=ROWS` instead of column A only — rows with data in non-A columns are now counted correctly
  • Fix Google Calendar first-poll seed to use `now - 30s` and advance cursor to `latestUpdated - 5s` for clock-skew safety; remove `orderBy: 'updated'` (incompatible with `updatedMin`)
  • Fix Google Drive resume token to use `newStartPageToken` (guaranteed by API) instead of stale `config.pageToken` when slicing occurs on a single oversized page
  • Add `triggerSave` to `SYSTEM_SUBBLOCK_IDS` to prevent the UI-only save button subblock from polluting `providerConfig`

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 0:21am

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 11, 2026

PR Summary

Medium Risk
Touches trigger deployment config building/validation and multiple polling cursors (Calendar/Drive/Sheets), which could change when webhooks are created or events are emitted if edge cases were previously relied on.

Overview
Fixes trigger config aggregation/deploy so defaultValue is applied for all empty fields (not just required ones) and UI-only subblocks (including new triggerSave) are excluded.

Improves webhook deploy validation by clearing stale providerConfig values and by treating canonical parameter groups as satisfied when any member is filled, avoiding false “missing required field” errors.

Hardens Google polling triggers: Calendar seeds/advances timestamps with clock-skew overlap and removes an incompatible orderBy; Drive resume tokens now rely on API-provided tokens and known-file tracking favors recent IDs; Sheets always fetches headers/maps rows and fixes row counting to include data outside column A.

Reviewed by Cursor Bugbot for commit 9b13e7e. Configure here.

…sing required-field validation

Use a dedicated `filledSubBlockIds` Set populated during the first pass so the second-pass skip guard is based solely on live `getConfigValue` results, not on stale entries spread from `baseConfig` (`triggerConfig`).
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 11, 2026

Greptile Summary

This PR is a focused bug-fix batch for polling trigger infrastructure: it corrects defaultValue application for optional fields (both in the client aggregation hook and the server-side deploy path), clears stale providerConfig entries that could leak old deployment values, improves row-count accuracy for Google Sheets (A:Z vs column-A-only), fixes the Google Calendar first-poll seed and clock-skew cursor, corrects the Google Drive resume token for single oversized pages, and keeps the triggerSave UI subblock out of providerConfig by adding it to SYSTEM_SUBBLOCK_IDS.

Confidence Score: 5/5

Safe to merge — all fixes are targeted and correct; no new bugs introduced.

Every fix in the PR has been traced through its logic: the Calendar Math.max regression guard is sound, the Drive single-page resume token correctly uses the API-guaranteed newStartPageToken, the Sheets row-count expansion to A:Z is a clear improvement (with the AA+ limitation already acknowledged by the team), buildProviderConfig stale-entry deletion is safe, and triggerSave correctly joins SYSTEM_SUBBLOCK_IDS. No P0/P1 issues found.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/hooks/use-trigger-config-aggregation.ts Applies defaultValue for all fields (not just required ones) in useTriggerConfigAggregation; logic is clean and symmetric with the server-side fix in deploy.ts.
apps/sim/lib/webhooks/deploy.ts Fixes getConfigValue default-value logic and adds stale-entry deletion in buildProviderConfig; two-pass required-field validation is preserved and sound.
apps/sim/lib/webhooks/polling/google-calendar.ts First-poll seed changed to now - 30s, cursor advances to max(latestUpdated - 5s, lastCheckedTimestamp) preventing regression, orderBy: updated removed; all edge-cases handled correctly.
apps/sim/lib/webhooks/polling/google-drive.ts Resume token logic corrected: single oversized page now uses newStartPageToken (API-guaranteed) instead of stale config.pageToken; multi-page and MAX_PAGES paths are also correct.
apps/sim/lib/webhooks/polling/google-sheets.ts getDataRowCount now fetches A:Z with majorDimension=ROWS, correctly counting rows where column A is empty; includeHeaders removed; row arithmetic is consistent with header-inclusive count.
apps/sim/triggers/constants.ts Adds triggerSave to SYSTEM_SUBBLOCK_IDS, preventing the UI-only save button from leaking into providerConfig.
apps/sim/triggers/google-sheets/poller.ts Removes the includeHeaders subblock; headers are always fetched and rows always mapped to key-value objects in the poller, making this option redundant.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Poll cycle starts] --> B{First poll?}
    B -- yes --> C[Seed cursor / pageToken\nnow - 30s for Calendar\nstartPageToken for Drive\nrowCount for Sheets]
    C --> Z[Mark success, return]

    B -- no --> D[Fetch events / changes / rows]
    D --> E{Any results?}
    E -- none --> F[Update cursor / pageToken\nMark success, return]
    E -- some --> G[Filter client-side]

    G --> H[Process each item\nwith idempotency]
    H --> I{failedCount > 0?}

    I -- all failed --> J[Keep cursor,\nMark failure]
    I -- some/none failed --> K[Advance cursor safely]

    K -- Calendar --> L[max latestUpdated - 5s,\nlastCheckedTimestamp]
    K -- Drive --> M[newStartPageToken if last page\nlastNextPageToken if mid-list]
    K -- Sheets --> N[lastKnownRowCount\n+ rowsToFetch]

    L --> Z2[Mark success, return]
    M --> Z2
    N --> Z2
Loading

Reviews (2): Last reviewed commit: "fix(trigger): prevent calendar cursor re..." | Re-trigger Greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

Addressed the Greptile P2 for the Calendar cursor regression (lines 138–144): fixed in 9b13e7e. When all returned events are filtered client-side, latestUpdated - 5s could fall below config.lastCheckedTimestamp, causing the cursor to regress and the same events to be re-fetched on every poll.

Fix: cursor now uses Math.max(latestUpdated - 5000ms, config.lastCheckedTimestamp), so it never goes backward. Clock-skew overlap still applies when latestUpdated is meaningfully ahead of the cursor.

@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 9b13e7e. Configure here.

@waleedlatif1 waleedlatif1 merged commit 8bbca9b into staging Apr 11, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/fix-sheets-trigger-header-mapping branch April 11, 2026 00:41
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