fix: SQLite database locked errors + add error status for 4xx/5xx

SQLite locking:
- Enable WAL journal mode in init_db (readers don't block writers)
- Set busy_timeout=30000ms in init_db
- Add timeout=30 to every aiosqlite.connect() across db.py, validator.py,
  enricher.py, main.py so connections wait up to 30s instead of crashing

Error status:
- 4xx/5xx HTTP responses are now prescreen_status='error' (server alive
  but broken/blocking) instead of 'live'
- Added 'error' counter to validator stats and orange Error stat box in UI
- Added ps-error CSS class (orange) and filter option in Browse tab

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-21 07:10:45 +02:00
parent 989717e479
commit db95876db2
5 changed files with 33 additions and 23 deletions

View File

@@ -132,7 +132,7 @@ async def enrich_status():
@app.post("/api/enrich/retry")
async def enrich_retry():
async with aiosqlite.connect(SQLITE_PATH) as db:
async with aiosqlite.connect(SQLITE_PATH, timeout=30) as db:
await db.execute("UPDATE job_queue SET status='pending', error=NULL WHERE status='failed'")
await db.commit()
resume_worker()
@@ -267,7 +267,7 @@ async def ai_worker_restart():
@app.post("/api/ai/reset")
async def ai_reset():
"""Reset all 'running' AI queue jobs back to 'pending' (unstick hung jobs)."""
async with aiosqlite.connect(SQLITE_PATH) as db:
async with aiosqlite.connect(SQLITE_PATH, timeout=30) as db:
r = await db.execute("UPDATE ai_queue SET status='pending' WHERE status='running'")
count = r.rowcount
await db.commit()
@@ -287,7 +287,7 @@ async def ai_debug():
except Exception:
pass
async with aiosqlite.connect(SQLITE_PATH) as db:
async with aiosqlite.connect(SQLITE_PATH, timeout=30) as db:
db.row_factory = aiosqlite.Row
async with db.execute(
"SELECT domain, status, created_at, completed_at, error FROM ai_queue ORDER BY created_at DESC LIMIT 10"