Skip to content

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

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

fix(sidecar): resume truncated Gmail history via page token (#595)#645
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/critical-bug-investigation-8154

Conversation

@cursor

@cursor cursor Bot commented Jul 23, 2026

Copy link
Copy Markdown

Summary

  • Fix a Gmail history listing deadlock where sidecar mailboxes silently stopped ingesting mail after a high-volume burst.
  • Persist history_page_token (migration 32) so truncated history listings can resume past the MAX_HISTORY_PAGES cap once the current slice is fully worked.
  • Clear the page token on history-gap re-anchor so a new cursor never resumes with a stale token.

Why

listNewMessageIds caps Gmail history fetches at 3 pages. When the listing is truncated 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 for sidecar-enabled mailboxes.

Concrete trigger: a burst of >3 pages of messageAdded events where the first three pages contain only already-ingested messages leaves the poller stuck re-listing the same deduped slice on every cron tick.

Test plan

  • npm test -- tests/providers/gmail-client.test.ts tests/providers/workspace-poll.test.ts test/durableObject/sidecar-state.test.ts passes locally (59 tests)
  • New regression test covers the truncated-history deadlock and two-poll resume path
  • npm run typecheck passes locally
  • npm test passes locally

Notes for reviewer

Open in Web View Automation 

cursoragent and others added 2 commits July 23, 2026 11:03
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>
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 c19396b Commit Preview URL

Branch Preview URL
Jul 23 2026, 11:04 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 c19396b Jul 23 2026, 11:05 AM

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