- PROXY_DRAIN_SECONDS (20): after the jobs are drained, keep the socket
open with /health/ready at 503 so Traefik pulls the instance out of
rotation while it can still answer. Coolify builds the container's
HEALTHCHECK from its own interval*retries, so closing earlier was up to
60 s of alternating 502/200 per deploy (retries lowered to 3 as well).
- HARD_EXIT_SECONDS (30): uvicorn finishing does not end the interpreter
while an executor thread hangs in a network probe (a /api/process cut
off mid-shutdown left yt-dlp running), which kept a drained container
alive for the full 900 s grace and the deploy in "Removing old
containers". Exit outright a little after handing uvicorn the signal.
- uvicorn --timeout-graceful-shutdown 15: after the drain, stop waiting
forever on open range downloads. The old container lived the full 900 s
stop grace with its port already closed, so Traefik alternated 502/200
for 15 minutes on 2026-08-25.
- /health/ready answers 503 once SIGTERM arrives, and a Dockerfile
HEALTHCHECK on it lets Traefik drop the instance within ~10 s while it
can still serve. Coolify's health check now waits on the same path
before stopping the old container. The marker drain does not flip it:
the new container is still booting at that point.
- ignore .worktrees
Coolify starts the new container before stopping the old one and both share
output/, so the new one used to re-enqueue at startup the very jobs the old
one was still rendering, and the old one had 30 s to live regardless.
- Each instance stamps output/.instance; an instance that sees another id
drains: finishes what it runs, starts nothing, leaves queued manifests.
- A running job heartbeats its manifest every 10 s; the resume scan (startup
and every 30 s) adopts only manifests nobody heartbeated for 60 s, so no
job runs twice and none is lost. Reservations of live-elsewhere jobs are
kept out of the orphan refund; poison jobs stay refundable.
- SIGTERM drains too (up to DRAIN_TIMEOUT_SECONDS, default 840) before the
signal reaches uvicorn, so the socket stays open and Traefik keeps getting
answers. The app's Coolify stop grace period is now 900 s.
- /api/status answers from disk for a job this instance never held, so a
poll landing on either container during the handover works.
Verified in the local stack: SIGTERM mid-job -> job finished its clips,
'Drained', exit 0; status polled 200 throughout an 8 min drain; a job
submitted during the drain was left for, and resumed by, the next instance.