Skip to content

fix(sidecar): resume Gmail history past page cap when pages are deduped - #686

Draft
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/critical-bug-investigation-53d1
Draft

cursor[bot] wants to merge 2 commits into
mainfrom
cursor/critical-bug-investigation-53d1

Conversation

@cursor

@cursor cursor Bot commented Aug 14, 2026

Copy link
Copy Markdown

Bug and impact

When a Gmail history listing spans more than MAX_HISTORY_PAGES (3) and pages 1–3 are fully deduped, truncated=true froze the cursor forever. The poller re-fetched the same three pages every cron tick and never reached page 4+ — silent mail loss during bursts on Workspace sidecar mailboxes.

Root cause

listNewMessageIds correctly sets truncated=true and blocks cursor advancement when a nextPageToken dangles past the page cap. However, the next poll restarted from the same history_cursor with no persisted page token, so already-deduped pages were re-fetched indefinitely.

Fix

  • Add history_page_token column to sidecar_state (migration 32)
  • Pass the saved token to listNewMessageIds on resume
  • Return nextPageToken from listNewMessageIds when truncated
  • Persist/clear the token in pollWorkspaceMailbox alongside cursor advancement rules
  • Clear token on history-gap re-anchor

Validation

Open in Web View Automation 

cursoragent and others added 2 commits August 14, 2026 11:16
…ed (#667)

When Gmail history spans more than MAX_HISTORY_PAGES (3) and pages 1–3 are
fully deduped, truncated=true froze the cursor forever and page 4+ messages
were never ingested — silent data loss during mail bursts.

Persist history_page_token in sidecar_state (migration 32) and pass it to
listNewMessageIds so the next poll resumes from the dangling pageToken
instead of re-fetching already-deduped pages.

Co-authored-by: schmug <schmug@users.noreply.github.com>
…nit test

Complements #667 cherry-pick: first truncated-history poll test now checks
the persisted page token, and gmail-client gets a resumePageToken test.

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 5692f6f Commit Preview URL

Branch Preview URL
Aug 14 2026, 11:17 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 5692f6f Aug 14 2026, 11:18 AM

This was referenced Aug 23, 2026
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