Skip to content

fix(platform): stop email attachments starving the RAG indexing cap - #2995

Merged
Israeltheminer merged 1 commit into
mainfrom
fix/email-attachment-rag-cap
Aug 17, 2026
Merged

Israeltheminer merged 1 commit into
mainfrom
fix/email-attachment-rag-cap

Conversation

@Israeltheminer

Copy link
Copy Markdown
Contributor

Storing an inbound email attachment left its fileMetadata row at ragStatus: 'queued' with no indexing job ever dispatched. countRagInFlight charges every unparked 'queued' row against MAX_CONCURRENT_RAG_INDEXING_PER_ORG (3), so three attachments saturate an organization's indexing budget permanently: every document a person uploads parks instead of indexing.

It fails invisibly. A parked row still reads "Queued", which is one of the statuses RagStatusBadge gives no retry affordance, and the watchdog skips parked rows by design. The watchdog does reclaim the phantom rows, but only after the 35-minute stale window, while a 5-minute mail poll refills them faster than they age out — so the cap never drops below its ceiling and promoteQueuedRagJobs never gets a slot to hand out.

Observed on a self-hosted deployment: nothing a person uploaded had indexed for a week, with no error surfaced anywhere.

Cause

One flag carrying two meanings, under a name that reads as the wrong one.

scheduleRag: false means "mark it queued, I will dispatch the job myself once the Hub document is linked" — so the job can read the document's folder and scope. Both OneDrive paths keep that promise via scheduleHubDocumentRagIndexing. The email path never made it: it wanted "don't index this" and reached for the only flag that looked like it said so.

Change

Split the flag in two so neither can be misread:

  • deferRagDispatch — queue without dispatching; the caller must follow through. Its doc now names the obligation and what breaks without it.
  • skipRagIndexing — never index; the row stays at ragStatus: undefined and costs no slot.

skipRagIndexing is not a new concept — the public saveFileMetadata already had this exact flag and folded it into shouldIndex the same way. The internal mutation now mirrors it instead of growing a second vocabulary for the same idea.

Email attachments are stored so the Inbox can show and download them, not to enter the corpus, so they skip indexing outright. A skipped file keeps undefined rather than the terminal unsupported: the format is indexable, it just isn't being indexed, so a later save of the same blob still queues it (needsRagRetry accepts an undefined status).

Also states the invariant in fileMetadata's schema comment as load-bearing rather than descriptive: never write 'queued' unless the job is dispatched, because the counter cannot tell the difference.

Tests

No test covered scheduleRag, which is how the two readings drifted. Adds:

  • the three indexing modes on saveFileMetadata, insert and patch paths, including that a skipped blob still indexes when saved again for indexing
  • an email-path regression test asserting it claims no indexing slot
  • the cost model the invariant rests on: an unparked 'queued' row is charged a slot on trust, so a writer that queues without dispatching is indistinguishable from live work

Each new assertion was mutation-tested — reverting the fix, dropping the shouldIndex fold, dispatching through a defer, and both counter directions each turn the relevant tests red.

Deploying

No data fix needed. Existing phantom rows are all past the stale window, so the watchdog fails them at 200 per 5-minute tick and each terminal transition promotes the parked uploads behind them.

Scope

Refs #2986, #2987. This is the cause underneath both, but neither is closed by it.

#2987 is framed as background ingestion sharing the interactive budget. It wasn't sharing it — it was consuming it without doing work. Rows at ragStatus: undefined cost nothing, so the duplicate blobs in #2985 were storage waste and nothing more; this flag is what converted them into starvation. A legitimately dispatched background job would still share the cap, so #2987's question stands on its own.

#2986 (a parked job has no recovery path and no signal) is untouched — parked rows are still excluded from the watchdog and still offer no way to invoke a retry.

#2985 (attachments never bound to their conversation) is untouched — the Inbox still shows no file and duplicates still accumulate, just no longer as cap starvation.

Storing an inbound email attachment left its `fileMetadata` row at
`ragStatus: 'queued'` with no indexing job ever dispatched. `countRagInFlight`
charges every unparked `'queued'` row against
`MAX_CONCURRENT_RAG_INDEXING_PER_ORG`, so three attachments saturated an
organization's indexing budget permanently: every document a person uploaded
parked instead of indexing, invisibly — a parked row reads "Queued", which
offers no retry affordance, and the watchdog skips parked rows by design. The
watchdog does reclaim the phantom rows, but only after 35 minutes, while a
5-minute mail poll refills them faster than they age out.

The cause was one flag carrying two meanings under a name that reads as the
wrong one. `scheduleRag: false` means "mark it queued, I will dispatch the job
myself once the Hub document is linked" — a promise both OneDrive paths keep and
the email path never made. Split it in two so neither can be misread:

- `deferRagDispatch` — queue without dispatching; the caller must follow
  through. Its doc names the obligation and what breaks without it.
- `skipRagIndexing` — never index; the row stays at `ragStatus: undefined` and
  costs no slot. Reuses the name and the `shouldIndex` shape the public
  `saveFileMetadata` already had for this, rather than adding a second concept.

Email attachments are stored so the Inbox can show and download them, not to
enter the corpus, so they now skip indexing outright. A skipped file keeps
`undefined` rather than the terminal `unsupported`, since the format is
indexable and a later save of the same blob should still index it.

No test covered the flag, which is how the two readings drifted. Adds the
mode-by-mode guard, an email-path regression test, and the cost model the
invariant rests on: an unparked queued row is charged a slot on trust, so a
writer that queues without dispatching is indistinguishable from live work.

Existing phantom rows need no data fix — they are all past the stale window, so
the watchdog fails them at 200 per tick and each terminal transition promotes
the parked uploads behind them.
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.

1 participant