From 51899c53ae91e2d9e61291d73cbad6afb8616628 Mon Sep 17 00:00:00 2001 From: Tirth Panchori Date: Fri, 31 Jul 2026 12:03:58 +0530 Subject: [PATCH 1/3] fix: migrate startup event to lifespan context manager - Fixes #306 --- backend/app/main.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/app/main.py b/backend/app/main.py index e976c02..b588905 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -14,6 +14,7 @@ from datetime import datetime, timezone from pathlib import Path from typing import List +from contextlib import asynccontextmanager import aiosqlite import httpx @@ -94,7 +95,13 @@ MAX_UPLOAD_SIZE = MAX_UPLOAD_MB * 1024 * 1024 logger = logging.getLogger(__name__) -app = FastAPI(title="PatchPilot API", version="0.1.0") +@asynccontextmanager +async def lifespan(app: FastAPI): + await init_db() + # Start background cleanup for finished ACTIVE_SCANS entries + asyncio.create_task(_cleanup_active_scans_loop()) + yield +app = FastAPI(title="PatchPilot API", version="0.1.0", lifespan=lifespan) ALLOWED_ORIGINS = [ "http://localhost:5173", @@ -128,13 +135,6 @@ ensure_dir(WORK_ROOT) -@app.on_event("startup") -async def startup(): - await init_db() - # Start background cleanup for finished ACTIVE_SCANS entries - asyncio.create_task(_cleanup_active_scans_loop()) - - @app.get("/health") def health(): scanners = { From 7b29bea0fdaa7b3b4011a5d27a4101c8b93c06fd Mon Sep 17 00:00:00 2001 From: Tirth Panchori Date: Fri, 31 Jul 2026 12:32:58 +0530 Subject: [PATCH 2/3] fix: correct import order per ruff (I001) --- backend/app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app/main.py b/backend/app/main.py index b588905..6947576 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -11,10 +11,10 @@ import tempfile import threading import uuid +from contextlib import asynccontextmanager from datetime import datetime, timezone from pathlib import Path from typing import List -from contextlib import asynccontextmanager import aiosqlite import httpx From faf96ec2ee7c5e5af5b6e333cca8c91acd8d1dd7 Mon Sep 17 00:00:00 2001 From: Tirth Panchori Date: Fri, 31 Jul 2026 12:40:56 +0530 Subject: [PATCH 3/3] fix: apply ruff formatting to lifespan block --- backend/app/main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/backend/app/main.py b/backend/app/main.py index 6947576..36fce86 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -95,12 +95,16 @@ MAX_UPLOAD_SIZE = MAX_UPLOAD_MB * 1024 * 1024 logger = logging.getLogger(__name__) + + @asynccontextmanager async def lifespan(app: FastAPI): await init_db() # Start background cleanup for finished ACTIVE_SCANS entries asyncio.create_task(_cleanup_active_scans_loop()) yield + + app = FastAPI(title="PatchPilot API", version="0.1.0", lifespan=lifespan) ALLOWED_ORIGINS = [