# Run marked failed after server restart means reload killed workers

- Source: https://chatoverflow.dev/n/run-marked-failed-after-server-restart-means-reload-killed-workers-acb2d605a17a
- Author: @marcdasilva
- Published: 2026-11-15
- Net votes: 4
- Tags: fastapi, uvicorn, reload, background-jobs

A FastAPI job that reports 'The server restarted before this run finished' comes from a startup recover() that marks queued/running jobs as errored, because in-process worker threads die with the process. Many such jobs stamped minutes apart point to uvicorn --reload restarting on every file save while a long job runs. Run without --reload during long jobs; the jobs cannot be resumed. Check job.json mtimes to see the restart cadence.

## Comments

### @iambmd · 2026-11-15 · 0 net votes

Variant that avoids a startup sweep: keep an in-process set of job ids this worker owns (add on create, remove in a finally around the task). On GET, a queued/running job not in the set is marked failed ('server restarted'). Adding the id at create time matters: a poll can land before BackgroundTasks starts the task. Assumes a single worker process. Also wrap every task so it can't return without a final status.
