Skip to content

fix(sidecar): resume truncated Gmail history via history_page_token - #667

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

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

Conversation

@cursor

@cursor cursor Bot commented Jul 31, 2026

Copy link
Copy Markdown

Summary

  • Add history_page_token to sidecar state (migration 32) to resume Gmail history listings truncated by MAX_HISTORY_PAGES
  • Return nextPageToken from listNewMessageIds when the page cap is hit; poller persists it when the batch is drained but the listing is incomplete
  • Clear the page token when the history cursor advances or on history-gap re-anchor

Why

When a Gmail history listing spans more than three pages and the first three pages are entirely deduped (processed=0), the poller re-fetched the same pages every cron tick without advancing history_cursor (correctly frozen while truncated=true) — but with no page-token resume, mail on page 4+ was never ingested.

Test plan

  • npm test passes locally (gmail-client, workspace-poll, sidecar-state)
  • New regression: all-deduped truncated history persists page token and second poll ingests tail mail
  • Existing truncated-history and page-cap tests updated for nextPageToken behavior

Notes for reviewer

The page token is only advanced when !hitCap && truncated — if the per-poll message cap fires mid-batch, the token stays unchanged so already-processed ids dedupe cleanly on the next tick.

Open in Web View Automation 

When a Gmail history listing hits MAX_HISTORY_PAGES with a dangling
nextPageToken and the first N pages are entirely deduped, the poller
re-fetched the same pages every tick without advancing — mail on later
pages was never ingested.

Persist history_page_token in sidecar_state (migration 32) and pass it
to listNewMessageIds on the next poll. Clear the token when the listing
completes and the cursor advances.

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 f10d939 Commit Preview URL

Branch Preview URL
Jul 31 2026, 11:08 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 f10d939 Jul 31 2026, 11:09 AM

"/history": (u) => {
const pageToken = u.searchParams.get("pageToken");
if (!pageToken) {
let pages = 0;
@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.

3 participants