FastAPI runs a sync dependency's setup, the endpoint and the teardown on whichever threadpool worker is free, so a connection opened on one thread was used/closed on another and sqlite3 raised ProgrammingError — 500s on /api/power, /api/energy/daily and /api/summary under concurrent requests (the dashboard fires three at once). Each request still gets its own connection, used by one thread at a time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>