Repository navigation
fix(platform): stop email attachments starving the RAG indexing cap - #2995
Merged
Merged
Conversation
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.
This was referenced Aug 17, 2026
This was referenced Aug 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Storing an inbound email attachment left its
fileMetadatarow atragStatus: 'queued'with no indexing job ever dispatched.countRagInFlightcharges every unparked'queued'row againstMAX_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
RagStatusBadgegives 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 andpromoteQueuedRagJobsnever 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: falsemeans "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 viascheduleHubDocumentRagIndexing. 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 atragStatus: undefinedand costs no slot.skipRagIndexingis not a new concept — the publicsaveFileMetadataalready had this exact flag and folded it intoshouldIndexthe 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
undefinedrather than the terminalunsupported: the format is indexable, it just isn't being indexed, so a later save of the same blob still queues it (needsRagRetryaccepts anundefinedstatus).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:saveFileMetadata, insert and patch paths, including that a skipped blob still indexes when saved again for indexing'queued'row is charged a slot on trust, so a writer that queues without dispatching is indistinguishable from live workEach new assertion was mutation-tested — reverting the fix, dropping the
shouldIndexfold, 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: undefinedcost 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.