Skip to content

Bug: imap-smtp re-ingests the same attachment forever because it never binds it to a conversation #2985

Closed

Description

@Israeltheminer

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:

  1. 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.
  2. 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 fileMetadata row, every cycle, forever.

Scale observed

One deployment, roughly 11 days of running:

  • 3,295 fileMetadata rows across 5 distinct filenames
  • a new storage blob every 5 minutes, each with its own ObjectKey, nothing consuming them
  • most rows failed; ~8 permanently queued

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-emails automation and its attachment handling
  • convex/file_metadata/internal_mutations.ts — saveFileMetadata

Activity

  1. Israeltheminer commented on Aug 19, 2026

    @Israeltheminer
    ContributorAuthor

    Fixed and verified on a self-hosted deployment.

    Two halves, both merged:

    Verification on a live deployment, from the corpus and metadata tables directly:

    • Duplication had produced 340 rows from two files, at a rate matching one per five-minute poll exactly.
    • After the fix, an inbound attachment produced a single row, and it carried its conversation binding.
    • The backlog needed no manual repair. The sync re-processes existing mail, so under feat(platform): index an emailed attachment for its conversation #3012 that path bound and queued the earlier attachments on its own.
    • All duplicates were confirmed byte-identical by blob SHA-256, and exactly one copy per group was referenced by a message — so nothing user-visible depended on the extras.

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority: highservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions