Skip to content

Conversation

@smoreinis
Copy link
Collaborator

Summary

Two quick performance/reliability fixes:

Issue #7: Inefficient single-result queries

  • Replaced .scalars().all()[0] with .scalars().first() in 4 methods in agent_api_key_repository.py
  • Before: Fetches ALL matching rows into memory, then accesses [0]
  • After: .first() stops after fetching one row

Methods fixed:

  • get_internal_api_key_by_agent_id
  • get_by_agent_id_and_name
  • get_by_agent_name_and_key_name
  • get_external_by_agent_id_and_key

Issue #8: HTTP client not closed on shutdown

  • Added HttpxGateway.close_clients() call to FastAPI lifespan shutdown
  • Ensures proper cleanup of TCP connections during graceful restarts
  • Removed TODO comment since it's now implemented

Test plan

  • Unit tests pass (184/184)
  • Lint passes

- Replace .scalars().all()[0] with .scalars().first() in 4 methods
  in agent_api_key_repository.py for more efficient single-result queries
- Add HttpxGateway.close_clients() call to FastAPI lifespan shutdown
  for proper HTTP client cleanup on application shutdown
- Remove TODO comment from close_clients() since it's now implemented
@smoreinis smoreinis requested a review from a team as a code owner December 24, 2025 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants