Skip to content

fix(sidecar): resume truncated Gmail history via page token - #635

Open
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-0c3d
Open

fix(sidecar): resume truncated Gmail history via page token#635
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-0c3d

Conversation

@cursor

@cursor cursor Bot commented Jul 20, 2026

Copy link
Copy Markdown

Summary

  • Persist history_page_token in sidecar_state (migration 32) when a Gmail history listing hits MAX_HISTORY_PAGES and the current slice is fully worked
  • Resume the next poll from the dangling nextPageToken instead of re-fetching pages 1–3 forever
  • Clear the token when the listing completes or when a batch cap leaves unprocessed ids in the current slice

Why

listNewMessageIds caps at 3 history pages and correctly freezes the cursor when truncated: true. However, if pages 1–3 are already ingested (all deduped), every subsequent poll re-listed the same pages and never reached page 4+ — silently skipping new mail for busy mailboxes catching up after downtime.

Concrete trigger: >3 pages of Gmail history since the cursor, with the first 3 pages already stored.

Test plan

  • npm test passes locally (workspace-poll, gmail-client, sidecar-state)
  • New regression test: deduped truncated pages save page token; next poll resumes and advances cursor

Notes for reviewer

Minimal fix scoped to the page-cap deadlock. Does not address the separate poll-lease TTL gap during very long batches (>5 min) — that remains a lower-likelihood race.

Open in Web View Automation 

When listNewMessageIds hits MAX_HISTORY_PAGES the cursor correctly stays
frozen, but if pages 1-3 are already deduped the poller re-fetched them
forever and never reached page 4+ — silently skipping new mail.

Persist history_page_token (migration 32) once a truncated slice is fully
worked; the next poll resumes from that nextPageToken with the same cursor.
Clear the token on a complete listing or when a batch cap leaves unprocessed
ids in the current slice.

Co-authored-by: schmug <schmug@users.noreply.github.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ais-hub 2490bb1 Commit Preview URL

Branch Preview URL
Jul 20 2026, 11:03 AM

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
agentic-inbox 2490bb1 Jul 20 2026, 11:04 AM

@schmug
schmug marked this pull request as ready for review July 20, 2026 11:39
@schmug
schmug self-requested a review as a code owner July 20, 2026 11:39
@cursor

cursor Bot commented Jul 20, 2026

Copy link
Copy Markdown
Author

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

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