Repository navigation
Description
What happens
Every mail sync poll re-fetches the newest already-synced message — its body, and all of its attachment bytes — indefinitely, until newer mail displaces it from the boundary. No new conversation or message is created (dedupe works), so the cost is invisible: wasted connector round-trips per poll, and a fresh blob per attachment per poll.
Cause
An off-by-one at the cursor boundary. The cursor is derived from the newest existing message's own timestamp, and the filter that applies it is inclusive.
convex/conversations/sync_mailbox.ts:154-167 — cursorFromMessage:
const since = message.deliveredAt ?? message.sentAt ?? message._creationTime ?? null;lib/connectors/natives/imap-smtp.ts — fetchSummaries, after the IMAP SEARCH:
const cursor = query.since;
return summaries
.filter((message) => cursor === undefined || message.sentAt >= cursor)>=, and cursor is that message's own sentAt. So the boundary message satisfies its own filter on every poll.
Note this is not the SEARCH SINCE date-granularity issue. SINCE is date-granular, but the millisecond re-filter above narrows the candidate set back down — the comment at imap-smtp.ts:1155 says so explicitly. What survives is precisely the messages at or after the cursor, i.e. the boundary message.
Consequences
- One redundant body fetch per poll per mailbox, plus one redundant blob write per attachment on that message.
- Attachment bytes are re-stored under a new
storageIdeach time, becausestoreOrgBlobis not content-addressed and nothing binds an attachment to its message (Bug: imap-smtp re-ingests the same attachment forever because it never binds it to a conversation #2985). Storage grows without bound while a message sits at the boundary. - A quiet mailbox is the worst case: the fewer messages arrive, the longer one message stays at the boundary being re-fetched.
- Since fix(platform): stop email attachments starving the RAG indexing cap #2995 those duplicate rows no longer consume the RAG indexing cap, so this is now storage and connector waste rather than an outage.
This is plausibly the root of the duplicate-blob volume reported under #2985; that issue attributes the re-ingestion to the missing conversation binding, which explains the lack of an idempotency key but not why the same message is fetched again in the first place.
Suggested fix
ConversationSyncCursor already carries the boundary message's identity:
export interface ConversationSyncCursor {
since: number | null;
messageId: string | null; // lib/connectors/natives/platform-conversations.ts:88
}cursorFromMessage populates messageId, but nothing reads it — the other messageId references in sync_mailbox.ts are on wire summaries, not the cursor.
So exclude the boundary by identity rather than by timestamp, and keep >= so a message sharing the boundary's exact timestamp is still picked up. Flipping to a strict > would fix the loop but silently drop same-timestamp siblings, which is how the inclusive compare was probably arrived at.
Verification
A regression test at the fetchSummaries seam: given a cursor equal to a summary's sentAt and that summary's id, the summary is excluded, while a second summary with the same sentAt and a different id is returned. Mutation-test it — a strict > must make the same-timestamp case fail.
Activity
Israeltheminer commentedon Aug 18, 2026
On hold — do not implement yet. The diagnosis above is a code reading and has not been distinguished from the alternative.
Live observation since re-enabling a 5-minute sync: 100+ new
fileMetadatarows, all for a single attachment, all withragStatusunset (so #2995 is confirmed working — none of them consume an indexing slot).That is consistent with the boundary compare described above, but it does not discriminate. Date-granular
SEARCH SINCEre-lists every message from the newest one's calendar day, and only messages carrying attachments producefileMetadatarows — so if the affected message is the only attachment-bearing one in that window, both explanations predict exactly one repeating file.The discriminating check: is the affected message the newest inbound message in that mailbox, or merely on the same calendar day as the newest?
A cleaner version of the same experiment: send a test message with a harmless attachment on a different calendar day from the affected one. Under the boundary explanation the test message becomes the new boundary, so it starts duplicating and the older one stops. If both keep duplicating, this issue is wrong about the mechanism.
Note the useful property — that experiment is also the mitigation, since it moves the boundary off the affected message.
Separately, and regardless of which explanation holds:
fetchBodiesmaterialises attachments before the message dedupe (sync_mailbox.ts:319, the #2985 ordering), so any re-fetch from any cause duplicates. This issue removes the trigger; that ordering removes the class. Both are worth doing, ordering second.Israeltheminer commentedon Aug 18, 2026
Off hold — mechanism confirmed, both in code and live.
Retracting the discriminating check proposed in the previous comment: it was ill-posed. The millisecond re-filter at
imap-smtp.ts:1196runs regardless ofSEARCH SINCEgranularity — it is the same line of code either way — so date-granularity only widens the IMAP candidate set before it is narrowed identically. Date-granularity alone cannot admit an already-ingested message. The inclusive compare is the whole cause, and the two explanations were never independent.The chain is exact, not inferred:
conversations/ingest/build_initial_message.ts:15,25,26—emailTimestamp = new Date(email.date).getTime(), and bothsentAtanddeliveredAtare set to that same instantcursorFromMessage(sync_mailbox.ts:154-167) —since = deliveredAt ?? sentAt ?? _creationTime, so for a delivered inbound message the cursor is that message's own timestampimap-smtp.ts:1196—.filter((message) => message.sentAt >= cursor)Same field, same source,
>=. The newest message satisfies its own filter on every poll, necessarily and indefinitely.Live confirmation: a test message with one attachment produced 4
fileMetadatarows in roughly 20 minutes on a 5-minute poll — one per poll — and all 4 carryragStatusunset, so #2995 continues to hold and none of them consume an indexing slot.Open question that affects where the fix goes, not whether it is right: mail sync fans out per credential, so each credential plausibly carries its own boundary message. If more than one message is repeating, the exclusion has to be per-cursor rather than global. Worth confirming before implementation.
The fix suggestion in the description stands — exclude the boundary by the
messageIdthe cursor already carries (and which nothing currently reads), keeping>=so a genuine same-timestamp sibling is still ingested.