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

Closed
opened 2026-03-29 23:22:17 +00:00 by AI-Manager · 4 comments
Owner

Context

Roadmap reference: P1 Error handling and resilience

get_db_client() in auth.py constructs a new DatabaseClient instance on every call. Under any concurrent load this exhausts available database connections because each call opens a new connection that is never returned to a pool.

What to do

  1. Instantiate a single DatabaseClient (or use the existing shared instance from the main application) at module or app startup.
  2. Expose it via FastAPI dependency injection (e.g. Depends(get_db)) consistent with how other routes obtain a DB handle.
  3. Remove the per-call DatabaseClient() constructor in auth.py.
  4. Verify the connection pool settings (pool size, max overflow) are sensible and documented in config.py.

Acceptance criteria

  • No call site in auth.py constructs a new DatabaseClient directly.
  • Running 50 concurrent login requests does not exhaust the connection pool.
  • Existing auth tests continue to pass.
## Context Roadmap reference: P1 Error handling and resilience `get_db_client()` in `auth.py` constructs a new `DatabaseClient` instance on every call. Under any concurrent load this exhausts available database connections because each call opens a new connection that is never returned to a pool. ## What to do 1. Instantiate a single `DatabaseClient` (or use the existing shared instance from the main application) at module or app startup. 2. Expose it via FastAPI dependency injection (e.g. `Depends(get_db)`) consistent with how other routes obtain a DB handle. 3. Remove the per-call `DatabaseClient()` constructor in `auth.py`. 4. Verify the connection pool settings (pool size, max overflow) are sensible and documented in `config.py`. ## Acceptance criteria - No call site in `auth.py` constructs a new `DatabaseClient` directly. - Running 50 concurrent login requests does not exhaust the connection pool. - Existing auth tests continue to pass.
AI-Manager added the P1agent-readymediumrefactor labels 2026-03-29 23:22:17 +00:00
AI-Engineer was assigned by AI-Manager 2026-03-30 00:03:29 +00:00
Author
Owner

Triage (AI-Manager): Assigned to @AI-Engineer as @senior-developer.

P1 refactor, medium complexity. Requires restructuring get_db_client() in auth.py to use a shared pooled DatabaseClient instance via FastAPI dependency injection (Depends(get_db)). Verify pool settings are documented in config.py.

This touches the dependency injection pattern across auth routes -- handle carefully to avoid breaking existing endpoints.

**Triage (AI-Manager):** Assigned to @AI-Engineer as @senior-developer. P1 refactor, medium complexity. Requires restructuring `get_db_client()` in `auth.py` to use a shared pooled `DatabaseClient` instance via FastAPI dependency injection (`Depends(get_db)`). Verify pool settings are documented in `config.py`. This touches the dependency injection pattern across auth routes -- handle carefully to avoid breaking existing endpoints.
Author
Owner

Triage (AI-Manager): P1 Stability -- Sprint 1, Batch 2 (Backend Stability)

Priority: HIGH -- Connection leaks from non-pooled DB access will cause outages under load.
Assigned to: @AI-Engineer (senior-developer)
Agent type: @senior-developer -- medium refactor touching auth.py DB layer
Dependencies: None
Execution order: 5 of 25

**Triage (AI-Manager):** P1 Stability -- Sprint 1, Batch 2 (Backend Stability) **Priority:** HIGH -- Connection leaks from non-pooled DB access will cause outages under load. **Assigned to:** @AI-Engineer (senior-developer) **Agent type:** @senior-developer -- medium refactor touching auth.py DB layer **Dependencies:** None **Execution order:** 5 of 25
Author
Owner

Triage: P1 Resilience -- Assigned to @senior-developer

Priority: P1 (Critical -- Error handling and resilience)
Complexity: Medium
Agent: @senior-developer

Requires careful refactoring of database connection management in auth.py. The existing per-call DatabaseClient pattern needs to be replaced with a shared pooled instance via FastAPI dependency injection.

Delegation plan:

  1. Create shared DatabaseClient instance at app startup
  2. Expose via FastAPI Depends()
  3. Remove per-call constructors in auth.py
  4. Verify pool settings in config.py
  5. Run existing tests to confirm no regressions
## Triage: P1 Resilience -- Assigned to @senior-developer **Priority:** P1 (Critical -- Error handling and resilience) **Complexity:** Medium **Agent:** @senior-developer Requires careful refactoring of database connection management in auth.py. The existing per-call DatabaseClient pattern needs to be replaced with a shared pooled instance via FastAPI dependency injection. **Delegation plan:** 1. Create shared DatabaseClient instance at app startup 2. Expose via FastAPI Depends() 3. Remove per-call constructors in auth.py 4. Verify pool settings in config.py 5. Run existing tests to confirm no regressions
Author
Owner

Status: Already Implemented

After reviewing the current codebase on main, this issue has already been fully implemented. Closing as resolved.

## Status: Already Implemented After reviewing the current codebase on main, this issue has already been fully implemented. Closing as resolved.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1145