fix(trigger): fix Google Sheets trigger header detection and row index tracking#4109
Conversation
…lastIndexChecked - Replace hardcoded !1:1 header fetch with detectHeaderRow(), which scans the first 10 rows and returns the first non-empty row as headers. This fixes row: null / headers: [] when a sheet has blank rows or a title row above the actual column headers (e.g. headers in row 3). - Rename lastKnownRowCount → lastIndexChecked in GoogleSheetsWebhookConfig and all usage sites to clarify that the value is a row index pointer, not a total count. - Remove config parameter from processRows() since it was unused after the includeHeaders flag was removed.
…data emission - Replace separate getDataRowCount() + detectHeaderRow() with a single fetchSheetState() call that returns rowCount, headers, and headerRowIndex from one A:Z fetch. Saves one Sheets API round-trip per poll cycle when new rows are detected. - Use headerRowIndex to compute adjustedStartRow, preventing the header row (and any blank rows above it) from being emitted as data events when lastIndexChecked was seeded from an empty sheet. - Handle the edge case where the entire batch falls within the header/blank window by advancing the pointer and returning early without fetching rows. - Skip empty rows (row.length === 0) in processRows rather than firing a workflow run with no meaningful data.
…er header skip When all rows in a batch fall within the header/blank window (adjustedStartRow > endRow), the early return was unconditionally updating lastModifiedTime to the current value. If there were additional rows beyond the batch cap, the next Drive pre-check would see an unchanged modifiedTime and skip polling entirely, leaving those rows unprocessed. Mirror the hasRemainingOrFailed pattern from the normal processing path.
…d consistent column scope
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Replaces Reviewed by Cursor Bugbot for commit 9b3af87. Configure here. |
Greptile SummaryThis PR fixes several correctness issues in the Google Sheets polling trigger: auto-detecting the header row (scanning up to 10 rows instead of hardcoding row 1), replacing the old Confidence Score: 5/5Safe to merge; all previously raised concerns are resolved and the updated logic handles edge cases correctly. Thorough review of the single changed file found no P0 or P1 issues. The adjustedStartRow offset, pointer advancement by rowsToFetch, empty-row skip, lastModifiedTime preservation, and first-poll seeding all behave correctly across the edge cases examined (empty leading rows, header mid-sheet, partial-failure retry, batch cap with remaining rows). All three threads from the previous review cycle are resolved. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A([pollWebhook]) --> B[resolveOAuthCredential]
B --> C[isDriveFileUnchanged]
C -->|unchanged| D[updateConfig lastCheckedTimestamp\nmarkWebhookSuccess]
C -->|changed| E[fetchSheetState A:Z\nrowCount · headers · headerRowIndex]
E --> F{lastIndexChecked\nundefined?}
F -->|yes — first poll| G[seed lastIndexChecked = rowCount\nmarkWebhookSuccess]
F -->|no| H{currentRowCount\n<= lastIndexChecked?}
H -->|yes — no new rows| I[update lastIndexChecked = currentRowCount\nmarkWebhookSuccess]
H -->|no — new rows found| J[compute startRow · endRow · rowsToFetch\nadjustedStartRow = max startRow headerRowIndex+1]
J --> K{adjustedStartRow\n> endRow?}
K -->|yes — batch is all header/blank| L[advance pointer by rowsToFetch\npreserve lastModifiedTime if remaining\nmarkWebhookSuccess]
K -->|no| M[fetchRowRange adjustedStartRow→endRow]
M --> N[processRows\nskip empty rows\nfire workflow per row via idempotency]
N --> O{failedCount > 0?}
O -->|all failed| P[markWebhookFailed\ndo NOT advance pointer\nreturn failure]
O -->|partial or none| Q[advance pointer by rowsToFetch\npreserve lastModifiedTime if remaining or failed\nmarkWebhookSuccess]
Reviews (3): Last reviewed commit: "fix(trigger): don't count skipped empty ..." | Re-trigger Greptile |
|
@greptile |
|
@cursor review |
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ 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 9b3af87. Configure here.
Summary
Type of Change
Testing
Tested manually
Checklist