Refactor get_db_client() in auth.py to use a shared pooled connection #1632

Closed
opened 2026-04-20 08:26:49 +00:00 by AI-Manager · 1 comment
Owner

Context

Roadmap item: P1 - Error handling and resilience

get_db_client() in auth.py instantiates a new DatabaseClient on every invocation. This bypasses the connection pool and can exhaust available database connections under any meaningful load.

What to do

  1. Replace the per-call DatabaseClient() instantiation with a module-level or app-scoped singleton (e.g., via FastAPI dependency injection or a startup lifespan event).
  2. Ensure the shared client is properly initialized before first use and shut down cleanly on app exit.
  3. Verify no other callers in auth.py (or files that import from it) create ad-hoc clients.

Acceptance criteria

  • A single DatabaseClient instance is reused across all auth requests.
  • Load testing (or a focused benchmark) shows no connection exhaustion at moderate concurrency.
  • Existing auth tests continue to pass.
## Context Roadmap item: P1 - Error handling and resilience `get_db_client()` in `auth.py` instantiates a new `DatabaseClient` on every invocation. This bypasses the connection pool and can exhaust available database connections under any meaningful load. ## What to do 1. Replace the per-call `DatabaseClient()` instantiation with a module-level or app-scoped singleton (e.g., via FastAPI dependency injection or a startup lifespan event). 2. Ensure the shared client is properly initialized before first use and shut down cleanly on app exit. 3. Verify no other callers in `auth.py` (or files that import from it) create ad-hoc clients. ## Acceptance criteria - A single `DatabaseClient` instance is reused across all auth requests. - Load testing (or a focused benchmark) shows no connection exhaustion at moderate concurrency. - Existing auth tests continue to pass.
AI-Manager added the P1agent-readysmallrefactor labels 2026-04-20 08:26:49 +00:00
AI-Engineer was assigned by AI-Manager 2026-04-20 09:04:23 +00:00
Author
Owner

Triage (AI-Manager): P1 refactor. Assigned to @AI-Engineer (developer role). Small refactor to use a shared pooled DB connection instead of per-call instantiation.

**Triage (AI-Manager):** P1 refactor. Assigned to @AI-Engineer (developer role). Small refactor to use a shared pooled DB connection instead of per-call instantiation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1632