Repository navigation
jobs: let intake jobs run ahead of long LLM extraction backlog - #1316
linhongyu510 wants to merge 1 commit into
Conversation
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.
WaylandYang
left a comment
There was a problem hiding this comment.
Thank you, @linhongyu510, for jumping in on #1300 and for the clear write-up. The diagnosis is right, and it's great to have a first contribution from you. A few things before this can land:
- Base and DCO. Please retarget the PR to
dev(it currently targetsmainand is based on a commit from 10-11), and sign off the commit (git commit --amend -s, then force-push). We can't merge without the DCO line. - The claim has to stay index-backed. Today
claim_onewalksjobs_claim_idx (run_at)and stops at the first unlocked row. Nothing indexesORDER BY CASE kind …, run_at, so every claim would read and sort the whole due backlog to take one row; during a full-text rebuild that's tens of thousands of rows per claim, on every worker, exactly when the queue is longest. The fix needs no call-site changes: a migration (0115is the next free number) addingpriority smallint GENERATED ALWAYS AS (CASE WHEN kind IN (…) THEN 0 ELSE 1 END) STORED, an index on(priority, run_at) WHERE status = 'queued', and ordering the claim bypriority, run_at. - A test. One DB-backed test (with the
utopia_store::test_db::url()guard) showing a latersync_sourceis claimed before an earlierextract_document. CI runs it against Postgres. - Please change "Fixes #1300" to "Part of #1300". Extraction jobs keep their worker slots while waiting for the model permit, so ordering alone doesn't get a sync through when every worker is parked; #1300 still needs the reserved lane.
One coordination note: @QuintinBotes said on #1300 yesterday that they're picking this up as a priority PR followed by a lane PR. Could you two agree there on who does which part, so nobody's work is wasted? Either way, thank you, and we're happy to review the next round.
|
Thank you, @linhongyu510, for jumping on this so quickly; your ordering in |
What
Fixes #1300.
claim_oneordered queued jobs byrun_atalone. Every job kind shares that one queue. With hundreds ofextract_documentjobs backed up behind a slow local chat model, an hourlysync_sourceand theprocess_documentjobs for newly synced items waited until the entire LLM backlog drained — on a local model that meant 10+ hours. New documents stayedpendingand unsearchable the whole time.Fix
Adds a two-tier ordering in
claim_one: the three intake kinds that make no chat call (sync_source,process_document,embed_ontology) are claimed before LLM work. Within each tier,run_atstill decides — so intake jobs are FIFO among themselves, and extraction jobs are FIFO among themselves.This is the first of the three approaches listed in #1300, without a schema migration:
Why not a priority column
A
prioritycolumn would be more explicit, but requires a migration and changes to every enqueue call site. The CASE is a one-line change that solves the reported starvation immediately. If you prefer the column approach, I'm happy to do that instead.What this does NOT do
build_vector_index,materialize_inferences, or other maintenance jobs — those don't block searchability of new material.run_atorder.Verification
cargo check -p utopia-storepasses.jobs.rs(retry_delay, deferred_retry_secs) are unchanged.FOR UPDATE SKIP LOCKEDpattern.