chore(backend): Ruff lint pass — deprecated APIs, exception leaks, dead patterns

Mechanical sweep of items called out in the PR review:

- qwen_llm_backend: AutoModelForCausalLM.from_pretrained(torch_dtype=…) is deprecated in transformers ≥4.41 in favor of dtype=. Renamed.
- routes/llm: try/except around backend.generate() raised HTTPException(500, detail=str(e)) which leaks stack traces / paths to clients and trips Ruff B904. Now logs the original exception server-side and hands the client a generic message; chained via `from e` to preserve traceback context.
- mcp_bindings + mcp_server/context: datetime.utcnow() is deprecated since 3.12. Switched the two assignment sites to datetime.now(timezone.utc). The schema-level `default=datetime.utcnow` defaults in database/models.py are left for a later schema-aware pass.
- routes/generations: `logger = …` sat between two import blocks (Ruff E402). Moved below imports.
- mcp_server/server + tests/test_refinement_samples: typing.Callable / typing.Iterable have been preferred-via collections.abc since 3.9 (Ruff UP035).
- routes/events: `except asyncio.TimeoutError` aliases plain `TimeoutError` since 3.11 (UP041).
- services/captures: hoisted WHISPER_NATIVE_FORMATS to module scope (was a function-local UPPER_SNAKE that tripped N806) and replaced the raw_path.unlink try/except OSError-pass with contextlib.suppress (SIM105). Semantic equivalence preserved — written_files.remove(raw_path) still only runs when unlink succeeds because it sits inside the suppressed block after the unlink call.
- database/migrations: hoisted the duplicate `import sqlite3` from inside two helper bodies to a single module-level import.
This commit is contained in:
Jamie Pine
2026-04-25 01:40:34 -07:00
parent 6cf8da2698
commit fe14df5fda
10 changed files with 27 additions and 22 deletions
+8 -1
View File
@@ -1,5 +1,7 @@
"""LLM inference endpoints."""
import logging
from fastapi import APIRouter, HTTPException
from fastapi.responses import JSONResponse
@@ -9,6 +11,8 @@ from ..services import llm
from ..services.task_queue import create_background_task
from ..utils.tasks import get_task_manager
logger = logging.getLogger(__name__)
router = APIRouter()
@@ -70,4 +74,7 @@ async def llm_generate(request: models.LLMGenerateRequest):
)
return models.LLMGenerateResponse(text=text, model_size=model_size)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
# The backend exception text can include filesystem paths and stack
# frames — log it server-side and hand the client a generic message.
logger.exception("LLM generate failed")
raise HTTPException(status_code=500, detail="LLM generation failed") from e