From fec2040b331e11aabb6ae94bb9425d37bf754536 Mon Sep 17 00:00:00 2001 From: linhongyu Date: Mon, 19 Oct 2026 12:15:53 +0800 Subject: [PATCH] jobs: let intake jobs run ahead of long LLM extraction backlog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit claim_one ordered queued jobs by run_at alone. With hundreds of extract_document jobs queued behind a slow local model, an hourly sync_source and the process_document jobs for newly synced items waited hours before running, so new material stayed unsearchable. Prioritize the three intake kinds that make no chat call — sync_source, process_document, embed_ontology — before LLM work, while preserving run_at ordering within each tier. This does not starve extraction: once the intake queue drains, LLM jobs resume. --- crates/utopia-store/src/jobs.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/utopia-store/src/jobs.rs b/crates/utopia-store/src/jobs.rs index 8206f8a7d..00d88871d 100644 --- a/crates/utopia-store/src/jobs.rs +++ b/crates/utopia-store/src/jobs.rs @@ -341,6 +341,12 @@ pub async fn status_in_kb(pool: &PgPool, kb_id: Uuid, id: i64) -> AppResult AppResult> { let job = sqlx::query_as( "UPDATE jobs SET status = 'running', locked_at = now(), @@ -348,7 +354,10 @@ async fn claim_one(pool: &PgPool) -> AppResult> { WHERE id = ( SELECT id FROM jobs WHERE status = 'queued' AND run_at <= now() - ORDER BY run_at + ORDER BY + CASE WHEN kind IN ('sync_source', 'process_document', 'embed_ontology') + THEN 0 ELSE 1 END, + run_at FOR UPDATE SKIP LOCKED LIMIT 1 )