fix(ml): per-task async engine for recompute_centroid (#881) #114
Reference in New Issue
Block a user
Delete Branch "dev"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes the flood of
recompute_centroidfailures in the activity view:RuntimeError: ... got Future ... attached to a different loop.Root cause
recompute_centroid+recompute_centroidswere the only tasks still using the process-wide singletonextensions.get_session()underasyncio.run(). The async engine's asyncpg pool is bound to the loop it was created on; each Celery task runs a fresh loop, so after the first invocation the cached engine handed old-loop connections to the new loop → fails on the first DB await (~35ms).Fix
Convert both to the established per-task
async_session_factory()pattern (NullPool engine created + disposed inside the task's own loop), matching scan/download/admin tasks. Noget_sessionusages remain intasks/.CI green on dev (run 1179,
51201b4). Deploy note: this runs on themlqueue → re-pull the ml-worker image.🤖 Generated with Claude Code