Skip to content

fix(platform): let an upload outrank a sync backlog when indexing - #3217

Merged
Israeltheminer merged 1 commit into
mainfrom
fix/interactive-rag-indexing-priority
Sep 4, 2026
Merged

Israeltheminer merged 1 commit into
mainfrom
fix/interactive-rag-indexing-priority

Conversation

@Israeltheminer

Copy link
Copy Markdown
Contributor

Closes #2987.

A background source that mints index jobs faster than they drain puts every
interactive upload behind it.

The mechanism changed; the starvation didn't

The issue was filed against 0.4, where a shared per-org cap of 3 was held
permanently by whatever produced rows fastest — an integration minting one row
every 5 minutes stalled all user uploads on a deployment for 7 days (#2985).

That cap died with Convex. But rag.index_file is still one queue for every
source
, and pg-boss fetches ORDER BY priority DESC, created_on, so a
backlog is simply ahead of the person. Same outcome, one less counter.

Neither is a bug in the source. The queue was undifferentiated, which is what
the issue actually said.

The fix the issue suggested

"Prefer interactive work at promotion time… source-aware priority would fit
there."

pg-boss takes a priority, and addJobInTx already threaded it — no
production caller had used it. The five doors where a person is waiting for
that file now pass PRIORITY_INTERACTIVE:

Interactive Background (unchanged)
upload (createDocumentFromUpload) OneDrive sync
hub create (createHubDocument) knowledge entries (crawler)
retry indexing (app) video links
retry indexing (REST door) WebDAV folder-move fixup
version replacement (bindReplacement) an agent writing a file
post-rebuild requeue

One level is enough. created_on stays the tiebreak, so interactive work is
still fair oldest-first among itself, and the backlog still drains whenever
nobody is waiting. No reserved slot, no second queue, no starved sources.

I confirmed the ordering from pg-boss's own plan — ORDER BY ${priority ? 'j.priority desc, ' : ''}${orderByCreatedOn ? 'j.created_on, ' : ''}j.id, with
priority = true its default — and that startWorker does not disable it.
Without that the field would have been inert.

Verification

The fix is one field per call site, which makes it exactly what a new call site
forgets, so the split is asserted from the source rather than from the five
files I happened to edit.

Mutation Went red
drop the priority from the upload door prioritizes every door a person waits at
give OneDrive sync the interactive priority leaves every background source unprioritized
set the level to 0 is a positive level, so it outranks an unset background job

The second direction matters as much as the first: a background enqueue that
claimed the priority would put a sync backlog level with an upload again, and
nothing else would notice.

Gate

typecheck 0 errors, oxlint --type-aware clean, oxfmt --check clean,
jobs + documents suites 49 passed (6 files).

A background source that mints index jobs faster than they drain puts every
interactive upload behind it. On 0.4 that happened by holding a shared
per-org cap of 3 — an integration minting one row every 5 minutes stalled
all user uploads on a deployment for 7 days (#2985). The cap is gone with
Convex, but `rag.index_file` is still ONE queue for every source, and
pg-boss fetches `priority DESC, created_on`, so the backlog is simply ahead.

Neither is a bug in the source. The queue was undifferentiated.

The five doors where a person is waiting for THAT file now enqueue at
`PRIORITY_INTERACTIVE` — upload, hub create, retry (app and REST), and a
version replacement. The seven background sources keep the default:
OneDrive sync, the crawler's knowledge entries, video links, WebDAV's
folder-move fixup, an agent writing a file, and the post-rebuild requeue.

One level is enough. `created_on` stays the tiebreak, so interactive work
is still fair among itself, and the backlog still drains whenever nobody is
waiting — no reserved slot, no second queue, no starved sources.

## Tests

The fix is one field per call site, which makes it exactly what a new call
site forgets, so the split is asserted from the source.

| Mutation | Went red |
| --- | --- |
| drop the priority from the upload door | `prioritizes every door a person waits at` |
| give OneDrive sync the interactive priority | `leaves every background source unprioritized` |
| set the level to 0 | `is a positive level, so it outranks an unset background job` |

The second direction matters as much as the first: a background enqueue that
claimed the priority would put a sync backlog level with an upload again.

Refs #2987.
@Israeltheminer
Israeltheminer merged commit 5deea36 into main Sep 4, 2026
48 checks passed
@Israeltheminer
Israeltheminer deleted the fix/interactive-rag-indexing-priority branch September 4, 2026 14:54
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.

Bug: background ingestion shares the interactive RAG indexing budget and can starve it

1 participant