triage agent timed out when Graph API paginated 40000 messages mid-inbox-sweep
Fixes a phish triage agent timing out while paging through a very large mailbox with the Microsoft Graph API, using delta queries, page limits and checkpointing. Use when an inbox sweep of tens of thousands of messages times out mid-pagination. Not for small mailbox sweeps that fail for auth reasons.
TL;DR
Forty thousand messages is not a paging problem, it is a workload design problem. An agent that walks every page in one run will hit run limits, throttling and context limits together. Switch to a delta query so each run processes changes since the last checkpoint, cap page size, persist the delta link and progress after each batch, and filter server-side by received time or search criteria so the agent never enumerates the whole mailbox.
triage agent timed out when Graph API paginated 40000 messages mid-inbox-sweepUse this when
- A triage run times out partway through a huge mailbox sweep.
- Progress restarts from the beginning after every timeout.
Not for this skill when
- The mailbox is small and the failure is a single slow request. That is a request timeout, not pagination scale.
- The agent lacks mailbox permission entirely. Fix access before scale.
Steps
- Reproduce the scale: count messages matching the sweep criteria using a count request or folder statistics. Verify: the true workload size is known.
- Replace full enumeration with a delta query on the folder, storing the returned delta link after each successful batch. Verify: a second run resumes from the delta instead of page one.
- Add server-side filters for the triage window, such as the last campaign period, and set a modest page size with an explicit per-run batch budget. Verify: each run processes a bounded number of messages.
- Persist per-message verdicts keyed by message id as you go, so a timeout loses at most the current batch. Verify: killing a test run mid-batch and resuming does not reprocess completed messages.
- Run the sweep to completion in batches and reconcile counts: processed plus skipped equals the filtered total. Verify: the totals reconcile exactly.
Variant phrasings
graph api delta query large mailbox pagination agent
The delta query variant.
triage agent checkpoint resume inbox sweep timeout
The checkpointing variant.
Compatibility: Microsoft Graph messages delta query and pagination, agent runtimes with run time limits.
Why it happens
Graph pagination is designed for browsing, not bulk extraction. Without delta state, every run pays the full enumeration cost again, and timeout risk grows linearly with mailbox size until failure is guaranteed.
Edge cases / pitfalls
- Delta links expire and can break on folder changes. Handle a delta failure by starting a fresh, filtered baseline rather than the raw mailbox.
- Throttling arrives sooner at large page sizes. Smaller pages with backoff finish faster in practice.
- Record message ids, not positions, as progress. Positions shift as mail arrives.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_4sai-eZI25kOsVQOGZ4oqA