Drop the retry around the queue's dedup race, fixed upstream

`_score_after_change` tried three times because `Jobs.enqueue` could re-raise an IntegrityError when the live job finished between its insert and its lookup. The queue now does both in one BEGIN IMMEDIATE transaction (boilerplate a1c6f0d), so the workaround and its test go.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-29 16:02:58 +02:00
1 parent 2e4624cbc4
commit 92466e2cd4
3 files changed
+11 -40

No files matched your search

+10 -22
View File
@@ -9,7 +9,6 @@ This is roledesk's own API, over the same store. Every refusal is
from __future__ import annotations
import sqlite3
from typing import Annotated, Any, Literal
from fastapi import APIRouter, HTTPException, Query, Response
@@ -405,27 +404,16 @@ def _score_after_change(queue: Any) -> Job | None:
the old state, so it gets one follow-up that waits for it (`depends_on`,
`after="done"`), deduped on `score:after:<id>`: ten requests during one
run are one extra pass. A pull's `score` stage is a plain `score` job
too, queued when its stage starts, so a request during a pull joins it.
The retry is for a race in `pipeline.table.Jobs.enqueue`: when the
INSERT collides with a live job that finishes before the SELECT after
it, the SELECT finds nothing and the `IntegrityError` is re-raised. That
job has finished by then, so a second try succeeds."""
for attempt in range(3):
try:
queued = queue.jobs.last("score", states=("queued",))
if queued is not None and (queued.dedup_key == "score"
or queued.dedup_key.startswith("score:after:")):
return queued
job = queue.enqueue("score")
if job is not None and job.state == "running":
job = queue.enqueue("score", depends_on=[job.id], after="done",
dedup_key=f"score:after:{job.id}")
return job
except sqlite3.IntegrityError:
if attempt == 2:
raise
return None
too, queued when its stage starts, so a request during a pull joins it."""
queued = queue.jobs.last("score", states=("queued",))
if queued is not None and (queued.dedup_key == "score"
or queued.dedup_key.startswith("score:after:")):
return queued
job: Job | None = queue.enqueue("score")
if job is not None and job.state == "running":
job = queue.enqueue("score", depends_on=[job.id], after="done",
dedup_key=f"score:after:{job.id}")
return job
@router.post("/score")