Repository navigation
Description
What happens
On a self-hosted deployment, the imap-smtp sync ingests an email attachment, writes the bytes to storage, and creates a fileMetadata row — but never binds the attachment to the conversation the email became. Two consequences, one of them silent data loss:
- The attachment is invisible in the inbox. The conversation shows no file. An operator reasonably concludes the sender didn't attach one. On this deployment that meant a job applicant's CV was treated as never sent.
- Every poll re-ingests it. With no binding there is no idempotency key, so the next sync sees the same attachment as new. A fresh blob and a fresh
fileMetadatarow, every cycle, forever.
Scale observed
One deployment, roughly 11 days of running:
- 3,295
fileMetadatarows across 5 distinct filenames - a new storage blob every 5 minutes, each with its own
ObjectKey, nothing consuming them - most rows
failed; ~8 permanentlyqueued
That works out to ~288 orphaned blobs a day indefinitely.
Why it is worse than duplicate rows
Those ~8 queued rows are not parked, so countRagInFlight (convex/file_metadata/rag_dispatch.ts) counts every one of them against MAX_CONCURRENT_RAG_INDEXING_PER_ORG = 3. The cap is therefore permanently saturated by a background job, and every user-uploaded document parks instead of indexing.
On the deployment where this was found, the oldest parked user upload was 7 days old. Nothing a person uploaded had been indexed for a week, with no error shown anywhere. See #2986 for that half.
It is also self-sustaining: the RAG watchdog does clear stale rows every 5 minutes, but the sync mints a replacement on the same cadence, so the in-flight count never drops below the cap and promoteQueuedRagJobs never fires.
Expected
- An ingested attachment is bound to its conversation and visible on it.
- Binding (or a stable external key derived from the message id + attachment) makes re-ingestion idempotent — a second poll of the same message must not create a second blob.
- Attachment ingestion must not consume the interactive indexing budget.
Also worth checking
The re-ingested PDFs on this deployment were 4,445 bytes — implausibly small for the document they claimed to be. The extracted attachment bytes may themselves be truncated or a stub, which would mean the content is wrong even once binding is fixed. Worth verifying extraction independently of this fix.
Where to look
convex/file_metadata/rag_dispatch.ts—countRagInFlight,maybeDispatchRagIndexing- the imap-smtp
sync-emailsautomation and its attachment handling convex/file_metadata/internal_mutations.ts—saveFileMetadata
Activity
Israeltheminer commentedon Aug 19, 2026
Fixed and verified on a self-hosted deployment.
Two halves, both merged:
Verification on a live deployment, from the corpus and metadata tables directly:
The accumulated duplicate rows are left in place. They are unreferenced, nothing indexes them, and cleanup of one deployment's history does not belong in the product.