Skip to content

fix(sidecar): persist Gmail history page token to prevent permanent mail loss - #685

Closed
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-investigation-f02d
Closed

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

Conversation

@cursor

@cursor cursor Bot commented Aug 13, 2026

Copy link
Copy Markdown

Summary

  • Persist Gmail history.list nextPageToken in sidecar_state when the 3-page history cap leaves more pages pending
  • Resume pagination from the stored token on the next poll instead of restarting at page 1
  • Clear the token when history listing completes or on history-gap re-anchor (migration 32)

Why

When listNewMessageIds hits MAX_HISTORY_PAGES=3 with a dangling nextPageToken, the poller correctly freezes history_cursor but restarts pagination at page 1 on every subsequent poll. Once pages 1–3 are fully deduped, the cursor can never advance and mail on page 4+ is permanently lost — silent data loss for Workspace sidecar mailboxes during bursts.

Test plan

  • npm test passes locally (gmail-client, workspace-poll, sidecar-state — 60 tests)
  • New regression: two-poll convergence test verifies resume token unblocks tail pages
  • listNewMessageIds returns resumePageToken when truncated

Notes for reviewer

Cherry-pick of validated fix from prior bug-finding runs (cursor/critical-bug-investigation-ba62). Same root cause identified on 2026-08-09 through 2026-08-12 scans; prior PR drafts never merged.

Open in Web View Automation 

…istory

When listNewMessageIds hits the 3-page cap with more pages pending, the
poller froze history_cursor but restarted pagination at page 1 on every
subsequent poll. Once pages 1-3 were fully deduped the cursor could never
advance and mail on page 4+ was permanently lost.

Persist the dangling nextPageToken in sidecar_state (migration 32) and
resume from it on the next poll. Clear the token when the listing completes
or on history-gap re-anchor.

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 0f8bee7 Commit Preview URL

Branch Preview URL
Aug 13 2026, 11:10 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 0f8bee7 Aug 13 2026, 11:11 AM

@schmug

schmug commented Aug 23, 2026

Copy link
Copy Markdown
Owner

Closing as superseded by #686.

This is one of 24 near-identical PRs re-filed daily by an automation that has since been fixed. #686 carries the same Gmail history page-token change and is the one kept open, so no work is lost here.

@schmug schmug closed this 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.

2 participants